pub struct Universe {
pub time: f64,
pub time_step: f64,
pub g: f64,
/* private fields */
}Expand description
Struct that represents the simulation of the universe.
Fields§
§time: f64The time elapsed in the universe, in seconds.
time_step: f64The time step of the simulation, in seconds.
g: f64The gravitational constant, in m^3 kg^-1 s^-2.
Implementations§
Source§impl Universe
impl Universe
Sourcepub fn add_body(
&mut self,
body: Body,
parent_id: Option<u64>,
) -> Result<u64, BodyAddError>
pub fn add_body( &mut self, body: Body, parent_id: Option<u64>, ) -> Result<u64, BodyAddError>
Adds a body to the universe.
body: The body to add into the universe.
parent_id: The index of the body that this body is orbiting.
Returns: The index of the newly-added body.
Sourcepub fn remove_body(&mut self, body_index: u64) -> Vec<Body>
pub fn remove_body(&mut self, body_index: u64) -> Vec<Body>
Removes a body from the universe.
body_index: The index of the body to remove.
Returns: A Vec of all bodies that were removed, including the one specified.
An empty Vec is returned if the body was not found.
Sourcepub fn get_bodies(&self) -> &HashMap<u64, BodyWrapper>
pub fn get_bodies(&self) -> &HashMap<u64, BodyWrapper>
Gets a reference to a HashMap of all bodies in the universe and their relations.
Sourcepub fn get_body_mut(&mut self, index: u64) -> Option<&mut Body>
pub fn get_body_mut(&mut self, index: u64) -> Option<&mut Body>
Gets a mutable reference to a body in the universe.
Sourcepub fn get_body(&self, index: u64) -> Option<&Body>
pub fn get_body(&self, index: u64) -> Option<&Body>
Gets an immutable reference to a body in the universe.
Sourcepub fn get_body_index_with_name(&self, name: &str) -> Option<u64>
pub fn get_body_index_with_name(&self, name: &str) -> Option<u64>
Gets the first index of a body with a given name, if any.
Sourcepub fn get_body_position(&self, index: u64) -> Option<DVec3>
pub fn get_body_position(&self, index: u64) -> Option<DVec3>
Gets the absolute position of a body in the universe.
Each coordinate is in meters.
index: The index of the body to get the position of.
Returns: The absolute position of the body.
The top ancestor of the body (i.e, the body with no parent) is at the origin (0, 0, 0).