summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2010-01-04 01:02:33 +0100
committerMatthias Schiffer <matthias@gamezock.de>2010-01-04 01:02:33 +0100
commit9d152e2773f28d4fb7066010d2ae9099873cb6fd (patch)
tree40f2b8faca60228934dbbd07c7c435424fd98221
parentcc2a07f13d5f6613dabcd454790b088c9c273cbf (diff)
downloadzoom++-9d152e2773f28d4fb7066010d2ae9099873cb6fd.tar
zoom++-9d152e2773f28d4fb7066010d2ae9099873cb6fd.zip
Corrected edge & vertex collision
-rw-r--r--src/Collision.cpp2
-rw-r--r--src/Game.cpp12
2 files changed, 8 insertions, 6 deletions
diff --git a/src/Collision.cpp b/src/Collision.cpp
index ea69b39..e552643 100644
--- a/src/Collision.cpp
+++ b/src/Collision.cpp
@@ -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) {
if(testEdge(t.getVertex(i), t.getVertex((i+1)%3), m, r, move, &d)) {
if(!collision || d < minDistance) {
+ collision = true;
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) {
if(testVertex(t.getVertex(i), m, r, move, &d)) {
if(!collision || d < minDistance) {
+ collision = true;
minDistance = d;
}
}
diff --git a/src/Game.cpp b/src/Game.cpp
index f583312..aea829f 100644
--- a/src/Game.cpp
+++ b/src/Game.cpp
@@ -131,10 +131,10 @@ void Game::run(int delta) {
vmml::vec3f origMove = playerMove;
- bool ok = false;
+ bool collision = true;
- while(!ok) {
- ok = true;
+ while(collision) {
+ collision = false;
MathUtil::Plane nearestPlane;
float nearestDistance;
@@ -150,8 +150,8 @@ void Game::run(int delta) {
vmml::vec3f intersection = p.intersection(MathUtil::Ray(playerPos, playerMove));
float distance = intersection.squared_distance(playerPos);
- if(ok || distance < nearestDistance) {
- ok = false;
+ if(!collision || distance < nearestDistance) {
+ collision = true;
nearestPlane = p;
nearestDistance = distance;
@@ -164,7 +164,7 @@ void Game::run(int delta) {
}
}
- if(!ok) {
+ if(collision) {
vmml::vec3f move;
if(playerMove.dot(nearestPlane.getNormal()) == 0)