src/proto2/Physics.cc
changeset 100 29c3d91cad82
parent 99 c9b96dcfe4ee
child 101 1c52bd7fbc43
equal deleted inserted replaced
99:c9b96dcfe4ee 100:29c3d91cad82
   339  * Bounces from straight wall in any direction.
   339  * Bounces from straight wall in any direction.
   340  * Direction given as normal of that wall
   340  * Direction given as normal of that wall
   341  */
   341  */
   342 void PhysicsObject::bounce (Vector normal) {
   342 void PhysicsObject::bounce (Vector normal) {
   343     Vector tangent(normal.y, -normal.x);
   343     Vector tangent(normal.y, -normal.x);
   344     Vector tprojection = (velocity * tangent) / tangent.length();
   344     Vector tprojection = (velocity * tangent)*tangent / (tangent.length()*tangent.length());
   345     Vector nprojection = (velocity * normal) / normal.length();
   345     Vector nprojection = (velocity * normal)*normal / (normal.length()*normal.length());
   346     velocity = tprojection - nprojection;
   346     velocity = tprojection - nprojection;
   347 }
   347 }
   348 
   348 
   349 /*bool PhysicsWorld::collided (Vector oldPos, Vector newPos) {
   349 /*bool PhysicsWorld::collided (Vector oldPos, Vector newPos) {
   350 	return false;
   350 	return false;