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
//! OpenXR virtual reality support for head-mounted displays.
//!
//! Run applications in VR with full 6DOF tracking and controller input:
//!
//! - [`XrContext`]: OpenXR session management and device access
//! - [`XrInput`]: Controller state including thumbsticks, triggers, and hand poses
//! - [`XrResources`]: World resource for VR state and locomotion settings
//! - [`XrRenderer`]: Stereo rendering pipeline for VR
//! - `launch_xr`: Entry point to run an application in VR mode
//!
//! Requires the `openxr` feature and a connected VR headset with OpenXR runtime.
//!
//! # Quick Start
//!
//! Launch your application in VR mode:
//!
//! ```ignore
//! use nightshade::xr::launch_xr;
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let state = MyGameState::new();
//! launch_xr(state)
//! }
//! ```
//!
//! # Reading Controller Input
//!
//! Access VR controller state through [`XrResources`]:
//!
//! ```ignore
//! fn run_systems(&mut self, world: &mut World) {
//! if let Some(input) = &world.resources.xr.input {
//! // Thumbstick movement (left controller)
//! let move_x = input.thumbstick.x;
//! let move_y = input.thumbstick.y;
//!
//! // Trigger and grip (0.0 - 1.0)
//! if input.left_trigger_pressed() {
//! // Left trigger held
//! }
//! if input.right_grip_pressed() {
//! // Right grip held
//! }
//!
//! // Face buttons
//! if input.a_button_pressed() {
//! // A button pressed
//! }
//!
//! // Hand tracking
//! if let Some(left_pos) = input.left_hand_position() {
//! // World-space left hand position
//! }
//! if let Some(left_rot) = input.left_hand_rotation() {
//! // Left hand orientation as quaternion
//! }
//!
//! // Head tracking
//! let head_pos = input.head_position;
//! let head_rot = input.head_orientation;
//! }
//! }
//! ```
//!
//! # Locomotion
//!
//! Enable thumbstick-based movement:
//!
//! ```ignore
//! fn initialize(&mut self, world: &mut World) {
//! // Enable smooth locomotion with left thumbstick
//! world.resources.xr.locomotion_enabled = true;
//! world.resources.xr.locomotion_speed = 3.0; // Units per second
//!
//! // Set initial player position
//! world.resources.xr.initial_player_position = Some(Vec3::new(0.0, 0.0, 5.0));
//! world.resources.xr.initial_player_yaw = Some(0.0);
//! }
//! ```
//!
//! # Syncing with Character Controller
//!
//! If your scene has a character controller, the VR player position automatically
//! syncs to it. The headset tracks relative to the character's floor position.
//!
//! # Input Properties
//!
//! | Property | Type | Description |
//! |----------|------|-------------|
//! | `thumbstick` | Vec2 | Left thumbstick X/Y (-1 to 1) |
//! | `right_thumbstick` | Vec2 | Right thumbstick X/Y (-1 to 1) |
//! | `left_trigger` | f32 | Left trigger (0 to 1) |
//! | `right_trigger` | f32 | Right trigger (0 to 1) |
//! | `left_grip` | f32 | Left grip (0 to 1) |
//! | `right_grip` | f32 | Right grip (0 to 1) |
//! | `a_button` | bool | A button state |
//! | `b_button` | bool | B button state |
//! | `left_hand_pose` | Option | Left controller pose |
//! | `right_hand_pose` | Option | Right controller pose |
//! | `head_position` | Vec3 | World-space head position |
//! | `head_orientation` | Quat | Head rotation |
//! | `player_yaw` | f32 | Player body rotation |
//!
//! # Supported Controllers
//!
//! Currently configured for Oculus Touch controllers. The input mapping:
//!
//! | Input | Binding |
//! |-------|---------|
//! | Movement | Left thumbstick |
//! | Turn | Right thumbstick |
//! | Left trigger | Left index trigger |
//! | Right trigger | Right index trigger |
//! | Left grip | Left squeeze |
//! | Right grip | Right squeeze |
//! | A button | Right controller A |
//! | B button | Right controller B |
//!
//! # Render Pipeline
//!
//! The VR renderer uses the same passes as the desktop renderer but renders
//! to each eye separately at the headset's native resolution. HDR rendering,
//! bloom, and tone mapping are all supported.
pub use XrContext;
pub use XrFrameContext;
pub use XrInput;
pub use launch_xr;
pub use XrRenderer;
pub use XrResources;