• Main Page
  • Classes
  • Files
  • File List

Physics/Contact.h

00001 /*
00002  * Contact.h
00003  *
00004  *  Created on: 2010-11-11
00005  *      Author: krejziwan
00006  */
00007 
00008 #ifndef CONTACT_H_
00009 #define CONTACT_H_
00010 
00011 #include "RigidBody.h"
00012 #include "../Common/Constants.h"
00013 
00014 class Contact {
00015         RigidBody* body[2];
00016         Vector normal;
00017         real penetration;
00018         real restitution, cushionRestitution;
00019 
00020         void resolveVelocity(real duration);
00021         void resolveInterpenetration(real duration);
00022         void resolveGroupVelocity(real duration, Vector direction, RigidBody * body);
00023 public:
00024         Contact(Vector _normal, RigidBody * b1, RigidBody * b2 = NULL): normal(_normal),penetration(0.0),restitution(RESTITUTION), cushionRestitution(CUSHION_RESTITUTION) {
00025                 body[0] = b1;
00026                 body[1] = b2;
00027         }
00028         Contact(Vector _normal, real p, RigidBody * b1, RigidBody * b2 = NULL): normal(_normal), penetration(p),
00029                         restitution(RESTITUTION), cushionRestitution(CUSHION_RESTITUTION)  {
00030                 body[0] = b1;
00031                 body[1] = b2;
00032         }
00033 
00034         real calculateRelativeVelocity() const {
00035                 Vector relVel = body[0]->getVelocity();
00036                 if(body[1]) relVel -= body[1]->getVelocity();
00037                 return relVel*normal;
00038 
00039         }
00040 
00041         void resolve(real duration) {
00042                 resolveInterpenetration(duration);
00043                 resolveVelocity(duration);
00044                 if(body[1] && body[1]->isPartOfGroup())
00045                         resolveGroupVelocity(duration, normal, body[1]);
00046         }
00047 
00048 
00049 };
00050 
00051 #endif /* CONTACT_H_ */

Generated on Sun Dec 5 2010 19:03:33 for Snook3d by  doxygen 1.7.2