summaryrefslogtreecommitdiffstats
path: root/src/Game.cpp
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-12-26 14:17:28 +0100
committerMatthias Schiffer <matthias@gamezock.de>2009-12-26 14:17:28 +0100
commitf945e21bbd225d9a2beb0f8e623bf5b9a66fc846 (patch)
tree78ec113701f971c6ccaa12189e794ec08c41b5e2 /src/Game.cpp
parent5dc3e727e0fc470d344da8b18c3588104585496f (diff)
downloadzoom++-f945e21bbd225d9a2beb0f8e623bf5b9a66fc846.tar
zoom++-f945e21bbd225d9a2beb0f8e623bf5b9a66fc846.zip
Optimized finding nearest plane
Diffstat (limited to 'src/Game.cpp')
-rw-r--r--src/Game.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/Game.cpp b/src/Game.cpp
index 5b61da7..e3aa72f 100644
--- a/src/Game.cpp
+++ b/src/Game.cpp
@@ -137,16 +137,24 @@ void Game::run(int delta) {
ok = true;
MathUtil::Plane nearestPlane;
+ float nearestDistance;
for(std::vector<TriangleRecord>::iterator t = triangles.begin(); t != triangles.end(); ++t) {
if(Collision::test(t->getTriangle(), playerPos, PLAYER_RADIUS, playerMove)) {
vmml::vec3f normal = t->getTriangle().computeNormal();
+ if(normal.dot(playerMove) >= 0)
+ continue;
+
MathUtil::Plane p(normal, vmml::dot(normal, t->getTriangle().getVertex(0)+PLAYER_RADIUS*normal));
if(p.isInFront(playerPos) || p.contains(playerPos)) {
- if(ok || p.distance(playerPos) < nearestPlane.distance(playerPos)) {
+ vmml::vec3f intersection = p.intersection(MathUtil::Ray(playerPos, playerMove));
+ float distance = intersection.squared_distance(playerPos);
+
+ if(ok || distance < nearestDistance) {
ok = false;
nearestPlane = p;
+ nearestDistance = distance;
}
}
}