update with VRPN integration
This commit is contained in:
parent
9c778afa2b
commit
d7bc604289
6 changed files with 1003 additions and 182 deletions
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
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue