mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-27 13:11:42 +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;
|
found = true;
|
||||||
// iterationFound = true;
|
// iterationFound = true;
|
||||||
i += 3;
|
i += 3;
|
||||||
|
// Debug.drawSphere(currentFinalPos, radius);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -971,6 +972,7 @@ class Marble extends GameObject {
|
||||||
lastContactPos = vertDiff.multiply(distanceAlongEdge / edgeLen).add(thisVert);
|
lastContactPos = vertDiff.multiply(distanceAlongEdge / edgeLen).add(thisVert);
|
||||||
lastVert = thisVert;
|
lastVert = thisVert;
|
||||||
found = true;
|
found = true;
|
||||||
|
// Debug.drawSphere(currentFinalPos, radius);
|
||||||
// iterationFound = true;
|
// iterationFound = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -1015,6 +1017,7 @@ class Marble extends GameObject {
|
||||||
currentFinalPos = position.add(relVel.multiply(finalT));
|
currentFinalPos = position.add(relVel.multiply(finalT));
|
||||||
lastContactPos = thisVert;
|
lastContactPos = thisVert;
|
||||||
found = true;
|
found = true;
|
||||||
|
// Debug.drawSphere(currentFinalPos, radius);
|
||||||
// iterationFound = true;
|
// iterationFound = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1062,6 +1065,7 @@ class Marble extends GameObject {
|
||||||
|
|
||||||
finalT = edgeCollisionTime;
|
finalT = edgeCollisionTime;
|
||||||
currentFinalPos = position.add(relVel.multiply(finalT));
|
currentFinalPos = position.add(relVel.multiply(finalT));
|
||||||
|
// Debug.drawSphere(currentFinalPos, radius);
|
||||||
|
|
||||||
lastVert = thisVert;
|
lastVert = thisVert;
|
||||||
found = true;
|
found = true;
|
||||||
|
|
@ -1268,13 +1272,30 @@ class Marble extends GameObject {
|
||||||
do {
|
do {
|
||||||
var resolved = 0;
|
var resolved = 0;
|
||||||
for (testTri in concernedContacts) {
|
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,
|
var tsi = Collision.TriangleSphereIntersection(testTri.v[0], testTri.v[1], testTri.v[2], testTri.n, position, radius, testTri.edge,
|
||||||
testTri.concavity);
|
testTri.concavity);
|
||||||
if (tsi.result) {
|
if (tsi.result) {
|
||||||
|
var separatingDistance = position.sub(tsi.point).normalized();
|
||||||
var distToContactPlane = tsi.point.distance(position);
|
var distToContactPlane = tsi.point.distance(position);
|
||||||
if (radius - 0.005 - distToContactPlane > 0.0001) {
|
if (radius - 0.005 - distToContactPlane > 0.0001) {
|
||||||
// Nudge to the surface of the contact plane
|
// 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++;
|
resolved++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ typedef ITSResult = {
|
||||||
var result:Bool;
|
var result:Bool;
|
||||||
var normal:Vector;
|
var normal:Vector;
|
||||||
var point:Vector;
|
var point:Vector;
|
||||||
|
var resIdx:Int;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Collision {
|
class Collision {
|
||||||
|
|
@ -67,7 +68,8 @@ class Collision {
|
||||||
var res:ITSResult = {
|
var res:ITSResult = {
|
||||||
result: false,
|
result: false,
|
||||||
point: null,
|
point: null,
|
||||||
normal: null
|
normal: null,
|
||||||
|
resIdx: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
var pnorm = normal.clone();
|
var pnorm = normal.clone();
|
||||||
|
|
@ -146,7 +148,8 @@ class Collision {
|
||||||
var res:ITSResult = {
|
var res:ITSResult = {
|
||||||
result: false,
|
result: false,
|
||||||
point: null,
|
point: null,
|
||||||
normal: null
|
normal: null,
|
||||||
|
resIdx: -1
|
||||||
};
|
};
|
||||||
|
|
||||||
var v0 = A;
|
var v0 = A;
|
||||||
|
|
@ -217,6 +220,7 @@ class Collision {
|
||||||
res.result = true;
|
res.result = true;
|
||||||
res.normal = N.clone();
|
res.normal = N.clone();
|
||||||
res.point = P.sub(N.multiply(P.sub(v0).dot(N)));
|
res.point = P.sub(N.multiply(P.sub(v0).dot(N)));
|
||||||
|
res.resIdx = 0;
|
||||||
} else {
|
} else {
|
||||||
var closestPt = P.sub(N.multiply(P.sub(v0).dot(N)));
|
var closestPt = P.sub(N.multiply(P.sub(v0).dot(N)));
|
||||||
var r1 = ClosestPointLine(v0, v1, closestPt);
|
var r1 = ClosestPointLine(v0, v1, closestPt);
|
||||||
|
|
@ -242,6 +246,8 @@ class Collision {
|
||||||
res.normal = P.sub(res.point).normalized();
|
res.normal = P.sub(res.point).normalized();
|
||||||
res.result = true;
|
res.result = true;
|
||||||
|
|
||||||
|
res.resIdx = chosenEdge;
|
||||||
|
|
||||||
// if (res.normal.dot(N) > 0.8) {
|
// if (res.normal.dot(N) > 0.8) {
|
||||||
// // Internal edge
|
// // Internal edge
|
||||||
// if (chosenEdge & edgeData > 0) {
|
// if (chosenEdge & edgeData > 0) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue