mirror of
https://github.com/mii443/rust-openvr.git
synced 2025-08-22 16:25:36 +00:00
Add chaperone examples to example
Generalize printing logic
This commit is contained in:
committed by
Benjamin Saunders
parent
41e8e1a552
commit
bf27407cc3
@ -1,18 +1,19 @@
|
||||
extern crate openvr;
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
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 print_matrix<M, N>(offset: u32, mat: M)
|
||||
where M: AsRef<[N]>,
|
||||
N: AsRef<[f32]>,
|
||||
{
|
||||
let offset: String = (0..offset).map(|_| ' ').collect();
|
||||
let mut is_first_row = true;
|
||||
for row in mat.as_ref() {
|
||||
if !is_first_row {
|
||||
print!("{}", offset);
|
||||
}
|
||||
let row_interior: Vec<_> = row.as_ref().iter().map(|x| format!("{:7.4}", x)).collect();
|
||||
println!("[{}]", row_interior.join(", "));
|
||||
is_first_row = false;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@ -38,17 +39,17 @@ fn main() {
|
||||
println!("\tVSync: {:?}", system.time_since_last_vsync());
|
||||
|
||||
print!("\tProjection matrix left ");
|
||||
print_matrix_4x4(31, system.projection_matrix(openvr::Eye::Left, 0.1, 100.));
|
||||
print_matrix(32, system.projection_matrix(openvr::Eye::Left, 0.1, 100.));
|
||||
print!("\tProjection matrix right ");
|
||||
print_matrix_4x4(31, system.projection_matrix(openvr::Eye::Right, 0.1, 100.));
|
||||
print_matrix(32, system.projection_matrix(openvr::Eye::Right, 0.1, 100.));
|
||||
|
||||
print!("\tEye to head left ");
|
||||
print_matrix_4x3(8+12, system.eye_to_head_transform(openvr::Eye::Left));
|
||||
print_matrix(25, system.eye_to_head_transform(openvr::Eye::Left));
|
||||
|
||||
print!("\tPoses ");
|
||||
let poses = system.device_to_absolute_tracking_pose(openvr::TrackingUniverseOrigin::RawAndUncalibrated, 0.0);
|
||||
for pose in poses.iter() {
|
||||
print_matrix_4x3(8+6, *pose.device_to_absolute_tracking());
|
||||
print_matrix(8+6, pose.device_to_absolute_tracking());
|
||||
break;
|
||||
}
|
||||
|
||||
@ -60,9 +61,9 @@ fn main() {
|
||||
u as f32 / 4.,
|
||||
v as f32 / 4.,
|
||||
).unwrap();
|
||||
print!("\t\t({:2.4}, {:2.4}) ", pos.red[0], pos.red[1]);
|
||||
print!("\t\t({:7.4}, {:7.4}) ", pos.red[0], pos.red[1]);
|
||||
}
|
||||
println!("");
|
||||
println!();
|
||||
}
|
||||
|
||||
let comp = match context.compositor() {
|
||||
@ -72,13 +73,34 @@ fn main() {
|
||||
return;
|
||||
}
|
||||
};
|
||||
println!();
|
||||
|
||||
println!("\nIVRCompositor was created");
|
||||
println!("IVRCompositor was created");
|
||||
println!("\tIs fullscreen = {}", comp.is_fullscreen());
|
||||
println!("\tVulkan Instance Extensions:");
|
||||
for ext in comp.vulkan_instance_extensions_required() {
|
||||
println!("\t\t{:?}", ext);
|
||||
}
|
||||
println!();
|
||||
|
||||
println!("IVRChaperone was created");
|
||||
let chaperone = match context.chaperone() {
|
||||
Ok(sys) => sys,
|
||||
Err(err) => {
|
||||
println!("Failed to get chaperone interface: {}", err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
println!("\tCalibration state: {:?}", chaperone.get_calibration_state());
|
||||
println!("\tPlay area size: {:?}", chaperone.get_play_area_size());
|
||||
print!("\tPlay area rect: ");
|
||||
if let Some(play_area_rect) = chaperone.get_play_area_rect() {
|
||||
print_matrix(24, &play_area_rect);
|
||||
} else {
|
||||
println!("None");
|
||||
}
|
||||
println!("\tAre bounds visible = {:?}", chaperone.are_bounds_visible());
|
||||
println!();
|
||||
|
||||
println!("Done! \\o/");
|
||||
}
|
||||
|
Reference in New Issue
Block a user