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

Simulator.h

Go to the documentation of this file.
00001 #ifndef SIMULATOR_H
00002 #define SIMULATOR_H
00003 
00004 #include "World.h"
00005 #include "Integrator.h"
00006 #include "GlobalContactInfo.h"
00007 #include "PhysicalObject.h"
00008 #include "ContactSolver.h"
00009 #include <set>
00010 
00013 class Simulator : public World {
00014 public:
00015    Simulator(); 
00016    virtual ~Simulator();
00017 
00018    virtual double getDt() const { return (double)integrator.getDt(); }
00019    
00023    virtual void advanceTime();
00024 
00026    void registerObject(PhysicalObject* object);
00027 
00029    void registerPrimitive(PhysicalObject* object);
00030 
00033    void setup(){}
00034 
00035 
00038    void indexContacts();
00039 
00041    void fillContactMatrix();
00042 
00043    virtual void detectContacts();
00044 
00045    void computeContacts();
00046 
00047    virtual void draw(GUI *gui);
00048 
00049    //Processing of user input: the user may apply forces to objects in the simulator,
00050    //by clicking and dragging with the mouse. 
00051 
00053    PhysicalObject* draggedObject;
00054    Vector2 draggingPoint;
00055 
00056    void setMouseForce(float x, float y);
00057 
00058    void unsetMouseForce();
00059 
00060    
00061    virtual void onMouseLeftDown(float x, float y){
00062       World::onMouseLeftDown(x,y);
00063       setMouseForce(x,y);
00064    }
00065 
00066    virtual void onMouseLeftUp(float x, float y){
00067       World::onMouseLeftUp(x,y);
00068       unsetMouseForce();
00069    }
00070    
00071 
00073    void applyMouseForce();
00074 
00075    ContactSolver* contactSolver;
00076    
00080    PhysicalObjectPVector objects;
00081 
00084    PhysicalObjectPVector primitives;
00085 
00088    GlobalContactInfoVector contacts;
00089 
00090 protected:
00091 
00092    Integrator integrator;
00093 
00094    virtual void controll();
00095 
00096    real realTime;
00097 
00098 private:
00100    void deleteObjects();
00101 
00104    void deleteContacts();
00105 
00106    bool isContact;
00107 
00110    PhysicalObjectPVector sortedObjects[2];
00112    void sortObjects(int n);
00113 
00115    class ObjectPair {
00116       public:
00117       ObjectPair() { o1=o2=NULL; }
00118       ObjectPair(PhysicalObject* no1, PhysicalObject* no2){
00119          //the pair is kept ordered in order to be unique
00120          if(no1<no2) {o1=no1; o2=no2;} else {o2=no1; o1=no2;}
00121       }
00122       PhysicalObject* o1;
00123       PhysicalObject* o2;
00124       bool operator<(const ObjectPair& p2) const{
00125          if(o1<p2.o1)return true;
00126          else if(o1==p2.o1) return o2<p2.o2;
00127          else return false;
00128       }
00129    };
00130 
00131    std::set<ObjectPair> xContacts, xyContacts;
00132 
00133 
00134 };
00135 
00136 #endif //SIMULATOR_H

Thyrix homepageUsers' guide

(C) Arxia 2004-2005