Skip to content

Commit

Permalink
added initial spacemouse support
Browse files Browse the repository at this point in the history
  • Loading branch information
gilescope committed May 14, 2022
1 parent 5885043 commit ed8e83b
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 26 deletions.
5 changes: 3 additions & 2 deletions .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-Clink-arg=-fuse-ld=lld", "-Zshare-generics=y"]
#rustflags = ["-Clink-arg=-fuse-ld=lld", "-Zshare-generics=y"]
rustflags = ["-Zshare-generics=y"]

# NOTE: you must manually install https://github.com/michaeleisel/zld on mac. you can easily do this with the "brew" package manager:
# `brew install michaeleisel/zld/zld`
Expand All @@ -22,4 +23,4 @@ rustflags = ["-Clink-arg=-fuse-ld=lld", "-Zshare-generics=y"]
# Optional: Uncommenting the following improves compile times, but reduces the amount of debug info to 'line number tables only'
# In most cases the gains are negligible, but if you are on macos and have slow compile times you should see significant gains.
[profile.dev]
debug = 1
debug = 1
42 changes: 42 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ repository = "https://github.com/gilescope/dotsamatown"
resolver = "2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = ["spacemouse"]
# 3d mouse support.
spacemouse = ["bevy_spacemouse"]

[dependencies]
sp-core = "*"

Expand All @@ -33,6 +38,7 @@ fastrand = "*"
bevy-inspector-egui = "0.10"
serde_bytes = "0.11"
#rayon = "*"
bevy_spacemouse = { path= "/home/gilescope/git/bevy-spacemouse-example", optional = true }
serde = "*"
bevy_egui = "*"
egui = "*"
Expand Down Expand Up @@ -93,6 +99,7 @@ opt-level = 1

[profile.release]

[features]


# lto = true
# opt-level = 's'
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,20 @@ I was using `trunk serve` to run up a wasm version but at the moment I'm using s

## Build and run native version
```
cargo run
cargo run --no-default-features
```

You will need to change Cargo.toml to wayland if your using that - at the moment it's set to X11.

## Features

Note: spacemouse is on by default at the moment.

| Feature | Description |
| spacemouse | n-degees of freedom mouse support |

## License

License: MIT/Apache2 just like rust.

## crazy idea holding ground:
Expand Down
31 changes: 21 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ use crate::details::Details;
use bevy_inspector_egui::RegisterInspectable;
use sp_core::H256;
use std::convert::AsRef;
#[cfg(feature="spacemouse")]
use bevy_spacemouse::{SpaceMouseControllable, SpaceMousePlugin};

// #[subxt::subxt(runtime_metadata_path = "wss://kusama-rpc.polkadot.io:443")]
// pub mod polkadot {}
Expand Down Expand Up @@ -78,15 +80,19 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut app = App::new();
app.insert_resource(Msaa { samples: 4 })
.add_plugins(DefaultPlugins)
.insert_resource(WinitSettings::desktop_app())
// .insert_resource(WinitSettings::desktop_app()) - this messes up the 3d space mouse?
.insert_resource(MovementSettings {
sensitivity: 0.00020, // default: 0.00012
speed: 12.0, // default: 12.0
})
})
.insert_resource(movement::MouseCapture::default())
.add_plugin(NoCameraPlayerPlugin)
.add_plugins(DefaultPickingPlugins)
.add_plugin(DebugCursorPickingPlugin) // <- Adds the green debug cursor.
.add_plugin(NoCameraPlayerPlugin);

#[cfg(feature="spacemouse")]
app.add_plugin(SpaceMousePlugin);

app.add_plugins(DefaultPickingPlugins)
// .add_plugin(DebugCursorPickingPlugin) // <- Adds the green debug cursor.
.add_plugin(InspectorPlugin::<Inspector>::new())
.register_inspectable::<Details>()
// .add_plugin(DebugEventsPickingPlugin)
Expand Down Expand Up @@ -134,7 +140,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
)
},
)
.add_system_to_stage(CoreStage::PostUpdate, print_events);
.add_system_to_stage(CoreStage::PostUpdate, print_events)
;

for (relay_id, relay) in relays.into_iter().enumerate() {
for (arc, mut chain_name) in relay {
Expand Down Expand Up @@ -1059,7 +1066,8 @@ fn setup(
//somehow this can change the color
// mesh_highlighting(None, None, None);
// camera
commands

let mut entity_comands = commands
.spawn_bundle(PerspectiveCameraBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
perspective_projection: PerspectiveProjection {
Expand All @@ -1075,9 +1083,12 @@ fn setup(
..default()
},
..default()
})
.insert_bundle(PickingCameraBundle { ..default() })
.insert(FlyCam);
});
entity_comands.insert(FlyCam)
.insert_bundle(PickingCameraBundle { ..default() });

#[cfg(feature="spacemouse")]
entity_comands.insert(SpaceMouseControllable);

use std::time::Duration;
commands.insert_resource(UpdateTimer {
Expand Down
24 changes: 12 additions & 12 deletions src/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ pub fn scroll(
windows: Res<Windows>,
mut query: Query<(&FlyCam, &mut Camera, &mut PerspectiveProjection)>,
) {
for event in mouse_wheel_events.iter() {
for (_camera, mut camera, mut project) in query.iter_mut() {
project.fov = (project.fov - event.y * 0.01).abs();
let prim = windows.get_primary().unwrap();
// for event in mouse_wheel_events.iter() {
// for (_camera, mut camera, mut project) in query.iter_mut() {
// project.fov = (project.fov - event.y * 0.01).abs();
// let prim = windows.get_primary().unwrap();

//Calculate projection with new fov
project.update(prim.width(), prim.height());
// //Calculate projection with new fov
// project.update(prim.width(), prim.height());

//Update camera with the new fov
camera.projection_matrix = project.get_projection_matrix();
camera.depth_calculation = project.depth_calculation();
// //Update camera with the new fov
// camera.projection_matrix = project.get_projection_matrix();
// camera.depth_calculation = project.depth_calculation();

// println!("FOV: {:?}", project.fov);
}
}
// // println!("FOV: {:?}", project.fov);
// }
// }
}

0 comments on commit ed8e83b

Please sign in to comment.