mirror of
https://github.com/zeldaret/botw
synced 2026-08-10 11:13:50 -04:00
ksys/phys: Add more RigidBody functions and Havok utils
This commit is contained in:
@@ -59,6 +59,8 @@ add_library(hkStubs OBJECT
|
||||
Havok/Common/Base/Types/Physics/MotionState/hkMotionState.h
|
||||
Havok/Common/Base/Types/Properties/hkSimpleProperty.h
|
||||
|
||||
Havok/Common/GeometryUtilities/Inertia/hkInertiaTensorComputer.h
|
||||
|
||||
Havok/Common/Serialize/Resource/hkResource.h
|
||||
Havok/Common/Serialize/Util/hkNativePackfileUtils.h
|
||||
Havok/Common/Serialize/Util/hkRootLevelContainer.h
|
||||
@@ -108,6 +110,7 @@ add_library(hkStubs OBJECT
|
||||
Havok/Physics2012/Dynamics/Entity/hkpEntity.h
|
||||
Havok/Physics2012/Dynamics/Entity/hkpRigidBody.h
|
||||
Havok/Physics2012/Dynamics/Entity/hkpRigidBodyCinfo.h
|
||||
Havok/Physics2012/Dynamics/Inertia/hkpInertiaTensorComputer.h
|
||||
Havok/Physics2012/Dynamics/Motion/hkpMotion.h
|
||||
Havok/Physics2012/Dynamics/Motion/Rigid/hkpBoxMotion.h
|
||||
Havok/Physics2012/Dynamics/Motion/Rigid/hkpFixedRigidMotion.h
|
||||
|
||||
@@ -8,33 +8,57 @@ public:
|
||||
|
||||
HK_FORCE_INLINE hkFloat32& operator()(int row, int col);
|
||||
HK_FORCE_INLINE const hkFloat32& operator()(int row, int col) const;
|
||||
template <int Row, int Col>
|
||||
HK_FORCE_INLINE hkSimdFloat32 get() const;
|
||||
template <int Row, int Col>
|
||||
HK_FORCE_INLINE void set(hkSimdFloat32Parameter s);
|
||||
|
||||
HK_FORCE_INLINE hkVector4f& getColumn(int i);
|
||||
HK_FORCE_INLINE const hkVector4f& getColumn(int i) const;
|
||||
template <int I>
|
||||
HK_FORCE_INLINE const hkVector4f& getColumn() const;
|
||||
|
||||
HK_FORCE_INLINE void getRows(hkVector4f& r0, hkVector4f& r1, hkVector4f& r2) const;
|
||||
|
||||
HK_FORCE_INLINE void setZero();
|
||||
HK_FORCE_INLINE void setIdentity();
|
||||
|
||||
hkVector4f m_col0;
|
||||
hkVector4f m_col1;
|
||||
hkVector4f m_col2;
|
||||
};
|
||||
|
||||
hkFloat32& hkMatrix3f::operator()(int row, int col) {
|
||||
inline hkFloat32& hkMatrix3f::operator()(int row, int col) {
|
||||
return getColumn(col)(row);
|
||||
}
|
||||
|
||||
const hkFloat32& hkMatrix3f::operator()(int row, int col) const {
|
||||
inline const hkFloat32& hkMatrix3f::operator()(int row, int col) const {
|
||||
return getColumn(col)(row);
|
||||
}
|
||||
|
||||
hkVector4f& hkMatrix3f::getColumn(int i) {
|
||||
template <int Row, int Col>
|
||||
inline hkSimdFloat32 hkMatrix3f::get() const {
|
||||
return getColumn<Col>().template getComponent<Row>();
|
||||
}
|
||||
|
||||
template <int Row, int Col>
|
||||
inline void hkMatrix3f::set(hkSimdFloat32Parameter s) {
|
||||
getColumn<Col>().template setComponent<Row>(s);
|
||||
}
|
||||
|
||||
inline hkVector4f& hkMatrix3f::getColumn(int i) {
|
||||
return (&m_col0)[i];
|
||||
}
|
||||
|
||||
const hkVector4f& hkMatrix3f::getColumn(int i) const {
|
||||
inline const hkVector4f& hkMatrix3f::getColumn(int i) const {
|
||||
return (&m_col0)[i];
|
||||
}
|
||||
|
||||
template <int I>
|
||||
inline const hkVector4f& hkMatrix3f::getColumn() const {
|
||||
return (&m_col0)[I];
|
||||
}
|
||||
|
||||
inline void hkMatrix3f::getRows(hkVector4f& r0, hkVector4f& r1, hkVector4f& r2) const {
|
||||
hkVector4f c0;
|
||||
c0.set(m_col0(0), m_col1(0), m_col2(0));
|
||||
@@ -47,3 +71,16 @@ inline void hkMatrix3f::getRows(hkVector4f& r0, hkVector4f& r1, hkVector4f& r2)
|
||||
r1 = c1;
|
||||
r2 = c2;
|
||||
}
|
||||
|
||||
inline void hkMatrix3f::setZero() {
|
||||
m_col0.setZero();
|
||||
m_col1.setZero();
|
||||
m_col2.setZero();
|
||||
}
|
||||
|
||||
inline void hkMatrix3f::setIdentity() {
|
||||
hkMatrix3f* __restrict d = this;
|
||||
d->m_col0 = hkVector4f::getConstant<HK_QUADREAL_1000>();
|
||||
d->m_col1 = hkVector4f::getConstant<HK_QUADREAL_0100>();
|
||||
d->m_col2 = hkVector4f::getConstant<HK_QUADREAL_0010>();
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
|
||||
HK_FORCE_INLINE void set(const hkRotationf& r, hkVector4fParameter t);
|
||||
HK_FORCE_INLINE void set(hkQuaternionfParameter q, hkVector4fParameter t);
|
||||
HK_FORCE_INLINE void setIdentity();
|
||||
|
||||
hkRotationf m_rotation;
|
||||
hkVector4f m_translation;
|
||||
@@ -54,3 +55,8 @@ inline void hkTransformf::set(const hkQuaternionf& q, const hkVector4f& t) {
|
||||
m_rotation.set(q);
|
||||
m_translation = t;
|
||||
}
|
||||
|
||||
inline void hkTransformf::setIdentity() {
|
||||
m_rotation.setIdentity();
|
||||
m_translation.setZero();
|
||||
}
|
||||
|
||||
@@ -141,6 +141,10 @@ public:
|
||||
hkSimdFloat32 getY() const { return getComponent<1>(); }
|
||||
hkSimdFloat32 getZ() const { return getComponent<2>(); }
|
||||
hkSimdFloat32 getW() const { return getComponent<3>(); }
|
||||
template <int I>
|
||||
HK_FORCE_INLINE void setComponent(hkSimdFloat32Parameter val) {
|
||||
v[I] = val;
|
||||
}
|
||||
void setComponent(int i, hkSimdFloat32Parameter val) { v[i] = val; }
|
||||
void setX(hkSimdFloat32Parameter val) { setComponent(0, val); }
|
||||
void setY(hkSimdFloat32Parameter val) { setComponent(1, val); }
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
#pragma once
|
||||
|
||||
#include <Havok/Common/Base/hkBase.h>
|
||||
|
||||
struct hkGeometry;
|
||||
struct hkStridedVertices;
|
||||
|
||||
struct hkMassProperties {
|
||||
HK_DECLARE_CLASS_ALLOCATOR(hkMassProperties)
|
||||
HK_DECLARE_REFLECTION()
|
||||
|
||||
hkMassProperties() : m_volume(0), m_mass(0) {
|
||||
m_centerOfMass.setZero();
|
||||
m_inertiaTensor.setZero();
|
||||
}
|
||||
|
||||
explicit hkMassProperties(hkFinishLoadedObjectFlag flag) {}
|
||||
|
||||
void scaleToDensity(hkSimdRealParameter density);
|
||||
void scaleToMass(hkSimdRealParameter newMass);
|
||||
|
||||
hkReal m_volume;
|
||||
hkReal m_mass;
|
||||
hkVector4 m_centerOfMass;
|
||||
hkMatrix3 m_inertiaTensor;
|
||||
};
|
||||
|
||||
struct hkMassElement {
|
||||
HK_DECLARE_CLASS_ALLOCATOR(hkMassElement)
|
||||
|
||||
HK_FORCE_INLINE hkMassElement() { m_transform.setIdentity(); }
|
||||
|
||||
HK_FORCE_INLINE hkMassElement(const hkMassProperties& properties, const hkTransform& transform)
|
||||
: m_properties(properties), m_transform(transform) {}
|
||||
|
||||
hkMassProperties m_properties;
|
||||
hkTransform m_transform;
|
||||
};
|
||||
|
||||
class hkInertiaTensorComputer {
|
||||
public:
|
||||
static hkResult computeSphereVolumeMassProperties(hkReal radius, hkReal mass,
|
||||
hkMassProperties& result);
|
||||
|
||||
static hkResult computeBoxVolumeMassProperties(hkVector4Parameter halfExtents, hkReal mass,
|
||||
hkMassProperties& result);
|
||||
|
||||
static hkResult computeBoxVolumeMassPropertiesDiagonalized(hkVector4Parameter halfExtents,
|
||||
hkReal mass,
|
||||
hkVector4& inertiaDiagonal,
|
||||
hkReal& volume);
|
||||
|
||||
static hkResult computeCapsuleVolumeMassProperties(hkVector4Parameter startAxis,
|
||||
hkVector4Parameter endAxis, hkReal radius,
|
||||
hkReal mass, hkMassProperties& result);
|
||||
|
||||
static hkResult computeSphereSurfaceMassProperties(hkReal radius, hkReal mass,
|
||||
hkReal surfaceThickness,
|
||||
hkMassProperties& result);
|
||||
|
||||
static hkResult computeBoxSurfaceMassProperties(hkVector4Parameter halfExtents, hkReal mass,
|
||||
hkReal surfaceThickness,
|
||||
hkMassProperties& result);
|
||||
|
||||
static hkResult computeTriangleSurfaceMassProperties(hkVector4Parameter v0,
|
||||
hkVector4Parameter v1,
|
||||
hkVector4Parameter v2, hkReal mass,
|
||||
hkReal surfaceThickness,
|
||||
hkMassProperties& result);
|
||||
|
||||
static hkResult computeCylinderVolumeMassProperties(hkVector4Parameter startAxis,
|
||||
hkVector4Parameter endAxis, hkReal radius,
|
||||
hkReal mass, hkMassProperties& result);
|
||||
|
||||
static hkResult computeConvexHullMassProperties(const hkStridedVertices& vertices,
|
||||
hkReal radius, hkMassProperties& result);
|
||||
|
||||
using ConvexHullMassPropertiesFunction = hkResult (*)(const hkStridedVertices&, hkReal,
|
||||
hkMassProperties&);
|
||||
|
||||
static ConvexHullMassPropertiesFunction s_computeConvexHullMassPropertiesFunction;
|
||||
|
||||
static hkResult computeVertexHullVolumeMassProperties(const hkReal* vertexIn, int striding,
|
||||
int numVertices, hkReal mass,
|
||||
hkMassProperties& result);
|
||||
|
||||
static hkResult computeVertexCloudMassProperties(const hkReal* vertexIn, int striding,
|
||||
int numVertices, hkReal mass,
|
||||
hkMassProperties& result);
|
||||
|
||||
static hkResult computeGeometrySurfaceMassProperties(const hkGeometry* geom,
|
||||
hkReal surfaceThickness,
|
||||
hkBool distributeUniformly, hkReal mass,
|
||||
hkMassProperties& result);
|
||||
|
||||
static void computeGeometryVolumeMassProperties(const hkGeometry* geom, hkReal mass,
|
||||
hkMassProperties& result);
|
||||
|
||||
static hkResult computeGeometryVolumeMassPropertiesChecked(const hkGeometry* geom, hkReal mass,
|
||||
hkMassProperties& result);
|
||||
|
||||
static hkResult combineMassProperties(const hkArray<hkMassElement>& elements,
|
||||
hkMassProperties& result);
|
||||
|
||||
static void simplifyInertiaTensorToOrientedParticle(hkMatrix3& inertia);
|
||||
|
||||
static void convertInertiaTensorToPrincipleAxis(hkMatrix3& inertia,
|
||||
hkRotation& principleAxisOut);
|
||||
|
||||
static void shiftInertiaToCom(hkVector4Parameter shift, hkSimdRealParameter mass,
|
||||
hkMatrix3& inertia);
|
||||
|
||||
static void shiftInertiaFromCom(hkVector4Parameter shift, hkSimdRealParameter mass,
|
||||
hkMatrix3& inertia);
|
||||
};
|
||||
@@ -141,3 +141,11 @@ public:
|
||||
struct hkConstraintInternal* m_internal;
|
||||
hkUint32 m_uid;
|
||||
};
|
||||
|
||||
inline const hkpConstraintData* hkpConstraintInstance::getData() const {
|
||||
return m_data;
|
||||
}
|
||||
|
||||
inline hkpConstraintData* hkpConstraintInstance::getDataRw() const {
|
||||
return m_data;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <Havok/Common/GeometryUtilities/Inertia/hkInertiaTensorComputer.h>
|
||||
|
||||
class hkcdShape;
|
||||
class hkpConstraintInstance;
|
||||
class hkpRigidBody;
|
||||
class hkpRigidBodyCinfo;
|
||||
class hkpShape;
|
||||
|
||||
class hkpInertiaTensorComputer : public hkInertiaTensorComputer {
|
||||
public:
|
||||
static void computeShapeVolumeMassProperties(const hkcdShape* shape, hkReal mass,
|
||||
hkMassProperties& result);
|
||||
|
||||
static void setShapeVolumeMassProperties(const hkpShape* shape, hkReal mass,
|
||||
hkpRigidBodyCinfo& bodyInfo);
|
||||
|
||||
static void setMassProperties(const hkMassProperties& props, hkpRigidBodyCinfo& bodyInfo);
|
||||
|
||||
static void setAndScaleToDensity(const hkMassProperties& props, hkSimdRealParameter density,
|
||||
hkpRigidBodyCinfo& bodyInfo);
|
||||
|
||||
static void setAndScaleToMass(const hkMassProperties& props, hkSimdRealParameter mass,
|
||||
hkpRigidBodyCinfo& bodyInfo);
|
||||
|
||||
static void clipInertia(hkReal maxInertiaRatio, hkpRigidBodyCinfo& bodyInfo);
|
||||
|
||||
static void optimizeInertiasOfConstraintTree(hkpConstraintInstance* const* constraints,
|
||||
int numConstraints, hkpRigidBody* rootBody,
|
||||
hkReal inertiaFactorHint = 1.5f);
|
||||
};
|
||||
Reference in New Issue
Block a user