Corrected edge & vertex collision
This commit is contained in:
parent
cc2a07f13d
commit
9d152e2773
2 changed files with 8 additions and 6 deletions
|
@ -118,6 +118,7 @@ bool Collision::test(const Triangle &t, const vmml::vec3f &m, float r, const vmm
|
||||||
for(int i = 0; i < 3; ++i) {
|
for(int i = 0; i < 3; ++i) {
|
||||||
if(testEdge(t.getVertex(i), t.getVertex((i+1)%3), m, r, move, &d)) {
|
if(testEdge(t.getVertex(i), t.getVertex((i+1)%3), m, r, move, &d)) {
|
||||||
if(!collision || d < minDistance) {
|
if(!collision || d < minDistance) {
|
||||||
|
collision = true;
|
||||||
minDistance = d;
|
minDistance = d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,6 +135,7 @@ bool Collision::test(const Triangle &t, const vmml::vec3f &m, float r, const vmm
|
||||||
for(int i = 0; i < 3; ++i) {
|
for(int i = 0; i < 3; ++i) {
|
||||||
if(testVertex(t.getVertex(i), m, r, move, &d)) {
|
if(testVertex(t.getVertex(i), m, r, move, &d)) {
|
||||||
if(!collision || d < minDistance) {
|
if(!collision || d < minDistance) {
|
||||||
|
collision = true;
|
||||||
minDistance = d;
|
minDistance = d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
src/Game.cpp
12
src/Game.cpp
|
@ -131,10 +131,10 @@ void Game::run(int delta) {
|
||||||
|
|
||||||
vmml::vec3f origMove = playerMove;
|
vmml::vec3f origMove = playerMove;
|
||||||
|
|
||||||
bool ok = false;
|
bool collision = true;
|
||||||
|
|
||||||
while(!ok) {
|
while(collision) {
|
||||||
ok = true;
|
collision = false;
|
||||||
|
|
||||||
MathUtil::Plane nearestPlane;
|
MathUtil::Plane nearestPlane;
|
||||||
float nearestDistance;
|
float nearestDistance;
|
||||||
|
@ -150,8 +150,8 @@ void Game::run(int delta) {
|
||||||
vmml::vec3f intersection = p.intersection(MathUtil::Ray(playerPos, playerMove));
|
vmml::vec3f intersection = p.intersection(MathUtil::Ray(playerPos, playerMove));
|
||||||
float distance = intersection.squared_distance(playerPos);
|
float distance = intersection.squared_distance(playerPos);
|
||||||
|
|
||||||
if(ok || distance < nearestDistance) {
|
if(!collision || distance < nearestDistance) {
|
||||||
ok = false;
|
collision = true;
|
||||||
|
|
||||||
nearestPlane = p;
|
nearestPlane = p;
|
||||||
nearestDistance = distance;
|
nearestDistance = distance;
|
||||||
|
@ -164,7 +164,7 @@ void Game::run(int delta) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!ok) {
|
if(collision) {
|
||||||
vmml::vec3f move;
|
vmml::vec3f move;
|
||||||
|
|
||||||
if(playerMove.dot(nearestPlane.getNormal()) == 0)
|
if(playerMove.dot(nearestPlane.getNormal()) == 0)
|
||||||
|
|
Reference in a new issue