-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2217499
commit 2b145e4
Showing
14 changed files
with
1,988 additions
and
1,193 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Binary file not shown.
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 was deleted.
Oops, something went wrong.
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,79 @@ | ||
use asteroids::{custom::ElementTrait, ValidState}; | ||
use glam::{vec3, Quat, Vec3}; | ||
use stardust_xr_fusion::{ | ||
core::schemas::zbus::Connection, | ||
node::{NodeError, NodeResult, NodeType}, | ||
objects::hmd, | ||
spatial::{Spatial, SpatialAspect, SpatialRef, SpatialRefAspect, Transform}, | ||
}; | ||
use std::f32::consts::PI; | ||
|
||
fn look_direction(direction: Vec3) -> Quat { | ||
let pitch = direction.y.asin(); | ||
let yaw = direction.z.atan2(direction.x); | ||
Quat::from_rotation_y(-yaw - PI / 2.0) * Quat::from_rotation_x(pitch) | ||
} | ||
|
||
async fn initial_placement(spatial_root: Spatial) -> NodeResult<()> { | ||
let client = spatial_root.client()?; | ||
let Some(hmd) = hmd(&client).await else { | ||
return Err(NodeError::NotAliased); | ||
}; | ||
let root = client.get_root(); | ||
|
||
let ( | ||
Ok(Transform { | ||
translation: item_translation, | ||
.. | ||
}), | ||
Ok(Transform { | ||
translation: hmd_translation, | ||
.. | ||
}), | ||
) = tokio::join!(spatial_root.get_transform(root), hmd.get_transform(root)) | ||
else { | ||
return Err(NodeError::NotAliased); | ||
}; | ||
|
||
// if the distance between the panel item and the client origin is basically nothing, it must be unpositioned | ||
if Vec3::from(item_translation.unwrap()).length_squared() < 0.001 { | ||
println!("launched without a sense of space"); | ||
// so we want to position it in front of the user | ||
let _ = spatial_root.set_relative_transform( | ||
&hmd, | ||
Transform::from_translation_rotation(vec3(0.0, 0.0, -0.25), Quat::IDENTITY), | ||
); | ||
return Ok(()); | ||
} | ||
|
||
// otherwise make the panel look at the user | ||
let look_rotation = look_direction( | ||
(Vec3::from(item_translation.unwrap()) - Vec3::from(hmd_translation.unwrap())).normalize(), | ||
); | ||
let _ = spatial_root.set_relative_transform(root, Transform::from_rotation(look_rotation)); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[derive(Debug, PartialEq, Clone, Copy)] | ||
pub struct InitialPanelPlacement; | ||
impl<State: ValidState> ElementTrait<State> for InitialPanelPlacement { | ||
type Inner = Spatial; | ||
type Error = NodeError; | ||
|
||
fn create_inner( | ||
&self, | ||
parent_space: &SpatialRef, | ||
_dbus_conn: &Connection, | ||
) -> Result<Self::Inner, Self::Error> { | ||
let spatial = Spatial::create(parent_space, Transform::identity(), false)?; | ||
tokio::task::spawn(initial_placement(spatial.clone())); | ||
Ok(spatial) | ||
} | ||
|
||
fn update(&self, _old_decl: &Self, _state: &mut State, _inner: &mut Self::Inner) {} | ||
|
||
fn spatial_aspect(&self, inner: &Self::Inner) -> SpatialRef { | ||
inner.clone().as_spatial_ref() | ||
} | ||
} |
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,29 @@ | ||
use asteroids::{custom::ElementTrait, ValidState}; | ||
use stardust_xr_fusion::{ | ||
core::schemas::zbus::Connection, | ||
node::NodeError, | ||
spatial::{Spatial, SpatialAspect, SpatialRef, Transform}, | ||
}; | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub struct InitialPositioner(pub SpatialRef); | ||
impl<State: ValidState> ElementTrait<State> for InitialPositioner { | ||
type Inner = Spatial; | ||
type Error = NodeError; | ||
|
||
fn create_inner( | ||
&self, | ||
parent_space: &SpatialRef, | ||
_dbus_conn: &Connection, | ||
) -> Result<Self::Inner, Self::Error> { | ||
let spatial = Spatial::create(parent_space, Transform::identity(), false)?; | ||
spatial.set_relative_transform(&self.0, Transform::identity())?; | ||
Ok(spatial) | ||
} | ||
|
||
fn update(&self, _old_decl: &Self, _state: &mut State, _inner: &mut Self::Inner) {} | ||
|
||
fn spatial_aspect(&self, inner: &Self::Inner) -> SpatialRef { | ||
inner.clone().as_spatial_ref() | ||
} | ||
} |
Oops, something went wrong.