8#ifdef JPH_DEBUG_RENDERER 
   26        outVolumeTimes6 = max((inV1 - inV4).Dot((inV2 - inV4).Cross(inV3 - inV4)), 0.0f); 
 
   27        outCenterTimes4 = inV1 + inV2 + inV3 + inV4;
 
   32    inline static Vec3  sGetPlaneIntersection(
Vec3Arg inV1, 
float inD1, 
Vec3Arg inV2, 
float inD2)
 
   34        JPH_ASSERT(
Sign(inD1) != 
Sign(inD2), 
"Assuming both points are on opposite ends of the plane");
 
   35        float delta = inD1 - inD2;
 
   36        if (abs(delta) < 1.0e-6f)
 
   39            return inV1 + inD1 * (inV2 - inV1) / delta;
 
   48        Vec3 v2 = sGetPlaneIntersection(inV1, inD1, inV2, inD2);
 
   49        Vec3 v3 = sGetPlaneIntersection(inV1, inD1, inV3, inD3);
 
   50        Vec3 v4 = sGetPlaneIntersection(inV1, inD1, inV4, inD4);
 
   52    #ifdef JPH_DEBUG_RENDERER 
   56            RVec3 v2w = mBaseOffset + v2;
 
   57            RVec3 v3w = mBaseOffset + v3;
 
   58            RVec3 v4w = mBaseOffset + v4;
 
   65        sTetrahedronVolume4(inV1, v2, v3, v4, outVolumeTimes6, outCenterTimes4);
 
   74        Vec3 c = sGetPlaneIntersection(inV1, inD1, inV3, inD3);
 
   75        Vec3 d = sGetPlaneIntersection(inV1, inD1, inV4, inD4);
 
   76        Vec3 e = sGetPlaneIntersection(inV2, inD2, inV4, inD4);
 
   77        Vec3 f = sGetPlaneIntersection(inV2, inD2, inV3, inD3);
 
   79    #ifdef JPH_DEBUG_RENDERER 
   83            RVec3 cw = mBaseOffset + c;
 
   84            RVec3 dw = mBaseOffset + d;
 
   85            RVec3 ew = mBaseOffset + e;
 
   86            RVec3 fw = mBaseOffset + f;
 
   97        Vec3 center1, center2, center3;
 
   98        float volume1, volume2, volume3;
 
   99        sTetrahedronVolume4(e, f, inV2, c, volume1, center1);
 
  100        sTetrahedronVolume4(e, inV1, d, c, volume2, center2);
 
  101        sTetrahedronVolume4(e, inV2, inV1, c, volume3, center3);
 
  104        outVolumeTimes6 = volume1 + volume2 + volume3;
 
  105        outCenterTimes4 = outVolumeTimes6 > 0.0f? (volume1 * center1 + volume2 * center2 + volume3 * center3) / outVolumeTimes6 : 
Vec3::sZero();
 
  114        Vec3 v1 = sGetPlaneIntersection(inV1, inD1, inV4, inD4);
 
  115        Vec3 v2 = sGetPlaneIntersection(inV2, inD2, inV4, inD4);
 
  116        Vec3 v3 = sGetPlaneIntersection(inV3, inD3, inV4, inD4);
 
  118    #ifdef JPH_DEBUG_RENDERER 
  122            RVec3 v1w = mBaseOffset + v1;
 
  123            RVec3 v2w = mBaseOffset + v2;
 
  124            RVec3 v3w = mBaseOffset + v3;
 
  131        Vec3 dry_center, total_center;
 
  132        float dry_volume, total_volume;
 
  135        sTetrahedronVolume4(v1, v2, v3, inV4, dry_volume, dry_center);
 
  138        sTetrahedronVolume4(inV1, inV2, inV3, inV4, total_volume, total_center);
 
  141        outVolumeTimes6 = max(total_volume - dry_volume, 0.0f);
 
  142        outCenterTimes4 = outVolumeTimes6 > 0.0f? (total_center * total_volume - dry_center * dry_volume) / outVolumeTimes6 : 
Vec3::sZero();
 
  162#ifdef JPH_DEBUG_RENDERER 
  166#ifdef JPH_DEBUG_RENDERER 
 
  171#ifdef JPH_DEBUG_RENDERER
 
  172        , mBaseOffset(inBaseOffset)
 
  176        float reference_dist = FLT_MAX;
 
  177        for (
int p = 0; p < inNumPoints; ++p)
 
  180            Vec3 transformed_point = inTransform * *
reinterpret_cast<const Vec3 *
>(
reinterpret_cast<const uint8 *
>(inPoints) + p * inPointStride);
 
  182            bool above = dist >= 0.0f;
 
  189            if (reference_dist > dist)
 
  191                mReferencePointIdx = p;
 
  192                reference_dist = dist;
 
  196            ioBuffer->mPosition = transformed_point;
 
  197            ioBuffer->mDistanceToSurface = dist;
 
  198            ioBuffer->mAboveSurface = above;
 
  218        return mReferencePointIdx;
 
  222    void                AddFace(
int inIdx1, 
int inIdx2, 
int inIdx3)
 
  224        JPH_ASSERT(inIdx1 != mReferencePointIdx && inIdx2 != mReferencePointIdx && inIdx3 != mReferencePointIdx, 
"A face using the reference point will not contribute to the volume");
 
  227        const Point &ref = mPoints[mReferencePointIdx];
 
  228        const Point &p1 = mPoints[inIdx1];
 
  229        const Point &p2 = mPoints[inIdx2];
 
  230        const Point &p3 = mPoints[inIdx3];
 
  287        mSubmergedVolume += volume;
 
  288        mCenterOfBuoyancy += volume * center;
 
  294        outCenterOfBuoyancy = mSubmergedVolume > 0.0f? mCenterOfBuoyancy / (4.0f * mSubmergedVolume) : 
Vec3::sZero(); 
 
  295        outSubmergedVolume = mSubmergedVolume / 6.0f;
 
  300    const Point *       mPoints;
 
  303    bool                mAllBelow = 
true;
 
  304    bool                mAllAbove = 
true;
 
  307    int                 mReferencePointIdx = 0;
 
  310    float               mSubmergedVolume = 0.0f;
 
  313#ifdef JPH_DEBUG_RENDERER 
std::uint8_t uint8
Definition: Core.h:453
 
#define JPH_IF_NOT_DEBUG_RENDERER(...)
Definition: Core.h:537
 
unsigned int uint
Definition: Core.h:452
 
#define JPH_NAMESPACE_END
Definition: Core.h:378
 
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:372
 
#define JPH_ASSERT(...)
Definition: IssueReporting.h:33
 
JPH_INLINE constexpr T Sign(T inV)
Get the sign of a value.
Definition: Math.h:66
 
static const Color sGreen
Definition: Color.h:57
 
static const Color sWhite
Definition: Color.h:67
 
void DrawWireTriangle(RVec3Arg inV1, RVec3Arg inV2, RVec3Arg inV3, ColorArg inColor)
Draw wireframe triangle.
Definition: DebugRenderer.cpp:242
 
static DebugRenderer * sInstance
Singleton instance.
Definition: DebugRenderer.h:179
 
virtual void DrawTriangle(RVec3Arg inV1, RVec3Arg inV2, RVec3Arg inV3, ColorArg inColor, ECastShadow inCastShadow=ECastShadow::Off)=0
Draw a single back face culled triangle.
 
Holds a 4x4 matrix of floats, but supports also operations on the 3x3 upper left part of the matrix.
Definition: Mat44.h:13
 
An infinite plane described by the formula X . Normal + Constant = 0.
Definition: Plane.h:11
 
float SignedDistance(Vec3Arg inPoint) const
Distance point to plane.
Definition: Plane.h:54
 
A helper class that contains cached information about a polyhedron vertex.
Definition: PolyhedronSubmergedVolumeCalculator.h:148
 
Vec3 mPosition
World space position of vertex.
Definition: PolyhedronSubmergedVolumeCalculator.h:150
 
float mDistanceToSurface
Signed distance to the surface (> 0 is above, < 0 is below)
Definition: PolyhedronSubmergedVolumeCalculator.h:151
 
bool mAboveSurface
If the point is above the surface (mDistanceToSurface > 0)
Definition: PolyhedronSubmergedVolumeCalculator.h:152
 
Definition: PolyhedronSubmergedVolumeCalculator.h:18
 
void AddFace(int inIdx1, int inIdx2, int inIdx3)
Add a polyhedron face. Supply the indices of the points that form the face (in counter clockwise orde...
Definition: PolyhedronSubmergedVolumeCalculator.h:222
 
PolyhedronSubmergedVolumeCalculator(const Mat44 &inTransform, const Vec3 *inPoints, int inPointStride, int inNumPoints, const Plane &inSurface, Point *ioBuffer, RVec3 inBaseOffset)
Definition: PolyhedronSubmergedVolumeCalculator.h:165
 
void GetResult(float &outSubmergedVolume, Vec3 &outCenterOfBuoyancy) const
Call after all faces have been added. Returns the submerged volume and the center of buoyancy for the...
Definition: PolyhedronSubmergedVolumeCalculator.h:292
 
bool AreAllBelow() const
Check if all points are below the surface. Should be used as early out.
Definition: PolyhedronSubmergedVolumeCalculator.h:210
 
int GetReferencePointIdx() const
Get the lowest point of the polyhedron. Used to form the 4th vertex to make a tetrahedron out of a po...
Definition: PolyhedronSubmergedVolumeCalculator.h:216
 
bool AreAllAbove() const
Check if all points are above the surface. Should be used as early out.
Definition: PolyhedronSubmergedVolumeCalculator.h:204
 
static bool sDrawSubmergedVolumes
Debug helper which draws the intersection between water and the shapes, the center of buoyancy and th...
Definition: Shape.h:450
 
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition: Vec3.inl:107