fixed collision detection again, and put some needed rounding to getNormal
authornireco
Fri, 28 Nov 2008 16:48:10 +0000
changeset 124 2fd698e04779
parent 123 7efb63402b2b
child 125 8e15c7db2333
fixed collision detection again, and put some needed rounding to getNormal
src/proto2/Physics.cc
src/proto2/Vector.hh
--- a/src/proto2/Physics.cc	Fri Nov 28 15:45:30 2008 +0000
+++ b/src/proto2/Physics.cc	Fri Nov 28 16:48:10 2008 +0000
@@ -165,9 +165,9 @@
         // Check if any of the shapes points collide
         for (uint64_t i = 0; i < shape.size(); i ++) {
             if (world.getType(reached+shape[i]) != EMPTY) {  // Collision
+                this->bounce(world.getNormal(reached+shape[i], reached-unitVector+shape[i]));
                 reached = reached - unitVector; // Return to last point
                 collided = true;
-                this->bounce(world.getNormal(reached+shape[i], reached-unitVector+shape[i]));
                 this->velocity *= COLLISION_ELASTICITY;
                 if (this->velocity.length() < PLAYER_MIN_SPEED) {
                     this->inAir = false;
@@ -278,7 +278,7 @@
 
     assert(hit != prev);
     
-    int dirIdx = getDirectionIndex(prev-hit);
+    int dirIdx = getDirectionIndex(prev.roundToInt() - hit.roundToInt());
     //float tmp1 = hit.x-prev.x;
     //float tmp2 = hit.y-prev.y;
     //    Engine::log(DEBUG, "physics.getNormal ") << dirIdx << " " << tmp1 << " " << tmp2;
--- a/src/proto2/Vector.hh	Fri Nov 28 15:45:30 2008 +0000
+++ b/src/proto2/Vector.hh	Fri Nov 28 16:48:10 2008 +0000
@@ -62,6 +62,9 @@
     T length() const {
         return sqrt(x*x+y*y);
     }
+    _Vector roundToInt() const {
+        return _Vector((int)x, (int)y);
+    }
 };
 
 template<typename T>