Skip to content

Commit

Permalink
Some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Dec 12, 2023
1 parent 2d3cbe8 commit 78fc2d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/geopos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl GeoPos {
DVec3::new(-cart.x(), -cart.y(), cart.z())
}

/// Compute the galactic position on the planet's surface.
pub fn to_cartesian(self, space: &FloatingOriginSettings) -> Position<'_> {
let pos = self.to_cartesian_vec();
let (cell, pos) = space.translation_to_grid(pos);
Expand Down
8 changes: 8 additions & 0 deletions src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use big_space::FloatingOriginSettings;
use glam::DVec3;

#[derive(SystemParam)]
/// A helper argument for bevy systems that obtains the main player's position.
pub struct Player<'w, 's> {
pub(crate) xr_pos: Query<
'w,
Expand All @@ -26,6 +27,7 @@ pub struct Player<'w, 's> {
pub(crate) space: Res<'w, FloatingOriginSettings>,
}

/// A helper for working with galactic positions.
pub struct Position<'a> {
pub pos: GalacticTransformOwned,
pub space: &'a FloatingOriginSettings,
Expand All @@ -40,9 +42,13 @@ impl<'a> std::ops::Deref for Position<'a> {
}

impl Position<'_> {
/// Compute the cartesian coordinates by combining the grid cell and the position from within
/// the grid.
pub fn pos(&self) -> DVec3 {
self.pos.position_double(self.space)
}

/// Calculates cardinal directions at any cartesian position.
pub fn directions(&self) -> Directions {
let up = self.pos().normalize().as_vec3();
let west = Vec3::Z.cross(up);
Expand All @@ -51,13 +57,15 @@ impl Position<'_> {
}
}

/// A coordinate system where "forward" is north, "right" is west and "up" is away from the planet.
pub struct Directions {
pub up: Vec3,
pub north: Vec3,
pub west: Vec3,
}

impl<'w, 's> Player<'w, 's> {
/// Computes the galactic position of the main player (prefers XR player).
pub fn pos(&self) -> Position<'_> {
let pos = if let Ok(xr_pos) = self.xr_pos.get_single() {
xr_pos
Expand Down

0 comments on commit 78fc2d6

Please sign in to comment.