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
// Author: Tom Olsson <tom.olsson@embark-studios.com>
// Copyright © 2019, Embark Studios, all rights reserved.
// Created: 17 June 2019

#![warn(clippy::all)]

/*!

*/

mod transform;
pub use transform::PxTransform;
mod quat;
pub use quat::PxQuat;
mod vec3;
pub use vec3::PxVec3;

#[derive(Copy, Clone)]
#[repr(transparent)]
pub struct PxExtendedVec3 {
    obj: physx_sys::PxExtendedVec3,
}

crate::DeriveClassForNewType!(PxExtendedVec3: PxExtendedVec3);

impl From<(f64, f64, f64)> for PxExtendedVec3 {
    fn from(vec: (f64, f64, f64)) -> Self {
        Self {
            obj: physx_sys::PxExtendedVec3 {
                x: vec.0,
                y: vec.1,
                z: vec.2,
            },
        }
    }
}

impl From<glam::Vec3> for PxExtendedVec3 {
    fn from(vec: glam::Vec3) -> Self {
        Self {
            obj: physx_sys::PxExtendedVec3 {
                x: vec.x as f64,
                y: vec.y as f64,
                z: vec.z as f64,
            },
        }
    }
}

impl From<physx_sys::PxExtendedVec3> for PxExtendedVec3 {
    fn from(bounds: physx_sys::PxExtendedVec3) -> Self {
        PxExtendedVec3 { obj: bounds }
    }
}

impl Into<physx_sys::PxExtendedVec3> for PxExtendedVec3 {
    fn into(self) -> physx_sys::PxExtendedVec3 {
        self.obj
    }
}

use crate::traits::Class;

#[repr(transparent)]
pub struct PxBounds3 {
    obj: physx_sys::PxBounds3,
}

impl PxBounds3 {
    /// Creates largest bounds that avoid floating point exceptions.
    pub fn max_bounds_extents() -> Self {
        unsafe {
            physx_sys::PxBounds3_new_1(
                &physx_sys::PxVec3_new_2(-f32::MAX / 4.0),
                &physx_sys::PxVec3_new_2(f32::MAX / 4.0),
            )
            .into()
        }
    }
}

crate::DeriveClassForNewType!(PxBounds3: PxBounds3);

impl From<physx_sys::PxBounds3> for PxBounds3 {
    fn from(bounds: physx_sys::PxBounds3) -> Self {
        PxBounds3 { obj: bounds }
    }
}

impl Into<physx_sys::PxBounds3> for PxBounds3 {
    fn into(self) -> physx_sys::PxBounds3 {
        self.obj
    }
}

impl Default for PxBounds3 {
    fn default() -> Self {
        Self::max_bounds_extents()
    }
}