-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add physics system to GraphicsApplication
- Loading branch information
1 parent
eee9701
commit 8fdcc89
Showing
5 changed files
with
95 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use maths_rs::Vec3f; | ||
|
||
use crate::orchestrator::{Entity, System, EntityReturn}; | ||
|
||
pub struct Sphere { | ||
position: Vec3f, | ||
velocity: Vec3f, | ||
radius: f32, | ||
} | ||
|
||
impl Sphere { | ||
pub fn new(position: Vec3f, velocity: Vec3f, radius: f32) -> Self { | ||
Self { | ||
position, | ||
velocity, | ||
radius, | ||
} | ||
} | ||
} | ||
|
||
pub struct PhysicsWorld { | ||
spheres: Vec<Sphere>, | ||
} | ||
|
||
impl PhysicsWorld { | ||
fn new() -> Self { | ||
Self { | ||
spheres: Vec::new(), | ||
} | ||
} | ||
|
||
pub fn new_as_system() -> EntityReturn<'static, Self> { | ||
EntityReturn::new(Self::new()) | ||
} | ||
|
||
pub fn add_sphere(&mut self, sphere: Sphere) { | ||
self.spheres.push(sphere); | ||
} | ||
|
||
pub fn update(&mut self) { | ||
for sphere in self.spheres.iter_mut() { | ||
sphere.position += sphere.velocity; | ||
|
||
log::info!("Sphere position: {:?}", sphere.position); | ||
} | ||
} | ||
} | ||
|
||
impl Entity for PhysicsWorld {} | ||
impl System for PhysicsWorld {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters