Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

PhysicalObject.h

Go to the documentation of this file.
00001 #ifndef PHYSICALOBJECT_H
00002 #define PHYSICALOBJECT_H
00003 
00004 #include "GraphicalObject.h"
00005 #include "ContactInfo.h"
00006 #include "GlobalContactInfo.h"
00007 #include "ContactSolver.h"
00008 #include "ThyrixParameters.h"
00009 #include <string>
00010 
00011 class Border;
00012 class Circle;
00013 class CappedRectangle;
00014 class Simulator;
00015 class Integrator;
00016 
00026 class PhysicalObject : public GraphicalObject {
00027 public:
00029    PhysicalObject(std::string label="", int nSensors=0, real saturationForce=0.5,
00030       Color outlineColor = GUI::colorBlack, Color fillColor = GUI::colorTransparent);
00031    
00033    virtual ~PhysicalObject(); 
00034 
00036    virtual void registerPrimitives(Simulator* simulator);
00037 
00039    virtual bool detectContacts(PhysicalObject* object, GlobalContactInfoVector* contacts) = 0;
00040 
00041   virtual bool detectContacts(Border* object, GlobalContactInfoVector* contacts) {
00042       return detectContacts((PhysicalObject*)object, contacts);
00043   }
00044   virtual bool detectContacts(Circle* object, GlobalContactInfoVector* contacts) { 
00045       return detectContacts((PhysicalObject*)object, contacts);
00046   }
00047   virtual bool detectContacts(CappedRectangle* object, GlobalContactInfoVector* contacts) { 
00048       return detectContacts((PhysicalObject*)object, contacts);
00049   }
00050 
00052    void setPosition (real x, real y) { r.x=x; r.y=y; }
00053 
00055    void setVelocity (real vx, real vy) { v.x=vx; v.y=vy; }
00056 
00058    void setMass (real m) { this->m=m; }
00059 
00061    virtual void computeMass(real density = ThyrixParameters::defaultDensity) { m=1.0;}
00062 
00065    virtual void computeInertia() { I=1.0; }
00066 
00070    virtual int isCircle() { return 0; }
00071 
00073    inline void normalizeAlpha();
00074 
00076    virtual void integrate(const Integrator &integrator);
00077 
00079    virtual void rollback();
00080 
00083    virtual void computeBox() {}
00084 
00087    virtual void computeDerivativesWithoutContacts(ContactSolver* contactSolver);
00088    
00091    virtual void computeDerivatives(GlobalContactInfoVector* globalContacts);
00092 
00095    virtual void setSensors();
00096 
00098    virtual void setSensor(ContactInfo* contact) {}
00099 
00102    virtual void controll() {}
00103 
00107    virtual void detectInternalContacts(GlobalContactInfoVector* globalContacts) {}
00108 
00110    virtual void deleteContacts();
00111 
00113    virtual void resetSensors();
00114 
00116    void addContact(ContactInfo* contact){
00117       contacts.push_back(contact);
00118    }
00119 
00122    virtual void fillContactMatrix(ContactSolver* contactSolver, ContactInfo* contact);
00123 
00125    void drawContactForces(GUI* gui);
00126 
00133    virtual bool detectMouseContact(const Vector2& rMouse, Vector2& p, PhysicalObject*& object) { return false; }
00134 
00135 
00137    Vector2 r;
00138 
00140    Vector2 rOld;
00141 
00143    Vector2 v;
00144    
00146    real m;
00147  
00149    real alpha;
00150 
00152    real alphaOld;
00153 
00155    real omega;
00156 
00158    real I;
00159 
00161    Vector2 externalForce;
00162 
00164    real externalTorque;
00165 
00168    PhysicalObject* parent;
00169 
00173    Vector2 relativeR;
00174 
00178    real relativeAlpha;
00179 
00181    Vector2 boxMin;
00182    
00184    Vector2 boxMax;
00185 
00187    ContactInfoPVector contacts;
00188 
00190    std::string label;
00191 
00193    real* activations;
00194 
00196    real saturationForce;
00197    
00198 protected:
00200    int nSensors;
00201 };
00202 
00203 void PhysicalObject::normalizeAlpha() { 
00204    assert(alpha >-100 && alpha<100);
00205    while(alpha>2*M_PI) 
00206         alpha-=2*M_PI;
00207     while(alpha<0.0)
00208         alpha+=2*M_PI;
00209 }
00210 
00211 typedef std::vector<PhysicalObject*> PhysicalObjectPVector;
00212 
00213 #endif //PHYSICALOBJECT_H

Thyrix homepageUsers' guide

(C) Arxia 2004-2005