commonlibsse_ng\re\h/
hkpKeyframedRigidMotion.rs

1use core::ops::{Add as _, Sub as _};
2
3use crate::re::hkMatrix3::hkMatrix3;
4use crate::re::hkVector4::hkVector4;
5use crate::re::hkpMotion::{MotionType, hkpMotion};
6use crate::re::offsets_rtti::RTTI_hkpKeyframedRigidMotion;
7use crate::re::offsets_rtti::RTTI_hkpMaxSizeMotion;
8use crate::re::offsets_vtable::VTABLE_hkpKeyframedRigidMotion;
9use crate::re::{hkClass, hkStatisticsCollector};
10use crate::rel::id::VariantID;
11
12use super::hkQuaternion::hkQuaternion;
13use super::hkTransform::hkTransform;
14
15/// Represents a keyframed rigid motion in the Havok system.
16///
17/// Inherits from `hkpMotion` and provides overrides for a keyframed (non-dynamic) motion type.
18///
19/// # Memory Layout:
20/// - `__base`: Base class `hkpMotion` (0x00 - 0x13F)
21#[repr(C)]
22#[derive(Debug)]
23pub struct hkpKeyframedRigidMotion {
24    /// Base class `hkpMotion`.
25    /// - Offset: 0x00
26    pub __base: hkpMotion,
27}
28
29// Compile-time memory layout verification
30const _: () = {
31    assert!(core::mem::offset_of!(hkpKeyframedRigidMotion, __base) == 0x0);
32    assert!(core::mem::size_of::<hkpKeyframedRigidMotion>() == 0x140);
33};
34
35impl hkpKeyframedRigidMotion {
36    /// RTTI identifier for this type.
37    pub const RTTI: VariantID = RTTI_hkpKeyframedRigidMotion;
38
39    /// Virtual function table addresses.
40    pub const VTABLE: [VariantID; 1] = VTABLE_hkpKeyframedRigidMotion;
41
42    /// Creates a new `hkpKeyframedRigidMotion` with default values.
43    #[inline]
44    pub fn new() -> Self {
45        let mut motion = hkpMotion::new();
46        motion.type_ = MotionType::Keyframed.into(); // Set to keyframed motion type
47        Self { __base: motion }
48    }
49
50    /// Computes the velocity of a point in world space.
51    #[inline]
52    pub fn GetPointVelocity(&self, a_point: &hkVector4) -> hkVector4 {
53        let center_of_mass_in_world = self.__base.motionState.sweptTransform.centerOfMass1;
54        let relative_point = a_point.sub(center_of_mass_in_world);
55        self.__base.linearVelocity.add(self.__base.angularVelocity.Cross(relative_point))
56    }
57}
58
59/// Virtual function table for `hkpKeyframedRigidMotion`.
60#[repr(C)]
61pub struct hkpKeyframedRigidMotionVtbl {
62    /// Destructor function pointer.
63    pub CxxDrop: fn(this: &mut hkpKeyframedRigidMotion),
64
65    /// Gets the class type (inherited from hkReferencedObject).
66    pub GetClassType: fn(this: &hkpKeyframedRigidMotion) -> Option<&hkClass>,
67
68    /// Calculates content statistics (inherited from hkReferencedObject).
69    pub CalcContentStatistics: fn(
70        this: &hkpKeyframedRigidMotion,
71        collector: &mut hkStatisticsCollector,
72        cls: Option<&hkClass>,
73    ),
74
75    /// Sets the mass (no-op for keyframed motion).
76    pub SetMass: fn(this: &mut hkpKeyframedRigidMotion, a_mass: f32),
77
78    /// Sets the inverse mass (no-op for keyframed motion).
79    pub SetMassInv: fn(this: &mut hkpKeyframedRigidMotion, a_massInv: f32),
80
81    /// Gets the local inertia tensor.
82    pub GetInertiaLocal: fn(this: &hkpKeyframedRigidMotion, a_inertiaOut: &mut hkMatrix3),
83
84    /// Gets the world inertia tensor.
85    pub GetInertiaWorld: fn(this: &hkpKeyframedRigidMotion, a_inertiaOut: &mut hkMatrix3),
86
87    /// Sets the local inertia tensor (no-op for keyframed motion).
88    pub SetInertiaLocal: fn(this: &mut hkpKeyframedRigidMotion, a_inertia: &hkMatrix3),
89
90    /// Sets the local inverse inertia tensor (no-op for keyframed motion).
91    pub SetInertiaInvLocal: fn(this: &mut hkpKeyframedRigidMotion, a_inertiaInv: &hkMatrix3),
92
93    /// Gets the local inverse inertia tensor.
94    pub GetInertiaInvLocal: fn(this: &hkpKeyframedRigidMotion, a_inertiaInvOut: &mut hkMatrix3),
95
96    /// Gets the world inverse inertia tensor.
97    pub GetInertiaInvWorld: fn(this: &hkpKeyframedRigidMotion, a_inertiaInvOut: &mut hkMatrix3),
98
99    /// Sets the center of mass in local space (inherited from hkpMotion).
100    pub SetCenterOfMassInLocal: fn(this: &mut hkpKeyframedRigidMotion, a_centerOfMass: hkVector4),
101
102    /// Sets the position (inherited from hkpMotion).
103    pub SetPosition: fn(this: &mut hkpKeyframedRigidMotion, a_position: hkVector4),
104
105    /// Sets the rotation (inherited from hkpMotion).
106    pub SetRotation: fn(this: &mut hkpKeyframedRigidMotion, a_rotation: hkQuaternion),
107
108    /// Sets both position and rotation (inherited from hkpMotion).
109    pub SetPositionAndRotation:
110        fn(this: &mut hkpKeyframedRigidMotion, a_position: hkVector4, a_rotation: hkQuaternion),
111
112    /// Sets the transform (inherited from hkpMotion).
113    pub SetTransform: fn(this: &mut hkpKeyframedRigidMotion, a_transform: hkTransform),
114
115    /// Sets the linear velocity (inherited from hkpMotion).
116    pub SetLinearVelocity: fn(this: &mut hkpKeyframedRigidMotion, a_newVel: hkVector4),
117
118    /// Sets the angular velocity (inherited from hkpMotion).
119    pub SetAngularVelocity: fn(this: &mut hkpKeyframedRigidMotion, a_newVel: hkVector4),
120
121    /// Gets the projected point velocity.
122    pub GetProjectedPointVelocity: fn(
123        this: &hkpKeyframedRigidMotion,
124        a_point: hkVector4,
125        a_normal: hkVector4,
126        a_velOut: &mut f32,
127        a_invVirtMassOut: &mut f32,
128    ),
129
130    /// Applies a linear impulse (no-op for keyframed motion).
131    pub ApplyLinearImpulse: fn(this: &mut hkpKeyframedRigidMotion, a_impulse: hkVector4),
132
133    /// Applies a point impulse (no-op for keyframed motion).
134    pub ApplyPointImpulse:
135        fn(this: &mut hkpKeyframedRigidMotion, a_impulse: hkVector4, a_point: hkVector4),
136
137    /// Applies an angular impulse (no-op for keyframed motion).
138    pub ApplyAngularImpulse: fn(this: &mut hkpKeyframedRigidMotion, a_impulse: hkVector4),
139
140    /// Applies a force (no-op for keyframed motion).
141    pub ApplyForce: fn(this: &mut hkpKeyframedRigidMotion, a_deltaTime: f32, a_force: hkVector4),
142
143    /// Applies a force at a point (no-op for keyframed motion).
144    pub ApplyForceAtPoint: fn(
145        this: &mut hkpKeyframedRigidMotion,
146        a_deltaTime: f32,
147        a_force: hkVector4,
148        a_point: hkVector4,
149    ),
150
151    /// Applies a torque (no-op for keyframed motion).
152    pub ApplyTorque: fn(this: &mut hkpKeyframedRigidMotion, a_deltaTime: f32, a_torque: hkVector4),
153
154    /// Gets motion state, velocities, and deactivation type (inherited from hkpMotion).
155    pub GetMotionStateAndVelocitiesAndDeactivationType:
156        fn(this: &hkpKeyframedRigidMotion, a_motionOut: &mut hkpMotion),
157
158    /// Sets the step position (virtual function).
159    pub SetStepPosition: fn(this: &mut hkpKeyframedRigidMotion, a_position: f32, a_timestep: f32),
160
161    /// Sets the stored motion (virtual function).
162    pub SetStoredMotion:
163        fn(this: &mut hkpKeyframedRigidMotion, a_savedMotion: Option<&mut hkpMaxSizeMotion>),
164}
165
166impl Default for hkpKeyframedRigidMotion {
167    #[inline]
168    fn default() -> Self {
169        Self::new()
170    }
171}
172
173/// Represents a maximum-size keyframed rigid motion in the Havok system.
174///
175/// Inherits from `hkpKeyframedRigidMotion` without adding new fields.
176///
177/// # Memory Layout:
178/// - `__base`: Base class `hkpKeyframedRigidMotion` (0x00 - 0x13F)
179#[repr(C)]
180pub struct hkpMaxSizeMotion {
181    /// Base class `hkpKeyframedRigidMotion`.
182    /// - Offset: 0x00
183    pub __base: hkpKeyframedRigidMotion,
184}
185
186// Compile-time memory layout verification
187const _: () = {
188    assert!(core::mem::offset_of!(hkpMaxSizeMotion, __base) == 0x0);
189    assert!(core::mem::size_of::<hkpMaxSizeMotion>() == 0x140);
190};
191
192impl hkpMaxSizeMotion {
193    /// RTTI identifier for this type.
194    pub const RTTI: VariantID = RTTI_hkpMaxSizeMotion;
195
196    /// Creates a new `hkpMaxSizeMotion` with default values.
197    #[inline]
198    pub fn new() -> Self {
199        Self { __base: hkpKeyframedRigidMotion::new() }
200    }
201}
202
203impl Default for hkpMaxSizeMotion {
204    #[inline]
205    fn default() -> Self {
206        Self::new()
207    }
208}