diff --git a/Jolt/Geometry/RayAABox.h b/Jolt/Geometry/RayAABox.h index 31970e7c1..90a08f617 100644 --- a/Jolt/Geometry/RayAABox.h +++ b/Jolt/Geometry/RayAABox.h @@ -21,7 +21,7 @@ class RayInvDirection mIsParallel = Vec3::sLessOrEqual(inDirection.Abs(), Vec3::sReplicate(1.0e-20f)); // Calculate 1 / direction while avoiding division by zero - mInvDirection = Vec3::sSelect(inDirection, Vec3::sReplicate(1.0f), mIsParallel).Reciprocal(); + mInvDirection = Vec3::sSelect(inDirection, Vec3::sOne(), mIsParallel).Reciprocal(); } Vec3 mInvDirection; ///< 1 / ray direction diff --git a/Jolt/Geometry/RayTriangle.h b/Jolt/Geometry/RayTriangle.h index dabd0275c..42dc921d7 100644 --- a/Jolt/Geometry/RayTriangle.h +++ b/Jolt/Geometry/RayTriangle.h @@ -15,7 +15,7 @@ JPH_INLINE float RayTriangle(Vec3Arg inOrigin, Vec3Arg inDirection, Vec3Arg inV0 // Zero & one Vec3 zero = Vec3::sZero(); - Vec3 one = Vec3::sReplicate(1.0f); + Vec3 one = Vec3::sOne(); // Find vectors for two edges sharing inV0 Vec3 e1 = inV1 - inV0; @@ -31,7 +31,7 @@ JPH_INLINE float RayTriangle(Vec3Arg inOrigin, Vec3Arg inDirection, Vec3Arg inV0 UVec4 det_near_zero = Vec3::sLess(det.Abs(), epsilon); // When the determinant is near zero, set it to one to avoid dividing by zero - det = Vec3::sSelect(det, Vec3::sReplicate(1.0f), det_near_zero); + det = Vec3::sSelect(det, Vec3::sOne(), det_near_zero); // Calculate distance from inV0 to ray origin Vec3 s = inOrigin - inV0; @@ -110,7 +110,7 @@ JPH_INLINE Vec4 RayTriangle4(Vec3Arg inOrigin, Vec3Arg inDirection, Vec4Arg inV0 UVec4 det_near_zero = Vec4::sLess(det, epsilon); // Set components of the determinant to 1 that are near zero to avoid dividing by zero - det = Vec4::sSelect(det, Vec4::sReplicate(1.0f), det_near_zero); + det = Vec4::sSelect(det, Vec4::sOne(), det_near_zero); // Calculate distance from inV0 to ray origin Vec4 sx = inOrigin.SplatX() - inV0X; diff --git a/Jolt/Math/DVec3.h b/Jolt/Math/DVec3.h index 74d209b2a..b2f901991 100644 --- a/Jolt/Math/DVec3.h +++ b/Jolt/Math/DVec3.h @@ -50,6 +50,9 @@ class [[nodiscard]] alignas(JPH_DVECTOR_ALIGNMENT) DVec3 /// Vector with all zeros static JPH_INLINE DVec3 sZero(); + /// Vector with all ones + static JPH_INLINE DVec3 sOne(); + /// Vectors with the principal axis static JPH_INLINE DVec3 sAxisX() { return DVec3(1, 0, 0); } static JPH_INLINE DVec3 sAxisY() { return DVec3(0, 1, 0); } diff --git a/Jolt/Math/DVec3.inl b/Jolt/Math/DVec3.inl index eb0bcf439..fd18db409 100644 --- a/Jolt/Math/DVec3.inl +++ b/Jolt/Math/DVec3.inl @@ -147,6 +147,11 @@ DVec3 DVec3::sReplicate(double inV) #endif } +DVec3 DVec3::sOne() +{ + return sReplicate(1.0); +} + DVec3 DVec3::sNaN() { return sReplicate(numeric_limits::quiet_NaN()); @@ -727,7 +732,7 @@ DVec3 DVec3::Abs() const DVec3 DVec3::Reciprocal() const { - return sReplicate(1.0) / mValue; + return sOne() / mValue; } DVec3 DVec3::Cross(DVec3Arg inV2) const diff --git a/Jolt/Math/Vec3.h b/Jolt/Math/Vec3.h index 18264db7e..76d42fb48 100644 --- a/Jolt/Math/Vec3.h +++ b/Jolt/Math/Vec3.h @@ -46,6 +46,9 @@ class [[nodiscard]] alignas(JPH_VECTOR_ALIGNMENT) Vec3 /// Vector with all zeros static JPH_INLINE Vec3 sZero(); + /// Vector with all ones + static JPH_INLINE Vec3 sOne(); + /// Vector with all NaN's static JPH_INLINE Vec3 sNaN(); diff --git a/Jolt/Math/Vec3.inl b/Jolt/Math/Vec3.inl index dba99360d..cea60f4d8 100644 --- a/Jolt/Math/Vec3.inl +++ b/Jolt/Math/Vec3.inl @@ -122,6 +122,11 @@ Vec3 Vec3::sReplicate(float inV) #endif } +Vec3 Vec3::sOne() +{ + return sReplicate(1.0f); +} + Vec3 Vec3::sNaN() { return sReplicate(numeric_limits::quiet_NaN()); @@ -584,7 +589,7 @@ Vec3 Vec3::Abs() const Vec3 Vec3::Reciprocal() const { - return sReplicate(1.0f) / mValue; + return sOne() / mValue; } Vec3 Vec3::Cross(Vec3Arg inV2) const diff --git a/Jolt/Math/Vec4.h b/Jolt/Math/Vec4.h index eb924a0f6..4098626a7 100644 --- a/Jolt/Math/Vec4.h +++ b/Jolt/Math/Vec4.h @@ -38,6 +38,9 @@ class [[nodiscard]] alignas(JPH_VECTOR_ALIGNMENT) Vec4 /// Vector with all zeros static JPH_INLINE Vec4 sZero(); + /// Vector with all ones + static JPH_INLINE Vec4 sOne(); + /// Vector with all NaN's static JPH_INLINE Vec4 sNaN(); diff --git a/Jolt/Math/Vec4.inl b/Jolt/Math/Vec4.inl index 43676361c..bcbd2fb38 100644 --- a/Jolt/Math/Vec4.inl +++ b/Jolt/Math/Vec4.inl @@ -82,6 +82,11 @@ Vec4 Vec4::sReplicate(float inV) #endif } +Vec4 Vec4::sOne() +{ + return sReplicate(1.0f); +} + Vec4 Vec4::sNaN() { return sReplicate(numeric_limits::quiet_NaN()); @@ -614,7 +619,7 @@ Vec4 Vec4::Abs() const Vec4 Vec4::Reciprocal() const { - return sReplicate(1.0f) / mValue; + return sOne() / mValue; } Vec4 Vec4::DotV(Vec4Arg inV2) const @@ -805,7 +810,7 @@ void Vec4::SinCos(Vec4 &outSin, Vec4 &outCos) const // Taylor expansion: // Cos(x) = 1 - x^2/2! + x^4/4! - x^6/6! + x^8/8! + ... = (((x2/8!- 1/6!) * x2 + 1/4!) * x2 - 1/2!) * x2 + 1 - Vec4 taylor_cos = ((2.443315711809948e-5f * x2 - Vec4::sReplicate(1.388731625493765e-3f)) * x2 + Vec4::sReplicate(4.166664568298827e-2f)) * x2 * x2 - 0.5f * x2 + Vec4::sReplicate(1.0f); + Vec4 taylor_cos = ((2.443315711809948e-5f * x2 - Vec4::sReplicate(1.388731625493765e-3f)) * x2 + Vec4::sReplicate(4.166664568298827e-2f)) * x2 * x2 - 0.5f * x2 + Vec4::sOne(); // Sin(x) = x - x^3/3! + x^5/5! - x^7/7! + ... = ((-x2/7! + 1/5!) * x2 - 1/3!) * x2 * x + x Vec4 taylor_sin = ((-1.9515295891e-4f * x2 + Vec4::sReplicate(8.3321608736e-3f)) * x2 - Vec4::sReplicate(1.6666654611e-1f)) * x2 * x + x; @@ -880,14 +885,14 @@ Vec4 Vec4::ASin() const Vec4 a = Vec4::sXor(*this, asin_sign.ReinterpretAsFloat()); // ASin is not defined outside the range [-1, 1] but it often happens that a value is slightly above 1 so we just clamp here - a = Vec4::sMin(a, Vec4::sReplicate(1.0f)); + a = Vec4::sMin(a, Vec4::sOne()); // When |x| <= 0.5 we use the asin approximation as is Vec4 z1 = a * a; Vec4 x1 = a; // When |x| > 0.5 we use the identity asin(x) = PI / 2 - 2 * asin(sqrt((1 - x) / 2)) - Vec4 z2 = 0.5f * (Vec4::sReplicate(1.0f) - a); + Vec4 z2 = 0.5f * (Vec4::sOne() - a); Vec4 x2 = z2.Sqrt(); // Select which of the two situations we have @@ -923,7 +928,7 @@ Vec4 Vec4::ATan() const // If x > Tan(PI / 8) UVec4 greater1 = Vec4::sGreater(x, Vec4::sReplicate(0.4142135623730950f)); - Vec4 x1 = (x - Vec4::sReplicate(1.0f)) / (x + Vec4::sReplicate(1.0f)); + Vec4 x1 = (x - Vec4::sOne()) / (x + Vec4::sOne()); // If x > Tan(3 * PI / 8) UVec4 greater2 = Vec4::sGreater(x, Vec4::sReplicate(2.414213562373095f)); diff --git a/Jolt/Physics/Body/Body.cpp b/Jolt/Physics/Body/Body.cpp index e5969eed8..5fdb92202 100644 --- a/Jolt/Physics/Body/Body.cpp +++ b/Jolt/Physics/Body/Body.cpp @@ -96,7 +96,7 @@ void Body::MoveKinematic(RVec3Arg inTargetPosition, QuatArg inTargetRotation, fl void Body::CalculateWorldSpaceBoundsInternal() { - mBounds = mShape->GetWorldSpaceBounds(GetCenterOfMassTransform(), Vec3::sReplicate(1.0f)); + mBounds = mShape->GetWorldSpaceBounds(GetCenterOfMassTransform(), Vec3::sOne()); } void Body::SetPositionAndRotationInternal(RVec3Arg inPosition, QuatArg inRotation, bool inResetSleepTimer) @@ -190,7 +190,7 @@ void Body::GetSubmergedVolume(RVec3Arg inSurfacePosition, Vec3Arg inSurfaceNorma Plane surface_relative_to_body = Plane::sFromPointAndNormal(inSurfacePosition - mPosition, inSurfaceNormal); // Calculate amount of volume that is submerged and what the center of buoyancy is - mShape->GetSubmergedVolume(rotation, Vec3::sReplicate(1.0f), surface_relative_to_body, outTotalVolume, outSubmergedVolume, outRelativeCenterOfBuoyancy JPH_IF_DEBUG_RENDERER(, mPosition)); + mShape->GetSubmergedVolume(rotation, Vec3::sOne(), surface_relative_to_body, outTotalVolume, outSubmergedVolume, outRelativeCenterOfBuoyancy JPH_IF_DEBUG_RENDERER(, mPosition)); } bool Body::ApplyBuoyancyImpulse(float inTotalVolume, float inSubmergedVolume, Vec3Arg inRelativeCenterOfBuoyancy, float inBuoyancy, float inLinearDrag, float inAngularDrag, Vec3Arg inFluidVelocity, Vec3Arg inGravity, float inDeltaTime) diff --git a/Jolt/Physics/Body/BodyManager.cpp b/Jolt/Physics/Body/BodyManager.cpp index a48e4b0f8..6040445e4 100644 --- a/Jolt/Physics/Body/BodyManager.cpp +++ b/Jolt/Physics/Body/BodyManager.cpp @@ -1014,15 +1014,15 @@ void BodyManager::Draw(const DrawSettings &inDrawSettings, const PhysicsSettings // Draw the results of GetSupportFunction if (inDrawSettings.mDrawGetSupportFunction) - body->mShape->DrawGetSupportFunction(inRenderer, body->GetCenterOfMassTransform(), Vec3::sReplicate(1.0f), color, inDrawSettings.mDrawSupportDirection); + body->mShape->DrawGetSupportFunction(inRenderer, body->GetCenterOfMassTransform(), Vec3::sOne(), color, inDrawSettings.mDrawSupportDirection); // Draw the results of GetSupportingFace if (inDrawSettings.mDrawGetSupportingFace) - body->mShape->DrawGetSupportingFace(inRenderer, body->GetCenterOfMassTransform(), Vec3::sReplicate(1.0f)); + body->mShape->DrawGetSupportingFace(inRenderer, body->GetCenterOfMassTransform(), Vec3::sOne()); // Draw the shape if (inDrawSettings.mDrawShape) - body->mShape->Draw(inRenderer, body->GetCenterOfMassTransform(), Vec3::sReplicate(1.0f), color, inDrawSettings.mDrawShapeColor == EShapeColor::MaterialColor, inDrawSettings.mDrawShapeWireframe || is_sensor); + body->mShape->Draw(inRenderer, body->GetCenterOfMassTransform(), Vec3::sOne(), color, inDrawSettings.mDrawShapeColor == EShapeColor::MaterialColor, inDrawSettings.mDrawShapeWireframe || is_sensor); // Draw bounding box if (inDrawSettings.mDrawBoundingBox) @@ -1147,7 +1147,7 @@ void BodyManager::ValidateActiveBodyBounds() { const Body *body = mBodies[id->GetIndex()]; AABox cached = body->GetWorldSpaceBounds(); - AABox calculated = body->GetShape()->GetWorldSpaceBounds(body->GetCenterOfMassTransform(), Vec3::sReplicate(1.0f)); + AABox calculated = body->GetShape()->GetWorldSpaceBounds(body->GetCenterOfMassTransform(), Vec3::sOne()); JPH_ASSERT(cached == calculated); } } diff --git a/Jolt/Physics/Body/MotionProperties.inl b/Jolt/Physics/Body/MotionProperties.inl index e9521f744..200ab680a 100644 --- a/Jolt/Physics/Body/MotionProperties.inl +++ b/Jolt/Physics/Body/MotionProperties.inl @@ -107,8 +107,8 @@ void MotionProperties::ApplyGyroscopicForceInternal(QuatArg inBodyRotation, floa // Calculate local space inertia tensor (a diagonal in local space) UVec4 is_zero = Vec3::sEquals(mInvInertiaDiagonal, Vec3::sZero()); - Vec3 denominator = Vec3::sSelect(mInvInertiaDiagonal, Vec3::sReplicate(1.0f), is_zero); - Vec3 nominator = Vec3::sSelect(Vec3::sReplicate(1.0f), Vec3::sZero(), is_zero); + Vec3 denominator = Vec3::sSelect(mInvInertiaDiagonal, Vec3::sOne(), is_zero); + Vec3 nominator = Vec3::sSelect(Vec3::sOne(), Vec3::sZero(), is_zero); Vec3 local_inertia = nominator / denominator; // Avoid dividing by zero, inertia in this axis will be zero // Calculate local space angular momentum diff --git a/Jolt/Physics/Character/Character.cpp b/Jolt/Physics/Character/Character.cpp index e2783d0ed..1efb683de 100644 --- a/Jolt/Physics/Character/Character.cpp +++ b/Jolt/Physics/Character/Character.cpp @@ -85,7 +85,7 @@ void Character::CheckCollision(RMat44Arg inCenterOfMassTransform, Vec3Arg inMove settings.mActiveEdgeMovementDirection = inMovementDirection; settings.mBackFaceMode = EBackFaceMode::IgnoreBackFaces; - sGetNarrowPhaseQuery(mSystem, inLockBodies).CollideShape(inShape, Vec3::sReplicate(1.0f), inCenterOfMassTransform, settings, inBaseOffset, ioCollector, broadphase_layer_filter, object_layer_filter, body_filter); + sGetNarrowPhaseQuery(mSystem, inLockBodies).CollideShape(inShape, Vec3::sOne(), inCenterOfMassTransform, settings, inBaseOffset, ioCollector, broadphase_layer_filter, object_layer_filter, body_filter); } void Character::CheckCollision(RVec3Arg inPosition, QuatArg inRotation, Vec3Arg inMovementDirection, float inMaxSeparationDistance, const Shape *inShape, RVec3Arg inBaseOffset, CollideShapeCollector &ioCollector, bool inLockBodies) const diff --git a/Jolt/Physics/Character/CharacterVirtual.cpp b/Jolt/Physics/Character/CharacterVirtual.cpp index 7af79b7fd..fe753f733 100644 --- a/Jolt/Physics/Character/CharacterVirtual.cpp +++ b/Jolt/Physics/Character/CharacterVirtual.cpp @@ -53,7 +53,7 @@ void CharacterVsCharacterCollisionSimple::CollideCharacter(const CharacterVirtua settings.mMaxSeparationDistance = inCollideShapeSettings.mMaxSeparationDistance + c->GetCharacterPadding(); // Note that this collides against the character's shape without padding, this will be corrected for in CharacterVirtual::GetContactsAtPosition - CollisionDispatch::sCollideShapeVsShape(shape, c->GetShape(), Vec3::sReplicate(1.0f), Vec3::sReplicate(1.0f), transform1, transform2, SubShapeIDCreator(), SubShapeIDCreator(), settings, ioCollector); + CollisionDispatch::sCollideShapeVsShape(shape, c->GetShape(), Vec3::sOne(), Vec3::sOne(), transform1, transform2, SubShapeIDCreator(), SubShapeIDCreator(), settings, ioCollector); } // Reset the user data @@ -64,7 +64,7 @@ void CharacterVsCharacterCollisionSimple::CastCharacter(const CharacterVirtual * { // Convert shape cast relative to inBaseOffset Mat44 transform1 = inCenterOfMassTransform.PostTranslated(-inBaseOffset).ToMat44(); - ShapeCast shape_cast(inCharacter->GetShape(), Vec3::sReplicate(1.0f), transform1, inDirection); + ShapeCast shape_cast(inCharacter->GetShape(), Vec3::sOne(), transform1, inDirection); // Iterate over all characters for (const CharacterVirtual *c : mCharacters) @@ -78,7 +78,7 @@ void CharacterVsCharacterCollisionSimple::CastCharacter(const CharacterVirtual * Mat44 transform2 = c->GetCenterOfMassTransform().PostTranslated(-inBaseOffset).ToMat44(); // Note that this collides against the character's shape without padding, this will be corrected for in CharacterVirtual::GetFirstContactForSweep - CollisionDispatch::sCastShapeVsShapeWorldSpace(shape_cast, inShapeCastSettings, c->GetShape(), Vec3::sReplicate(1.0f), { }, transform2, SubShapeIDCreator(), SubShapeIDCreator(), ioCollector); + CollisionDispatch::sCastShapeVsShapeWorldSpace(shape_cast, inShapeCastSettings, c->GetShape(), Vec3::sOne(), { }, transform2, SubShapeIDCreator(), SubShapeIDCreator(), ioCollector); } // Reset the user data @@ -371,7 +371,7 @@ void CharacterVirtual::CheckCollision(RVec3Arg inPosition, QuatArg inRotation, V auto collide_shape_function = mEnhancedInternalEdgeRemoval? &NarrowPhaseQuery::CollideShapeWithInternalEdgeRemoval : &NarrowPhaseQuery::CollideShape; // Collide shape - (mSystem->GetNarrowPhaseQuery().*collide_shape_function)(inShape, Vec3::sReplicate(1.0f), transform, settings, inBaseOffset, ioCollector, inBroadPhaseLayerFilter, inObjectLayerFilter, body_filter, inShapeFilter); + (mSystem->GetNarrowPhaseQuery().*collide_shape_function)(inShape, Vec3::sOne(), transform, settings, inBaseOffset, ioCollector, inBroadPhaseLayerFilter, inObjectLayerFilter, body_filter, inShapeFilter); // Also collide with other characters if (mCharacterVsCharacterCollision != nullptr) @@ -557,7 +557,7 @@ bool CharacterVirtual::GetFirstContactForSweep(RVec3Arg inPosition, Vec3Arg inDi RVec3 base_offset = start.GetTranslation(); ContactCastCollector collector(mSystem, this, inDisplacement, mUp, inIgnoredContacts, base_offset, contact); collector.ResetEarlyOutFraction(contact.mFraction); - RShapeCast shape_cast(mShape, Vec3::sReplicate(1.0f), start, inDisplacement); + RShapeCast shape_cast(mShape, Vec3::sOne(), start, inDisplacement); mSystem->GetNarrowPhaseQuery().CastShape(shape_cast, settings, base_offset, collector, inBroadPhaseLayerFilter, inObjectLayerFilter, body_filter, inShapeFilter); // Also collide with other characters @@ -602,7 +602,7 @@ bool CharacterVirtual::GetFirstContactForSweep(RVec3Arg inPosition, Vec3Arg inDi AddConvexRadius add_cvx(polygon, character_padding); // Correct fraction to hit this inflated face instead of the inner shape - corrected = sCorrectFractionForCharacterPadding(mShape, start.GetRotation(), inDisplacement, Vec3::sReplicate(1.0f), add_cvx, outContact.mFraction); + corrected = sCorrectFractionForCharacterPadding(mShape, start.GetRotation(), inDisplacement, Vec3::sOne(), add_cvx, outContact.mFraction); } if (!corrected) { @@ -1602,7 +1602,7 @@ bool CharacterVirtual::WalkStairs(float inDeltaTime, Vec3Arg inStepUp, Vec3Arg i RVec3 debug_pos = new_position + contact.mFraction * down; DebugRenderer::sInstance->DrawArrow(new_position, debug_pos, Color::sWhite, 0.01f); DebugRenderer::sInstance->DrawArrow(contact.mPosition, contact.mPosition + contact.mSurfaceNormal, Color::sWhite, 0.01f); - mShape->Draw(DebugRenderer::sInstance, GetCenterOfMassTransform(debug_pos, mRotation, mShape), Vec3::sReplicate(1.0f), Color::sWhite, false, true); + mShape->Draw(DebugRenderer::sInstance, GetCenterOfMassTransform(debug_pos, mRotation, mShape), Vec3::sOne(), Color::sWhite, false, true); } #endif // JPH_DEBUG_RENDERER @@ -1640,7 +1640,7 @@ bool CharacterVirtual::WalkStairs(float inDeltaTime, Vec3Arg inStepUp, Vec3Arg i RVec3 debug_pos = test_position + test_contact.mFraction * down; DebugRenderer::sInstance->DrawArrow(test_position, debug_pos, Color::sCyan, 0.01f); DebugRenderer::sInstance->DrawArrow(test_contact.mPosition, test_contact.mPosition + test_contact.mSurfaceNormal, Color::sCyan, 0.01f); - mShape->Draw(DebugRenderer::sInstance, GetCenterOfMassTransform(debug_pos, mRotation, mShape), Vec3::sReplicate(1.0f), Color::sCyan, false, true); + mShape->Draw(DebugRenderer::sInstance, GetCenterOfMassTransform(debug_pos, mRotation, mShape), Vec3::sOne(), Color::sCyan, false, true); } #endif // JPH_DEBUG_RENDERER @@ -1680,7 +1680,7 @@ bool CharacterVirtual::StickToFloor(Vec3Arg inStepDown, const BroadPhaseLayerFil if (sDrawStickToFloor) { DebugRenderer::sInstance->DrawArrow(mPosition, new_position, Color::sOrange, 0.01f); - mShape->Draw(DebugRenderer::sInstance, GetCenterOfMassTransform(new_position, mRotation, mShape), Vec3::sReplicate(1.0f), Color::sOrange, false, true); + mShape->Draw(DebugRenderer::sInstance, GetCenterOfMassTransform(new_position, mRotation, mShape), Vec3::sOne(), Color::sOrange, false, true); } #endif // JPH_DEBUG_RENDERER diff --git a/Jolt/Physics/Collision/BroadPhase/QuadTree.cpp b/Jolt/Physics/Collision/BroadPhase/QuadTree.cpp index 323609955..4908248fd 100644 --- a/Jolt/Physics/Collision/BroadPhase/QuadTree.cpp +++ b/Jolt/Physics/Collision/BroadPhase/QuadTree.cpp @@ -1534,7 +1534,7 @@ void QuadTree::ValidateTree(const BodyVector &inBodies, const TrackingVector &in node.GetChildBounds(i, body_bounds); const Body *body = inBodies[child_node_id.GetBodyID().GetIndex()]; AABox cached_body_bounds = body->GetWorldSpaceBounds(); - AABox real_body_bounds = body->GetShape()->GetWorldSpaceBounds(body->GetCenterOfMassTransform(), Vec3::sReplicate(1.0f)); + AABox real_body_bounds = body->GetShape()->GetWorldSpaceBounds(body->GetCenterOfMassTransform(), Vec3::sOne()); JPH_ASSERT(cached_body_bounds == real_body_bounds); // Check that cached body bounds are up to date JPH_ASSERT(body_bounds.Contains(real_body_bounds)); } diff --git a/Jolt/Physics/Collision/Shape/ConvexShape.cpp b/Jolt/Physics/Collision/Shape/ConvexShape.cpp index e9fa343ab..0c9fbf35e 100644 --- a/Jolt/Physics/Collision/Shape/ConvexShape.cpp +++ b/Jolt/Physics/Collision/Shape/ConvexShape.cpp @@ -171,7 +171,7 @@ bool ConvexShape::CastRay(const RayCast &inRay, const SubShapeIDCreator &inSubSh // Create support function SupportBuffer buffer; - const Support *support = GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sReplicate(1.0f)); + const Support *support = GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sOne()); // Cast ray GJKClosestPoint gjk; @@ -241,7 +241,7 @@ void ConvexShape::CollidePoint(Vec3Arg inPoint, const SubShapeIDCreator &inSubSh { // Create support function SupportBuffer buffer; - const Support *support = GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sReplicate(1.0f)); + const Support *support = GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sOne()); // Create support function for point PointConvexSupport point { inPoint }; @@ -319,7 +319,7 @@ class ConvexShape::CSGetTrianglesContext mLocalToWorld(Mat44::sRotationTranslation(inRotation, inPositionCOM) * Mat44::sScale(inScale)), mIsInsideOut(ScaleHelpers::IsInsideOut(inScale)) { - mSupport = inShape->GetSupportFunction(ESupportMode::IncludeConvexRadius, mSupportBuffer, Vec3::sReplicate(1.0f)); + mSupport = inShape->GetSupportFunction(ESupportMode::IncludeConvexRadius, mSupportBuffer, Vec3::sOne()); } SupportBuffer mSupportBuffer; diff --git a/Jolt/Physics/Collision/Shape/HeightFieldShape.h b/Jolt/Physics/Collision/Shape/HeightFieldShape.h index fa3e24c48..5aa6de889 100644 --- a/Jolt/Physics/Collision/Shape/HeightFieldShape.h +++ b/Jolt/Physics/Collision/Shape/HeightFieldShape.h @@ -69,7 +69,7 @@ class JPH_EXPORT HeightFieldShapeSettings final : public ShapeSettings /// The height field is a surface defined by: mOffset + mScale * (x, mHeightSamples[y * mSampleCount + x], y). /// where x and y are integers in the range x and y e [0, mSampleCount - 1]. Vec3 mOffset = Vec3::sZero(); - Vec3 mScale = Vec3::sReplicate(1.0f); + Vec3 mScale = Vec3::sOne(); uint32 mSampleCount = 0; /// Artificial minimal value of mHeightSamples, used for compression and can be used to update the terrain after creating with lower height values. If there are any lower values in mHeightSamples, this value will be ignored. @@ -349,7 +349,7 @@ class JPH_EXPORT HeightFieldShape final : public Shape /// The height field is a surface defined by: mOffset + mScale * (x, mHeightSamples[y * mSampleCount + x], y). /// where x and y are integers in the range x and y e [0, mSampleCount - 1]. Vec3 mOffset = Vec3::sZero(); - Vec3 mScale = Vec3::sReplicate(1.0f); + Vec3 mScale = Vec3::sOne(); /// Height data uint32 mSampleCount = 0; ///< See HeightFieldShapeSettings::mSampleCount diff --git a/Jolt/Physics/Collision/Shape/MeshShape.cpp b/Jolt/Physics/Collision/Shape/MeshShape.cpp index 852021a04..f703ad86c 100644 --- a/Jolt/Physics/Collision/Shape/MeshShape.cpp +++ b/Jolt/Physics/Collision/Shape/MeshShape.cpp @@ -349,7 +349,7 @@ MassProperties MeshShape::GetMassProperties() const // creating a Body: // // BodyCreationSettings::mOverrideMassProperties = EOverrideMassProperties::MassAndInertiaProvided; - // BodyCreationSettings::mMassPropertiesOverride.SetMassAndInertiaOfSolidBox(Vec3::sReplicate(1.0f), 1000.0f); + // BodyCreationSettings::mMassPropertiesOverride.SetMassAndInertiaOfSolidBox(Vec3::sOne(), 1000.0f); // // Note that for a mesh shape to simulate properly, it is best if the mesh is manifold // (i.e. closed, all edges shared by only two triangles, consistent winding order). diff --git a/Jolt/Physics/Collision/Shape/MutableCompoundShape.cpp b/Jolt/Physics/Collision/Shape/MutableCompoundShape.cpp index a83fc9aad..696223fc0 100644 --- a/Jolt/Physics/Collision/Shape/MutableCompoundShape.cpp +++ b/Jolt/Physics/Collision/Shape/MutableCompoundShape.cpp @@ -181,7 +181,7 @@ void MutableCompoundShape::CalculateSubShapeBounds(uint inStartIdx, uint inNumbe Mat44 transform = Mat44::sRotationTranslation(sub_shape.GetRotation(), sub_shape.GetPositionCOM()); // Get the bounding box - sub_shape_bounds = sub_shape.mShape->GetWorldSpaceBounds(transform, Vec3::sReplicate(1.0f)); + sub_shape_bounds = sub_shape.mShape->GetWorldSpaceBounds(transform, Vec3::sOne()); } // Put the bounds as columns in a matrix diff --git a/Jolt/Physics/Collision/Shape/ScaleHelpers.h b/Jolt/Physics/Collision/Shape/ScaleHelpers.h index 4035dd77a..f1c9f6fa7 100644 --- a/Jolt/Physics/Collision/Shape/ScaleHelpers.h +++ b/Jolt/Physics/Collision/Shape/ScaleHelpers.h @@ -18,7 +18,7 @@ namespace ScaleHelpers static constexpr float cScaleToleranceSq = 1.0e-8f; /// Test if a scale is identity - inline bool IsNotScaled(Vec3Arg inScale) { return inScale.IsClose(Vec3::sReplicate(1.0f), cScaleToleranceSq); } + inline bool IsNotScaled(Vec3Arg inScale) { return inScale.IsClose(Vec3::sOne(), cScaleToleranceSq); } /// Test if a scale is uniform inline bool IsUniformScale(Vec3Arg inScale) { return inScale.Swizzle().IsClose(inScale, cScaleToleranceSq); } diff --git a/Jolt/Physics/Collision/Shape/Shape.cpp b/Jolt/Physics/Collision/Shape/Shape.cpp index a3c37c0da..e5af580bb 100644 --- a/Jolt/Physics/Collision/Shape/Shape.cpp +++ b/Jolt/Physics/Collision/Shape/Shape.cpp @@ -233,7 +233,7 @@ Vec3 Shape::MakeScaleValid(Vec3Arg inScale) const Shape::ShapeResult Shape::ScaleShape(Vec3Arg inScale) const { - const Vec3 unit_scale = Vec3::sReplicate(1.0f); + const Vec3 unit_scale = Vec3::sOne(); if (inScale.IsNearZero()) { diff --git a/Jolt/Physics/Collision/Shape/SphereShape.cpp b/Jolt/Physics/Collision/Shape/SphereShape.cpp index b44dd77a1..00bf4ee35 100644 --- a/Jolt/Physics/Collision/Shape/SphereShape.cpp +++ b/Jolt/Physics/Collision/Shape/SphereShape.cpp @@ -303,7 +303,7 @@ void SphereShape::CollideSoftBodyVertices(Mat44Arg inCenterOfMassTransform, Vec3 void SphereShape::GetTrianglesStart(GetTrianglesContext &ioContext, const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale) const { float scaled_radius = GetScaledRadius(inScale); - new (&ioContext) GetTrianglesContextVertexList(inPositionCOM, inRotation, Vec3::sReplicate(1.0f), Mat44::sScale(scaled_radius), sUnitSphereTriangles.data(), sUnitSphereTriangles.size(), GetMaterial()); + new (&ioContext) GetTrianglesContextVertexList(inPositionCOM, inRotation, Vec3::sOne(), Mat44::sScale(scaled_radius), sUnitSphereTriangles.data(), sUnitSphereTriangles.size(), GetMaterial()); } int SphereShape::GetTrianglesNext(GetTrianglesContext &ioContext, int inMaxTrianglesRequested, Float3 *outTriangleVertices, const PhysicsMaterial **outMaterials) const diff --git a/Jolt/Physics/Collision/Shape/StaticCompoundShape.cpp b/Jolt/Physics/Collision/Shape/StaticCompoundShape.cpp index eb9ec06b9..88db1689f 100644 --- a/Jolt/Physics/Collision/Shape/StaticCompoundShape.cpp +++ b/Jolt/Physics/Collision/Shape/StaticCompoundShape.cpp @@ -234,7 +234,7 @@ StaticCompoundShape::StaticCompoundShape(const StaticCompoundShapeSettings &inSe // Transform the shape's bounds into our local space Mat44 transform = Mat44::sRotationTranslation(shape.GetRotation(), shape.GetPositionCOM()); - AABox shape_bounds = shape.mShape->GetWorldSpaceBounds(transform, Vec3::sReplicate(1.0f)); + AABox shape_bounds = shape.mShape->GetWorldSpaceBounds(transform, Vec3::sOne()); // Store bounds and body index for tree construction bounds[i] = shape_bounds; diff --git a/Jolt/Physics/Collision/Shape/TaperedCapsuleShape.cpp b/Jolt/Physics/Collision/Shape/TaperedCapsuleShape.cpp index a3a9e020d..3f9a3ebfb 100644 --- a/Jolt/Physics/Collision/Shape/TaperedCapsuleShape.cpp +++ b/Jolt/Physics/Collision/Shape/TaperedCapsuleShape.cpp @@ -376,7 +376,7 @@ void TaperedCapsuleShape::Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMa if (mGeometry == nullptr) { SupportBuffer buffer; - const Support *support = GetSupportFunction(ESupportMode::IncludeConvexRadius, buffer, Vec3::sReplicate(1.0f)); + const Support *support = GetSupportFunction(ESupportMode::IncludeConvexRadius, buffer, Vec3::sOne()); mGeometry = inRenderer->CreateTriangleGeometryForConvex([support](Vec3Arg inDirection) { return support->GetSupport(inDirection); }); } diff --git a/Jolt/Physics/Collision/Shape/TriangleShape.cpp b/Jolt/Physics/Collision/Shape/TriangleShape.cpp index e7514a77f..ee22c7ce2 100644 --- a/Jolt/Physics/Collision/Shape/TriangleShape.cpp +++ b/Jolt/Physics/Collision/Shape/TriangleShape.cpp @@ -188,7 +188,7 @@ MassProperties TriangleShape::GetMassProperties() const // creating a Body: // // BodyCreationSettings::mOverrideMassProperties = EOverrideMassProperties::MassAndInertiaProvided; - // BodyCreationSettings::mMassPropertiesOverride.SetMassAndInertiaOfSolidBox(Vec3::sReplicate(1.0f), 1000.0f); + // BodyCreationSettings::mMassPropertiesOverride.SetMassAndInertiaOfSolidBox(Vec3::sOne(), 1000.0f); // // Note that this makes the triangle shape behave the same as a mesh shape with a single triangle. // In practice there is very little use for a dynamic triangle shape as back side collisions will be ignored diff --git a/Jolt/Physics/PhysicsScene.cpp b/Jolt/Physics/PhysicsScene.cpp index 1e9c60d23..e1c4145f9 100644 --- a/Jolt/Physics/PhysicsScene.cpp +++ b/Jolt/Physics/PhysicsScene.cpp @@ -42,7 +42,7 @@ void PhysicsScene::AddSoftBody(const SoftBodyCreationSettings &inSoftBody) bool PhysicsScene::FixInvalidScales() { - const Vec3 unit_scale = Vec3::sReplicate(1.0f); + const Vec3 unit_scale = Vec3::sOne(); bool success = true; for (BodyCreationSettings &b : mBodies) diff --git a/Jolt/Physics/PhysicsSystem.cpp b/Jolt/Physics/PhysicsSystem.cpp index 215693764..73a775671 100644 --- a/Jolt/Physics/PhysicsSystem.cpp +++ b/Jolt/Physics/PhysicsSystem.cpp @@ -1139,7 +1139,7 @@ void PhysicsSystem::ProcessBodyPair(ContactAllocator &ioContactAllocator, const // Perform collision detection between the two shapes SubShapeIDCreator part1, part2; auto f = enhanced_active_edges? InternalEdgeRemovingCollector::sCollideShapeVsShape : CollisionDispatch::sCollideShapeVsShape; - f(body1->GetShape(), body2->GetShape(), Vec3::sReplicate(1.0f), Vec3::sReplicate(1.0f), transform1, transform2, part1, part2, settings, collector, shape_filter); + f(body1->GetShape(), body2->GetShape(), Vec3::sOne(), Vec3::sOne(), transform1, transform2, part1, part2, settings, collector, shape_filter); // Add the contacts for (ContactManifold &manifold : collector.mManifolds) @@ -1240,7 +1240,7 @@ void PhysicsSystem::ProcessBodyPair(ContactAllocator &ioContactAllocator, const // Perform collision detection between the two shapes SubShapeIDCreator part1, part2; auto f = enhanced_active_edges? InternalEdgeRemovingCollector::sCollideShapeVsShape : CollisionDispatch::sCollideShapeVsShape; - f(body1->GetShape(), body2->GetShape(), Vec3::sReplicate(1.0f), Vec3::sReplicate(1.0f), transform1, transform2, part1, part2, settings, collector, shape_filter); + f(body1->GetShape(), body2->GetShape(), Vec3::sOne(), Vec3::sOne(), transform1, transform2, part1, part2, settings, collector, shape_filter); constraint_created = collector.mConstraintCreated; } @@ -1709,9 +1709,9 @@ void PhysicsSystem::JobFindCCDContacts(const PhysicsUpdateContext *ioContext, Ph if (sDrawMotionQualityLinearCast) { RMat44 com = body.GetCenterOfMassTransform(); - body.GetShape()->Draw(DebugRenderer::sInstance, com, Vec3::sReplicate(1.0f), Color::sGreen, false, true); + body.GetShape()->Draw(DebugRenderer::sInstance, com, Vec3::sOne(), Color::sGreen, false, true); DebugRenderer::sInstance->DrawArrow(com.GetTranslation(), com.GetTranslation() + ccd_body.mDeltaPosition, Color::sGreen, 0.1f); - body.GetShape()->Draw(DebugRenderer::sInstance, com.PostTranslated(ccd_body.mDeltaPosition), Vec3::sReplicate(1.0f), Color::sRed, false, true); + body.GetShape()->Draw(DebugRenderer::sInstance, com.PostTranslated(ccd_body.mDeltaPosition), Vec3::sOne(), Color::sRed, false, true); } #endif // JPH_DEBUG_RENDERER @@ -1917,7 +1917,7 @@ void PhysicsSystem::JobFindCCDContacts(const PhysicsUpdateContext *ioContext, Ph SimShapeFilterWrapper &shape_filter = shape_filter_union.GetSimShapeFilterWrapper(); // Check if we collide with any other body. Note that we use the non-locking interface as we know the broadphase cannot be modified at this point. - RShapeCast shape_cast(body.GetShape(), Vec3::sReplicate(1.0f), body.GetCenterOfMassTransform(), ccd_body.mDeltaPosition); + RShapeCast shape_cast(body.GetShape(), Vec3::sOne(), body.GetCenterOfMassTransform(), ccd_body.mDeltaPosition); CCDBroadPhaseCollector bp_collector(ccd_body, body, shape_cast, settings, shape_filter, np_collector, mBodyManager, ioStep, ioContext->mStepDeltaTime); mBroadPhase->CastAABoxNoLock({ shape_cast.mShapeWorldBounds, shape_cast.mDirection }, bp_collector, broadphase_layer_filter, object_layer_filter); @@ -2184,11 +2184,11 @@ void PhysicsSystem::JobResolveCCDContacts(PhysicsUpdateContext *ioContext, Physi { // Draw the collision location RMat44 collision_transform = body1.GetCenterOfMassTransform().PostTranslated(ccd_body->mFraction * ccd_body->mDeltaPosition); - body1.GetShape()->Draw(DebugRenderer::sInstance, collision_transform, Vec3::sReplicate(1.0f), Color::sYellow, false, true); + body1.GetShape()->Draw(DebugRenderer::sInstance, collision_transform, Vec3::sOne(), Color::sYellow, false, true); // Draw the collision location + slop RMat44 collision_transform_plus_slop = body1.GetCenterOfMassTransform().PostTranslated(ccd_body->mFractionPlusSlop * ccd_body->mDeltaPosition); - body1.GetShape()->Draw(DebugRenderer::sInstance, collision_transform_plus_slop, Vec3::sReplicate(1.0f), Color::sOrange, false, true); + body1.GetShape()->Draw(DebugRenderer::sInstance, collision_transform_plus_slop, Vec3::sOne(), Color::sOrange, false, true); // Draw contact normal DebugRenderer::sInstance->DrawArrow(ccd_body->mContactPointOn2, ccd_body->mContactPointOn2 - ccd_body->mContactNormal, Color::sYellow, 0.1f); diff --git a/Jolt/Physics/SoftBody/SoftBodyMotionProperties.cpp b/Jolt/Physics/SoftBody/SoftBodyMotionProperties.cpp index 80871375e..b7b0c2e7f 100644 --- a/Jolt/Physics/SoftBody/SoftBodyMotionProperties.cpp +++ b/Jolt/Physics/SoftBody/SoftBodyMotionProperties.cpp @@ -170,7 +170,7 @@ void SoftBodyMotionProperties::DetermineCollidingShapes(const SoftBodyUpdateCont Array mHits; }; LeafShapeCollector collector; - body.GetShape()->CollectTransformedShapes(mLocalBounds, com.GetTranslation(), com.GetQuaternion(), Vec3::sReplicate(1.0f), SubShapeIDCreator(), collector, mShapeFilter); + body.GetShape()->CollectTransformedShapes(mLocalBounds, com.GetTranslation(), com.GetQuaternion(), Vec3::sOne(), SubShapeIDCreator(), collector, mShapeFilter); if (collector.mHits.empty()) return; diff --git a/Jolt/Physics/Vehicle/VehicleCollisionTester.cpp b/Jolt/Physics/Vehicle/VehicleCollisionTester.cpp index 562468357..11756e293 100644 --- a/Jolt/Physics/Vehicle/VehicleCollisionTester.cpp +++ b/Jolt/Physics/Vehicle/VehicleCollisionTester.cpp @@ -139,7 +139,7 @@ bool VehicleCollisionTesterCastSphere::Collide(PhysicsSystem &inPhysicsSystem, c const WheelSettings *wheel_settings = inVehicleConstraint.GetWheel(inWheelIndex)->GetSettings(); float wheel_radius = wheel_settings->mRadius; float shape_cast_length = wheel_settings->mSuspensionMaxLength + wheel_radius - mRadius; - RShapeCast shape_cast(&sphere, Vec3::sReplicate(1.0f), RMat44::sTranslation(inOrigin), inDirection * shape_cast_length); + RShapeCast shape_cast(&sphere, Vec3::sOne(), RMat44::sTranslation(inOrigin), inDirection * shape_cast_length); ShapeCastSettings settings; settings.mUseShrunkenShapeAndConvexRadius = true; @@ -261,7 +261,7 @@ bool VehicleCollisionTesterCastCylinder::Collide(PhysicsSystem &inPhysicsSystem, CylinderShape cylinder(wheel_half_width, wheel_settings->mRadius, min(wheel_half_width, wheel_settings->mRadius) * mConvexRadiusFraction); cylinder.SetEmbedded(); - RShapeCast shape_cast(&cylinder, Vec3::sReplicate(1.0f), shape_cast_start, inDirection * max_suspension_length); + RShapeCast shape_cast(&cylinder, Vec3::sOne(), shape_cast_start, inDirection * max_suspension_length); ShapeCastSettings settings; settings.mUseShrunkenShapeAndConvexRadius = true; diff --git a/Samples/SamplesApp.cpp b/Samples/SamplesApp.cpp index 740d2a226..acbea8972 100644 --- a/Samples/SamplesApp.cpp +++ b/Samples/SamplesApp.cpp @@ -928,7 +928,7 @@ RefConst SamplesApp::CreateProbeShape() JPH_ASSERT(shape != nullptr); // Scale the shape - Vec3 scale = mScaleShape? shape->MakeScaleValid(mShapeScale) : Vec3::sReplicate(1.0f); + Vec3 scale = mScaleShape? shape->MakeScaleValid(mShapeScale) : Vec3::sOne(); JPH_ASSERT(shape->IsValidScale(scale)); // Double check the MakeScaleValid function if (!ScaleHelpers::IsNotScaled(scale)) shape = new ScaledShape(shape, scale); @@ -939,7 +939,7 @@ RefConst SamplesApp::CreateProbeShape() RefConst SamplesApp::CreateShootObjectShape() { // Get the scale - Vec3 scale = mShootObjectScaleShape? mShootObjectShapeScale : Vec3::sReplicate(1.0f); + Vec3 scale = mShootObjectScaleShape? mShootObjectShapeScale : Vec3::sOne(); // Make it minimally -0.1 or 0.1 depending on the sign Vec3 clamped_value = Vec3::sSelect(Vec3::sReplicate(-0.1f), Vec3::sReplicate(0.1f), Vec3::sGreaterOrEqual(scale, Vec3::sZero())); @@ -1001,7 +1001,7 @@ RefConst SamplesApp::CreateShootObjectShape() } // Scale shape if needed - if (scale != Vec3::sReplicate(1.0f)) + if (scale != Vec3::sOne()) shape = new ScaledShape(shape, scale); return shape; @@ -1294,21 +1294,21 @@ bool SamplesApp::CastProbe(float inProbeLength, float &outFraction, RVec3 &outPo if (mMaxHits == 0) { AnyHitCollisionCollector collector; - (mPhysicsSystem->GetNarrowPhaseQuery().*collide_shape_function)(shape, Vec3::sReplicate(1.0f), shape_transform, settings, base_offset, collector, { }, { }, { }, { }); + (mPhysicsSystem->GetNarrowPhaseQuery().*collide_shape_function)(shape, Vec3::sOne(), shape_transform, settings, base_offset, collector, { }, { }, { }, { }); if (collector.HadHit()) hits.push_back(collector.mHit); } else if (mMaxHits == 1) { ClosestHitCollisionCollector collector; - (mPhysicsSystem->GetNarrowPhaseQuery().*collide_shape_function)(shape, Vec3::sReplicate(1.0f), shape_transform, settings, base_offset, collector, { }, { }, { }, { }); + (mPhysicsSystem->GetNarrowPhaseQuery().*collide_shape_function)(shape, Vec3::sOne(), shape_transform, settings, base_offset, collector, { }, { }, { }, { }); if (collector.HadHit()) hits.push_back(collector.mHit); } else { AllHitCollisionCollector collector; - (mPhysicsSystem->GetNarrowPhaseQuery().*collide_shape_function)(shape, Vec3::sReplicate(1.0f), shape_transform, settings, base_offset, collector, { }, { }, { }, { }); + (mPhysicsSystem->GetNarrowPhaseQuery().*collide_shape_function)(shape, Vec3::sOne(), shape_transform, settings, base_offset, collector, { }, { }, { }, { }); collector.Sort(); hits.insert(hits.end(), collector.mHits.begin(), collector.mHits.end()); if ((int)hits.size() > mMaxHits) @@ -1359,7 +1359,7 @@ bool SamplesApp::CastProbe(float inProbeLength, float &outFraction, RVec3 &outPo #ifdef JPH_DEBUG_RENDERER // Draw shape - shape->Draw(mDebugRenderer, shape_transform, Vec3::sReplicate(1.0f), had_hit? Color::sGreen : Color::sGrey, false, false); + shape->Draw(mDebugRenderer, shape_transform, Vec3::sOne(), had_hit? Color::sGreen : Color::sGrey, false, false); #endif // JPH_DEBUG_RENDERER } break; @@ -1369,7 +1369,7 @@ bool SamplesApp::CastProbe(float inProbeLength, float &outFraction, RVec3 &outPo // Create shape cast RefConst shape = CreateProbeShape(); Mat44 rotation = Mat44::sRotation(Vec3::sAxisX(), 0.1f * JPH_PI) * Mat44::sRotation(Vec3::sAxisY(), 0.2f * JPH_PI); - RShapeCast shape_cast = RShapeCast::sFromWorldTransform(shape, Vec3::sReplicate(1.0f), RMat44::sTranslation(start) * rotation, direction); + RShapeCast shape_cast = RShapeCast::sFromWorldTransform(shape, Vec3::sOne(), RMat44::sTranslation(start) * rotation, direction); // Settings ShapeCastSettings settings; @@ -1434,7 +1434,7 @@ bool SamplesApp::CastProbe(float inProbeLength, float &outFraction, RVec3 &outPo // Draw shape Color color = hit_body.IsDynamic()? Color::sYellow : Color::sOrange; #ifdef JPH_DEBUG_RENDERER - shape_cast.mShape->Draw(mDebugRenderer, shape_cast.mCenterOfMassStart.PostTranslated(hit.mFraction * shape_cast.mDirection), Vec3::sReplicate(1.0f), color, false, false); + shape_cast.mShape->Draw(mDebugRenderer, shape_cast.mCenterOfMassStart.PostTranslated(hit.mFraction * shape_cast.mDirection), Vec3::sOne(), color, false, false); #endif // JPH_DEBUG_RENDERER // Draw normal @@ -1470,7 +1470,7 @@ bool SamplesApp::CastProbe(float inProbeLength, float &outFraction, RVec3 &outPo // Draw 'miss' mDebugRenderer->DrawLine(start, start + direction, Color::sRed); #ifdef JPH_DEBUG_RENDERER - shape_cast.mShape->Draw(mDebugRenderer, shape_cast.mCenterOfMassStart.PostTranslated(shape_cast.mDirection), Vec3::sReplicate(1.0f), Color::sRed, false, false); + shape_cast.mShape->Draw(mDebugRenderer, shape_cast.mCenterOfMassStart.PostTranslated(shape_cast.mDirection), Vec3::sOne(), Color::sRed, false, false); #endif // JPH_DEBUG_RENDERER } } @@ -1511,7 +1511,7 @@ bool SamplesApp::CastProbe(float inProbeLength, float &outFraction, RVec3 &outPo CollideShapeSettings settings; settings.mMaxSeparationDistance = sqrt(3.0f) * max_distance; // Box is extended in all directions by max_distance ClosestHitCollisionCollector collide_shape_collector; - ts.CollideShape(&point_sphere, Vec3::sReplicate(1.0f), RMat44::sTranslation(start + position), settings, start, collide_shape_collector); + ts.CollideShape(&point_sphere, Vec3::sOne(), RMat44::sTranslation(start + position), settings, start, collide_shape_collector); if (collide_shape_collector.HadHit()) { closest_point = collide_shape_collector.mHit.mContactPointOn2; @@ -2338,7 +2338,7 @@ void SamplesApp::DrawPhysics() // Start iterating all triangles of the shape Shape::GetTrianglesContext context; - transformed_shape.mShape->GetTrianglesStart(context, AABox::sBiggest(), Vec3::sZero(), Quat::sIdentity(), Vec3::sReplicate(1.0f)); + transformed_shape.mShape->GetTrianglesStart(context, AABox::sBiggest(), Vec3::sZero(), Quat::sIdentity(), Vec3::sOne()); for (;;) { // Get the next batch of vertices diff --git a/Samples/SamplesApp.h b/Samples/SamplesApp.h index 9f6f56033..91de0cf7d 100644 --- a/Samples/SamplesApp.h +++ b/Samples/SamplesApp.h @@ -191,9 +191,9 @@ class SamplesApp : public Application EProbeMode mProbeMode = EProbeMode::Pick; // Mouse probe mode. Determines what happens under the crosshair. EProbeShape mProbeShape = EProbeShape::Sphere; // Shape to use for the mouse probe. bool mScaleShape = false; // If the shape is scaled or not. When true mShapeScale is taken into account. - Vec3 mShapeScale = Vec3::sReplicate(1.0f); // Scale in local space for the probe shape. + Vec3 mShapeScale = Vec3::sOne(); // Scale in local space for the probe shape. EBackFaceMode mBackFaceModeTriangles = EBackFaceMode::CollideWithBackFaces; // How to handle back facing triangles when doing a collision probe check. - EBackFaceMode mBackFaceModeConvex = EBackFaceMode::CollideWithBackFaces; // How to handle back facing convex shapes when doing a collision probe check. + EBackFaceMode mBackFaceModeConvex = EBackFaceMode::CollideWithBackFaces; // How to handle back facing convex shapes when doing a collision probe check. EActiveEdgeMode mActiveEdgeMode = EActiveEdgeMode::CollideOnlyWithActive; // How to handle active edges when doing a collision probe check. ECollectFacesMode mCollectFacesMode = ECollectFacesMode::NoFaces; // If we should collect colliding faces float mMaxSeparationDistance = 0.0f; // Max separation distance for collide shape test @@ -219,7 +219,7 @@ class SamplesApp : public Application float mShootObjectFriction = 0.2f; // Friction for the object that is shot float mShootObjectRestitution = 0.0f; // Restitution for the object that is shot bool mShootObjectScaleShape = false; // If the shape should be scaled - Vec3 mShootObjectShapeScale = Vec3::sReplicate(1.0f); // Scale of the object to shoot + Vec3 mShootObjectShapeScale = Vec3::sOne(); // Scale of the object to shoot bool mWasShootKeyPressed = false; // Remembers if the shoot key was pressed last frame // Mouse dragging diff --git a/Samples/Tests/Character/CharacterBaseTest.cpp b/Samples/Tests/Character/CharacterBaseTest.cpp index 93e1f4a81..510412880 100644 --- a/Samples/Tests/Character/CharacterBaseTest.cpp +++ b/Samples/Tests/Character/CharacterBaseTest.cpp @@ -523,7 +523,7 @@ void CharacterBaseTest::Initialize() // Create a sensor { - BodyCreationSettings sensor(new BoxShape(Vec3::sReplicate(1.0f)), cSensorPosition, Quat::sIdentity(), EMotionType::Kinematic, Layers::SENSOR); + BodyCreationSettings sensor(new BoxShape(Vec3::sOne()), cSensorPosition, Quat::sIdentity(), EMotionType::Kinematic, Layers::SENSOR); sensor.mIsSensor = true; mSensorBody = mBodyInterface->CreateAndAddBody(sensor, EActivation::Activate); } @@ -639,7 +639,7 @@ void CharacterBaseTest::PrePhysicsUpdate(const PreUpdateParams &inParams) if (character != nullptr) { #ifdef JPH_DEBUG_RENDERER - character->GetShape()->Draw(mDebugRenderer, character->GetCenterOfMassTransform(), Vec3::sReplicate(1.0f), Color::sOrange, false, true); + character->GetShape()->Draw(mDebugRenderer, character->GetCenterOfMassTransform(), Vec3::sOne(), Color::sOrange, false, true); #else mDebugRenderer->DrawCapsule(character->GetCenterOfMassTransform(), 0.5f * cCharacterHeightStanding, cCharacterRadiusStanding + character->GetCharacterPadding(), Color::sOrange, DebugRenderer::ECastShadow::Off, DebugRenderer::EDrawMode::Wireframe); #endif // JPH_DEBUG_RENDERER diff --git a/Samples/Tests/Character/CharacterPlanetTest.cpp b/Samples/Tests/Character/CharacterPlanetTest.cpp index f7f7f9561..4ed42d0d3 100644 --- a/Samples/Tests/Character/CharacterPlanetTest.cpp +++ b/Samples/Tests/Character/CharacterPlanetTest.cpp @@ -83,7 +83,7 @@ void CharacterPlanetTest::PrePhysicsUpdate(const PreUpdateParams &inParams) // Draw character pre update (the sim is also drawn pre update) #ifdef JPH_DEBUG_RENDERER - mCharacter->GetShape()->Draw(mDebugRenderer, mCharacter->GetCenterOfMassTransform(), Vec3::sReplicate(1.0f), Color::sGreen, false, true); + mCharacter->GetShape()->Draw(mDebugRenderer, mCharacter->GetCenterOfMassTransform(), Vec3::sOne(), Color::sGreen, false, true); #endif // JPH_DEBUG_RENDERER // Determine new character velocity diff --git a/Samples/Tests/Character/CharacterSpaceShipTest.cpp b/Samples/Tests/Character/CharacterSpaceShipTest.cpp index e49baf77f..9d4b6b924 100644 --- a/Samples/Tests/Character/CharacterSpaceShipTest.cpp +++ b/Samples/Tests/Character/CharacterSpaceShipTest.cpp @@ -86,7 +86,7 @@ void CharacterSpaceShipTest::PrePhysicsUpdate(const PreUpdateParams &inParams) // Draw character pre update (the sim is also drawn pre update) // Note that we have first updated the position so that it matches the new position of the ship #ifdef JPH_DEBUG_RENDERER - mCharacter->GetShape()->Draw(mDebugRenderer, mCharacter->GetCenterOfMassTransform(), Vec3::sReplicate(1.0f), Color::sGreen, false, true); + mCharacter->GetShape()->Draw(mDebugRenderer, mCharacter->GetCenterOfMassTransform(), Vec3::sOne(), Color::sGreen, false, true); #endif // JPH_DEBUG_RENDERER // Determine new character velocity diff --git a/Samples/Tests/Character/CharacterVirtualTest.cpp b/Samples/Tests/Character/CharacterVirtualTest.cpp index ddfa4dae5..d29fdb73f 100644 --- a/Samples/Tests/Character/CharacterVirtualTest.cpp +++ b/Samples/Tests/Character/CharacterVirtualTest.cpp @@ -53,7 +53,7 @@ void CharacterVirtualTest::PrePhysicsUpdate(const PreUpdateParams &inParams) RMat44 com = mCharacter->GetCenterOfMassTransform(); RMat44 world_transform = mCharacter->GetWorldTransform(); #ifdef JPH_DEBUG_RENDERER - mCharacter->GetShape()->Draw(mDebugRenderer, com, Vec3::sReplicate(1.0f), Color::sGreen, false, true); + mCharacter->GetShape()->Draw(mDebugRenderer, com, Vec3::sOne(), Color::sGreen, false, true); #endif // JPH_DEBUG_RENDERER // Draw shape including padding (only implemented for capsules right now) @@ -257,7 +257,7 @@ void CharacterVirtualTest::OnContactCommon(const CharacterVirtual *inCharacter, // Draw a box around the character when it enters the sensor if (inBodyID2 == mSensorBody) { - AABox box = inCharacter->GetShape()->GetWorldSpaceBounds(inCharacter->GetCenterOfMassTransform(), Vec3::sReplicate(1.0f)); + AABox box = inCharacter->GetShape()->GetWorldSpaceBounds(inCharacter->GetCenterOfMassTransform(), Vec3::sOne()); mDebugRenderer->DrawBox(box, Color::sGreen, DebugRenderer::ECastShadow::Off, DebugRenderer::EDrawMode::Wireframe); } diff --git a/Samples/Tests/Constraints/HingeConstraintTest.cpp b/Samples/Tests/Constraints/HingeConstraintTest.cpp index 417bf699f..f06afd74f 100644 --- a/Samples/Tests/Constraints/HingeConstraintTest.cpp +++ b/Samples/Tests/Constraints/HingeConstraintTest.cpp @@ -88,10 +88,10 @@ void HingeConstraintTest::Initialize() { // Two bodies connected with a hard hinge - Body *body1 = mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3::sReplicate(1.0f)), RVec3(4, 5, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING)); + Body *body1 = mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3::sOne()), RVec3(4, 5, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING)); body1->SetCollisionGroup(CollisionGroup(group_filter, 0, 0)); mBodyInterface->AddBody(body1->GetID(), EActivation::DontActivate); - Body *body2 = mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3::sReplicate(1.0f)), RVec3(6, 5, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING)); + Body *body2 = mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3::sOne()), RVec3(6, 5, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING)); body2->SetCollisionGroup(CollisionGroup(group_filter, 0, 1)); mBodyInterface->AddBody(body2->GetID(), EActivation::Activate); @@ -106,10 +106,10 @@ void HingeConstraintTest::Initialize() { // Two bodies connected with a soft hinge - Body *body1 = mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3::sReplicate(1.0f)), RVec3(10, 5, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING)); + Body *body1 = mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3::sOne()), RVec3(10, 5, 0), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING)); body1->SetCollisionGroup(CollisionGroup(group_filter, 0, 0)); mBodyInterface->AddBody(body1->GetID(), EActivation::DontActivate); - Body *body2 = mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3::sReplicate(1.0f)), RVec3(12, 5, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING)); + Body *body2 = mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3::sOne()), RVec3(12, 5, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING)); body2->SetCollisionGroup(CollisionGroup(group_filter, 0, 1)); mBodyInterface->AddBody(body2->GetID(), EActivation::Activate); diff --git a/Samples/Tests/Constraints/SliderConstraintTest.cpp b/Samples/Tests/Constraints/SliderConstraintTest.cpp index 725f296c3..07d1b5f41 100644 --- a/Samples/Tests/Constraints/SliderConstraintTest.cpp +++ b/Samples/Tests/Constraints/SliderConstraintTest.cpp @@ -111,10 +111,10 @@ void SliderConstraintTest::Initialize() { // Two bodies vertically stacked with a slider constraint - Body *vert1 = mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3::sReplicate(1.0f)), RVec3(5, 9, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING)); + Body *vert1 = mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3::sOne()), RVec3(5, 9, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING)); vert1->SetCollisionGroup(CollisionGroup(group_filter, group_id, 0)); mBodyInterface->AddBody(vert1->GetID(), EActivation::Activate); - Body *vert2 = mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3::sReplicate(1.0f)), RVec3(5, 3, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING)); + Body *vert2 = mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3::sOne()), RVec3(5, 3, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING)); vert2->SetCollisionGroup(CollisionGroup(group_filter, group_id, 1)); mBodyInterface->AddBody(vert2->GetID(), EActivation::Activate); ++group_id; @@ -129,10 +129,10 @@ void SliderConstraintTest::Initialize() { // Two bodies vertically stacked with a slider constraint using soft limits - Body *vert1 = mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3::sReplicate(1.0f)), RVec3(10, 9, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING)); + Body *vert1 = mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3::sOne()), RVec3(10, 9, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING)); vert1->SetCollisionGroup(CollisionGroup(group_filter, group_id, 0)); mBodyInterface->AddBody(vert1->GetID(), EActivation::Activate); - Body *vert2 = mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3::sReplicate(1.0f)), RVec3(10, 3, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING)); + Body *vert2 = mBodyInterface->CreateBody(BodyCreationSettings(new BoxShape(Vec3::sOne()), RVec3(10, 3, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING)); vert2->SetCollisionGroup(CollisionGroup(group_filter, group_id, 1)); mBodyInterface->AddBody(vert2->GetID(), EActivation::Activate); ++group_id; diff --git a/Samples/Tests/ConvexCollision/CapsuleVsBoxTest.cpp b/Samples/Tests/ConvexCollision/CapsuleVsBoxTest.cpp index c32c84a09..885cbf918 100644 --- a/Samples/Tests/ConvexCollision/CapsuleVsBoxTest.cpp +++ b/Samples/Tests/ConvexCollision/CapsuleVsBoxTest.cpp @@ -43,12 +43,12 @@ void CapsuleVsBoxTest::PrePhysicsUpdate(const PreUpdateParams &inParams) // Collide the two shapes AllHitCollisionCollector collector; - CollisionDispatch::sCollideShapeVsShape(capsule_shape, box_shape, Vec3::sReplicate(1.0f), Vec3::sReplicate(1.0f), capsule_transform, box_transform, SubShapeIDCreator(), SubShapeIDCreator(), settings, collector); + CollisionDispatch::sCollideShapeVsShape(capsule_shape, box_shape, Vec3::sOne(), Vec3::sOne(), capsule_transform, box_transform, SubShapeIDCreator(), SubShapeIDCreator(), settings, collector); #ifdef JPH_DEBUG_RENDERER // Draw the shapes - box_shape->Draw(mDebugRenderer, RMat44(box_transform), Vec3::sReplicate(1.0f), Color::sWhite, false, false); - capsule_shape->Draw(mDebugRenderer, RMat44(capsule_transform), Vec3::sReplicate(1.0f), Color::sWhite, false, false); + box_shape->Draw(mDebugRenderer, RMat44(box_transform), Vec3::sOne(), Color::sWhite, false, false); + capsule_shape->Draw(mDebugRenderer, RMat44(capsule_transform), Vec3::sOne(), Color::sWhite, false, false); #endif // JPH_DEBUG_RENDERER // Draw contact points @@ -66,7 +66,7 @@ void CapsuleVsBoxTest::PrePhysicsUpdate(const PreUpdateParams &inParams) #ifdef JPH_DEBUG_RENDERER Mat44 resolved_box = box_transform.PostTranslated(pen_axis); - box_shape->Draw(mDebugRenderer, RMat44(resolved_box), Vec3::sReplicate(1.0f), Color::sGreen, false, false); + box_shape->Draw(mDebugRenderer, RMat44(resolved_box), Vec3::sOne(), Color::sGreen, false, false); #endif // JPH_DEBUG_RENDERER } } diff --git a/Samples/Tests/ConvexCollision/ConvexHullShrinkTest.cpp b/Samples/Tests/ConvexCollision/ConvexHullShrinkTest.cpp index 43ec89876..c9f27cfb5 100644 --- a/Samples/Tests/ConvexCollision/ConvexHullShrinkTest.cpp +++ b/Samples/Tests/ConvexCollision/ConvexHullShrinkTest.cpp @@ -139,7 +139,7 @@ void ConvexHullShrinkTest::PrePhysicsUpdate(const PreUpdateParams &inParams) { // Get the support function of the shape excluding convex radius and add the convex radius ConvexShape::SupportBuffer buffer; - const ConvexShape::Support *support = shape->GetSupportFunction(ConvexShape::ESupportMode::ExcludeConvexRadius, buffer, Vec3::sReplicate(1.0f)); + const ConvexShape::Support *support = shape->GetSupportFunction(ConvexShape::ESupportMode::ExcludeConvexRadius, buffer, Vec3::sOne()); AddConvexRadius add_cvx(*support, convex_radius); // Calculate the error w.r.t. the original hull @@ -169,8 +169,8 @@ void ConvexHullShrinkTest::PrePhysicsUpdate(const PreUpdateParams &inParams) #ifdef JPH_DEBUG_RENDERER // Draw the hulls - shape->Draw(DebugRenderer::sInstance, RMat44::sIdentity(), Vec3::sReplicate(1.0f), Color::sRed, false, false); - shape->DrawGetSupportFunction(DebugRenderer::sInstance, RMat44::sIdentity(), Vec3::sReplicate(1.0f), Color::sLightGrey, false); - shape->DrawShrunkShape(DebugRenderer::sInstance, RMat44::sIdentity(), Vec3::sReplicate(1.0f)); + shape->Draw(DebugRenderer::sInstance, RMat44::sIdentity(), Vec3::sOne(), Color::sRed, false, false); + shape->DrawGetSupportFunction(DebugRenderer::sInstance, RMat44::sIdentity(), Vec3::sOne(), Color::sLightGrey, false); + shape->DrawShrunkShape(DebugRenderer::sInstance, RMat44::sIdentity(), Vec3::sOne()); #endif // JPH_DEBUG_RENDERER } diff --git a/Samples/Tests/ConvexCollision/RandomRayTest.cpp b/Samples/Tests/ConvexCollision/RandomRayTest.cpp index decdf8eaa..270296258 100644 --- a/Samples/Tests/ConvexCollision/RandomRayTest.cpp +++ b/Samples/Tests/ConvexCollision/RandomRayTest.cpp @@ -138,10 +138,10 @@ void RandomRayTest::PrePhysicsUpdate(const PreUpdateParams &inParams) RVec3 render_offset(5, 0, 0); SphereShape sphere_shape(1.1f); #ifdef JPH_DEBUG_RENDERER - sphere_shape.Draw(mDebugRenderer, RMat44::sTranslation(render_offset), Vec3::sReplicate(1.0f), Color::sYellow, false, false); + sphere_shape.Draw(mDebugRenderer, RMat44::sTranslation(render_offset), Vec3::sOne(), Color::sYellow, false, false); #endif // JPH_DEBUG_RENDERER ConvexShape::SupportBuffer buffer; - const ConvexShape::Support *support = sphere_shape.GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sReplicate(1.0f)); + const ConvexShape::Support *support = sphere_shape.GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sOne()); TestRay("Sphere Shape", render_offset, *support, sphere_shape, [](const SphereShape &inSphere, Vec3Arg inRayOrigin, Vec3Arg inRayDirection) { return RaySphere(inRayOrigin, inRayDirection, Vec3::sZero(), inSphere.GetRadius()); }); @@ -161,10 +161,10 @@ void RandomRayTest::PrePhysicsUpdate(const PreUpdateParams &inParams) RVec3 render_offset(15, 0, 0); BoxShape box_shape(Vec3(0.9f, 1.0f, 1.1f), 0.0f); #ifdef JPH_DEBUG_RENDERER - box_shape.Draw(mDebugRenderer, RMat44::sTranslation(render_offset), Vec3::sReplicate(1.0f), Color::sYellow, false, false); + box_shape.Draw(mDebugRenderer, RMat44::sTranslation(render_offset), Vec3::sOne(), Color::sYellow, false, false); #endif // JPH_DEBUG_RENDERER ConvexShape::SupportBuffer buffer; - const ConvexShape::Support *support = box_shape.GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sReplicate(1.0f)); + const ConvexShape::Support *support = box_shape.GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sOne()); TestRay("Box Shape", render_offset, *support, box_shape, [](const BoxShape &inBox, Vec3Arg inRayOrigin, Vec3Arg inRayDirection) { float fraction = RayAABox(inRayOrigin, RayInvDirection(inRayDirection), -inBox.GetHalfExtent(), inBox.GetHalfExtent()); return max(fraction, 0.0f); @@ -175,10 +175,10 @@ void RandomRayTest::PrePhysicsUpdate(const PreUpdateParams &inParams) RVec3 render_offset(20, 0, 0); CapsuleShape capsule_shape(1.1f, 0.6f); #ifdef JPH_DEBUG_RENDERER - capsule_shape.Draw(mDebugRenderer, RMat44::sTranslation(render_offset), Vec3::sReplicate(1.0f), Color::sYellow, false, false); + capsule_shape.Draw(mDebugRenderer, RMat44::sTranslation(render_offset), Vec3::sOne(), Color::sYellow, false, false); #endif // JPH_DEBUG_RENDERER ConvexShape::SupportBuffer buffer; - const ConvexShape::Support *support = capsule_shape.GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sReplicate(1.0f)); + const ConvexShape::Support *support = capsule_shape.GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sOne()); TestRay("Capsule Shape", render_offset, *support, capsule_shape, [](const CapsuleShape &inCapsule, Vec3Arg inRayOrigin, Vec3Arg inRayDirection) { return RayCapsule(inRayOrigin, inRayDirection, inCapsule.GetHalfHeightOfCylinder(), inCapsule.GetRadius()); }); @@ -188,10 +188,10 @@ void RandomRayTest::PrePhysicsUpdate(const PreUpdateParams &inParams) RVec3 render_offset(25, 0, 0); CylinderShape cylinder_shape(1.5f, 0.6f, 0.0f); #ifdef JPH_DEBUG_RENDERER - cylinder_shape.Draw(mDebugRenderer, RMat44::sTranslation(render_offset), Vec3::sReplicate(1.0f), Color::sYellow, false, false); + cylinder_shape.Draw(mDebugRenderer, RMat44::sTranslation(render_offset), Vec3::sOne(), Color::sYellow, false, false); #endif // JPH_DEBUG_RENDERER ConvexShape::SupportBuffer buffer; - const ConvexShape::Support *support = cylinder_shape.GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sReplicate(1.0f)); + const ConvexShape::Support *support = cylinder_shape.GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sOne()); TestRay("Cylinder Shape", render_offset, *support, cylinder_shape, [](const CylinderShape &inCylinder, Vec3Arg inRayOrigin, Vec3Arg inRayDirection) { return RayCylinder(inRayOrigin, inRayDirection, inCylinder.GetHalfHeight(), inCylinder.GetRadius()); }); diff --git a/Samples/Tests/General/ShapeFilterTest.cpp b/Samples/Tests/General/ShapeFilterTest.cpp index ada259a26..a7aabda5a 100644 --- a/Samples/Tests/General/ShapeFilterTest.cpp +++ b/Samples/Tests/General/ShapeFilterTest.cpp @@ -108,5 +108,5 @@ void ShapeFilterTest::PostPhysicsUpdate(float inDeltaTime) color = Color::sRed; } mDebugRenderer->DrawArrow(cast_origin, cast_point, Color::sOrange, 0.1f); - JPH_IF_DEBUG_RENDERER(mCastShape->Draw(mDebugRenderer, RMat44::sTranslation(RVec3(cast_point)), Vec3::sReplicate(1.0f), color, false, true);) + JPH_IF_DEBUG_RENDERER(mCastShape->Draw(mDebugRenderer, RMat44::sTranslation(RVec3(cast_point)), Vec3::sOne(), color, false, true);) } diff --git a/Samples/Tests/Rig/BigWorldTest.cpp b/Samples/Tests/Rig/BigWorldTest.cpp index cf668cb94..06f80e283 100644 --- a/Samples/Tests/Rig/BigWorldTest.cpp +++ b/Samples/Tests/Rig/BigWorldTest.cpp @@ -131,7 +131,7 @@ void BigWorldTest::PrePhysicsUpdate(const PreUpdateParams &inParams) #ifdef JPH_DEBUG_RENDERER // Draw the shape - body.GetShape()->Draw(mDebugRenderer, transform, Vec3::sReplicate(1.0f), color, false, sDrawWireframe); + body.GetShape()->Draw(mDebugRenderer, transform, Vec3::sOne(), color, false, sDrawWireframe); #endif // JPH_DEBUG_RENDERER } } diff --git a/Samples/Tests/ScaledShapes/DynamicScaledShape.cpp b/Samples/Tests/ScaledShapes/DynamicScaledShape.cpp index b8b18c4b8..d026a477e 100644 --- a/Samples/Tests/ScaledShapes/DynamicScaledShape.cpp +++ b/Samples/Tests/ScaledShapes/DynamicScaledShape.cpp @@ -21,7 +21,7 @@ void DynamicScaledShape::Initialize() CreateHeightFieldTerrain(); // Create scaled sphere - RefConst scaled_sphere_shape = new ScaledShape(new SphereShape(2.0f), Vec3::sReplicate(1.0f)); + RefConst scaled_sphere_shape = new ScaledShape(new SphereShape(2.0f), Vec3::sOne()); mBodyID = mBodyInterface->CreateAndAddBody(BodyCreationSettings(scaled_sphere_shape, RVec3(0, 10, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING), EActivation::Activate); } diff --git a/Samples/Tests/Shapes/DeformedHeightFieldShapeTest.cpp b/Samples/Tests/Shapes/DeformedHeightFieldShapeTest.cpp index 3ad45e34f..92dc83b3f 100644 --- a/Samples/Tests/Shapes/DeformedHeightFieldShapeTest.cpp +++ b/Samples/Tests/Shapes/DeformedHeightFieldShapeTest.cpp @@ -49,7 +49,7 @@ void DeformedHeightFieldShapeTest::Initialize() Vec3 center = offset + GetPathCenter(t); // Cast a ray onto the terrain - RShapeCast shape_cast(sphere_shape, Vec3::sReplicate(1.0f), RMat44::sTranslation(RVec3(0, 10, 0) + center), Vec3(0, -20, 0)); + RShapeCast shape_cast(sphere_shape, Vec3::sOne(), RMat44::sTranslation(RVec3(0, 10, 0) + center), Vec3(0, -20, 0)); ClosestHitCollisionCollector collector; mPhysicsSystem->GetNarrowPhaseQuery().CastShape(shape_cast, { }, RVec3::sZero(), collector); if (collector.mHit.mBodyID2 == mHeightFieldID) diff --git a/Samples/Tests/SoftBody/SoftBodyCustomUpdateTest.cpp b/Samples/Tests/SoftBody/SoftBodyCustomUpdateTest.cpp index c035d7616..a49669bb6 100644 --- a/Samples/Tests/SoftBody/SoftBodyCustomUpdateTest.cpp +++ b/Samples/Tests/SoftBody/SoftBodyCustomUpdateTest.cpp @@ -39,7 +39,7 @@ void SoftBodyCustomUpdateTest::PrePhysicsUpdate(const PreUpdateParams &inParams) #ifdef JPH_DEBUG_RENDERER // Draw it as well since it's not added to the world - mBody->GetShape()->Draw(mDebugRenderer, mBody->GetCenterOfMassTransform(), Vec3::sReplicate(1.0f), Color::sWhite, false, false); + mBody->GetShape()->Draw(mDebugRenderer, mBody->GetCenterOfMassTransform(), Vec3::sOne(), Color::sWhite, false, false); #else // Draw the vertices RMat44 com = mBody->GetCenterOfMassTransform(); diff --git a/Samples/Tests/SoftBody/SoftBodyStressTest.cpp b/Samples/Tests/SoftBody/SoftBodyStressTest.cpp index ba28a492f..2465e201c 100644 --- a/Samples/Tests/SoftBody/SoftBodyStressTest.cpp +++ b/Samples/Tests/SoftBody/SoftBodyStressTest.cpp @@ -37,7 +37,7 @@ void SoftBodyStressTest::Initialize() sphere.mPressure = 2000.0f; // Box settings - BodyCreationSettings box(new BoxShape(Vec3::sReplicate(1.0f)), RVec3::sZero(), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING); + BodyCreationSettings box(new BoxShape(Vec3::sOne()), RVec3::sZero(), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING); box.mOverrideMassProperties = EOverrideMassProperties::CalculateInertia; box.mMassPropertiesOverride.mMass = 100.0f; diff --git a/Samples/Tests/Vehicle/MotorcycleTest.cpp b/Samples/Tests/Vehicle/MotorcycleTest.cpp index 06cbaae2f..70982f008 100644 --- a/Samples/Tests/Vehicle/MotorcycleTest.cpp +++ b/Samples/Tests/Vehicle/MotorcycleTest.cpp @@ -206,7 +206,7 @@ void MotorcycleTest::PrePhysicsUpdate(const PreUpdateParams &inParams) // When overriding gravity is requested, we cast a sphere downwards (opposite to the previous up position) and use the contact normal as the new gravity direction SphereShape sphere(0.5f); sphere.SetEmbedded(); - RShapeCast shape_cast(&sphere, Vec3::sReplicate(1.0f), RMat44::sTranslation(mMotorcycleBody->GetPosition()), -3.0f * mVehicleConstraint->GetWorldUp()); + RShapeCast shape_cast(&sphere, Vec3::sOne(), RMat44::sTranslation(mMotorcycleBody->GetPosition()), -3.0f * mVehicleConstraint->GetWorldUp()); ShapeCastSettings settings; ClosestHitCollisionCollector collector; mPhysicsSystem->GetNarrowPhaseQuery().CastShape(shape_cast, settings, mMotorcycleBody->GetPosition(), collector, SpecifiedBroadPhaseLayerFilter(BroadPhaseLayers::NON_MOVING), SpecifiedObjectLayerFilter(Layers::NON_MOVING)); diff --git a/Samples/Tests/Vehicle/VehicleConstraintTest.cpp b/Samples/Tests/Vehicle/VehicleConstraintTest.cpp index f8eb1e608..be6a40be1 100644 --- a/Samples/Tests/Vehicle/VehicleConstraintTest.cpp +++ b/Samples/Tests/Vehicle/VehicleConstraintTest.cpp @@ -249,7 +249,7 @@ void VehicleConstraintTest::PrePhysicsUpdate(const PreUpdateParams &inParams) // When overriding gravity is requested, we cast a sphere downwards (opposite to the previous up position) and use the contact normal as the new gravity direction SphereShape sphere(0.5f); sphere.SetEmbedded(); - RShapeCast shape_cast(&sphere, Vec3::sReplicate(1.0f), RMat44::sTranslation(mCarBody->GetPosition()), -3.0f * mVehicleConstraint->GetWorldUp()); + RShapeCast shape_cast(&sphere, Vec3::sOne(), RMat44::sTranslation(mCarBody->GetPosition()), -3.0f * mVehicleConstraint->GetWorldUp()); ShapeCastSettings settings; ClosestHitCollisionCollector collector; mPhysicsSystem->GetNarrowPhaseQuery().CastShape(shape_cast, settings, mCarBody->GetPosition(), collector, SpecifiedBroadPhaseLayerFilter(BroadPhaseLayers::NON_MOVING), SpecifiedObjectLayerFilter(Layers::NON_MOVING)); diff --git a/UnitTests/Geometry/GJKTests.cpp b/UnitTests/Geometry/GJKTests.cpp index 1e43d6d20..f6e7e4f74 100644 --- a/UnitTests/Geometry/GJKTests.cpp +++ b/UnitTests/Geometry/GJKTests.cpp @@ -192,7 +192,7 @@ TEST_SUITE("GJKTests") { SphereShape sphere_shape(1.1f); ConvexShape::SupportBuffer buffer; - const ConvexShape::Support *support = sphere_shape.GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sReplicate(1.0f)); + const ConvexShape::Support *support = sphere_shape.GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sOne()); TestRay(*support, sphere_shape, [](const SphereShape &inSphere, Vec3Arg inRayOrigin, Vec3Arg inRayDirection) { return RaySphere(inRayOrigin, inRayDirection, Vec3::sZero(), inSphere.GetRadius()); }); @@ -211,7 +211,7 @@ TEST_SUITE("GJKTests") { BoxShape box_shape(Vec3(0.9f, 1.0f, 1.1f), 0.0f); ConvexShape::SupportBuffer buffer; - const ConvexShape::Support *support = box_shape.GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sReplicate(1.0f)); + const ConvexShape::Support *support = box_shape.GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sOne()); TestRay(*support, box_shape, [](const BoxShape &inBox, Vec3Arg inRayOrigin, Vec3Arg inRayDirection) { float fraction = RayAABox(inRayOrigin, RayInvDirection(inRayDirection), -inBox.GetHalfExtent(), inBox.GetHalfExtent()); return max(fraction, 0.0f); @@ -222,7 +222,7 @@ TEST_SUITE("GJKTests") { CapsuleShape capsule_shape(1.1f, 0.6f); ConvexShape::SupportBuffer buffer; - const ConvexShape::Support *support = capsule_shape.GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sReplicate(1.0f)); + const ConvexShape::Support *support = capsule_shape.GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sOne()); TestRay(*support, capsule_shape, [](const CapsuleShape &inCapsule, Vec3Arg inRayOrigin, Vec3Arg inRayDirection) { return RayCapsule(inRayOrigin, inRayDirection, inCapsule.GetHalfHeightOfCylinder(), inCapsule.GetRadius()); }); @@ -232,7 +232,7 @@ TEST_SUITE("GJKTests") { CylinderShape cylinder_shape(1.5f, 0.6f, 0.0f); ConvexShape::SupportBuffer buffer; - const ConvexShape::Support *support = cylinder_shape.GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sReplicate(1.0f)); + const ConvexShape::Support *support = cylinder_shape.GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sOne()); TestRay(*support, cylinder_shape, [](const CylinderShape &inCylinder, Vec3Arg inRayOrigin, Vec3Arg inRayDirection) { return RayCylinder(inRayOrigin, inRayDirection, inCylinder.GetHalfHeight(), inCylinder.GetRadius()); }); diff --git a/UnitTests/Geometry/RayAABoxTests.cpp b/UnitTests/Geometry/RayAABoxTests.cpp index 0596e5fc5..c91440d5c 100644 --- a/UnitTests/Geometry/RayAABoxTests.cpp +++ b/UnitTests/Geometry/RayAABoxTests.cpp @@ -10,7 +10,7 @@ TEST_SUITE("RayAABoxTests") { TEST_CASE("TestRayAABox") { - AABox box(Vec3::sReplicate(-1.0f), Vec3::sReplicate(1.0f)); + AABox box(Vec3::sReplicate(-1.0f), Vec3::sOne()); for (int axis = 0; axis < 3; ++axis) { diff --git a/UnitTests/Math/Vec4Tests.cpp b/UnitTests/Math/Vec4Tests.cpp index 83d8e2621..de30d0607 100644 --- a/UnitTests/Math/Vec4Tests.cpp +++ b/UnitTests/Math/Vec4Tests.cpp @@ -593,7 +593,7 @@ TEST_SUITE("Vec4Tests") { // Check edge cases CHECK(Vec4::sReplicate(0.0f).ASin() == Vec4::sZero()); - CHECK(Vec4::sReplicate(1.0f).ASin() == Vec4::sReplicate(0.5f * JPH_PI)); + CHECK(Vec4::sOne().ASin() == Vec4::sReplicate(0.5f * JPH_PI)); CHECK(Vec4::sReplicate(-1.0f).ASin() == Vec4::sReplicate(-0.5f * JPH_PI)); double ma = 0.0; @@ -601,7 +601,7 @@ TEST_SUITE("Vec4Tests") for (float x = -1.0f; x <= 1.0f; x += 1.0e-3f) { // Create a vector with intermediate values - Vec4 xv = Vec4::sMin(Vec4::sReplicate(x) + Vec4(0.0e-4f, 2.5e-4f, 5.0e-4f, 7.5e-4f), Vec4::sReplicate(1.0f)); + Vec4 xv = Vec4::sMin(Vec4::sReplicate(x) + Vec4(0.0e-4f, 2.5e-4f, 5.0e-4f, 7.5e-4f), Vec4::sOne()); // Calculate asin Vec4 va = xv.ASin(); @@ -626,7 +626,7 @@ TEST_SUITE("Vec4Tests") { // Check edge cases CHECK(Vec4::sReplicate(0.0f).ACos() == Vec4::sReplicate(0.5f * JPH_PI)); - CHECK(Vec4::sReplicate(1.0f).ACos() == Vec4::sZero()); + CHECK(Vec4::sOne().ACos() == Vec4::sZero()); CHECK(Vec4::sReplicate(-1.0f).ACos() == Vec4::sReplicate(JPH_PI)); double ma = 0.0; @@ -634,7 +634,7 @@ TEST_SUITE("Vec4Tests") for (float x = -1.0f; x <= 1.0f; x += 1.0e-3f) { // Create a vector with intermediate values - Vec4 xv = Vec4::sMin(Vec4::sReplicate(x) + Vec4(0.0e-4f, 2.5e-4f, 5.0e-4f, 7.5e-4f), Vec4::sReplicate(1.0f)); + Vec4 xv = Vec4::sMin(Vec4::sReplicate(x) + Vec4(0.0e-4f, 2.5e-4f, 5.0e-4f, 7.5e-4f), Vec4::sOne()); // Calculate acos Vec4 va = xv.ACos(); diff --git a/UnitTests/Physics/ActiveEdgesTests.cpp b/UnitTests/Physics/ActiveEdgesTests.cpp index 16d52f22b..052d5f1d8 100644 --- a/UnitTests/Physics/ActiveEdgesTests.cpp +++ b/UnitTests/Physics/ActiveEdgesTests.cpp @@ -50,7 +50,7 @@ TEST_SUITE("ActiveEdgesTest") { float samples[8*8]; memset(samples, 0, sizeof(samples)); - return new HeightFieldShapeSettings(samples, Vec3(-3.5f, 0, -3.5f), Vec3::sReplicate(1.0f), 8); + return new HeightFieldShapeSettings(samples, Vec3(-3.5f, 0, -3.5f), Vec3::sOne(), 8); } // This struct indicates what we hope to find as hit @@ -84,7 +84,7 @@ TEST_SUITE("ActiveEdgesTest") static void sTestCollideShape(Shape *inProbeShape, Shape *inTestShape, Vec3Arg inTestShapeScale, const CollideShapeSettings &inSettings, Vec3Arg inProbeShapePos, const Array &inExpectedHits) { AllHitCollisionCollector collector; - CollisionDispatch::sCollideShapeVsShape(inProbeShape, inTestShape, Vec3::sReplicate(1.0f), inTestShapeScale, Mat44::sTranslation(inProbeShapePos), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), inSettings, collector); + CollisionDispatch::sCollideShapeVsShape(inProbeShape, inTestShape, Vec3::sOne(), inTestShapeScale, Mat44::sTranslation(inProbeShapePos), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), inSettings, collector); sCheckMatch(collector.mHits, inExpectedHits, 1.0e-8f); } @@ -116,9 +116,9 @@ TEST_SUITE("ActiveEdgesTest") { Ref shape = sCreateMeshShape(); - sTestCollideShape(shape, Vec3::sReplicate(1.0f), false); + sTestCollideShape(shape, Vec3::sOne(), false); - sTestCollideShape(shape, Vec3::sReplicate(1.0f), true); + sTestCollideShape(shape, Vec3::sOne(), true); sTestCollideShape(shape, Vec3(-1, 1, 1), false); @@ -129,9 +129,9 @@ TEST_SUITE("ActiveEdgesTest") { Ref shape = sCreateHeightFieldShape(); - sTestCollideShape(shape, Vec3::sReplicate(1.0f), false); + sTestCollideShape(shape, Vec3::sOne(), false); - sTestCollideShape(shape, Vec3::sReplicate(1.0f), true); + sTestCollideShape(shape, Vec3::sOne(), true); sTestCollideShape(shape, Vec3(-1, 1, 1), false); @@ -142,7 +142,7 @@ TEST_SUITE("ActiveEdgesTest") static void sTestCastShape(Shape *inProbeShape, Shape *inTestShape, Vec3Arg inTestShapeScale, const ShapeCastSettings &inSettings, Vec3Arg inProbeShapePos, Vec3Arg inProbeShapeDirection, const Array &inExpectedHits) { AllHitCollisionCollector collector; - ShapeCast shape_cast(inProbeShape, Vec3::sReplicate(1.0f), Mat44::sTranslation(inProbeShapePos), inProbeShapeDirection); + ShapeCast shape_cast(inProbeShape, Vec3::sOne(), Mat44::sTranslation(inProbeShapePos), inProbeShapeDirection); CollisionDispatch::sCastShapeVsShapeLocalSpace(shape_cast, inSettings, inTestShape, inTestShapeScale, ShapeFilter(), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), collector); sCheckMatch(collector.mHits, inExpectedHits, 1.0e-6f); @@ -173,9 +173,9 @@ TEST_SUITE("ActiveEdgesTest") { Ref shape = sCreateMeshShape(); - sTestCastShape(shape, Vec3::sReplicate(1.0f), false); + sTestCastShape(shape, Vec3::sOne(), false); - sTestCastShape(shape, Vec3::sReplicate(1.0f), true); + sTestCastShape(shape, Vec3::sOne(), true); sTestCastShape(shape, Vec3(-1, 1, 1), false); @@ -186,9 +186,9 @@ TEST_SUITE("ActiveEdgesTest") { Ref shape = sCreateHeightFieldShape(); - sTestCastShape(shape, Vec3::sReplicate(1.0f), false); + sTestCastShape(shape, Vec3::sOne(), false); - sTestCastShape(shape, Vec3::sReplicate(1.0f), true); + sTestCastShape(shape, Vec3::sOne(), true); sTestCastShape(shape, Vec3(-1, 1, 1), false); diff --git a/UnitTests/Physics/BroadPhaseTests.cpp b/UnitTests/Physics/BroadPhaseTests.cpp index 37511ce92..fd9ccaf5e 100644 --- a/UnitTests/Physics/BroadPhaseTests.cpp +++ b/UnitTests/Physics/BroadPhaseTests.cpp @@ -27,7 +27,7 @@ TEST_SUITE("BroadPhaseTests") broadphase.Init(&body_manager, broad_phase_layer_interface); // Create a box - BodyCreationSettings settings(new BoxShape(Vec3::sReplicate(1.0f)), RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING); + BodyCreationSettings settings(new BoxShape(Vec3::sOne()), RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING); Body &body = *body_manager.AllocateBody(settings); body_manager.AddBody(&body); diff --git a/UnitTests/Physics/CastShapeTests.cpp b/UnitTests/Physics/CastShapeTests.cpp index d3cc7afe2..b43431d85 100644 --- a/UnitTests/Physics/CastShapeTests.cpp +++ b/UnitTests/Physics/CastShapeTests.cpp @@ -24,12 +24,12 @@ TEST_SUITE("CastShapeTests") /// Helper function that tests a sphere against a triangle static void sTestCastSphereVertexOrEdge(const Shape *inSphere, Vec3Arg inPosition, Vec3Arg inDirection, const Shape *inTriangle) { - ShapeCast shape_cast(inSphere, Vec3::sReplicate(1.0f), Mat44::sTranslation(inPosition - inDirection), inDirection); + ShapeCast shape_cast(inSphere, Vec3::sOne(), Mat44::sTranslation(inPosition - inDirection), inDirection); ShapeCastSettings cast_settings; cast_settings.mBackFaceModeTriangles = EBackFaceMode::CollideWithBackFaces; cast_settings.mBackFaceModeConvex = EBackFaceMode::CollideWithBackFaces; AllHitCollisionCollector collector; - CollisionDispatch::sCastShapeVsShapeLocalSpace(shape_cast, cast_settings, inTriangle, Vec3::sReplicate(1.0f), ShapeFilter(), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), collector); + CollisionDispatch::sCastShapeVsShapeLocalSpace(shape_cast, cast_settings, inTriangle, Vec3::sOne(), ShapeFilter(), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), collector); CHECK(collector.mHits.size() == 1); const ShapeCastResult &result = collector.mHits.back(); CHECK_APPROX_EQUAL(result.mFraction, 1.0f - 0.2f / inDirection.Length(), 1.0e-4f); @@ -47,13 +47,13 @@ TEST_SUITE("CastShapeTests") { // Hit front face - ShapeCast shape_cast(sphere, Vec3::sReplicate(1.0f), Mat44::sTranslation(Vec3(0, 0, 15)), Vec3(0, 0, -30)); + ShapeCast shape_cast(sphere, Vec3::sOne(), Mat44::sTranslation(Vec3(0, 0, 15)), Vec3(0, 0, -30)); ShapeCastSettings cast_settings; cast_settings.mBackFaceModeTriangles = EBackFaceMode::IgnoreBackFaces; cast_settings.mBackFaceModeConvex = EBackFaceMode::IgnoreBackFaces; cast_settings.mReturnDeepestPoint = false; AllHitCollisionCollector collector; - CollisionDispatch::sCastShapeVsShapeLocalSpace(shape_cast, cast_settings, inTriangle, Vec3::sReplicate(1.0f), ShapeFilter(), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), collector); + CollisionDispatch::sCastShapeVsShapeLocalSpace(shape_cast, cast_settings, inTriangle, Vec3::sOne(), ShapeFilter(), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), collector); CHECK(collector.mHits.size() == 1); const ShapeCastResult &result = collector.mHits.back(); CHECK_APPROX_EQUAL(result.mFraction, (15.0f - 0.2f) / 30.0f, 1.0e-4f); @@ -66,19 +66,19 @@ TEST_SUITE("CastShapeTests") { // Hit back face -> ignored - ShapeCast shape_cast(sphere, Vec3::sReplicate(1.0f), Mat44::sTranslation(Vec3(0, 0, -15)), Vec3(0, 0, 30)); + ShapeCast shape_cast(sphere, Vec3::sOne(), Mat44::sTranslation(Vec3(0, 0, -15)), Vec3(0, 0, 30)); ShapeCastSettings cast_settings; cast_settings.mBackFaceModeTriangles = EBackFaceMode::IgnoreBackFaces; cast_settings.mBackFaceModeConvex = EBackFaceMode::IgnoreBackFaces; cast_settings.mReturnDeepestPoint = false; AllHitCollisionCollector collector; - CollisionDispatch::sCastShapeVsShapeLocalSpace(shape_cast, cast_settings, inTriangle, Vec3::sReplicate(1.0f), ShapeFilter(), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), collector); + CollisionDispatch::sCastShapeVsShapeLocalSpace(shape_cast, cast_settings, inTriangle, Vec3::sOne(), ShapeFilter(), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), collector); CHECK(collector.mHits.empty()); // Hit back face -> collision cast_settings.mBackFaceModeTriangles = EBackFaceMode::CollideWithBackFaces; cast_settings.mBackFaceModeConvex = EBackFaceMode::CollideWithBackFaces; - CollisionDispatch::sCastShapeVsShapeLocalSpace(shape_cast, cast_settings, inTriangle, Vec3::sReplicate(1.0f), ShapeFilter(), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), collector); + CollisionDispatch::sCastShapeVsShapeLocalSpace(shape_cast, cast_settings, inTriangle, Vec3::sOne(), ShapeFilter(), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), collector); CHECK(collector.mHits.size() == 1); const ShapeCastResult &result = collector.mHits.back(); CHECK_APPROX_EQUAL(result.mFraction, (15.0f - 0.2f) / 30.0f, 1.0e-4f); @@ -91,19 +91,19 @@ TEST_SUITE("CastShapeTests") { // Hit back face while starting in collision -> ignored - ShapeCast shape_cast(sphere, Vec3::sReplicate(1.0f), Mat44::sTranslation(Vec3(0, 0, -0.1f)), Vec3(0, 0, 15)); + ShapeCast shape_cast(sphere, Vec3::sOne(), Mat44::sTranslation(Vec3(0, 0, -0.1f)), Vec3(0, 0, 15)); ShapeCastSettings cast_settings; cast_settings.mBackFaceModeTriangles = EBackFaceMode::IgnoreBackFaces; cast_settings.mBackFaceModeConvex = EBackFaceMode::IgnoreBackFaces; cast_settings.mReturnDeepestPoint = true; AllHitCollisionCollector collector; - CollisionDispatch::sCastShapeVsShapeLocalSpace(shape_cast, cast_settings, inTriangle, Vec3::sReplicate(1.0f), ShapeFilter(), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), collector); + CollisionDispatch::sCastShapeVsShapeLocalSpace(shape_cast, cast_settings, inTriangle, Vec3::sOne(), ShapeFilter(), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), collector); CHECK(collector.mHits.empty()); // Hit back face while starting in collision -> collision cast_settings.mBackFaceModeTriangles = EBackFaceMode::CollideWithBackFaces; cast_settings.mBackFaceModeConvex = EBackFaceMode::CollideWithBackFaces; - CollisionDispatch::sCastShapeVsShapeLocalSpace(shape_cast, cast_settings, inTriangle, Vec3::sReplicate(1.0f), ShapeFilter(), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), collector); + CollisionDispatch::sCastShapeVsShapeLocalSpace(shape_cast, cast_settings, inTriangle, Vec3::sOne(), ShapeFilter(), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), collector); CHECK(collector.mHits.size() == 1); const ShapeCastResult &result = collector.mHits.back(); CHECK_APPROX_EQUAL(result.mFraction, 0.0f); @@ -143,7 +143,7 @@ TEST_SUITE("CastShapeTests") // Create box to collide against (shape 2) // The box is scaled up by a factor 10 in the X axis and then rotated so that the X axis is up - BoxShapeSettings box(Vec3::sReplicate(1.0f)); + BoxShapeSettings box(Vec3::sOne()); box.SetEmbedded(); ScaledShapeSettings scaled_box(&box, Vec3(10, 1, 1)); scaled_box.SetEmbedded(); @@ -158,7 +158,7 @@ TEST_SUITE("CastShapeTests") { // Create shape cast Ref normal_sphere = new SphereShape(1.0f); - RShapeCast shape_cast { normal_sphere, Vec3::sReplicate(1.0f), RMat44::sTranslation(RVec3(0, 11, 0)), Vec3(0, 1, 0) }; + RShapeCast shape_cast { normal_sphere, Vec3::sOne(), RMat44::sTranslation(RVec3(0, 11, 0)), Vec3(0, 1, 0) }; // Shape is intersecting at the start AllHitCollisionCollector collector; @@ -219,7 +219,7 @@ TEST_SUITE("CastShapeTests") { // Create shape cast in X from -5 to 5 RefConst sphere = new SphereShape(1.0f); - RShapeCast shape_cast { sphere, Vec3::sReplicate(1.0f), RMat44::sTranslation(RVec3(-5, 0, 0)), Vec3(10, 0, 0) }; + RShapeCast shape_cast { sphere, Vec3::sOne(), RMat44::sTranslation(RVec3(-5, 0, 0)), Vec3(10, 0, 0) }; // We should hit the first body ClosestHitCollisionCollector collector; @@ -237,7 +237,7 @@ TEST_SUITE("CastShapeTests") { // Create shape cast in X from 5 to -5 RefConst sphere = new SphereShape(1.0f); - RShapeCast shape_cast { sphere, Vec3::sReplicate(1.0f), RMat44::sTranslation(RVec3(5, 0, 0)), Vec3(-10, 0, 0) }; + RShapeCast shape_cast { sphere, Vec3::sOne(), RMat44::sTranslation(RVec3(5, 0, 0)), Vec3(-10, 0, 0) }; // We should hit the last body ClosestHitCollisionCollector collector; @@ -255,7 +255,7 @@ TEST_SUITE("CastShapeTests") { // Create shape cast in X from 1.05 to 11, this should intersect with all bodies and have deepest penetration in bodies[5] RefConst sphere = new SphereShape(1.0f); - RShapeCast shape_cast { sphere, Vec3::sReplicate(1.0f), RMat44::sTranslation(RVec3(1.05_r, 0, 0)), Vec3(10, 0, 0) }; + RShapeCast shape_cast { sphere, Vec3::sOne(), RMat44::sTranslation(RVec3(1.05_r, 0, 0)), Vec3(10, 0, 0) }; // We should hit bodies[5] AllHitCollisionCollector collector; @@ -315,7 +315,7 @@ TEST_SUITE("CastShapeTests") // Cast the shape starting inside the mesh with a long distance so that internally in the mesh shape the RayAABox4 test will return a low negative fraction. // This used to be confused with the penetration depth and would cause an early out and return the wrong result. const float capsule_offset = 0.1f; - RShapeCast shape_cast(cast_shape, Vec3::sReplicate(1.0f), RMat44::sTranslation(RVec3(0, capsule_half_height + capsule_offset, 0)), Vec3(0, -100, 0)); + RShapeCast shape_cast(cast_shape, Vec3::sOne(), RMat44::sTranslation(RVec3(0, capsule_half_height + capsule_offset, 0)), Vec3(0, -100, 0)); // Cast first using the closest hit collector ClosestHitCollisionCollector collector; @@ -353,9 +353,9 @@ TEST_SUITE("CastShapeTests") AllHitCollisionCollector collector; SphereShape sphere(0.2f); sphere.SetEmbedded(); - ShapeCast cast(&sphere, Vec3::sReplicate(1.0f), Mat44::sTranslation(Vec3(14.8314590f, 8.19055080f, -4.30825043f)), Vec3(-0.0988006592f, 5.96046448e-08f, 0.000732421875f)); + ShapeCast cast(&sphere, Vec3::sOne(), Mat44::sTranslation(Vec3(14.8314590f, 8.19055080f, -4.30825043f)), Vec3(-0.0988006592f, 5.96046448e-08f, 0.000732421875f)); ShapeCastSettings settings; - CastSphereVsTriangles caster(cast, settings, Vec3::sReplicate(1.0f), Mat44::sIdentity(), { }, collector); + CastSphereVsTriangles caster(cast, settings, Vec3::sOne(), Mat44::sIdentity(), { }, collector); caster.Cast(Vec3(14.5536213f, 10.5973721f, -0.00600051880f), Vec3(14.5536213f, 10.5969315f, -3.18638134f), Vec3(14.5536213f, 10.5969315f, -5.18637228f), 0b111, SubShapeID()); CHECK(!collector.HadHit()); } diff --git a/UnitTests/Physics/CollideShapeTests.cpp b/UnitTests/Physics/CollideShapeTests.cpp index 6741ebe89..a22a3fac0 100644 --- a/UnitTests/Physics/CollideShapeTests.cpp +++ b/UnitTests/Physics/CollideShapeTests.cpp @@ -89,7 +89,7 @@ TEST_SUITE("CollideShapeTests") settings.mBackFaceMode = EBackFaceMode::CollideWithBackFaces; // Test against wrong layer - c.GetSystem()->GetNarrowPhaseQuery().CollideShape(shape1, Vec3::sReplicate(1.0f), shape1_transform, settings, RVec3::sZero(), fail_collector, broadphase_moving_filter, object_moving_filter); + c.GetSystem()->GetNarrowPhaseQuery().CollideShape(shape1, Vec3::sOne(), shape1_transform, settings, RVec3::sZero(), fail_collector, broadphase_moving_filter, object_moving_filter); // Collector that tests that collision happens at position A class PositionACollideShapeCollector : public CollideShapeCollector @@ -116,20 +116,20 @@ TEST_SUITE("CollideShapeTests") // Test collision against correct layer CHECK(!position_a_collector.mWasHit); - c.GetSystem()->GetNarrowPhaseQuery().CollideShape(shape1, Vec3::sReplicate(1.0f), shape1_transform, settings, RVec3::sZero(), position_a_collector, broadphase_non_moving_filter, object_non_moving_filter); + c.GetSystem()->GetNarrowPhaseQuery().CollideShape(shape1, Vec3::sOne(), shape1_transform, settings, RVec3::sZero(), position_a_collector, broadphase_non_moving_filter, object_non_moving_filter); CHECK(position_a_collector.mWasHit); // Now move body to position B c.GetSystem()->GetBodyInterface().SetPositionAndRotation(body2.GetID(), cPosition2B, Quat::sRotation(Vec3::sAxisY(), 0.2f * JPH_PI), EActivation::DontActivate); // Test that original position doesn't collide anymore - c.GetSystem()->GetNarrowPhaseQuery().CollideShape(shape1, Vec3::sReplicate(1.0f), shape1_transform, settings, RVec3::sZero(), fail_collector, broadphase_non_moving_filter, object_non_moving_filter); + c.GetSystem()->GetNarrowPhaseQuery().CollideShape(shape1, Vec3::sOne(), shape1_transform, settings, RVec3::sZero(), fail_collector, broadphase_non_moving_filter, object_non_moving_filter); // Move test shape to position B shape1_transform = RMat44::sTranslation(cPosition1B) * Mat44::sRotationZ(0.3f * JPH_PI) * shape1_com; // Test against wrong layer - c.GetSystem()->GetNarrowPhaseQuery().CollideShape(shape1, Vec3::sReplicate(1.0f), shape1_transform, settings, RVec3::sZero(), fail_collector, broadphase_moving_filter, object_moving_filter); + c.GetSystem()->GetNarrowPhaseQuery().CollideShape(shape1, Vec3::sOne(), shape1_transform, settings, RVec3::sZero(), fail_collector, broadphase_moving_filter, object_moving_filter); // Callback that tests that collision happens at position B class PositionBCollideShapeCollector : public CollideShapeCollector @@ -163,19 +163,19 @@ TEST_SUITE("CollideShapeTests") // Test collision CHECK(!position_b_collector.mWasHit); - c.GetSystem()->GetNarrowPhaseQuery().CollideShape(shape1, Vec3::sReplicate(1.0f), shape1_transform, settings, RVec3::sZero(), position_b_collector, broadphase_non_moving_filter, object_non_moving_filter); + c.GetSystem()->GetNarrowPhaseQuery().CollideShape(shape1, Vec3::sOne(), shape1_transform, settings, RVec3::sZero(), position_b_collector, broadphase_non_moving_filter, object_non_moving_filter); CHECK(position_b_collector.mWasHit); // Update the physics system (optimizes the broadphase) c.Simulate(c.GetDeltaTime()); // Test against wrong layer - c.GetSystem()->GetNarrowPhaseQuery().CollideShape(shape1, Vec3::sReplicate(1.0f), shape1_transform, settings, RVec3::sZero(), fail_collector, broadphase_moving_filter, object_moving_filter); + c.GetSystem()->GetNarrowPhaseQuery().CollideShape(shape1, Vec3::sOne(), shape1_transform, settings, RVec3::sZero(), fail_collector, broadphase_moving_filter, object_moving_filter); // Test collision again position_b_collector.Reset(); CHECK(!position_b_collector.mWasHit); - c.GetSystem()->GetNarrowPhaseQuery().CollideShape(shape1, Vec3::sReplicate(1.0f), shape1_transform, settings, RVec3::sZero(), position_b_collector, broadphase_non_moving_filter, object_non_moving_filter); + c.GetSystem()->GetNarrowPhaseQuery().CollideShape(shape1, Vec3::sOne(), shape1_transform, settings, RVec3::sZero(), position_b_collector, broadphase_non_moving_filter, object_non_moving_filter); CHECK(position_b_collector.mWasHit); } @@ -186,7 +186,7 @@ TEST_SUITE("CollideShapeTests") // Create box to collide against (shape 2) // The box is scaled up by a factor 10 in the X axis and then rotated so that the X axis is up - BoxShapeSettings box(Vec3::sReplicate(1.0f)); + BoxShapeSettings box(Vec3::sOne()); box.SetEmbedded(); ScaledShapeSettings scaled_box(&box, Vec3(10, 1, 1)); scaled_box.SetEmbedded(); @@ -203,7 +203,7 @@ TEST_SUITE("CollideShapeTests") // Collect hit with normal sphere AllHitCollisionCollector collector; - c.GetSystem()->GetNarrowPhaseQuery().CollideShape(normal_sphere, Vec3::sReplicate(1.0f), RMat44::sTranslation(RVec3(0, 11, 0)), settings, RVec3::sZero(), collector); + c.GetSystem()->GetNarrowPhaseQuery().CollideShape(normal_sphere, Vec3::sOne(), RMat44::sTranslation(RVec3(0, 11, 0)), settings, RVec3::sZero(), collector); CHECK(collector.mHits.size() == 1); const CollideShapeResult &result = collector.mHits.front(); CHECK(result.mBodyID2 == body2.GetID()); @@ -258,7 +258,7 @@ TEST_SUITE("CollideShapeTests") // Collide the two shapes AllHitCollisionCollector collector; - CollisionDispatch::sCollideShapeVsShape(capsule_shape, box_shape, Vec3::sReplicate(1.0f), Vec3::sReplicate(1.0f), capsule_transform, box_transform, SubShapeIDCreator(), SubShapeIDCreator(), settings, collector); + CollisionDispatch::sCollideShapeVsShape(capsule_shape, box_shape, Vec3::sOne(), Vec3::sOne(), capsule_transform, box_transform, SubShapeIDCreator(), SubShapeIDCreator(), settings, collector); // Check that there was a hit CHECK(collector.mHits.size() == 1); @@ -268,11 +268,11 @@ TEST_SUITE("CollideShapeTests") Vec3 distance_to_move_box = result.mPenetrationAxis.Normalized() * result.mPenetrationDepth; collector.Reset(); CHECK(!collector.HadHit()); - CollisionDispatch::sCollideShapeVsShape(capsule_shape, box_shape, Vec3::sReplicate(1.0f), Vec3::sReplicate(1.0f), capsule_transform, Mat44::sTranslation(1.01f * distance_to_move_box) * box_transform, SubShapeIDCreator(), SubShapeIDCreator(), settings, collector); + CollisionDispatch::sCollideShapeVsShape(capsule_shape, box_shape, Vec3::sOne(), Vec3::sOne(), capsule_transform, Mat44::sTranslation(1.01f * distance_to_move_box) * box_transform, SubShapeIDCreator(), SubShapeIDCreator(), settings, collector); CHECK(!collector.HadHit()); // Now check that moving 1% less than the penetration distance makes the shapes still overlap - CollisionDispatch::sCollideShapeVsShape(capsule_shape, box_shape, Vec3::sReplicate(1.0f), Vec3::sReplicate(1.0f), capsule_transform, Mat44::sTranslation(0.99f * distance_to_move_box) * box_transform, SubShapeIDCreator(), SubShapeIDCreator(), settings, collector); + CollisionDispatch::sCollideShapeVsShape(capsule_shape, box_shape, Vec3::sOne(), Vec3::sOne(), capsule_transform, Mat44::sTranslation(0.99f * distance_to_move_box) * box_transform, SubShapeIDCreator(), SubShapeIDCreator(), settings, collector); CHECK(collector.mHits.size() == 1); } @@ -303,7 +303,7 @@ TEST_SUITE("CollideShapeTests") // Create the convex hull support function ConvexShape::SupportBuffer buffer; - const ConvexShape::Support *support = convex_hull->GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sReplicate(1.0f)); + const ConvexShape::Support *support = convex_hull->GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sOne()); // Triangle is close enough to make GJK report indeterminate Vec3 penetration_axis = Vec3::sAxisX(), point1, point2; @@ -331,7 +331,7 @@ TEST_SUITE("CollideShapeTests") CollideShapeSettings settings; AllHitCollisionCollector collector; - CollisionDispatch::sCollideShapeVsShape(&triangle, &capsule, Vec3::sReplicate(1.0f), Vec3::sReplicate(1.0f), Mat44::sIdentity(), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), settings, collector); + CollisionDispatch::sCollideShapeVsShape(&triangle, &capsule, Vec3::sOne(), Vec3::sOne(), Mat44::sIdentity(), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), settings, collector); // The capsule's center is closest to the triangle's edge v2 v3 Vec3 capsule_center_to_triangle_v2_v3 = v3; @@ -365,7 +365,7 @@ TEST_SUITE("CollideShapeTests") CollideShapeSettings settings; AllHitCollisionCollector collector; - CollisionDispatch::sCollideShapeVsShape(&triangle, &capsule, Vec3::sReplicate(1.0f), Vec3::sReplicate(1.0f), Mat44::sIdentity(), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), settings, collector); + CollisionDispatch::sCollideShapeVsShape(&triangle, &capsule, Vec3::sOne(), Vec3::sOne(), Mat44::sIdentity(), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), settings, collector); // The capsule intersects with the triangle and the closest point is in the interior of the triangle Vec3 expected_penetration_axis = Vec3(0, 0, -1); // Triangle is in the XY plane so the normal is Z @@ -397,7 +397,7 @@ TEST_SUITE("CollideShapeTests") CollideShapeSettings settings; settings.mMaxSeparationDistance = 0.120000005f; ClosestHitCollisionCollector collector; - CollisionDispatch::sCollideShapeVsShape(&capsule, &triangle, Vec3::sReplicate(1.0f), Vec3::sReplicate(1.0f), Mat44::sIdentity(), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), settings, collector); + CollisionDispatch::sCollideShapeVsShape(&capsule, &triangle, Vec3::sOne(), Vec3::sOne(), Mat44::sIdentity(), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), settings, collector); CHECK(collector.HadHit()); Vec3 expected_normal = (v2 - v1).Cross(v3 - v1).Normalized(); @@ -418,7 +418,7 @@ TEST_SUITE("CollideShapeTests") CollideShapeSettings settings; settings.mMaxSeparationDistance = 0.001f; ClosestHitCollisionCollector collector; - CollideConvexVsTriangles c(&cylinder, Vec3::sReplicate(1.0f), Vec3::sReplicate(1.0f), cylinder_transform, Mat44::sIdentity(), SubShapeID(), settings, collector); + CollideConvexVsTriangles c(&cylinder, Vec3::sOne(), Vec3::sOne(), cylinder_transform, Mat44::sIdentity(), SubShapeID(), settings, collector); Vec3 v0(-42.7954292f, -0.647318780f, 12.4227943f); Vec3 v1(-29.9111290f, -0.647318780f, 12.4227943f); @@ -471,7 +471,7 @@ TEST_SUITE("CollideShapeTests") CollideShapeSettings settings; settings.mMaxSeparationDistance = separation_distance; ClosestHitCollisionCollector collector; - CollisionDispatch::sCollideShapeVsShape(box_shape, hull_shape, Vec3::sReplicate(1.0f), Vec3::sReplicate(1.0f), box_transform, hull_transform, SubShapeIDCreator(), SubShapeIDCreator(), settings, collector); + CollisionDispatch::sCollideShapeVsShape(box_shape, hull_shape, Vec3::sOne(), Vec3::sOne(), box_transform, hull_transform, SubShapeIDCreator(), SubShapeIDCreator(), settings, collector); // Check that there was a hit and that the contact normal is correct CHECK(collector.HadHit()); @@ -499,7 +499,7 @@ TEST_SUITE("CollideShapeTests") CollideShapeSettings collide_settings; collide_settings.mMaxSeparationDistance = max_separation; ClosestHitCollisionCollector collector; - CollisionDispatch::sCollideShapeVsShape(box_shape, sphere_shape, Vec3::sReplicate(1.0f), Vec3::sReplicate(1.0f), Mat44::sIdentity(), Mat44::sTranslation(Vec3(x, 0, 0)), SubShapeIDCreator(), SubShapeIDCreator(), collide_settings, collector); + CollisionDispatch::sCollideShapeVsShape(box_shape, sphere_shape, Vec3::sOne(), Vec3::sOne(), Mat44::sIdentity(), Mat44::sTranslation(Vec3(x, 0, 0)), SubShapeIDCreator(), SubShapeIDCreator(), collide_settings, collector); float expected_penetration = cHalfExtent - (x - cRadius); if (collector.HadHit()) @@ -524,7 +524,7 @@ TEST_SUITE("CollideShapeTests") CollideShapeSettings collide_settings; collide_settings.mMaxSeparationDistance = max_separation; ClosestHitCollisionCollector collector; - CollisionDispatch::sCollideShapeVsShape(triangle_shape, box_shape, Vec3::sReplicate(1.0f), Vec3::sReplicate(1.0f), Mat44::sIdentity(), Mat44::sTranslation(Vec3(x, 0, 0)), SubShapeIDCreator(), SubShapeIDCreator(), collide_settings, collector); + CollisionDispatch::sCollideShapeVsShape(triangle_shape, box_shape, Vec3::sOne(), Vec3::sOne(), Mat44::sIdentity(), Mat44::sTranslation(Vec3(x, 0, 0)), SubShapeIDCreator(), SubShapeIDCreator(), collide_settings, collector); float expected_penetration = cTriangleX - (x - cHalfExtent); if (collector.HadHit()) diff --git a/UnitTests/Physics/ContactListenerTests.cpp b/UnitTests/Physics/ContactListenerTests.cpp index fc5495c07..dd78f7981 100644 --- a/UnitTests/Physics/ContactListenerTests.cpp +++ b/UnitTests/Physics/ContactListenerTests.cpp @@ -375,7 +375,7 @@ TEST_SUITE("ContactListenerTests") for (int iteration = 0; iteration < 2; ++iteration) { - Body &box = c.CreateBox(RVec3(0, 0.999f, 0), Quat::sRotation(Vec3::sAxisY(), DegreesToRadians(30.0f)), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3::sReplicate(1.0f)); + Body &box = c.CreateBox(RVec3(0, 0.999f, 0), Quat::sRotation(Vec3::sAxisY(), DegreesToRadians(30.0f)), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3::sOne()); box.SetFriction(1.0f); // Contact listener sets a constant surface velocity diff --git a/UnitTests/Physics/ConvexVsTrianglesTest.cpp b/UnitTests/Physics/ConvexVsTrianglesTest.cpp index 18a2877be..f5c20cd03 100644 --- a/UnitTests/Physics/ConvexVsTrianglesTest.cpp +++ b/UnitTests/Physics/ConvexVsTrianglesTest.cpp @@ -31,7 +31,7 @@ TEST_SUITE("ConvexVsTrianglesTest") { // Collide sphere AllHitCollisionCollector collector; - Collider collider(sphere, Vec3::sReplicate(1.0f), Vec3::sReplicate(1.0f), Mat44::sTranslation(inCenter), Mat44::sIdentity(), SubShapeID(), inSettings, collector); + Collider collider(sphere, Vec3::sOne(), Vec3::sOne(), Mat44::sTranslation(inCenter), Mat44::sIdentity(), SubShapeID(), inSettings, collector); collider.Collide(v1, v2, v3, inActiveEdges, SubShapeID()); CHECK(!collector.HadHit()); } @@ -45,7 +45,7 @@ TEST_SUITE("ConvexVsTrianglesTest") // Collide sphere AllHitCollisionCollector collector; - context.GetSystem()->GetNarrowPhaseQuery().CollideShape(sphere, Vec3::sReplicate(1.0f), RMat44::sTranslation(RVec3(inCenter)), inSettings, RVec3::sZero(), collector); + context.GetSystem()->GetNarrowPhaseQuery().CollideShape(sphere, Vec3::sOne(), RMat44::sTranslation(RVec3(inCenter)), inSettings, RVec3::sZero(), collector); CHECK(!collector.HadHit()); } @@ -60,7 +60,7 @@ TEST_SUITE("ConvexVsTrianglesTest") // Collide sphere AllHitCollisionCollector collector; - context.GetSystem()->GetNarrowPhaseQuery().CollideShape(sphere, Vec3::sReplicate(1.0f), RMat44::sTranslation(RVec3(inCenter)), inSettings, RVec3::sZero(), collector); + context.GetSystem()->GetNarrowPhaseQuery().CollideShape(sphere, Vec3::sOne(), RMat44::sTranslation(RVec3(inCenter)), inSettings, RVec3::sZero(), collector); CHECK(!collector.HadHit()); } } @@ -97,7 +97,7 @@ TEST_SUITE("ConvexVsTrianglesTest") // Collide sphere AllHitCollisionCollector collector; - Collider collider(sphere, Vec3::sReplicate(1.0f), Vec3::sReplicate(1.0f), sphere_transform, transform, sub_shape_id1, settings, collector); + Collider collider(sphere, Vec3::sOne(), Vec3::sOne(), sphere_transform, transform, sub_shape_id1, settings, collector); collider.Collide(v1, v2, v3, inActiveEdges, sub_shape_id2); // Test result @@ -125,7 +125,7 @@ TEST_SUITE("ConvexVsTrianglesTest") // Collide sphere AllHitCollisionCollector collector; - context.GetSystem()->GetNarrowPhaseQuery().CollideShape(sphere, Vec3::sReplicate(1.0f), RMat44(sphere_transform), settings, RVec3::sZero(), collector); + context.GetSystem()->GetNarrowPhaseQuery().CollideShape(sphere, Vec3::sOne(), RMat44(sphere_transform), settings, RVec3::sZero(), collector); // Test result CHECK(collector.mHits.size() == 1); @@ -154,7 +154,7 @@ TEST_SUITE("ConvexVsTrianglesTest") // Collide sphere AllHitCollisionCollector collector; - context.GetSystem()->GetNarrowPhaseQuery().CollideShape(sphere, Vec3::sReplicate(1.0f), RMat44(sphere_transform), settings, RVec3::sZero(), collector); + context.GetSystem()->GetNarrowPhaseQuery().CollideShape(sphere, Vec3::sOne(), RMat44(sphere_transform), settings, RVec3::sZero(), collector); // Test result CHECK(collector.mHits.size() == 1); diff --git a/UnitTests/Physics/MutableCompoundShapeTests.cpp b/UnitTests/Physics/MutableCompoundShapeTests.cpp index f85d30fd5..8b336fda1 100644 --- a/UnitTests/Physics/MutableCompoundShapeTests.cpp +++ b/UnitTests/Physics/MutableCompoundShapeTests.cpp @@ -128,12 +128,12 @@ TEST_SUITE("MutableCompoundShapeTests") { // Start with a box at (-1 0 0) MutableCompoundShapeSettings settings; - Ref box_shape1 = new BoxShape(Vec3::sReplicate(1.0f)); + Ref box_shape1 = new BoxShape(Vec3::sOne()); box_shape1->SetUserData(1); settings.AddShape(Vec3(-1.0f, 0.0f, 0.0f), Quat::sIdentity(), box_shape1); Ref shape = StaticCast(settings.Create().Get()); CHECK(shape->GetCenterOfMass() == Vec3(-1.0f, 0.0f, 0.0f)); - CHECK(shape->GetLocalBounds() == AABox(Vec3::sReplicate(-1.0f), Vec3::sReplicate(1.0f))); + CHECK(shape->GetLocalBounds() == AABox(Vec3::sReplicate(-1.0f), Vec3::sOne())); // Check that we can hit the box AllHitCollisionCollector collector; @@ -143,7 +143,7 @@ TEST_SUITE("MutableCompoundShapeTests") CHECK(collector.mHits.empty()); // Now add another box at (1 0 0) - Ref box_shape2 = new BoxShape(Vec3::sReplicate(1.0f)); + Ref box_shape2 = new BoxShape(Vec3::sOne()); box_shape2->SetUserData(2); shape->AddShape(Vec3(1.0f, 0.0f, 0.0f), Quat::sIdentity(), box_shape2); CHECK(shape->GetCenterOfMass() == Vec3(-1.0f, 0.0f, 0.0f)); diff --git a/UnitTests/Physics/PhysicsStepListenerTests.cpp b/UnitTests/Physics/PhysicsStepListenerTests.cpp index 57d497a6a..126a1b339 100644 --- a/UnitTests/Physics/PhysicsStepListenerTests.cpp +++ b/UnitTests/Physics/PhysicsStepListenerTests.cpp @@ -49,7 +49,7 @@ TEST_SUITE("StepListenerTest") CHECK(l.mCount == 0); // Now add an active body - c.CreateBox(RVec3::sZero(), Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3::sReplicate(1.0f)); + c.CreateBox(RVec3::sZero(), Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3::sOne()); // Step the simulation c.SimulateSingleStep(); diff --git a/UnitTests/Physics/PhysicsTests.cpp b/UnitTests/Physics/PhysicsTests.cpp index fef2794d3..d9cdddd95 100644 --- a/UnitTests/Physics/PhysicsTests.cpp +++ b/UnitTests/Physics/PhysicsTests.cpp @@ -57,13 +57,13 @@ TEST_SUITE("PhysicsTests") BodyID body1_id; { // Create a box - Body &body1 = c.CreateBox(RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, EMotionQuality::Discrete, 0, Vec3::sReplicate(1.0f)); + Body &body1 = c.CreateBox(RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, EMotionQuality::Discrete, 0, Vec3::sOne()); body1_id = body1.GetID(); CHECK(body1_id.GetIndex() == 0); CHECK(body1_id.GetSequenceNumber() == 1); // Create another box - Body &body2 = c.CreateBox(RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, EMotionQuality::Discrete, 0, Vec3::sReplicate(1.0f)); + Body &body2 = c.CreateBox(RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, EMotionQuality::Discrete, 0, Vec3::sOne()); BodyID body2_id = body2.GetID(); CHECK(body2_id.GetIndex() == 1); CHECK(body2_id.GetSequenceNumber() == 1); @@ -97,7 +97,7 @@ TEST_SUITE("PhysicsTests") } // Create another box - Body &body3 = c.CreateBox(RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, EMotionQuality::Discrete, 0, Vec3::sReplicate(1.0f)); + Body &body3 = c.CreateBox(RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, EMotionQuality::Discrete, 0, Vec3::sOne()); BodyID body3_id = body3.GetID(); CHECK(body3_id.GetIndex() == 0); // Check index reused CHECK(body3_id.GetSequenceNumber() == 2); // Check sequence number changed @@ -131,8 +131,8 @@ TEST_SUITE("PhysicsTests") { // Create two bodies - Body &body1 = c.CreateBox(RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, EMotionQuality::Discrete, 0, Vec3::sReplicate(1.0f)); - Body &body2 = c.CreateBox(RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, EMotionQuality::Discrete, 0, Vec3::sReplicate(1.0f)); + Body &body1 = c.CreateBox(RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, EMotionQuality::Discrete, 0, Vec3::sOne()); + Body &body2 = c.CreateBox(RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, EMotionQuality::Discrete, 0, Vec3::sOne()); BodyID bodies[] = { body1.GetID(), body2.GetID() }; { @@ -199,7 +199,7 @@ TEST_SUITE("PhysicsTests") BodyInterface &bi = c.GetBodyInterface(); // Dummy creation settings - BodyCreationSettings bc(new BoxShape(Vec3::sReplicate(1.0f)), RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING); + BodyCreationSettings bc(new BoxShape(Vec3::sOne()), RVec3::sZero(), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING); // Create a body Body *b1 = bi.CreateBody(bc); @@ -260,7 +260,7 @@ TEST_SUITE("PhysicsTests") BodyInterface &bi = c.GetBodyInterface(); // Create a body and pass user data through the creation settings - BodyCreationSettings body_settings(new BoxShape(Vec3::sReplicate(1.0f)), RVec3::sZero(), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING); + BodyCreationSettings body_settings(new BoxShape(Vec3::sOne()), RVec3::sZero(), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING); body_settings.mUserData = 0x1234567887654321; Body *body = bi.CreateBody(body_settings); CHECK(body->GetUserData() == 0x1234567887654321); @@ -279,7 +279,7 @@ TEST_SUITE("PhysicsTests") PhysicsTestContext c; // Create a body - Body &body = c.CreateBox(RVec3::sZero(), Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3::sReplicate(1.0f)); + Body &body = c.CreateBox(RVec3::sZero(), Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3::sOne()); // Create constraint with user data PointConstraintSettings constraint_settings; @@ -312,7 +312,7 @@ TEST_SUITE("PhysicsTests") RMat44 com_transform = body_transform * Mat44::sTranslation(box_pos); // Create body - BodyCreationSettings body_settings(new RotatedTranslatedShapeSettings(box_pos, box_rotation, new BoxShape(Vec3::sReplicate(1.0f))), body_pos, body_rotation, EMotionType::Static, Layers::NON_MOVING); + BodyCreationSettings body_settings(new RotatedTranslatedShapeSettings(box_pos, box_rotation, new BoxShape(Vec3::sOne())), body_pos, body_rotation, EMotionType::Static, Layers::NON_MOVING); Body *body = bi.CreateBody(body_settings); // Check that the correct positions / rotations are reported @@ -1436,10 +1436,10 @@ TEST_SUITE("PhysicsTests") c2.ZeroGravity(); const RVec3 cBox1Position(1.0f, 2.0f, 3.0f); - Body &box1 = c1.CreateBox(cBox1Position, Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3::sReplicate(1.0f), EActivation::Activate); + Body &box1 = c1.CreateBox(cBox1Position, Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3::sOne(), EActivation::Activate); const RVec3 cBox2Position(4.0f, 5.0f, 6.0f); - Body& box2 = c2.CreateBox(cBox2Position, Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3::sReplicate(1.0f), EActivation::Activate); + Body& box2 = c2.CreateBox(cBox2Position, Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3::sOne(), EActivation::Activate); const Vec3 cBox1Velocity(1.0f, 0, 0); const Vec3 cBox2Velocity(2.0f, 0, 0); @@ -1504,14 +1504,14 @@ TEST_SUITE("PhysicsTests") // The first 8 boxes should be fine for (int i = 0; i < 8; ++i) - c.CreateBox(RVec3(3.0_r * i, 0.9_r, 0), Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3::sReplicate(1.0f), EActivation::Activate); + c.CreateBox(RVec3(3.0_r * i, 0.9_r, 0), Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3::sOne(), EActivation::Activate); // Step EPhysicsUpdateError errors = c.SimulateSingleStep(); CHECK(errors == EPhysicsUpdateError::None); // Adding one more box should introduce an error - c.CreateBox(RVec3(24.0_r, 0.9_r, 0), Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3::sReplicate(1.0f), EActivation::Activate); + c.CreateBox(RVec3(24.0_r, 0.9_r, 0), Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3::sOne(), EActivation::Activate); // Step { @@ -1537,7 +1537,7 @@ TEST_SUITE("PhysicsTests") floor.SetFriction(friction_floor); // Create box with a velocity that will make it slide over the floor (making sure it intersects a little bit initially) - BodyCreationSettings box_settings(new BoxShape(Vec3::sReplicate(1.0f)), RVec3(0, 0.999_r, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING); + BodyCreationSettings box_settings(new BoxShape(Vec3::sOne()), RVec3(0, 0.999_r, 0), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING); box_settings.mFriction = friction_box; box_settings.mLinearDamping = 0; box_settings.mLinearVelocity = Vec3(Sin(DegreesToRadians(angle)), 0, Cos(DegreesToRadians(angle))) * 20.0f; @@ -1596,7 +1596,7 @@ TEST_SUITE("PhysicsTests") c.SimulateSingleStep(); // Cancel components that should not be allowed by the allowed DOFs - Vec3 linear_lock = Vec3::sReplicate(1.0f), angular_lock = Vec3::sReplicate(1.0f); + Vec3 linear_lock = Vec3::sOne(), angular_lock = Vec3::sOne(); for (uint axis = 0; axis < 3; ++axis) { if ((allowed_dofs & (1 << axis)) == 0) @@ -1637,7 +1637,7 @@ TEST_SUITE("PhysicsTests") // Create box that can only rotate around Y that intersects with the floor RVec3 initial_position(0, 0.99f, 0); - BodyCreationSettings box_settings(new BoxShape(Vec3::sReplicate(1.0f)), initial_position, Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING); + BodyCreationSettings box_settings(new BoxShape(Vec3::sOne()), initial_position, Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING); box_settings.mAllowedDOFs = EAllowedDOFs::RotationY; box_settings.mAngularDamping = 0.0f; // No damping to make the calculation for expected angular velocity simple box_settings.mOverrideMassProperties = EOverrideMassProperties::CalculateInertia; @@ -1698,10 +1698,10 @@ TEST_SUITE("PhysicsTests") Body &ground = c.CreateFloor(); // Create two sets of bodies that each overlap - Body &box1 = c.CreateBox(RVec3(0, 1, 0), Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3::sReplicate(1.0f), EActivation::Activate); + Body &box1 = c.CreateBox(RVec3(0, 1, 0), Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3::sOne(), EActivation::Activate); Body &sphere1 = c.CreateSphere(RVec3(0, 1, 0.1f), 1.0f, EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, EActivation::Activate); - Body &box2 = c.CreateBox(RVec3(5, 1, 0), Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3::sReplicate(1.0f), EActivation::Activate); + Body &box2 = c.CreateBox(RVec3(5, 1, 0), Quat::sIdentity(), EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, Vec3::sOne(), EActivation::Activate); Body &sphere2 = c.CreateSphere(RVec3(5, 1, 0.1f), 1.0f, EMotionType::Dynamic, EMotionQuality::Discrete, Layers::MOVING, EActivation::Activate); // Store the absolute initial state, that will be used for the final test. diff --git a/UnitTests/Physics/ShapeTests.cpp b/UnitTests/Physics/ShapeTests.cpp index ed53c56d7..2cffd0e05 100644 --- a/UnitTests/Physics/ShapeTests.cpp +++ b/UnitTests/Physics/ShapeTests.cpp @@ -85,7 +85,7 @@ TEST_SUITE("ShapeTests") // Extract support points ConvexShape::SupportBuffer buffer; - const ConvexShape::Support *support = capsule.GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sReplicate(1.0f)); + const ConvexShape::Support *support = capsule.GetSupportFunction(ConvexShape::ESupportMode::IncludeConvexRadius, buffer, Vec3::sOne()); Array capsule_points; capsule_points.reserve(Vec3::sUnitSphere.size()); for (const Vec3 &v : Vec3::sUnitSphere) @@ -715,7 +715,7 @@ TEST_SUITE("ShapeTests") // Create a heightfield float *samples = new float [cHeightFieldSamples * cHeightFieldSamples]; memset(samples, 0, cHeightFieldSamples * cHeightFieldSamples * sizeof(float)); - RefConst previous_shape = HeightFieldShapeSettings(samples, Vec3::sZero(), Vec3::sReplicate(1.0f), cHeightFieldSamples).Create().Get(); + RefConst previous_shape = HeightFieldShapeSettings(samples, Vec3::sZero(), Vec3::sOne(), cHeightFieldSamples).Create().Get(); delete [] samples; // Calculate the amount of bits needed to address all triangles in the heightfield @@ -868,7 +868,7 @@ TEST_SUITE("ShapeTests") AllHitCollisionCollector collector; CollideShapeSettings settings; settings.mCollectFacesMode = ECollectFacesMode::CollectFaces; - CollisionDispatch::sCollideShapeVsShape(box, compound, Vec3::sReplicate(1.0f), Vec3::sReplicate(1.0f), Mat44::sTranslation(Vec3(100.0f, 0, 100.0f)), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), settings, collector); + CollisionDispatch::sCollideShapeVsShape(box, compound, Vec3::sOne(), Vec3::sOne(), Mat44::sTranslation(Vec3(100.0f, 0, 100.0f)), Mat44::sIdentity(), SubShapeIDCreator(), SubShapeIDCreator(), settings, collector); CHECK(collector.mHits.size() == triangles[0].size() + triangles[1].size()); for (const CollideShapeResult &r : collector.mHits) {