Havok: Add hkpConvexTransformShape and hkQsTransform (stub)

This commit is contained in:
Léo Lam 2022-01-30 20:03:44 +01:00
parent 3a2ba7a23a
commit 9c68ef62b5
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
10 changed files with 235 additions and 0 deletions

View File

@ -21,6 +21,9 @@ add_library(hkStubs OBJECT
Havok/Common/Base/Math/Matrix/hkRotationf.h
Havok/Common/Base/Math/Matrix/hkTransform.h
Havok/Common/Base/Math/Matrix/hkTransformf.h
Havok/Common/Base/Math/QsTransform/hkQsTransform.h
Havok/Common/Base/Math/QsTransform/hkQsTransformf.h
Havok/Common/Base/Math/QsTransform/hkQsTransformf.inl
Havok/Common/Base/Math/Quaternion/hkQuaternion.h
Havok/Common/Base/Math/Quaternion/hkQuaternionf.h
Havok/Common/Base/Math/Quaternion/hkQuaternionf.inl
@ -111,6 +114,7 @@ add_library(hkStubs OBJECT
Havok/Physics2012/Collide/Shape/Convex/hkpConvexShape.h
Havok/Physics2012/Collide/Shape/Convex/Box/hkpBoxShape.h
Havok/Physics2012/Collide/Shape/Convex/Capsule/hkpCapsuleShape.h
Havok/Physics2012/Collide/Shape/Convex/ConvexTransform/hkpConvexTransformShape.h
Havok/Physics2012/Collide/Shape/HeightField/hkpSphereRepShape.h
Havok/Physics2012/Collide/Shape/Query/hkpRayShapeCollectionFilter.h
Havok/Physics2012/Collide/Shape/Query/hkpShapeRayCastInput.h

View File

@ -0,0 +1,5 @@
#pragma once
#include <Havok/Common/Base/Math/QsTransform/hkQsTransformf.h>
using hkQsTransform = hkQsTransformf;

View File

@ -0,0 +1,41 @@
#pragma once
class hkQsTransformf {
public:
// Initialisation tags.
enum class IdentityInitializer {};
enum class ZeroInitializer {};
HK_FORCE_INLINE hkQsTransformf() = default;
// NOLINTNEXTLINE(google-explicit-constructor)
HK_FORCE_INLINE hkQsTransformf(IdentityInitializer init);
// NOLINTNEXTLINE(google-explicit-constructor)
HK_FORCE_INLINE hkQsTransformf(ZeroInitializer init);
HK_FORCE_INLINE hkQsTransformf(hkVector4fParameter translation, hkQuaternionfParameter rotation,
hkVector4fParameter scale);
HK_FORCE_INLINE hkQsTransformf(hkVector4fParameter translation,
hkQuaternionfParameter rotation);
HK_FORCE_INLINE hkQsTransformf(const hkQsTransformf& other);
HK_FORCE_INLINE const hkVector4f& getTranslation() const;
HK_FORCE_INLINE const hkQuaternionf& getRotation() const;
HK_FORCE_INLINE const hkVector4f& getScale() const;
HK_FORCE_INLINE void setIdentity();
HK_FORCE_INLINE void setZero();
void setFromTransformNoScale(const hkTransformf& transform);
void copyToTransformNoScale(hkTransformf& transformOut) const;
void setFromTransform(const hkTransformf& transform);
void setFromTransform(const hkQTransformf& qt);
void copyToTransform(hkTransformf& transformOut) const;
hkVector4f m_translation;
hkQuaternionf m_rotation;
hkVector4f m_scale;
};

View File

@ -0,0 +1,49 @@
#pragma once
inline hkQsTransformf::hkQsTransformf(IdentityInitializer) {
setIdentity();
}
inline hkQsTransformf::hkQsTransformf(ZeroInitializer) {
setZero();
}
inline hkQsTransformf::hkQsTransformf(hkVector4fParameter translation,
hkQuaternionfParameter rotation, hkVector4fParameter scale)
: m_translation(translation), m_rotation(rotation), m_scale(scale) {}
inline hkQsTransformf::hkQsTransformf(hkVector4fParameter translation,
hkQuaternionfParameter rotation)
: m_translation(translation), m_rotation(rotation) {
m_scale = hkVector4f::getConstant<HK_QUADREAL_1>();
}
inline hkQsTransformf::hkQsTransformf(const hkQsTransformf& other) {
m_translation = other.m_translation;
m_rotation = other.m_rotation;
m_scale = other.m_scale;
}
inline const hkVector4f& hkQsTransformf::getTranslation() const {
return m_translation;
}
inline const hkQuaternionf& hkQsTransformf::getRotation() const {
return m_rotation;
}
inline const hkVector4f& hkQsTransformf::getScale() const {
return m_scale;
}
inline void hkQsTransformf::setIdentity() {
m_translation.setZero();
m_rotation.setIdentity();
m_scale = hkVector4f::getConstant<HK_QUADREAL_1>();
}
inline void hkQsTransformf::setZero() {
m_translation.setZero();
m_rotation.m_vec.setZero();
m_scale.setZero();
}

View File

@ -36,6 +36,7 @@ public:
HK_FORCE_INLINE void normalize();
HK_FORCE_INLINE static const hkQuaternionf& getIdentity();
HK_FORCE_INLINE void setIdentity();
hkVector4f m_vec;
};

View File

@ -98,3 +98,7 @@ inline void hkQuaternionf::normalize() {
inline const hkQuaternionf& hkQuaternionf::getIdentity() {
return reinterpret_cast<const hkQuaternionf&>(g_vectorfConstants[HK_QUADREAL_0001]);
}
inline void hkQuaternionf::setIdentity() {
m_vec = hkVector4f::getConstant<HK_QUADREAL_0001>();
}

View File

@ -16,6 +16,8 @@ class hkQuaternionf;
class hkMatrix3f;
class hkRotationf;
class hkTransformf;
class hkQTransformf;
class hkQsTransformf;
// Type aliases
using hkVector4fParameter = const hkVector4f&;
@ -31,12 +33,14 @@ using hkQuaternionfParameter = const hkQuaternionf&;
#include <Havok/Common/Base/Math/Matrix/hkMatrix3.h>
#include <Havok/Common/Base/Math/Matrix/hkRotation.h>
#include <Havok/Common/Base/Math/Matrix/hkTransform.h>
#include <Havok/Common/Base/Math/QsTransform/hkQsTransform.h>
// Implementations
#include <Havok/Common/Base/Math/Vector/hkVector4f.inl>
#include <Havok/Common/Base/Math/Vector/hkVector4fComparison.inl>
#include <Havok/Common/Base/Math/Quaternion/hkQuaternionf.inl>
#include <Havok/Common/Base/Math/Matrix/hkMatrix3f.inl>
#include <Havok/Common/Base/Math/QsTransform/hkQsTransformf.inl>
// clang-format on

View File

@ -5,3 +5,5 @@
#define HK_NEVER_INLINE __attribute__((noinline))
#define HK_VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
#define HK_RESTRICT __restrict

View File

@ -0,0 +1,104 @@
#pragma once
#include <Havok/Physics2012/Collide/Shape/Convex/hkpConvexShape.h>
class hkpConvexTransformShape : public hkpConvexTransformShapeBase {
public:
HK_DECLARE_CLASS_ALLOCATOR(hkpConvexTransformShape)
HK_DECLARE_REFLECTION()
HKCD_DECLARE_SHAPE_TYPE(hkcdShapeType::CONVEX_TRANSFORM)
HK_FORCE_INLINE hkpConvexTransformShape() {}
hkpConvexTransformShape(
const hkpConvexShape* childShape, const hkTransform& transform,
hkpShapeContainer::ReferencePolicy ref = hkpShapeContainer::REFERENCE_POLICY_INCREMENT);
hkpConvexTransformShape(
const hkpConvexShape* childShape, const hkQsTransform& transform,
hkpShapeContainer::ReferencePolicy ref = hkpShapeContainer::REFERENCE_POLICY_INCREMENT);
explicit hkpConvexTransformShape(hkFinishLoadedObjectFlag flag);
void setTransform(const hkQsTransform& transform);
inline void setTransform(const hkTransform& transform);
inline void getTransform(hkTransform* HK_RESTRICT transform) const;
inline const hkQsTransform& getQsTransform() const;
inline const hkVector4& getExtraScale() const;
inline const hkpConvexShape* getChildShape() const;
inline void transformVertex(hkVector4Parameter localVertex,
hkVector4* HK_RESTRICT vertexOut) const;
void getSupportingVertex(hkVector4Parameter direction,
hkcdVertex& supportingVertexOut) const override;
void convertVertexIdsToVertices(const hkpVertexId* ids, int numIds,
hkcdVertex* verticesOut) const override;
void getCentre(hkVector4& centreOut) const override;
int getNumCollisionSpheres() const override;
const hkSphere* getCollisionSpheres(hkSphere* sphereBuffer) const override;
void getAabb(const hkTransform& localToWorld, hkReal tolerance, hkAabb& out) const override;
hkBool castRay(const hkpShapeRayCastInput& input,
hkpShapeRayCastOutput& results) const override;
void castRayWithCollector(const hkpShapeRayCastInput& input, const hkpCdBody& cdBody,
hkpRayHitCollector& collector) const override;
const hkpShapeContainer* getContainer() const override;
int calcSizeForSpu(const CalcSizeForSpuInput& input, int spuBufferSizeLeft) const override;
void getFirstVertex(hkVector4& v) const override;
protected:
hkQsTransform m_transform;
hkVector4 m_extraScale;
};
inline void hkpConvexTransformShape::setTransform(const hkTransform& transform) {
m_transform.setFromTransformNoScale(transform);
m_extraScale.setZero();
}
inline void hkpConvexTransformShape::getTransform(hkTransform* transform) const {
m_transform.copyToTransformNoScale(*transform);
}
inline const hkQsTransform& hkpConvexTransformShape::getQsTransform() const {
return m_transform;
}
inline const hkVector4& hkpConvexTransformShape::getExtraScale() const {
return m_extraScale;
}
inline const hkpConvexShape* hkpConvexTransformShape::getChildShape() const {
return static_cast<const hkpConvexShape*>(m_childShape.getChild());
}
inline void hkpConvexTransformShape::transformVertex(const hkVector4f& localVertex,
hkVector4* vertexOut) const {
hkVector4 center;
center.set(m_transform.m_translation.getW(), m_transform.m_scale.getW(), m_extraScale.getW(),
hkSimdReal::getConstant<HK_QUADREAL_0>());
hkVector4 relVertex;
relVertex.setSub(localVertex, center);
vertexOut->setMul(localVertex, m_transform.getScale());
vertexOut->addMul(m_extraScale, relVertex);
vertexOut->_setRotatedDir(m_transform.getRotation(), *vertexOut);
vertexOut->add(m_transform.getTranslation());
}
inline int hkpConvexTransformShape::getNumCollisionSpheres() const {
return getChildShape()->getNumCollisionSpheres();
}

View File

@ -3,6 +3,7 @@
#include <Havok/Common/Base/hkBase.h>
#include <Havok/Physics2012/Collide/Shape/HeightField/hkpSphereRepShape.h>
#include <Havok/Physics2012/Collide/Shape/hkpShape.h>
#include <Havok/Physics2012/Collide/Shape/hkpShapeContainer.h>
extern hkReal hkConvexShapeDefaultRadius;
@ -47,6 +48,26 @@ protected:
hkReal m_radius;
};
class hkpConvexTransformShapeBase : public hkpConvexShape {
public:
HK_DECLARE_CLASS_ALLOCATOR(hkpConvexTransformShapeBase)
HK_DECLARE_REFLECTION()
public:
hkpConvexTransformShapeBase() {}
explicit hkpConvexTransformShapeBase(hkFinishLoadedObjectFlag flag)
: hkpConvexShape(flag), m_childShape(flag) {}
protected:
hkpConvexTransformShapeBase(ShapeType type, hkReal radius, const hkpConvexShape* childShape,
hkpShapeContainer::ReferencePolicy ref);
void getChildShapeFromPpu(int thisShapeSize) const;
hkpSingleShapeContainer m_childShape;
mutable int m_childShapeSizeForSpu;
};
inline const hkReal& hkpConvexShape::getRadius() const {
return m_radius;
}