mirror of
https://github.com/mii443/rust-openvr.git
synced 2025-08-23 00:35:31 +00:00
Fixed testing example add minor functionality
This commit is contained in:
@ -16,44 +16,57 @@ fn print_matrix_4x3(offset: u32, mat: [[f32; 4]; 3]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let system = match openvr::init() {
|
let context = match openvr::init(openvr::ApplicationType::Other) {
|
||||||
Ok(ivr) => ivr,
|
Ok(ivr) => ivr,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
println!("Failed to create IVR subsystem {:?}", err);
|
println!("Failed to initialize openvr {:?}", err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("IVRSystem was created");
|
println!("OpenVR was initialized successfully..");
|
||||||
|
|
||||||
println!("\trecommended size: {:?}", system.recommended_render_target_size());
|
let system = match context.system() {
|
||||||
println!("\tvsync: {:?}", system.time_since_last_vsync());
|
Ok(sys) => sys,
|
||||||
|
Err(err) => {
|
||||||
|
println!("Failed to get system interface {:?}", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
print!("\tprojection matrix left ");
|
println!("\tRecommended size: {:?}", system.recommended_render_target_size());
|
||||||
|
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_4x4(31, system.projection_matrix(openvr::Eye::Left, 0.1, 100.));
|
||||||
print!("\tprojection matrix right ");
|
print!("\tProjection matrix right ");
|
||||||
print_matrix_4x4(31, system.projection_matrix(openvr::Eye::Right, 0.1, 100.));
|
print_matrix_4x4(31, system.projection_matrix(openvr::Eye::Right, 0.1, 100.));
|
||||||
|
|
||||||
print!("\teye_to_head ");
|
print!("\tEye_to_head ");
|
||||||
print_matrix_4x3(8+12, system.eye_to_head_transform(openvr::Eye::Left));
|
print_matrix_4x3(8+12, system.eye_to_head_transform(openvr::Eye::Left));
|
||||||
|
|
||||||
print!("\tposes ");
|
print!("\tPoses ");
|
||||||
print_matrix_4x3(8+6, system.tracked_devices(0.).as_slice()[0].to_device);
|
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());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
println!("Distortion example");
|
println!("\tDistortion example");
|
||||||
for u in 0..2 {
|
for u in 0..2 {
|
||||||
for v in 0..2 {
|
for v in 0..2 {
|
||||||
let pos = system.compute_distortion(
|
let pos = system.compute_distortion(
|
||||||
openvr::Eye::Left,
|
openvr::Eye::Left,
|
||||||
u as f32 / 4.,
|
u as f32 / 4.,
|
||||||
v as f32 / 4.,
|
v as f32 / 4.,
|
||||||
);
|
).unwrap();
|
||||||
print!("\t({:2.4}, {:2.4}) ", pos.red[0], pos.red[1]);
|
print!("\t\t({:2.4}, {:2.4}) ", pos.red[0], pos.red[1]);
|
||||||
}
|
}
|
||||||
println!("");
|
println!("");
|
||||||
}
|
}
|
||||||
|
|
||||||
let ext = match openvr::extended_display() {
|
/*
|
||||||
|
let ext = match context.extended_display() {
|
||||||
Ok(ext) => ext,
|
Ok(ext) => ext,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
println!("Failed to create IVRExtendedDisplay subsystem {:?}", err);
|
println!("Failed to create IVRExtendedDisplay subsystem {:?}", err);
|
||||||
@ -61,10 +74,12 @@ fn main() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
println!("\nIVRExtendedDisplay was created");
|
println!("\nIVRExtendedDisplay was created");
|
||||||
println!("\tbounds: {:?}", ext.window_bounds());
|
|
||||||
println!("\teye output: {:?} {:?}", ext.eye_viewport(openvr::Eye::Left), ext.eye_viewport(openvr::Eye::Right));
|
|
||||||
|
|
||||||
let comp = match openvr::compositor() {
|
println!("\tBounds: {:?}", ext.window_bounds());
|
||||||
|
println!("\tEye output: {:?} {:?}", ext.eye_viewport(openvr::Eye::Left), ext.eye_viewport(openvr::Eye::Right));
|
||||||
|
*/
|
||||||
|
|
||||||
|
let comp = match context.compositor() {
|
||||||
Ok(ext) => ext,
|
Ok(ext) => ext,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
println!("Failed to create IVRCompositor subsystem {:?}", err);
|
println!("Failed to create IVRCompositor subsystem {:?}", err);
|
||||||
@ -73,10 +88,14 @@ fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
println!("\nIVRCompositor was created");
|
println!("\nIVRCompositor was created");
|
||||||
println!("\tis fullscreen = {}", comp.is_fullscreen());
|
println!("\tIs fullscreen = {}", comp.is_fullscreen());
|
||||||
println!("\tcan render scene = {}", comp.can_render_scene());
|
println!("\tInstance Extensions:");
|
||||||
|
for ext in comp.vulkan_instance_extensions_required() {
|
||||||
|
println!("\t\t{:?}", ext);
|
||||||
|
}
|
||||||
|
|
||||||
let model = match openvr::render_models() {
|
/*
|
||||||
|
let model = match context.render_models() {
|
||||||
Ok(ext) => ext,
|
Ok(ext) => ext,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
println!("Failed to create IVRRenderModels subsystem {:?}", err);
|
println!("Failed to create IVRRenderModels subsystem {:?}", err);
|
||||||
@ -88,9 +107,7 @@ fn main() {
|
|||||||
for i in 0..model.get_count() {
|
for i in 0..model.get_count() {
|
||||||
println!("\t{}", model.get_name(i));
|
println!("\t{}", model.get_name(i));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
openvr::shutdown();
|
|
||||||
println!("Done! \\o/");
|
println!("Done! \\o/");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,11 @@ impl<'a> Compositor<'a> {
|
|||||||
pub fn post_present_handoff(&self) {
|
pub fn post_present_handoff(&self) {
|
||||||
unsafe { (self.0.PostPresentHandoff.unwrap())() };
|
unsafe { (self.0.PostPresentHandoff.unwrap())() };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return whether the compositor is fullscreen.
|
||||||
|
pub fn is_fullscreen(&self) -> bool {
|
||||||
|
unsafe { (self.0.IsFullscreen.unwrap())() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
@ -115,6 +115,27 @@ impl<'a> System<'a> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Computes the distortion caused by the optics
|
||||||
|
/// Gets the result of a single distortion value for use in a distortion map. Input UVs are in a single eye's viewport, and output UVs are for the source render target in the distortion shader.
|
||||||
|
pub fn compute_distortion(&self, eye: Eye, u: f32, v: f32) -> Option<DistortionCoordinates> {
|
||||||
|
let mut coord = unsafe { mem::uninitialized() };
|
||||||
|
let success = unsafe { self.0.ComputeDistortion.unwrap()(
|
||||||
|
eye as sys::EVREye,
|
||||||
|
u, v,
|
||||||
|
&mut coord
|
||||||
|
) };
|
||||||
|
|
||||||
|
if !success {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(DistortionCoordinates {
|
||||||
|
red: coord.rfRed,
|
||||||
|
blue: coord.rfBlue,
|
||||||
|
green: coord.rfGreen
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Values represent the tangents of the half-angles from the center view axis
|
/// Values represent the tangents of the half-angles from the center view axis
|
||||||
@ -129,3 +150,10 @@ pub struct RawProjection {
|
|||||||
/// tangent of the half-angle from center axis to the bottom clipping plane
|
/// tangent of the half-angle from center axis to the bottom clipping plane
|
||||||
pub bottom: f32,
|
pub bottom: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct DistortionCoordinates {
|
||||||
|
pub red: [f32; 2],
|
||||||
|
pub green: [f32; 2],
|
||||||
|
pub blue: [f32; 2],
|
||||||
|
}
|
Reference in New Issue
Block a user