mirror of
https://github.com/zeldaret/botw
synced 2026-08-13 04:00:00 -04:00
ksys/phys: Add most remaining parts of RayCast
One last function remaining (0x0000007100fc4844) but it looks obnoxious so I'll leave it for later.
This commit is contained in:
@@ -140,6 +140,8 @@ add_library(hkStubs OBJECT
|
||||
Havok/Physics2012/Collide/Shape/HeightField/hkpHeightFieldShape.h
|
||||
Havok/Physics2012/Collide/Shape/HeightField/hkpSphereRepShape.h
|
||||
Havok/Physics2012/Collide/Shape/HeightField/Plane/hkpPlaneShape.h
|
||||
Havok/Physics2012/Collide/Shape/HeightField/SampledHeightField/hkpSampledHeightFieldBaseCinfo.h
|
||||
Havok/Physics2012/Collide/Shape/HeightField/SampledHeightField/hkpSampledHeightFieldShape.h
|
||||
Havok/Physics2012/Collide/Shape/Query/hkpRayShapeCollectionFilter.h
|
||||
Havok/Physics2012/Collide/Shape/Query/hkpShapeRayCastCollectorOutput.h
|
||||
Havok/Physics2012/Collide/Shape/Query/hkpShapeRayCastInput.h
|
||||
@@ -199,12 +201,14 @@ add_library(hkStubs OBJECT
|
||||
Havok/Physics2012/Dynamics/World/Simulation/hkpSimulation.h
|
||||
Havok/Physics2012/Dynamics/World/Util/hkpWorldConstraintUtil.h
|
||||
|
||||
Havok/Physics2012/Internal/Collide/BvCompressedMesh/hkpBvCompressedMeshShape.h
|
||||
Havok/Physics2012/Internal/Collide/Mopp/Code/hkpMoppCode.h
|
||||
Havok/Physics2012/Internal/Collide/StaticCompound/hkpShapeKeyTable.h
|
||||
Havok/Physics2012/Internal/Collide/StaticCompound/hkpStaticCompoundShape.h
|
||||
Havok/Physics2012/Internal/Solver/Contact/hkpSimpleContactConstraintDataInfo.h
|
||||
|
||||
Havok/Physics2012/Utilities/CharacterControl/CharacterRigidBody/hkpCharacterRigidBody.h
|
||||
Havok/Physics2012/Utilities/Collide/ShapeUtils/ShapeKeyPath/hkpShapeKeyPath.h
|
||||
Havok/Physics2012/Utilities/Collide/ShapeUtils/ShapeScaling/hkpShapeScalingUtility.h
|
||||
Havok/Physics2012/Utilities/Dynamics/ScaleSystem/hkpSystemScalingUtility.h
|
||||
Havok/Physics2012/Utilities/Serialize/hkpPhysicsData.h
|
||||
|
||||
@@ -7,3 +7,5 @@
|
||||
#define HK_VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
|
||||
|
||||
#define HK_RESTRICT __restrict
|
||||
|
||||
#define HK_MAX_NUM_THREADS 12
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <Havok/Common/Base/hkBase.h>
|
||||
|
||||
class hkpSampledHeightFieldBaseCinfo {
|
||||
public:
|
||||
HK_DECLARE_CLASS_ALLOCATOR(hkpSampledHeightFieldBaseCinfo)
|
||||
|
||||
hkpSampledHeightFieldBaseCinfo() {
|
||||
m_scale.set(1.0f, 1.0f, 1.0f);
|
||||
m_xRes = 2;
|
||||
m_zRes = 2;
|
||||
m_minHeight = 0.0f;
|
||||
m_maxHeight = -1.0f;
|
||||
m_useProjectionBasedHeight = false;
|
||||
}
|
||||
|
||||
hkVector4 m_scale;
|
||||
hkInt32 m_xRes;
|
||||
hkInt32 m_zRes;
|
||||
hkReal m_minHeight;
|
||||
hkReal m_maxHeight;
|
||||
hkBool m_useProjectionBasedHeight;
|
||||
};
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
#pragma once
|
||||
|
||||
#include <Havok/Common/Base/Types/Geometry/Aabb/hkAabb.h>
|
||||
#include <Havok/Common/Base/hkBase.h>
|
||||
#include <Havok/Physics2012/Collide/Shape/HeightField/SampledHeightField/hkpSampledHeightFieldBaseCinfo.h>
|
||||
#include <Havok/Physics2012/Collide/Shape/HeightField/hkpHeightFieldShape.h>
|
||||
|
||||
class hkpSampledHeightFieldShape : public hkpHeightFieldShape {
|
||||
public:
|
||||
HK_DECLARE_CLASS_ALLOCATOR(hkpHeightFieldShape)
|
||||
HK_DECLARE_REFLECTION()
|
||||
HKCD_DECLARE_SHAPE_TYPE(hkcdShapeType::SAMPLED_HEIGHT_FIELD)
|
||||
|
||||
enum HeightFieldType {
|
||||
/// hkpStorageSampledHeightFieldShape, stores values as hkReals
|
||||
HEIGHTFIELD_STORAGE = 0,
|
||||
/// hkpCompressedSampledHeightFieldShape, stores values as hkUint16s
|
||||
HEIGHTFIELD_COMPRESSED,
|
||||
HEIGHTFIELD_USER,
|
||||
HEIGHTFIELD_MAX_ID
|
||||
};
|
||||
|
||||
explicit hkpSampledHeightFieldShape(const hkpSampledHeightFieldBaseCinfo& ci,
|
||||
HeightFieldType type = HEIGHTFIELD_USER);
|
||||
|
||||
hkpSampledHeightFieldShape()
|
||||
: hkpHeightFieldShape(HKCD_SHAPE_TYPE_FROM_CLASS(hkpSampledHeightFieldShape)) {}
|
||||
|
||||
explicit hkpSampledHeightFieldShape(hkFinishLoadedObjectFlag flag);
|
||||
|
||||
~hkpSampledHeightFieldShape() override;
|
||||
|
||||
void getCinfo(hkpSampledHeightFieldBaseCinfo& cinfo) const;
|
||||
|
||||
HK_FORCE_INLINE hkReal getHeightAt(int x, int z) const;
|
||||
|
||||
HK_FORCE_INLINE hkBool getTriangleFlip() const;
|
||||
|
||||
void buildCoarseMinMaxTree(int coarseness = 3);
|
||||
|
||||
virtual void getCoarseMinMax(int level, int x, int z, hkVector4& minOut,
|
||||
hkVector4& maxOut) const;
|
||||
|
||||
void setMinMaxTreeCoarseness(int coarseness);
|
||||
|
||||
void getAabb(const hkTransform& localToWorld, hkReal tolerance, hkAabb& out) const override;
|
||||
|
||||
void collideSpheres(const CollideSpheresInput& input,
|
||||
SphereCollisionOutput* outputArray) const override;
|
||||
|
||||
void castSphere(const hkpSphereCastInput& input, const hkpCdBody& cdBody,
|
||||
hkpRayHitCollector& collector) const override;
|
||||
|
||||
hkBool castRay(const hkpShapeRayCastInput& input, hkpShapeRayCastOutput& output) const override;
|
||||
|
||||
void castRayWithCollector(const hkpShapeRayCastInput& input, const hkpCdBody& cdBody,
|
||||
hkpRayHitCollector& collector) const override;
|
||||
|
||||
virtual hkReal getHeightAtImpl(int x, int z) const;
|
||||
virtual hkBool getTriangleFlipImpl() const;
|
||||
|
||||
using RayCastInternalFunc = void (hkpSampledHeightFieldShape::*)(const hkpShapeRayCastInput&,
|
||||
const hkpCdBody&,
|
||||
hkpRayHitCollector&) const;
|
||||
static RayCastInternalFunc s_rayCastFunc;
|
||||
|
||||
void castRayDefault(const hkpShapeRayCastInput& input, const hkpCdBody& cdBody,
|
||||
hkpRayHitCollector& collector) const;
|
||||
void castRayDda(const hkpShapeRayCastInput& input, const hkpCdBody& cdBody,
|
||||
hkpRayHitCollector& collector) const;
|
||||
void castRayCoarseTree(const hkpShapeRayCastInput& input, const hkpCdBody& cdBody,
|
||||
hkpRayHitCollector& collector) const;
|
||||
|
||||
using SphereCastInternalFunc = void (hkpSampledHeightFieldShape::*)(const hkpSphereCastInput&,
|
||||
const hkpCdBody&,
|
||||
hkpRayHitCollector&) const;
|
||||
static SphereCastInternalFunc s_sphereCastFunc;
|
||||
|
||||
void castSphereDefault(const hkpSphereCastInput& input, const hkpCdBody& cdBody,
|
||||
hkpRayHitCollector& collector) const;
|
||||
void castSphereDda(const hkpSphereCastInput& input, const hkpCdBody& cdBody,
|
||||
hkpRayHitCollector& collector) const;
|
||||
void castSphereCoarseTree(const hkpSphereCastInput& input, const hkpCdBody& cdBody,
|
||||
hkpRayHitCollector& collector) const;
|
||||
|
||||
protected:
|
||||
void castRayDdaInternal(const hkpShapeRayCastInput& input, const hkpCdBody& cdBody,
|
||||
hkBool reportPenetratingStartPosition, hkReal maxExtraPenetration,
|
||||
hkpRayHitCollector& collector) const;
|
||||
|
||||
void castRayCoarseTreeInternal(const hkVector4& from, const hkVector4& to,
|
||||
const hkpCdBody& cdBody, hkpRayHitCollector& collector) const;
|
||||
|
||||
HK_FORCE_INLINE void _getHeightAndNormalAt(int xPos, int zPos, hkReal subX, hkReal subZ,
|
||||
hkVector4& normalOut, hkReal& heightOut,
|
||||
int& triangleIndexOut) const;
|
||||
|
||||
HK_FORCE_INLINE void calcMinMax(int coarseness, int x, int z, hkReal& minheightOut,
|
||||
hkReal& maxheightOut) const;
|
||||
|
||||
struct AABBStackElement {
|
||||
hkAabb aabb;
|
||||
int level;
|
||||
int x;
|
||||
int z;
|
||||
};
|
||||
|
||||
HK_FORCE_INLINE void findStartCell(AABBStackElement& startOut, const hkVector4& from,
|
||||
const hkVector4& to) const;
|
||||
|
||||
HK_FORCE_INLINE void rayTriangleQuadCheck(const struct hkcdRay& ray, hkAabb& aabb, int x, int z,
|
||||
const hkVector4Comparison& flipSelect,
|
||||
const hkpCdBody& cdBody,
|
||||
hkpRayHitCollector& collector) const;
|
||||
|
||||
public:
|
||||
struct CoarseMinMaxLevel {
|
||||
HK_DECLARE_CLASS_ALLOCATOR(CoarseMinMaxLevel)
|
||||
HK_DECLARE_REFLECTION()
|
||||
|
||||
CoarseMinMaxLevel() {}
|
||||
explicit CoarseMinMaxLevel(hkFinishLoadedObjectFlag f) : m_minMaxData(f) {}
|
||||
CoarseMinMaxLevel(const CoarseMinMaxLevel& l) : m_xRes(l.m_xRes), m_zRes(l.m_zRes) {
|
||||
m_minMaxData = l.m_minMaxData;
|
||||
}
|
||||
|
||||
hkArray<hkVector4> m_minMaxData;
|
||||
int m_xRes;
|
||||
int m_zRes;
|
||||
};
|
||||
hkArray<CoarseMinMaxLevel> m_coarseTreeData;
|
||||
|
||||
void getHeightAndNormalAt(int xPos, int zPos, hkReal subX, hkReal subZ, hkVector4& normalOut,
|
||||
hkReal& heightOut, int& triangleIndexOut) const;
|
||||
|
||||
int m_coarseness;
|
||||
hkReal m_raycastMinY;
|
||||
hkReal m_raycastMaxY;
|
||||
|
||||
int m_xRes;
|
||||
int m_zRes;
|
||||
|
||||
hkReal m_heightCenter;
|
||||
|
||||
hkBool m_useProjectionBasedHeight;
|
||||
|
||||
hkEnum<HeightFieldType, hkUint8> m_heightfieldType;
|
||||
|
||||
hkVector4 m_intToFloatScale;
|
||||
hkVector4 m_floatToIntScale;
|
||||
hkVector4 m_floatToIntOffsetFloorCorrected;
|
||||
hkVector4 m_extents;
|
||||
};
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
#pragma once
|
||||
|
||||
#include <Havok/Common/Base/hkBase.h>
|
||||
#include <Havok/Physics2012/Collide/Shape/Compound/Tree/hkpBvTreeShape.h>
|
||||
#include <Havok/Physics2012/Collide/Shape/hkpShapeContainer.h>
|
||||
#include <Havok/Physics2012/Collide/Util/Welding/hkpWeldingUtility.h>
|
||||
|
||||
struct hkGeometry;
|
||||
class hkpBvCompressedMeshShapeCinfo;
|
||||
|
||||
class hkpBvCompressedMeshShape : public hkpBvTreeShape, public hkpShapeContainer {
|
||||
public:
|
||||
enum PerPrimitiveDataMode {
|
||||
PER_PRIMITIVE_DATA_NONE,
|
||||
PER_PRIMITIVE_DATA_8_BIT,
|
||||
PER_PRIMITIVE_DATA_PALETTE,
|
||||
PER_PRIMITIVE_DATA_STRING_PALETTE,
|
||||
};
|
||||
|
||||
enum PrimitiveType {
|
||||
PRIMITIVE_TYPE_BOX,
|
||||
PRIMITIVE_TYPE_HULL,
|
||||
PRIMITIVE_TYPE_SPHERE,
|
||||
PRIMITIVE_TYPE_CAPSULE,
|
||||
PRIMITIVE_TYPE_CYLINDER,
|
||||
};
|
||||
|
||||
enum Config {
|
||||
#if HK_POINTER_SIZE == 8
|
||||
#ifdef HK_REAL_IS_DOUBLE
|
||||
NUM_BYTES_FOR_TREE = 224,
|
||||
#else
|
||||
NUM_BYTES_FOR_TREE = 160,
|
||||
#endif
|
||||
#else
|
||||
#ifdef HK_REAL_IS_DOUBLE
|
||||
NUM_BYTES_FOR_TREE = 224,
|
||||
#else
|
||||
NUM_BYTES_FOR_TREE = 144,
|
||||
#endif
|
||||
#endif
|
||||
|
||||
MAX_NUM_VERTICES_PER_HULL = 255,
|
||||
|
||||
MAX_NUM_PRIMITIVES = 1 << 23
|
||||
};
|
||||
|
||||
public:
|
||||
HK_DECLARE_CLASS_ALLOCATOR(hkpBvCompressedMeshShape)
|
||||
HK_DECLARE_REFLECTION()
|
||||
HKCD_DECLARE_SHAPE_TYPE(hkcdShapeType::BV_COMPRESSED_MESH)
|
||||
|
||||
explicit hkpBvCompressedMeshShape(const hkpBvCompressedMeshShapeCinfo& cInfo);
|
||||
explicit hkpBvCompressedMeshShape(hkFinishLoadedObjectFlag flag);
|
||||
HK_FORCE_INLINE hkpBvCompressedMeshShape() {}
|
||||
|
||||
~hkpBvCompressedMeshShape() override;
|
||||
|
||||
HK_FORCE_INLINE hkReal getConvexRadius() const;
|
||||
|
||||
hkUint32 getPrimitiveUserData(hkpShapeKey key) const;
|
||||
hkStringPtr getPrimitiveUserString(hkpShapeKey key) const;
|
||||
|
||||
HK_FORCE_INLINE PerPrimitiveDataMode getCollisionFilterInfoMode() const;
|
||||
HK_FORCE_INLINE PerPrimitiveDataMode getUserDataMode() const;
|
||||
HK_FORCE_INLINE hkArray<hkUint32>& accessCollisionFilterInfoPalette();
|
||||
HK_FORCE_INLINE hkArray<hkUint32>& accessUserDataPalette();
|
||||
HK_FORCE_INLINE hkArray<hkStringPtr>& accessUserStringPalette();
|
||||
|
||||
void convertToGeometry(hkGeometry& geometryOut, const hkArray<hkpShapeKey>* inclKeys = nullptr,
|
||||
const hkArray<hkpShapeKey>* exclKeys = nullptr) const;
|
||||
|
||||
const hkpShapeContainer* getContainer() const override { return this; }
|
||||
|
||||
int calcSizeForSpu(const CalcSizeForSpuInput& input, int spuBufferSizeLeft) 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& body,
|
||||
hkpRayHitCollector& collector) const override;
|
||||
|
||||
void queryAabb(const hkAabb& aabb, hkArray<hkpShapeKey>& hits) const override;
|
||||
|
||||
hkUint32 queryAabbImpl(const hkAabb& aabb, hkpShapeKey* hits, int maxNumKeys) const override;
|
||||
|
||||
void castAabbImpl(const hkAabb& from, hkVector4Parameter to,
|
||||
hkpAabbCastCollector& collector) const override;
|
||||
|
||||
int getNumChildShapes() const override;
|
||||
|
||||
hkpShapeKey getFirstKey() const override;
|
||||
|
||||
hkpShapeKey getNextKey(hkpShapeKey oldKey) const override;
|
||||
|
||||
const hkpShape* getChildShape(hkpShapeKey key, hkpShapeBuffer& buffer) const override;
|
||||
|
||||
hkUint32 getCollisionFilterInfo(hkpShapeKey key) const override;
|
||||
|
||||
protected:
|
||||
hkReal m_convexRadius;
|
||||
hkEnum<hkpWeldingUtility::WeldingType, hkUint8> m_weldingType;
|
||||
hkBool m_hasPerPrimitiveCollisionFilterInfo;
|
||||
hkBool m_hasPerPrimitiveUserData;
|
||||
hkArray<hkUint32> m_collisionFilterInfoPalette;
|
||||
hkArray<hkUint32> m_userDataPalette;
|
||||
hkArray<hkStringPtr> m_userStringPalette;
|
||||
alignas(16) hkUint8 m_tree[NUM_BYTES_FOR_TREE];
|
||||
|
||||
friend struct hkpBvCompressedMeshShape_Internals;
|
||||
|
||||
public:
|
||||
alignas(16) static hkVector4 g_vertexBufferPool[HK_MAX_NUM_THREADS][MAX_NUM_VERTICES_PER_HULL];
|
||||
};
|
||||
|
||||
inline hkReal hkpBvCompressedMeshShape::getConvexRadius() const {
|
||||
return m_convexRadius;
|
||||
}
|
||||
|
||||
inline hkpBvCompressedMeshShape::PerPrimitiveDataMode
|
||||
hkpBvCompressedMeshShape::getCollisionFilterInfoMode() const {
|
||||
return m_hasPerPrimitiveCollisionFilterInfo ?
|
||||
(m_collisionFilterInfoPalette.getSize() ? PER_PRIMITIVE_DATA_PALETTE :
|
||||
PER_PRIMITIVE_DATA_8_BIT) :
|
||||
PER_PRIMITIVE_DATA_NONE;
|
||||
}
|
||||
|
||||
inline hkpBvCompressedMeshShape::PerPrimitiveDataMode
|
||||
hkpBvCompressedMeshShape::getUserDataMode() const {
|
||||
if (!m_hasPerPrimitiveUserData)
|
||||
return PER_PRIMITIVE_DATA_NONE;
|
||||
|
||||
if (m_userDataPalette.getSize() > 0)
|
||||
return PER_PRIMITIVE_DATA_PALETTE;
|
||||
|
||||
if (m_userStringPalette.getSize() > 0)
|
||||
return PER_PRIMITIVE_DATA_STRING_PALETTE;
|
||||
|
||||
return PER_PRIMITIVE_DATA_8_BIT;
|
||||
}
|
||||
|
||||
inline hkArray<hkUint32>& hkpBvCompressedMeshShape::accessCollisionFilterInfoPalette() {
|
||||
return m_collisionFilterInfoPalette;
|
||||
}
|
||||
|
||||
inline hkArray<hkUint32>& hkpBvCompressedMeshShape::accessUserDataPalette() {
|
||||
return m_userDataPalette;
|
||||
}
|
||||
|
||||
inline hkArray<hkStringPtr>& hkpBvCompressedMeshShape::accessUserStringPalette() {
|
||||
return m_userStringPalette;
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
#include <Havok/Common/Base/hkBase.h>
|
||||
#include <Havok/Physics2012/Collide/Shape/hkpShape.h>
|
||||
#include <Havok/Physics2012/Collide/Shape/hkpShapeBuffer.h>
|
||||
|
||||
class hkpContactPointEvent;
|
||||
struct hkpRootCdPoint;
|
||||
struct hkpShapeRayBundleCastOutput;
|
||||
struct hkpWorldRayCastOutput;
|
||||
|
||||
class hkpShapeKeyPath {
|
||||
public:
|
||||
HK_DECLARE_CLASS_ALLOCATOR(hkpShapeKeyPath)
|
||||
|
||||
class Iterator;
|
||||
|
||||
hkpShapeKeyPath(const hkpContactPointEvent& event, int bodyIdx);
|
||||
explicit hkpShapeKeyPath(const hkpWorldRayCastOutput& output);
|
||||
hkpShapeKeyPath(const hkpShape* shape, const hkpShapeRayCastOutput& output);
|
||||
|
||||
hkpShapeKey getShapeKey(int keyIndex) const;
|
||||
|
||||
Iterator getIterator() const;
|
||||
|
||||
void getShapes(int maxShapesOut, hkpShapeBuffer* buffers, const hkpShape** shapesOut,
|
||||
int& numShapesOut);
|
||||
|
||||
class Iterator {
|
||||
public:
|
||||
HK_DECLARE_CLASS_ALLOCATOR(Iterator)
|
||||
|
||||
friend class hkpShapeKeyPath;
|
||||
|
||||
/// Returns nullptr if the iterator is invalid.
|
||||
const hkpShape* getShape() const;
|
||||
|
||||
/// @warning This can invalidate the shape.
|
||||
void next();
|
||||
|
||||
hkBool isValid() const;
|
||||
|
||||
private:
|
||||
Iterator(const hkpShapeKeyPath* path, const hkpShape* rootShape);
|
||||
void nextImpl(hkpShapeBuffer* buf);
|
||||
|
||||
const hkpShapeKeyPath* m_path;
|
||||
const hkpShape* m_currentShape;
|
||||
int m_currentKeyIdx;
|
||||
hkBool m_isValid;
|
||||
hkpShapeBuffer m_tempBuffer;
|
||||
};
|
||||
|
||||
private:
|
||||
void init(const hkpShape* shape, const hkpShapeKey* keys, int maxKeys);
|
||||
|
||||
const hkpShape* m_rootShape;
|
||||
const hkpShapeKey* m_keys;
|
||||
int m_numKeys;
|
||||
hkBool m_isOrderLeafToRoot;
|
||||
};
|
||||
|
||||
inline hkpShapeKeyPath::Iterator hkpShapeKeyPath::getIterator() const {
|
||||
return {this, m_rootShape};
|
||||
}
|
||||
|
||||
inline const hkpShape* hkpShapeKeyPath::Iterator::getShape() const {
|
||||
return m_currentShape;
|
||||
}
|
||||
|
||||
inline void hkpShapeKeyPath::Iterator::next() {
|
||||
return nextImpl(&m_tempBuffer);
|
||||
}
|
||||
|
||||
inline hkBool hkpShapeKeyPath::Iterator::isValid() const {
|
||||
return m_isValid;
|
||||
}
|
||||
Reference in New Issue
Block a user