mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-01-22 15:05:55 +00:00
don't collide with tiny triangles
This commit is contained in:
parent
92fd215fa0
commit
402e7a9893
2 changed files with 30 additions and 3 deletions
|
|
@ -892,6 +892,7 @@ class Marble extends GameObject {
|
|||
found = true;
|
||||
// iterationFound = true;
|
||||
i += 3;
|
||||
// Debug.drawSphere(currentFinalPos, radius);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
@ -971,6 +972,7 @@ class Marble extends GameObject {
|
|||
lastContactPos = vertDiff.multiply(distanceAlongEdge / edgeLen).add(thisVert);
|
||||
lastVert = thisVert;
|
||||
found = true;
|
||||
// Debug.drawSphere(currentFinalPos, radius);
|
||||
// iterationFound = true;
|
||||
continue;
|
||||
}
|
||||
|
|
@ -1015,6 +1017,7 @@ class Marble extends GameObject {
|
|||
currentFinalPos = position.add(relVel.multiply(finalT));
|
||||
lastContactPos = thisVert;
|
||||
found = true;
|
||||
// Debug.drawSphere(currentFinalPos, radius);
|
||||
// iterationFound = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1062,6 +1065,7 @@ class Marble extends GameObject {
|
|||
|
||||
finalT = edgeCollisionTime;
|
||||
currentFinalPos = position.add(relVel.multiply(finalT));
|
||||
// Debug.drawSphere(currentFinalPos, radius);
|
||||
|
||||
lastVert = thisVert;
|
||||
found = true;
|
||||
|
|
@ -1268,13 +1272,30 @@ class Marble extends GameObject {
|
|||
do {
|
||||
var resolved = 0;
|
||||
for (testTri in concernedContacts) {
|
||||
// Check if we are on wrong side of the triangle
|
||||
if (testTri.n.dot(position) - testTri.n.dot(testTri.v[0]) < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var t1 = testTri.v[1].sub(testTri.v[0]);
|
||||
var t2 = testTri.v[2].sub(testTri.v[0]);
|
||||
var tarea = Math.abs(t1.cross(t2).length()) / 2.0;
|
||||
|
||||
// Check if our triangle is too small to be collided with
|
||||
if (tarea < 0.001) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var tsi = Collision.TriangleSphereIntersection(testTri.v[0], testTri.v[1], testTri.v[2], testTri.n, position, radius, testTri.edge,
|
||||
testTri.concavity);
|
||||
if (tsi.result) {
|
||||
var separatingDistance = position.sub(tsi.point).normalized();
|
||||
var distToContactPlane = tsi.point.distance(position);
|
||||
if (radius - 0.005 - distToContactPlane > 0.0001) {
|
||||
// Nudge to the surface of the contact plane
|
||||
position = position.add(tsi.normal.multiply(radius - distToContactPlane - 0.005));
|
||||
Debug.drawTriangle(testTri.v[0], testTri.v[1], testTri.v[2]);
|
||||
Debug.drawSphere(position, radius);
|
||||
position = position.add(separatingDistance.multiply(radius - distToContactPlane - 0.005));
|
||||
resolved++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ typedef ITSResult = {
|
|||
var result:Bool;
|
||||
var normal:Vector;
|
||||
var point:Vector;
|
||||
var resIdx:Int;
|
||||
}
|
||||
|
||||
class Collision {
|
||||
|
|
@ -67,7 +68,8 @@ class Collision {
|
|||
var res:ITSResult = {
|
||||
result: false,
|
||||
point: null,
|
||||
normal: null
|
||||
normal: null,
|
||||
resIdx: 0
|
||||
};
|
||||
|
||||
var pnorm = normal.clone();
|
||||
|
|
@ -146,7 +148,8 @@ class Collision {
|
|||
var res:ITSResult = {
|
||||
result: false,
|
||||
point: null,
|
||||
normal: null
|
||||
normal: null,
|
||||
resIdx: -1
|
||||
};
|
||||
|
||||
var v0 = A;
|
||||
|
|
@ -217,6 +220,7 @@ class Collision {
|
|||
res.result = true;
|
||||
res.normal = N.clone();
|
||||
res.point = P.sub(N.multiply(P.sub(v0).dot(N)));
|
||||
res.resIdx = 0;
|
||||
} else {
|
||||
var closestPt = P.sub(N.multiply(P.sub(v0).dot(N)));
|
||||
var r1 = ClosestPointLine(v0, v1, closestPt);
|
||||
|
|
@ -242,6 +246,8 @@ class Collision {
|
|||
res.normal = P.sub(res.point).normalized();
|
||||
res.result = true;
|
||||
|
||||
res.resIdx = chosenEdge;
|
||||
|
||||
// if (res.normal.dot(N) > 0.8) {
|
||||
// // Internal edge
|
||||
// if (chosenEdge & edgeData > 0) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue