From 1c25af23b26b73f7b2b478e043d8e0119427ad63 Mon Sep 17 00:00:00 2001 From: Colin Sherratt Date: Sun, 5 Jul 2015 00:44:59 -0400 Subject: [PATCH] ade the test app print a prettier output --- examples/test.rs | 59 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/examples/test.rs b/examples/test.rs index 4f759da..6663c44 100644 --- a/examples/test.rs +++ b/examples/test.rs @@ -1,29 +1,60 @@ extern crate vr; -fn main() { - let ivr = vr::IVRSystem::init().unwrap(); - println!("bounds: {:?}", ivr.bounds()); - println!("recommended size: {:?}", ivr.recommended_render_target_size()); - println!("eye output: {:?} {:?}", ivr.eye_viewport(vr::Eye::Left), ivr.eye_viewport(vr::Eye::Right)); - println!("projection matrix left {:?}", ivr.projection_matrix(vr::Eye::Left, 0.1, 100.)); - println!("projection matrix right {:?}", ivr.projection_matrix(vr::Eye::Right, 0.1, 100.)); +fn print_matrix_4x4(offset: u32, mat: [[f32; 4]; 4]) { + let off: String = (0..offset).map(|_| ' ').collect(); + println!("{:?}", mat[0]); + println!("{}{:?}", off, mat[1]); + println!("{}{:?}", off, mat[2]); + println!("{}{:?}", off, mat[3]); +} - for u in 0..4 { - for v in 0..4 { +fn print_matrix_4x3(offset: u32, mat: [[f32; 4]; 3]) { + let off: String = (0..offset).map(|_| ' ').collect(); + println!("{:?}", mat[0]); + println!("{}{:?}", off, mat[1]); + println!("{}{:?}", off, mat[2]); +} + +fn main() { + let ivr = match vr::IVRSystem::init() { + Ok(ivr) => ivr, + Err(err) => { + println!("Failed to create IVR subsystem {:?}", err); + return; + } + }; + + println!("IVR was created"); + println!("\tbounds: {:?}", ivr.bounds()); + println!("\trecommended size: {:?}", ivr.recommended_render_target_size()); + println!("\teye output: {:?} {:?}", ivr.eye_viewport(vr::Eye::Left), ivr.eye_viewport(vr::Eye::Right)); + println!("\tvsync: {:?}", ivr.time_since_last_vsync()); + + print!("\tprojection matrix left "); + print_matrix_4x4(31, ivr.projection_matrix(vr::Eye::Left, 0.1, 100.)); + print!("\tprojection matrix right "); + print_matrix_4x4(31, ivr.projection_matrix(vr::Eye::Right, 0.1, 100.)); + + print!("\teye_to_head "); + print_matrix_4x3(8+12, ivr.eye_to_head_transform(vr::Eye::Left)); + + print!("\tposes "); + print_matrix_4x3(8+6, ivr.tracked_devices(0.).as_slice()[0].to_device); + + + println!("Distortion example"); + for u in 0..2 { + for v in 0..2 { let pos = ivr.compute_distortion( vr::Eye::Left, u as f32 / 4., v as f32 / 4., ); - print!("({:2.4}, {:2.4}) ", pos.red[0], pos.red[1]); + print!("\t({:2.4}, {:2.4}) ", pos.red[0], pos.red[1]); } println!(""); } - println!("eye_to_head: {:?}", ivr.eye_to_head_transform(vr::Eye::Left)); - println!("vsync: {:?}", ivr.time_since_last_vsync()); - println!("poses {:?}", ivr.tracked_devices(0.).as_slice()); - println!("Trying to create a compositor"); match ivr.compositor() { Err(err) => println!("Could not create compositor {:?}", err),