update with VRPN integration
This commit is contained in:
parent
9c778afa2b
commit
d7bc604289
6 changed files with 1003 additions and 182 deletions
1025
Cargo.lock
generated
1025
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -10,7 +10,7 @@ edition = "2021"
|
||||||
bevy = { version = "0.9.1", features = ["dynamic"] }
|
bevy = { version = "0.9.1", features = ["dynamic"] }
|
||||||
rand = "0.8.4"
|
rand = "0.8.4"
|
||||||
# vrpn = "0.1.0" # not compatible with 2021
|
# vrpn = "0.1.0" # not compatible with 2021
|
||||||
|
vrpn = { git = "https://github.com/seichter/vrpn-rs" }
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
opt-level = 3
|
opt-level = 3
|
12
src/main.rs
12
src/main.rs
|
@ -8,10 +8,11 @@
|
||||||
use crate::scene::*;
|
use crate::scene::*;
|
||||||
use crate::utils::*;
|
use crate::utils::*;
|
||||||
use crate::viewer::*;
|
use crate::viewer::*;
|
||||||
|
use crate::tracker::*;
|
||||||
|
|
||||||
use bevy::{prelude::*, window::PresentMode, render::camera::CameraProjectionPlugin};
|
use bevy::{prelude::*, window::PresentMode, render::camera::CameraProjectionPlugin};
|
||||||
use offaxis::{offaxis_camera_setup, OffAxisProjection};
|
use offaxis::{offaxis_camera_setup, OffAxisProjection};
|
||||||
|
use tracker::setup_tracker;
|
||||||
|
|
||||||
mod offaxis;
|
mod offaxis;
|
||||||
mod scene;
|
mod scene;
|
||||||
|
@ -19,6 +20,7 @@ mod screeninfo;
|
||||||
mod utils;
|
mod utils;
|
||||||
mod viewer;
|
mod viewer;
|
||||||
mod projection;
|
mod projection;
|
||||||
|
mod tracker;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
|
@ -33,6 +35,11 @@ fn main() {
|
||||||
},
|
},
|
||||||
..default()
|
..default()
|
||||||
}))
|
}))
|
||||||
|
// use hot reloading
|
||||||
|
// .add_plugins(DefaultPlugins.set(AssetPlugin {
|
||||||
|
// watch_for_changes: true,
|
||||||
|
// ..Default::default()
|
||||||
|
// }))
|
||||||
// .add_plugin(scene::BuildScenePlugin)
|
// .add_plugin(scene::BuildScenePlugin)
|
||||||
.add_system(bevy::window::close_on_esc)
|
.add_system(bevy::window::close_on_esc)
|
||||||
.add_system(cycle_msaa)
|
.add_system(cycle_msaa)
|
||||||
|
@ -40,6 +47,9 @@ fn main() {
|
||||||
// .add_system(modify_projection)
|
// .add_system(modify_projection)
|
||||||
|
|
||||||
.add_startup_system(offaxis_camera_setup)
|
.add_startup_system(offaxis_camera_setup)
|
||||||
|
.add_startup_system(setup_tracker)
|
||||||
|
.add_system(update_tracker)
|
||||||
|
|
||||||
.add_plugin(CameraProjectionPlugin::<OffAxisProjection>::default())
|
.add_plugin(CameraProjectionPlugin::<OffAxisProjection>::default())
|
||||||
.add_system(simulate_viewer)
|
.add_system(simulate_viewer)
|
||||||
.add_system(apply_viewer_to_projections)
|
.add_system(apply_viewer_to_projections)
|
||||||
|
|
73
src/scene.rs
73
src/scene.rs
|
@ -1,74 +1,4 @@
|
||||||
use bevy::{prelude::*, math::bool, render::primitives::Frustum};
|
use bevy::prelude::*;
|
||||||
use rand::prelude::*;
|
|
||||||
use bevy::render::primitives::Plane;
|
|
||||||
|
|
||||||
// pub struct BuildScenePlugin;
|
|
||||||
|
|
||||||
// impl Plugin for BuildScenePlugin {
|
|
||||||
// fn build(&self, app: &mut App) {
|
|
||||||
// app.add_startup_system(build_scene) // actual scene
|
|
||||||
// .add_system(print_positions); // debugging
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
pub struct ProjectionScreen {
|
|
||||||
bottom_left: Vec3,
|
|
||||||
bottom_right: Vec3,
|
|
||||||
top_left: Vec3,
|
|
||||||
top_right: Vec3,
|
|
||||||
|
|
||||||
dir_right: Vec3,
|
|
||||||
dir_up: Vec3,
|
|
||||||
dir_normal: Vec3,
|
|
||||||
|
|
||||||
matrix: Mat4
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn generalized_projection_stereo(eyePos : Vec3)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fn generalized_projection (
|
|
||||||
projectionScreen: ProjectionScreen,
|
|
||||||
eyePos: Vec3,
|
|
||||||
mut camera: Camera3dBundle,
|
|
||||||
clampNearPlane: bool,
|
|
||||||
)
|
|
||||||
{
|
|
||||||
let pa = projectionScreen.bottom_left;
|
|
||||||
let pb = projectionScreen.bottom_right;
|
|
||||||
let pc = projectionScreen.top_left;
|
|
||||||
let pd = projectionScreen.top_right;
|
|
||||||
|
|
||||||
let vu = projectionScreen.dir_up;
|
|
||||||
let vr = projectionScreen.dir_right;
|
|
||||||
let vn = projectionScreen.dir_normal;
|
|
||||||
|
|
||||||
// let m = projectionScreen.matrix;
|
|
||||||
|
|
||||||
//let m = Mat4::from_cols(vu., y_axis, z_axis, w_axis)
|
|
||||||
|
|
||||||
let va = pa - eyePos;
|
|
||||||
let vb = pb - eyePos;
|
|
||||||
let vc = pc - eyePos;
|
|
||||||
let vd = pd - eyePos;
|
|
||||||
|
|
||||||
let viewDir = eyePos + va + vb + vc + vd;
|
|
||||||
|
|
||||||
let d = -va.dot(vn);
|
|
||||||
|
|
||||||
|
|
||||||
if clampNearPlane {
|
|
||||||
_ = 33;
|
|
||||||
// camera.frustum.planes[4]. // should be near
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn build_scene(
|
pub fn build_scene(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
|
@ -98,5 +28,4 @@ pub fn build_scene(
|
||||||
transform: Transform::from_xyz(4.0, 1.0, -4.0),
|
transform: Transform::from_xyz(4.0, 1.0, -4.0),
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
65
src/tracker.rs
Normal file
65
src/tracker.rs
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
extern crate vrpn;
|
||||||
|
// extern crate tokio;
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use vrpn::{
|
||||||
|
async_io::{ping, ConnectionIp, ConnectionIpStream},
|
||||||
|
handler::{HandlerCode, TypedHandler},
|
||||||
|
ping::Server,
|
||||||
|
prelude::*,
|
||||||
|
tracker::PoseReport,
|
||||||
|
Message, Result, ServerInfo, StaticSenderName,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct Tracker {
|
||||||
|
stream: ConnectionIpStream,
|
||||||
|
connection: Arc<ConnectionIp>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Tracker {
|
||||||
|
pub fn from_info(server_ip: &str, port: u16) -> Self {
|
||||||
|
let server = format!("tcp://{}:{}", server_ip, port)
|
||||||
|
.parse::<ServerInfo>()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let connection = ConnectionIp::new_client(server, None, None).expect("msg");
|
||||||
|
|
||||||
|
let sender = connection
|
||||||
|
.register_sender(StaticSenderName(b"Tracker0"))
|
||||||
|
.expect("should be able to register sender");
|
||||||
|
|
||||||
|
let ping_client = ping::Client::new(sender, Arc::clone(&connection))
|
||||||
|
.expect("should be able to create ping client");
|
||||||
|
|
||||||
|
Self {
|
||||||
|
stream: ConnectionIpStream::new(Arc::clone(&connection)),
|
||||||
|
connection
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_typed(&mut self, msg: &Message<PoseReport>) -> Result<HandlerCode> {
|
||||||
|
info!("{:?}\n {:?}", msg.header, msg.body);
|
||||||
|
Ok(HandlerCode::ContinueProcessing)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn setup_tracker(mut commands: Commands)
|
||||||
|
{
|
||||||
|
commands.spawn(Tracker::from_info("127.0.0.1",3883));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_tracker(mut query:Query<&mut Tracker>)
|
||||||
|
{
|
||||||
|
for mut tracker in query.iter_mut() {
|
||||||
|
|
||||||
|
// tracker.connection.poll_endpoints();
|
||||||
|
// tracker
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,8 @@ pub fn apply_viewer_to_projections(mut query: Query<(&Viewer,&ScreenInfo,&mut Of
|
||||||
|
|
||||||
*transform = Transform::from_matrix(view.inverse());
|
*transform = Transform::from_matrix(view.inverse());
|
||||||
|
|
||||||
|
// *transform = Transform::from_translation(eye).looking_at(Vec3::ZERO, Vec3::Y);
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,12 +64,12 @@ pub fn simulate_viewer(mut query: Query<&mut Viewer>,time: Res<Time>) {
|
||||||
|
|
||||||
let radius = 1.0;
|
let radius = 1.0;
|
||||||
|
|
||||||
let z_distance = 2.0_f32;
|
let z_distance = 3.0_f32;
|
||||||
|
|
||||||
v.position = Vec3::new(
|
v.position = Vec3::new(
|
||||||
v.alpha.sin() * radius,
|
v.alpha.sin() * radius,
|
||||||
v.alpha.cos() * radius,
|
v.alpha.cos() * radius,
|
||||||
z_distance,
|
z_distance + v.alpha.sin(),
|
||||||
);
|
);
|
||||||
|
|
||||||
info!("Viewer {:?}",v.position);
|
info!("Viewer {:?}",v.position);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue