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
use crate::{ffi, math::Matrix};

use static_assertions::{assert_eq_align, assert_eq_size};

/// VrDeviceInfo, Head-Mounted-Display device parameters
#[repr(C)]
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct VrDeviceInfo {
    /// Horizontal resolution in pixels
    pub horizontal_resolution: u32,
    /// Vertical resolution in pixels
    pub vertical_resolution: u32,
    /// Horizontal size in meters
    pub horizontal_screen_size: f32,
    /// Vertical size in meters
    pub vertical_screen_size: f32,
    /// Screen center in meters
    pub screen_center_v: f32,
    /// Distance between eye and display in meters
    pub eye_to_screen_distance: f32,
    /// Lens separation distance in meters
    pub lens_separation_distance: f32,
    /// IPD (distance between pupils) in meters
    pub interpupillary_distance: f32,
    /// Lens distortion constant parameters
    pub lens_distortion_values: [f32; 4],
    /// Chromatic aberration correction parameters
    pub chroma_ab_correction: [f32; 4],
}

assert_eq_size!(VrDeviceInfo, ffi::VrDeviceInfo);
assert_eq_align!(VrDeviceInfo, ffi::VrDeviceInfo);

impl From<VrDeviceInfo> for ffi::VrDeviceInfo {
    #[inline]
    fn from(val: VrDeviceInfo) -> Self {
        unsafe { std::mem::transmute(val) }
    }
}

impl From<ffi::VrDeviceInfo> for VrDeviceInfo {
    #[inline]
    fn from(value: ffi::VrDeviceInfo) -> Self {
        unsafe { std::mem::transmute(value) }
    }
}

/// VrStereoConfig, VR stereo rendering configuration for simulator
#[repr(C)]
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct VrStereoConfig {
    /// VR projection matrices (per eye)
    pub projection: [Matrix; 2],
    /// VR view offset matrices (per eye)
    pub view_offset: [Matrix; 2],
    /// VR left lens center
    pub left_lens_center: [f32; 2],
    /// VR right lens center
    pub right_lens_center: [f32; 2],
    /// VR left screen center
    pub left_screen_center: [f32; 2],
    /// VR right screen center
    pub right_screen_center: [f32; 2],
    /// VR distortion scale
    pub scale: [f32; 2],
    /// VR distortion scale in
    pub scale_in: [f32; 2],
}

impl VrStereoConfig {
    /// Load VR stereo config for VR simulator device parameters
    pub fn load(device: VrDeviceInfo) -> Self {
        // raylib 4.5.0 doesn't allocate VrStereoConfig and UnloadVrStereoConfig is an empty func
        assert_eq!(crate::RAYLIB_VERSION, "4.5");

        unsafe { ffi::LoadVrStereoConfig(device.into()).into() }
    }
}

assert_eq_size!(VrStereoConfig, ffi::VrStereoConfig);
assert_eq_align!(VrStereoConfig, ffi::VrStereoConfig);

impl From<VrStereoConfig> for ffi::VrStereoConfig {
    #[inline]
    fn from(val: VrStereoConfig) -> Self {
        // raylib 4.5.0 doesn't allocate VrStereoConfig and UnloadVrStereoConfig is an empty func
        assert_eq!(crate::RAYLIB_VERSION, "4.5");

        unsafe { std::mem::transmute(val) }
    }
}

impl From<ffi::VrStereoConfig> for VrStereoConfig {
    #[inline]
    fn from(value: ffi::VrStereoConfig) -> Self {
        // raylib 4.5.0 doesn't allocate VrStereoConfig and UnloadVrStereoConfig is an empty func
        assert_eq!(crate::RAYLIB_VERSION, "4.5");

        unsafe { std::mem::transmute(value) }
    }
}

impl Drop for VrStereoConfig {
    #[inline]
    fn drop(&mut self) {
        // raylib 4.5.0 doesn't allocate VrStereoConfig and UnloadVrStereoConfig is an empty func
        assert_eq!(crate::RAYLIB_VERSION, "4.5");

        // unsafe { ffi::UnloadVrStereoConfig( ... ) }
    }
}