This repository has been archived by the owner on Jul 10, 2023. It is now read-only.
/
display.rs
155 lines (125 loc) · 5.26 KB
/
display.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
use {VRDisplay, VRDisplayData, VRFramebuffer, VRFramebufferAttributes, VRFrameData, VRGamepadPtr, VRStageParameters, VRLayer, VRViewport};
use rust_webvr_api::utils;
use std::sync::Arc;
use std::cell::RefCell;
pub type MockVRDisplayPtr = Arc<RefCell<MockVRDisplay>>;
use std::time::Duration;
use std::thread;
pub struct MockVRDisplay {
display_id: u32,
attributes: VRFramebufferAttributes,
}
unsafe impl Send for MockVRDisplay {}
unsafe impl Sync for MockVRDisplay {}
impl MockVRDisplay {
pub fn new() -> MockVRDisplayPtr {
Arc::new(RefCell::new(MockVRDisplay {
display_id: utils::new_id(),
attributes: Default::default(),
}))
}
}
impl VRDisplay for MockVRDisplay {
fn id(&self) -> u32 {
self.display_id
}
fn data(&self) -> VRDisplayData {
let mut data = VRDisplayData::default();
// Mock display data
// Simulates a virtual HTC Vive
data.display_name = "Mock VRDisplay".into();
data.display_id = self.display_id;
data.connected = true;
data.capabilities.can_present = true;
data.capabilities.has_orientation = true;
data.capabilities.has_external_display = true;
data.capabilities.has_position = true;
data.stage_parameters = Some(VRStageParameters {
sitting_to_standing_transform: [-0.9317312, 0.0, 0.36314875, 0.0, 0.0, 0.99999994, 0.0, 0.0, -0.36314875,
0.0, -0.9317312, 0.0, 0.23767996, 1.6813644, 0.45370483, 1.0],
size_x: 2.0,
size_z: 2.0
});
data.left_eye_parameters.offset = [0.035949998, 0.0, 0.015];
data.left_eye_parameters.render_width = 1512;
data.left_eye_parameters.render_height = 1680;
data.left_eye_parameters.field_of_view.up_degrees = 55.82093048095703;
data.left_eye_parameters.field_of_view.right_degrees = 51.26948547363281;
data.left_eye_parameters.field_of_view.down_degrees = 55.707801818847656;
data.left_eye_parameters.field_of_view.left_degrees = 54.42263412475586;
data.right_eye_parameters.offset = [-0.035949998, 0.0, 0.015];
data.right_eye_parameters.render_width = 1512;
data.right_eye_parameters.render_height = 1680;
data.right_eye_parameters.field_of_view.up_degrees = 55.898048400878906;
data.right_eye_parameters.field_of_view.right_degrees = 54.37410354614258;
data.right_eye_parameters.field_of_view.down_degrees = 55.614715576171875;
data.right_eye_parameters.field_of_view.left_degrees = 51.304901123046875;
data
}
fn immediate_frame_data(&self, _near_z: f64, _far_z: f64) -> VRFrameData {
let mut data = VRFrameData::default();
// Position vector
data.pose.position = Some([0.5, -0.7, -0.3]);
// Orientation quaternion
// TODO: Add animation
data.pose.orientation = Some([0.9385081, -0.08066622, -0.3347714, 0.024972256]);
// Simulates HTC Vive projections
data.left_projection_matrix = [0.75620246, 0.0, 0.0, 0.0,
0.0, 0.68050665, 0.0, 0.0,
-0.05713458, -0.0021225351, -1.0000999, -1.0,
0.0, 0.0, -0.10000999, 0.0];
data.left_view_matrix = [1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
-0.035949998, 0.0, 0.015, 1.0];
data.right_projection_matrix = [0.75646526, 0.0, 0.0, 0.0,
0.0, 0.68069947, 0.0, 0.0,
0.055611316, -0.005315368, -1.0000999, -1.0,
0.0, 0.0, -0.10000999, 0.0];
data.right_view_matrix = [1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.035949998, 0.0, 0.015, 1.0];
data.timestamp = utils::timestamp();
data
}
fn synced_frame_data(&self, near_z: f64, far_z: f64) -> VRFrameData {
self.immediate_frame_data(near_z, far_z)
}
fn reset_pose(&mut self) {
// No op
}
fn sync_poses(&mut self) {
// Simulate Vsync
thread::sleep(Duration::from_millis(1));
}
fn bind_framebuffer(&mut self, _index: u32) {
// No op
}
fn get_framebuffers(&self) -> Vec<VRFramebuffer> {
vec![VRFramebuffer {
eye_index: 0,
attributes: self.attributes,
viewport: VRViewport::new(0, 0, 1512/2, 1680)
},
VRFramebuffer {
eye_index: 1,
attributes: self.attributes,
viewport: VRViewport::new(1512/2, 0, 1512/2, 1680)
}]
}
fn render_layer(&mut self, _layer: &VRLayer) {
// No op
}
fn fetch_gamepads(&mut self) -> Result<Vec<VRGamepadPtr>,String> {
Ok(Vec::new())
}
fn submit_frame(&mut self) {
// No op
}
fn start_present(&mut self, attributes: Option<VRFramebufferAttributes>) {
if let Some(attributes) = attributes {
self.attributes = attributes;
}
}
}