commonlibsse_ng\re\h/
hkpMotion.rs

1use crate::re::hkBaseTypes::hkHalf;
2use crate::re::hkMatrix3::hkMatrix3;
3use crate::re::hkMotionState::hkMotionState;
4use crate::re::hkQuaternion::hkQuaternion;
5use crate::re::hkReferencedObject::hkReferencedObject;
6use crate::re::hkTransform::hkTransform;
7use crate::re::hkVector4::hkVector4;
8use crate::re::hkpKeyframedRigidMotion::hkpMaxSizeMotion;
9use crate::re::offsets_rtti::RTTI_hkpMotion;
10use crate::re::offsets_vtable::VTABLE_hkpMotion;
11use crate::re::{hkClass, hkStatisticsCollector};
12use crate::rel::id::VariantID;
13
14/// Represents a physics motion object in the Havok system.
15///
16/// Inherits from `hkReferencedObject` and manages motion properties like mass, inertia, and velocity.
17#[repr(C)]
18#[derive(Debug)]
19pub struct hkpMotion {
20    /// Base class `hkReferencedObject`.
21    pub __base: hkReferencedObject,
22
23    /// Motion type enumeration.
24    /// - Offset: 0x010
25    pub type_: MotionType_CEnum,
26
27    /// Counter for deactivation integration.
28    /// - Offset: 0x011
29    pub deactivationIntegrateCounter: u8,
30
31    /// Number of inactive frames for deactivation.
32    /// - Offset: 0x012
33    pub deactivationNumInactiveFrames: [u16; 2],
34
35    /// Padding to align memory.
36    /// - Offset: 0x016
37    pub pad016: u16,
38
39    /// Padding to align memory.
40    /// - Offset: 0x018
41    pub pad018: u64,
42
43    /// Motion state data.
44    /// - Offset: 0x020
45    pub motionState: hkMotionState,
46
47    /// Inertia tensor and inverse mass.
48    /// - Offset: 0x0D0
49    pub inertiaAndMassInv: hkVector4,
50
51    /// Linear velocity vector.
52    /// - Offset: 0x0E0
53    pub linearVelocity: hkVector4,
54
55    /// Angular velocity vector.
56    /// - Offset: 0x0F0
57    pub angularVelocity: hkVector4,
58
59    /// Deactivation reference positions.
60    /// - Offset: 0x100
61    pub deactivationRefPosition: [hkVector4; 2],
62
63    /// Deactivation reference orientations.
64    /// - Offset: 0x120
65    pub deactivationRefOrientation: [u32; 2],
66
67    /// Pointer to saved motion data.
68    /// - Offset: 0x128
69    pub savedMotion: *mut hkpMaxSizeMotion,
70
71    /// Saved quality type index.
72    /// - Offset: 0x130
73    pub savedQualityTypeIndex: u16,
74
75    /// Padding to align memory.
76    /// - Offset: 0x132
77    pub pad132: u16,
78
79    /// Gravity factor.
80    /// - Offset: 0x134
81    pub gravityFactor: hkHalf,
82
83    /// Padding to align memory.
84    /// - Offset: 0x138
85    pub pad138: u64,
86}
87
88// Compile-time memory layout verification
89const _: () = {
90    assert!(core::mem::offset_of!(hkpMotion, __base) == 0x0);
91    assert!(core::mem::offset_of!(hkpMotion, type_) == 0x010);
92    assert!(core::mem::offset_of!(hkpMotion, deactivationIntegrateCounter) == 0x011);
93    assert!(core::mem::offset_of!(hkpMotion, deactivationNumInactiveFrames) == 0x012);
94    assert!(core::mem::offset_of!(hkpMotion, pad016) == 0x016);
95    assert!(core::mem::offset_of!(hkpMotion, pad018) == 0x018);
96    assert!(core::mem::offset_of!(hkpMotion, motionState) == 0x020);
97    assert!(core::mem::offset_of!(hkpMotion, inertiaAndMassInv) == 0x0D0);
98    assert!(core::mem::offset_of!(hkpMotion, linearVelocity) == 0x0E0);
99    assert!(core::mem::offset_of!(hkpMotion, angularVelocity) == 0x0F0);
100    assert!(core::mem::offset_of!(hkpMotion, deactivationRefPosition) == 0x100);
101    assert!(core::mem::offset_of!(hkpMotion, deactivationRefOrientation) == 0x120);
102    assert!(core::mem::offset_of!(hkpMotion, savedMotion) == 0x128);
103    assert!(core::mem::offset_of!(hkpMotion, savedQualityTypeIndex) == 0x130);
104    assert!(core::mem::offset_of!(hkpMotion, pad132) == 0x132);
105    assert!(core::mem::offset_of!(hkpMotion, gravityFactor) == 0x134);
106    assert!(core::mem::offset_of!(hkpMotion, pad138) == 0x138);
107    assert!(core::mem::size_of::<hkpMotion>() == 0x140);
108};
109
110/// Enumeration of motion types for `hkpMotion`.
111#[commonlibsse_ng_derive_internal::ffi_enum]
112#[repr(u8)]
113#[derive(Debug, Clone, Copy)]
114pub enum MotionType {
115    Invalid = 0,
116    Dynamic = 1,
117    SphereInertia = 2,
118    BoxInertia = 3,
119    Keyframed = 4,
120    Fixed = 5,
121    ThinBoxInertia = 6,
122    Character = 7,
123    Total = 8,
124}
125
126impl hkpMotion {
127    /// RTTI identifier for this type.
128    pub const RTTI: VariantID = RTTI_hkpMotion;
129
130    /// Virtual function table addresses.
131    pub const VTABLE: [VariantID; 1] = VTABLE_hkpMotion;
132
133    /// Number of inactive frames required to deactivate.
134    pub const NUM_INACTIVE_FRAMES_TO_DEACTIVATE: i32 = 5;
135
136    /// Creates a new `hkpMotion` instance with default values.
137    #[inline]
138    pub fn new() -> Self {
139        Self {
140            __base: hkReferencedObject::new(),
141            type_: MotionType_CEnum::Invalid,
142            deactivationIntegrateCounter: 0,
143            deactivationNumInactiveFrames: [0; 2],
144            pad016: 0,
145            pad018: 0,
146            motionState: hkMotionState::default(),
147            inertiaAndMassInv: hkVector4::default(),
148            linearVelocity: hkVector4::default(),
149            angularVelocity: hkVector4::default(),
150            deactivationRefPosition: [hkVector4::default(); 2],
151            deactivationRefOrientation: [0; 2],
152            savedMotion: core::ptr::null_mut(),
153            savedQualityTypeIndex: 0,
154            pad132: 0,
155            gravityFactor: hkHalf::default(), // Assuming hkHalf has a default
156            pad138: 0,
157        }
158    }
159
160    /// Gets the mass of the motion object.
161    #[inline]
162    pub fn GetMass(&self) -> f32 {
163        let mass_inv = self.inertiaAndMassInv.get_component(3); // Assuming hkVector4 has a method to access components
164        if mass_inv != 0.0 { 1.0 / mass_inv } else { 0.0 }
165    }
166}
167
168/// Virtual function table for `hkpMotion`.
169#[repr(C)]
170pub struct hkpMotionVtbl {
171    /// Destructor function pointer.
172    pub CxxDrop: fn(this: &mut hkpMotion),
173
174    /// Gets the class type (inherited from hkReferencedObject).
175    pub GetClassType: fn(this: &hkpMotion) -> Option<&hkClass>,
176
177    /// Calculates content statistics (inherited from hkReferencedObject).
178    pub CalcContentStatistics:
179        fn(this: &hkpMotion, collector: &mut hkStatisticsCollector, cls: Option<&hkClass>),
180
181    /// Sets the mass.
182    pub SetMass: fn(this: &mut hkpMotion, a_mass: f32),
183
184    /// Sets the inverse mass.
185    pub SetMassInv: fn(this: &mut hkpMotion, a_massInv: f32),
186
187    /// Gets the local inertia tensor.
188    pub GetInertiaLocal: fn(this: &hkpMotion, a_inertiaOut: &mut hkMatrix3),
189
190    /// Gets the world inertia tensor.
191    pub GetInertiaWorld: fn(this: &hkpMotion, a_inertiaOut: &mut hkMatrix3),
192
193    /// Sets the local inertia tensor.
194    pub SetInertiaLocal: fn(this: &mut hkpMotion, a_inertia: &hkMatrix3),
195
196    /// Sets the local inverse inertia tensor.
197    pub SetInertiaInvLocal: fn(this: &mut hkpMotion, a_inertiaInv: &hkMatrix3),
198
199    /// Gets the local inverse inertia tensor.
200    pub GetInertiaInvLocal: fn(this: &hkpMotion, a_inertiaInvOut: &mut hkMatrix3),
201
202    /// Gets the world inverse inertia tensor.
203    pub GetInertiaInvWorld: fn(this: &hkpMotion, a_inertiaInvOut: &mut hkMatrix3),
204
205    /// Sets the center of mass in local space.
206    pub SetCenterOfMassInLocal: fn(this: &mut hkpMotion, a_centerOfMass: hkVector4),
207
208    /// Sets the position.
209    pub SetPosition: fn(this: &mut hkpMotion, a_position: hkVector4),
210
211    /// Sets the rotation.
212    pub SetRotation: fn(this: &mut hkpMotion, a_rotation: hkQuaternion),
213
214    /// Sets both position and rotation.
215    pub SetPositionAndRotation:
216        fn(this: &mut hkpMotion, a_position: hkVector4, a_rotation: hkQuaternion),
217
218    /// Sets the transform.
219    pub SetTransform: fn(this: &mut hkpMotion, a_transform: hkTransform),
220
221    /// Sets the linear velocity.
222    pub SetLinearVelocity: fn(this: &mut hkpMotion, a_newVel: hkVector4),
223
224    /// Sets the angular velocity.
225    pub SetAngularVelocity: fn(this: &mut hkpMotion, a_newVel: hkVector4),
226
227    /// Gets the projected point velocity.
228    pub GetProjectedPointVelocity: fn(
229        this: &hkpMotion,
230        a_point: hkVector4,
231        a_normal: hkVector4,
232        a_velOut: &mut f32,
233        a_invVirtMassOut: &mut f32,
234    ),
235
236    /// Applies a linear impulse.
237    pub ApplyLinearImpulse: fn(this: &mut hkpMotion, a_impulse: hkVector4),
238
239    /// Applies a point impulse.
240    pub ApplyPointImpulse: fn(this: &mut hkpMotion, a_impulse: hkVector4, a_point: hkVector4),
241
242    /// Applies an angular impulse.
243    pub ApplyAngularImpulse: fn(this: &mut hkpMotion, a_impulse: hkVector4),
244
245    /// Applies a force.
246    pub ApplyForce: fn(this: &mut hkpMotion, a_deltaTime: f32, a_force: hkVector4),
247
248    /// Applies a force at a point.
249    pub ApplyForceAtPoint:
250        fn(this: &mut hkpMotion, a_deltaTime: f32, a_force: hkVector4, a_point: hkVector4),
251
252    /// Applies a torque.
253    pub ApplyTorque: fn(this: &mut hkpMotion, a_deltaTime: f32, a_torque: hkVector4),
254
255    /// Gets motion state, velocities, and deactivation type.
256    pub GetMotionStateAndVelocitiesAndDeactivationType:
257        fn(this: &hkpMotion, a_motionOut: &mut hkpMotion),
258}
259
260impl Default for hkpMotion {
261    #[inline]
262    fn default() -> Self {
263        Self::new()
264    }
265}