aboutsummaryrefslogtreecommitdiff
path: root/Client/Source/Phy2DLite/Collide.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-12-02 11:41:42 +0800
committerchai <chaifix@163.com>2021-12-02 11:41:42 +0800
commit7a798253441a8bd499d36bd8153b92ab08de8a9f (patch)
tree32e4ee995534a4a8cd7c2e0b530ff02c45217e8f /Client/Source/Phy2DLite/Collide.cpp
parentbcc11176480f403ab294de24d61bab993ce2fdfd (diff)
*fixed
Diffstat (limited to 'Client/Source/Phy2DLite/Collide.cpp')
-rw-r--r--Client/Source/Phy2DLite/Collide.cpp33
1 files changed, 17 insertions, 16 deletions
diff --git a/Client/Source/Phy2DLite/Collide.cpp b/Client/Source/Phy2DLite/Collide.cpp
index 6849c0e..116a72e 100644
--- a/Client/Source/Phy2DLite/Collide.cpp
+++ b/Client/Source/Phy2DLite/Collide.cpp
@@ -2,6 +2,7 @@
#include "Body.h"
#include "World.h"
#include "Joint.h"
+#include "Constants.h"
using namespace Phy2D;
@@ -58,16 +59,16 @@ int ClipSegmentToLine(ClipVertex vOut[2], ClipVertex vIn[2],
number distance1 = Dot(normal, vIn[1].v) - offset;
// If the points are behind the plane
- if (distance0 <= 0.0f) vOut[numOut++] = vIn[0];
- if (distance1 <= 0.0f) vOut[numOut++] = vIn[1];
+ if (distance0 <= _0) vOut[numOut++] = vIn[0];
+ if (distance1 <= _0) vOut[numOut++] = vIn[1];
// If the points are on different sides of the plane
- if (distance0 * distance1 < 0.0f)
+ if (distance0 * distance1 < _0)
{
// Find intersection point of edge and plane
number interp = distance0 / (distance0 - distance1);
vOut[numOut].v = vIn[0].v + interp * (vIn[1].v - vIn[0].v);
- if (distance0 > 0.0f)
+ if (distance0 > _0)
{
vOut[numOut].fp = vIn[0].fp;
vOut[numOut].fp.e.inEdge1 = clipEdge;
@@ -96,7 +97,7 @@ static void ComputeIncidentEdge(ClipVertex c[2], const Vec2& h, const Vec2& pos,
if (nAbs.x > nAbs.y)
{
- if (Sign(n.x) > 0.0f)
+ if (Sign(n.x) > _0)
{
c[0].v.Set(h.x, -h.y);
c[0].fp.e.inEdge2 = EDGE3;
@@ -119,7 +120,7 @@ static void ComputeIncidentEdge(ClipVertex c[2], const Vec2& h, const Vec2& pos,
}
else
{
- if (Sign(n.y) > 0.0f)
+ if (Sign(n.y) > _0)
{
c[0].v.Set(h.x, h.y);
c[0].fp.e.inEdge2 = EDGE4;
@@ -152,8 +153,8 @@ namespace Phy2D
int Collide(Contact* contacts, Body* bodyA, Body* bodyB)
{
// Setup
- Vec2 hA = 0.5f * bodyA->width;
- Vec2 hB = 0.5f * bodyB->width;
+ Vec2 hA = _0_5 * bodyA->width;
+ Vec2 hB = _0_5 * bodyB->width;
Vec2 posA = bodyA->position;
Vec2 posB = bodyB->position;
@@ -173,12 +174,12 @@ namespace Phy2D
// Box A faces
Vec2 faceA = Abs(dA) - hA - absC * hB;
- if (faceA.x > 0.0f || faceA.y > 0.0f)
+ if (faceA.x > _0 || faceA.y > _0)
return 0;
// Box B faces
Vec2 faceB = Abs(dB) - absCT * hA - hB;
- if (faceB.x > 0.0f || faceB.y > 0.0f)
+ if (faceB.x > _0 || faceB.y > _0)
return 0;
// Find best axis
@@ -189,16 +190,16 @@ namespace Phy2D
// Box A faces
axis = FACE_A_X;
separation = faceA.x;
- normal = dA.x > 0.0f ? RotA.col1 : -RotA.col1;
+ normal = dA.x > _0 ? RotA.col1 : -RotA.col1;
- const number relativeTol = 0.95f;
- const number absoluteTol = 0.01f;
+ const number relativeTol = _0_95;
+ const number absoluteTol = _0_01;
if (faceA.y > relativeTol * separation + absoluteTol * hA.y)
{
axis = FACE_A_Y;
separation = faceA.y;
- normal = dA.y > 0.0f ? RotA.col2 : -RotA.col2;
+ normal = dA.y > _0 ? RotA.col2 : -RotA.col2;
}
// Box B faces
@@ -206,14 +207,14 @@ namespace Phy2D
{
axis = FACE_B_X;
separation = faceB.x;
- normal = dB.x > 0.0f ? RotB.col1 : -RotB.col1;
+ normal = dB.x > _0 ? RotB.col1 : -RotB.col1;
}
if (faceB.y > relativeTol * separation + absoluteTol * hB.y)
{
axis = FACE_B_Y;
separation = faceB.y;
- normal = dB.y > 0.0f ? RotB.col2 : -RotB.col2;
+ normal = dB.y > _0 ? RotB.col2 : -RotB.col2;
}
// Setup clipping plane data based on the separating axis