# HG changeset patch # User nireco # Date 1227890890 0 # Node ID 2fd698e04779c1d76e26a47eceb2ff83e1c80f2f # Parent 7efb63402b2bbc1b3f110571a2fe5d3344e0e21c fixed collision detection again, and put some needed rounding to getNormal diff -r 7efb63402b2b -r 2fd698e04779 src/proto2/Physics.cc --- 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; diff -r 7efb63402b2b -r 2fd698e04779 src/proto2/Vector.hh --- 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