Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up #35

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/graphics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::resources::{

use openxr as xr;

#[allow(clippy::type_complexity)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could add this to cargo.toml (latest Rust version has a section for it):

[lints.clippy]
type_complexity = "allow"
too_many_arguments = "allow"

pub fn initialize_xr_graphics(
window: Option<RawHandleWrapper>,
) -> anyhow::Result<(
Expand Down
3 changes: 2 additions & 1 deletion src/graphics/vulkan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::resources::{
};
use crate::VIEW_TYPE;

#[allow(clippy::type_complexity)]
pub fn initialize_xr_graphics(
window: Option<RawHandleWrapper>,
) -> anyhow::Result<(
Expand Down Expand Up @@ -352,7 +353,7 @@ pub fn initialize_xr_graphics(
None,
)
};

unsafe {
wgpu_device.create_texture_from_hal::<V>(
wgpu_hal_texture,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub const RIGHT_XR_TEXTURE_HANDLE: ManualTextureViewHandle = ManualTextureViewHa
/// Adds OpenXR support to an App
#[derive(Default)]
pub struct OpenXrPlugin;

#[allow(clippy::type_complexity)]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be simplified, but lacked the expertise to be sure

#[derive(Resource)]
pub struct FutureXrResources(
pub Arc<
Expand Down
1 change: 1 addition & 0 deletions src/xr_input/debug_gizmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ impl Plugin for OpenXrDebugRenderer {
}
}

#[allow(clippy::type_complexity, clippy::too_many_arguments)]
pub fn draw_gizmos(
mut gizmos: Gizmos,
oculus_controller: Res<OculusController>,
Expand Down
3 changes: 2 additions & 1 deletion src/xr_input/hand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ impl HandState {
}



#[allow(clippy::type_complexity)]
pub fn update_hand_bones_emulated(
controller_transform: Transform,
hand: Hand,
Expand Down Expand Up @@ -1035,6 +1035,7 @@ fn log_hand(hand_pose: [Posef; 26]) {
);
}

#[allow(clippy::too_many_arguments, clippy::type_complexity)]
pub fn update_hand_skeletons(
tracking_root_query: Query<(&Transform, With<OpenXRTrackingRoot>)>,
right_controller_query: Query<(&GlobalTransform, With<OpenXRRightController>)>,
Expand Down
219 changes: 102 additions & 117 deletions src/xr_input/interactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,28 @@ pub struct XRSocketInteractor;
#[derive(Component)]
pub struct Touched(pub bool);

#[derive(Component, Clone, Copy, PartialEq, PartialOrd, Debug)]
#[derive(Default)]
#[derive(Component, Clone, Copy, PartialEq, PartialOrd, Debug, Default)]
pub enum XRInteractableState {
#[default]
Idle,
Hover,
Select,
}



#[derive(Component)]
#[derive(Default)]
#[derive(Component, Default)]
pub enum XRInteractorState {
#[default]
Idle,
Selecting,
}

#[derive(Component)]
#[derive(Default)]
#[derive(Component, Default)]
pub enum XRSelection {
#[default]
Empty,
Full(Entity),
}


#[derive(Component)]
pub struct XRInteractable;

Expand All @@ -71,6 +65,7 @@ pub fn draw_socket_gizmos(
}
}

#[allow(clippy::type_complexity)]
pub fn draw_interaction_gizmos(
mut gizmos: Gizmos,
interactable_query: Query<
Expand Down Expand Up @@ -103,27 +98,24 @@ pub fn draw_interaction_gizmos(
for (interactor_global_transform, interactor_state, direct, ray, aim) in interactor_query.iter()
{
let transform = interactor_global_transform.compute_transform();
match direct {
Some(_) => {
let mut local = transform;
local.scale = Vec3::splat(0.1);
let quat = Quat::from_euler(
bevy::prelude::EulerRot::XYZ,
45.0 * (PI / 180.0),
0.0,
45.0 * (PI / 180.0),
);
local.rotation = quat;
let color = match interactor_state {
XRInteractorState::Idle => Color::BLUE,
XRInteractorState::Selecting => Color::PURPLE,
};
gizmos.cuboid(local, color);
}
None => (),
if direct.is_some() {
let mut local = transform;
local.scale = Vec3::splat(0.1);
let quat = Quat::from_euler(
bevy::prelude::EulerRot::XYZ,
45.0 * (PI / 180.0),
0.0,
45.0 * (PI / 180.0),
);
local.rotation = quat;
let color = match interactor_state {
XRInteractorState::Idle => Color::BLUE,
XRInteractorState::Selecting => Color::PURPLE,
};
gizmos.cuboid(local, color);
}
match ray {
Some(_) => match aim {
if ray.is_some() {
match aim {
Some(aim) => {
let color = match interactor_state {
XRInteractorState::Idle => Color::BLUE,
Expand All @@ -136,8 +128,7 @@ pub fn draw_interaction_gizmos(
);
}
None => todo!(),
},
None => (),
}
}
}
}
Expand All @@ -149,6 +140,7 @@ pub struct InteractionEvent {
pub interactable_state: XRInteractableState,
}

#[allow(clippy::type_complexity)]
pub fn socket_interactions(
interactable_query: Query<
(&GlobalTransform, &mut XRInteractableState, Entity),
Expand Down Expand Up @@ -206,7 +198,7 @@ pub fn socket_interactions(
}
}
}

#[allow(clippy::type_complexity)]
pub fn interactions(
interactable_query: Query<
(&GlobalTransform, Entity),
Expand All @@ -230,88 +222,82 @@ pub fn interactions(
for (interactor_global_transform, interactor_state, interactor_entity, direct, ray, aim) in
interactor_query.iter()
{
match direct {
Some(_) => {
//check for sphere overlaps
let size = 0.1;
if interactor_global_transform
.compute_transform()
.translation
.distance_squared(
xr_interactable_global_transform
.compute_transform()
.translation,
)
< (size * size) * 2.0
{
//check for selections first
match interactor_state {
XRInteractorState::Idle => {
let event = InteractionEvent {
interactor: interactor_entity,
interactable: interactable_entity,
interactable_state: XRInteractableState::Hover,
};
writer.send(event);
}
XRInteractorState::Selecting => {
let event = InteractionEvent {
interactor: interactor_entity,
interactable: interactable_entity,
interactable_state: XRInteractableState::Select,
};
writer.send(event);
}
if direct.is_some() {
//check for sphere overlaps
let size = 0.1;
if interactor_global_transform
.compute_transform()
.translation
.distance_squared(
xr_interactable_global_transform
.compute_transform()
.translation,
)
< (size * size) * 2.0
{
//check for selections first
match interactor_state {
XRInteractorState::Idle => {
let event = InteractionEvent {
interactor: interactor_entity,
interactable: interactable_entity,
interactable_state: XRInteractableState::Hover,
};
writer.send(event);
}
XRInteractorState::Selecting => {
let event = InteractionEvent {
interactor: interactor_entity,
interactable: interactable_entity,
interactable_state: XRInteractableState::Select,
};
writer.send(event);
}
}
}
None => (),
}
match ray {
Some(_) => {
//check for ray-sphere intersection
let sphere_transform = xr_interactable_global_transform.compute_transform();
let center = sphere_transform.translation;
let radius: f32 = 0.1;
//I hate this but the aim pose needs the root for now
let root = tracking_root_query.get_single().unwrap().0;
match aim {
Some(aim) => {
let ray_origin =
root.translation + root.rotation.mul_vec3(aim.0.translation);
let ray_dir = root.rotation.mul_vec3(aim.0.forward());
if ray.is_some() {
//check for ray-sphere intersection
let sphere_transform = xr_interactable_global_transform.compute_transform();
let center = sphere_transform.translation;
let radius: f32 = 0.1;
//I hate this but the aim pose needs the root for now
let root = tracking_root_query.get_single().unwrap().0;
match aim {
Some(aim) => {
let ray_origin =
root.translation + root.rotation.mul_vec3(aim.0.translation);
let ray_dir = root.rotation.mul_vec3(aim.0.forward());

if ray_sphere_intersection(
center,
radius,
ray_origin,
ray_dir.normalize_or_zero(),
) {
//check for selections first
match interactor_state {
XRInteractorState::Idle => {
let event = InteractionEvent {
interactor: interactor_entity,
interactable: interactable_entity,
interactable_state: XRInteractableState::Hover,
};
writer.send(event);
}
XRInteractorState::Selecting => {
let event = InteractionEvent {
interactor: interactor_entity,
interactable: interactable_entity,
interactable_state: XRInteractableState::Select,
};
writer.send(event);
}
if ray_sphere_intersection(
center,
radius,
ray_origin,
ray_dir.normalize_or_zero(),
) {
//check for selections first
match interactor_state {
XRInteractorState::Idle => {
let event = InteractionEvent {
interactor: interactor_entity,
interactable: interactable_entity,
interactable_state: XRInteractableState::Hover,
};
writer.send(event);
}
XRInteractorState::Selecting => {
let event = InteractionEvent {
interactor: interactor_entity,
interactable: interactable_entity,
interactable_state: XRInteractableState::Select,
};
writer.send(event);
}
}
}
None => info!("no aim pose"),
}
None => info!("no aim pose"),
}
None => (),
}
}
}
Expand All @@ -330,20 +316,19 @@ pub fn update_interactable_states(
}
for event in events.read() {
//lets change the state
match interactable_query.get_mut(event.interactable) {
Ok((_entity, mut entity_state, mut touched)) => {
//since we have an event we were touched this frame, i hate this name
*touched = Touched(true);
if event.interactable_state > *entity_state {
// info!(
// "event.state: {:?}, interactable.state: {:?}",
// event.interactable_state, entity_state
// );
// info!("event has a higher state");
}
*entity_state = event.interactable_state;
if let Ok((_entity, mut entity_state, mut touched)) =
interactable_query.get_mut(event.interactable)
{
//since we have an event we were touched this frame, i hate this name
*touched = Touched(true);
if event.interactable_state > *entity_state {
// info!(
// "event.state: {:?}, interactable.state: {:?}",
// event.interactable_state, entity_state
// );
// info!("event has a higher state");
}
Err(_) => {}
*entity_state = event.interactable_state;
}
}
//lets go through all the untouched interactables and set them to idle
Expand Down
19 changes: 8 additions & 11 deletions src/xr_input/prototype_locomotion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Default for PrototypeLocomotionConfig {
}
}
}
#[allow(unused_assignments)]
#[allow(unused_assignments, clippy::too_many_arguments)]
pub fn proto_locomotion(
time: Res<Time>,
mut tracking_root_query: Query<(&mut Transform, With<OpenXRTrackingRoot>)>,
Expand Down Expand Up @@ -136,16 +136,13 @@ pub fn proto_locomotion(
//apply rotation
let v = views.lock().unwrap();
let views = v.get(0);
match views {
Some(view) => {
let mut hmd_translation = view.pose.position.to_vec3();
hmd_translation.y = 0.0;
let local = position.0.translation;
let global = position.0.rotation.mul_vec3(hmd_translation) + local;
gizmos.circle(global, Vec3::Y, 0.1, Color::GREEN);
position.0.rotate_around(global, smoth_rot);
}
None => (),
if let Some(view) = views {
let mut hmd_translation = view.pose.position.to_vec3();
hmd_translation.y = 0.0;
let local = position.0.translation;
let global = position.0.rotation.mul_vec3(hmd_translation) + local;
gizmos.circle(global, Vec3::Y, 0.1, Color::GREEN);
position.0.rotate_around(global, smoth_rot);
}
}
RotationType::Snap => {
Expand Down
Loading