Skip to content

Commit

Permalink
RE constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
W-Drew committed Jan 12, 2024
1 parent 573b349 commit 7c5df1b
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 12 deletions.
26 changes: 14 additions & 12 deletions include/RE/H/hkpConstraintAtom.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace RE
{
class hkpConstraintMotor;

struct hkpConstraintAtom
{
public:
Expand Down Expand Up @@ -150,23 +152,23 @@ namespace RE

struct hkpAngMotorConstraintAtom : public hkpConstraintAtom
{
bool enabled; // 02
uint8_t motorAxis; // 03
int16_t initializedOffset; // 04
int16_t previousTargetAngleOffset; // 06
int16_t correspondingAngLimitSolverResultOffset; // 08
float targetAngle; // 0C
uintptr_t motor; // 10
bool enabled; // 02
uint8_t motorAxis; // 03
int16_t initializedOffset; // 04
int16_t previousTargetAngleOffset; // 06
int16_t correspondingAngLimitSolverResultOffset; // 08
float targetAngle; // 0C
hkpConstraintMotor* motor; // 10
};
static_assert(sizeof(hkpAngMotorConstraintAtom) == 0x18);

struct hkpRagdollMotorConstraintAtom : public hkpConstraintAtom
{
bool enabled; // 02
int16_t initializedOffset; // 04
int16_t previousTargetAnglesOffset; // 06
hkMatrix3 target_bRca; // 10
uintptr_t motors[3]; // 40
bool enabled; // 02
int16_t initializedOffset; // 04
int16_t previousTargetAnglesOffset; // 06
hkMatrix3 target_bRca; // 10
hkpConstraintMotor* motors[3]; // 40
};
static_assert(sizeof(hkpRagdollMotorConstraintAtom) == 0x60);
}
108 changes: 108 additions & 0 deletions include/RE/H/hkpConstraintMotor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#pragma once

#include "RE/H/hkReferencedObject.h"

namespace RE
{
class hkpConstraintMotor : public hkReferencedObject
{
public:
enum class MotorType
{
kInvalid = 0,

kPosition,
kVelocity,
kSpring,
kCallback,

kNUM
};

inline static constexpr auto RTTI = RTTI_hkpConstraintMotor;
inline static constexpr auto VTABLE = VTABLE_hkpConstraintMotor;

// members
stl::enumeration<MotorType, uint8_t> type; // 10
};
static_assert(sizeof(hkpConstraintMotor) == 0x18);

class hkpLimitedForceConstraintMotor : public hkpConstraintMotor
{
public:
inline static constexpr auto RTTI = RTTI_hkpLimitedForceConstraintMotor;
inline static constexpr auto VTABLE = VTABLE_hkpLimitedForceConstraintMotor;

// members
float minForce; // 18
float maxForce; // 1C
};
static_assert(sizeof(hkpLimitedForceConstraintMotor) == 0x20);

class hkpPositionConstraintMotor : public hkpLimitedForceConstraintMotor
{
public:
inline static constexpr auto RTTI = RTTI_hkpPositionConstraintMotor;
inline static constexpr auto VTABLE = VTABLE_hkpPositionConstraintMotor;

// members
float tau; // 20
float damping; // 24
float proportionalRecoveryVelocity; // 28
float constantRecoveryVelocity; // 2C
};
static_assert(sizeof(hkpPositionConstraintMotor) == 0x30);

class hkpVelocityConstraintMotor : public hkpLimitedForceConstraintMotor
{
public:
inline static constexpr auto RTTI = RTTI_hkpVelocityConstraintMotor;
inline static constexpr auto VTABLE = VTABLE_hkpVelocityConstraintMotor;

// members
float tau; // 20
float targetVelocity; // 24
bool useConstraintTarget; // 28
};
static_assert(sizeof(hkpVelocityConstraintMotor) == 0x30);

class hkpSpringDamperConstraintMotor : public hkpLimitedForceConstraintMotor
{
public:
inline static constexpr auto RTTI = RTTI_hkpSpringDamperConstraintMotor;
inline static constexpr auto VTABLE = VTABLE_hkpSpringDamperConstraintMotor;

// members
float springConstant; // 20
float springDamping; // 24
};
static_assert(sizeof(hkpSpringDamperConstraintMotor) == 0x28);

class hkpCallbackConstraintMotor : public hkpLimitedForceConstraintMotor
{
public:
enum class CallbackType
{
kUnk = 0,

kUser0,
kUser1,
kUser2,

kNUM
};

inline static constexpr auto RTTI = RTTI_hkpCallbackConstraintMotor;
inline static constexpr auto VTABLE = VTABLE_hkpCallbackConstraintMotor;

using CallbackFunction = void(const hkpCallbackConstraintMotor& motor, const void* unk0, void* unk1);

// members
CallbackFunction* func; // 20
stl::enumeration<CallbackType, std::uint32_t> callbackType; // 28
std::uint64_t userData0; // 30
std::uint64_t userData1; // 38
std::uint64_t userData2; // 40
};
static_assert(sizeof(hkpCallbackConstraintMotor) == 0x48);
}
30 changes: 30 additions & 0 deletions include/RE/H/hkpLimitedHingeConstraintData.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,29 @@

#include "RE/H/hkpConstraintAtom.h"
#include "RE/H/hkpConstraintData.h"
#include "RE/H/hkpSolverResults.h"

namespace RE
{
class hkpLimitedHingeConstraintData : public hkpConstraintData
{
public:
enum SolverResultType
{
kMotor = 0,
kFriction,
kLimit,

kAngle0,
kAngle1,

kLinear0,
kLinear1,
kLinear2,

kNUM
};

inline static constexpr auto RTTI = RTTI_hkpLimitedHingeConstraintData;
inline static constexpr auto VTABLE = VTABLE_hkpLimitedHingeConstraintData;

Expand All @@ -23,6 +40,19 @@ namespace RE
};
static_assert(sizeof(Atoms) == 0xF0);

struct Runtime
{
inline float getCurrentAngle()
{
return solverResults[SolverResultType::kLimit].data * -1.f;
}

hkpSolverResults solverResults[SolverResultType::kNUM]; // 00
bool previousTargetInitialized; // 40
float previousTargetAngle; // 44
};
static_assert(sizeof(Runtime) == 0x48);

// members
Atoms atoms; // 18
};
Expand Down
31 changes: 31 additions & 0 deletions include/RE/H/hkpRagdollConstraintData.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,34 @@

#include "RE/H/hkpConstraintAtom.h"
#include "RE/H/hkpConstraintData.h"
#include "RE/H/hkpSolverResults.h"

namespace RE
{
class hkpRagdollConstraintData : public hkpConstraintData
{
public:
enum SolverResultType
{
kMotor0 = 0,
kMotor1,
kMotor2,

kFriction0,
kFriction1,
kFriction2,

kTwist,
kCone,
kPlane,

kLinear0,
kLinear1,
kLinear2,

kNUM
};

inline static constexpr auto RTTI = RTTI_hkpRagdollConstraintData;
inline static constexpr auto VTABLE = VTABLE_hkpRagdollConstraintData;

Expand All @@ -24,6 +46,15 @@ namespace RE
};
static_assert(sizeof(Atoms) == 0x160);

struct Runtime
{
hkpSolverResults solverResults[SolverResultType::kNUM]; // 00
bool previousTargetInitialized[3]; // 60
float previousTargetAngle[3]; // 64
float coneAngle; // 70
};
static_assert(sizeof(Runtime) == 0x74);

// members
Atoms atoms; // 18
};
Expand Down
14 changes: 14 additions & 0 deletions include/RE/H/hkpSolverResults.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

namespace RE
{

class hkpSolverResults
{
public:
float impulse; // 00
float data; // 04
};
static_assert(sizeof(hkpSolverResults) == 0x08);

}
2 changes: 2 additions & 0 deletions include/RE/Skyrim.h
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@
#include "RE/H/hkpConstraintData.h"
#include "RE/H/hkpConstraintInfo.h"
#include "RE/H/hkpConstraintInstance.h"
#include "RE/H/hkpConstraintMotor.h"
#include "RE/H/hkpConstraintOwner.h"
#include "RE/H/hkpContactListener.h"
#include "RE/H/hkpContactPointEvent.h"
Expand Down Expand Up @@ -1030,6 +1031,7 @@
#include "RE/H/hkpSimulationIsland.h"
#include "RE/H/hkpSingleShapeContainer.h"
#include "RE/H/hkpSolverInfo.h"
#include "RE/H/hkpSolverResults.h"
#include "RE/H/hkpSphereRepShape.h"
#include "RE/H/hkpSphereShape.h"
#include "RE/H/hkpTypedBroadPhaseHandle.h"
Expand Down

0 comments on commit 7c5df1b

Please sign in to comment.