Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

PhysicalEngine.h

Go to the documentation of this file.
00001 /*
00002     Enki - a fast 2D robot simulator
00003     Copyright (C) 1999-2005 Stephane Magnenat <stephane at magnenat dot net>
00004     Copyright (C) 2004-2005 Markus Waibel <markus dot waibel at epfl dot ch>
00005     Copyright (C) 2005 Laboratory of Intelligent Systems, EPFL, Lausanne
00006     See AUTHORS for details
00007 
00008     This program is free software; the authors of any publication 
00009     arising from research using this software are asked to add the 
00010     following reference:
00011     Enki - a fast 2D robot simulator part of the Teem framework
00012     http://teem.epfl.ch
00013     Stephane Magnenat <stephane at magnenat dot net>,
00014     Markus Waibel <markus dot waibel at epfl dot ch>
00015     Laboratory of Intelligent Systems, EPFL, Lausanne.
00016 
00017     You can redistribute this program and/or modify
00018     it under the terms of the GNU General Public License as published by
00019     the Free Software Foundation; either version 2 of the License, or
00020     (at your option) any later version.
00021 
00022     This program is distributed in the hope that it will be useful,
00023     but WITHOUT ANY WARRANTY; without even the implied warranty of
00024     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025     GNU General Public License for more details.
00026 
00027     You should have received a copy of the GNU General Public License
00028     along with this program; if not, write to the Free Software
00029     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00030 */
00031 
00032 #ifndef __PHYSICALENGINE_H
00033 #define __PHYSICALENGINE_H
00034 
00035 #include <iostream>
00036 #include <vector>
00037 #include <valarray>
00038 #include <an/Types.h>
00039 #include <an/Geometry.h>
00040 #include <an/Random.h>
00041 #include "Interaction.h"
00042 
00114 
00115 namespace Enki
00116 {
00117     class World;
00118 
00120 
00121     class PhysicalObject
00122     {
00123     public:
00125         An::Point pos;
00127         double height;
00129         double angle;
00131         An::Vector speed;
00133         double angSpeed;
00135         double mass;
00137         double staticFrictionThreshold;
00139         double viscousFrictionTau;
00141         double viscousMomentFrictionTau;
00143         double collisionAngularFrictionFactor;
00145         const An::Polygone *boundingSurface;
00147         An::Polygone absBoundingSurface;
00149         double r;
00151         An::Color color;
00153         std::valarray<An::Texture> textures;
00154         
00155     protected:
00157         An::Vector deinterlaceVector;
00158 
00160         void collideWithStaticObject(const An::Vector &n);
00162         void computeAbsBoundingSurface(void);
00163 
00164     public:
00166         PhysicalObject();
00168         virtual ~PhysicalObject();
00169         
00171         void setBoundingSurface(const An::Polygone *bs);
00173         const An::Polygone &getTrueBoundingSurface(void) const { return absBoundingSurface; }
00174 
00175         // Physical Actions
00177         virtual void step(double dt);
00178 
00180         virtual void initLocalInteractions();
00182         virtual void doLocalInteractions(World *w, PhysicalObject *o, double dt, bool firstInteraction);
00184         virtual void doLocalWallsInteraction(World *w);
00186         virtual void finalizeLocalInteractions(double dt);
00187 
00189         virtual void initGlobalInteractions() { }
00191         virtual void doGlobalInteractions(World *w, double dt) { }
00193         virtual void finalizeGlobalInteractions() { }
00194 
00196         void collideWithStaticObject(const An::Point &cp1, const An::Point &cp2, const An::Vector &n1, const An::Vector &n2, const An::Vector &dist);
00198         void collideWithObject(PhysicalObject &object, const An::Point &cp, const An::Vector &dist);
00199         
00200     };
00201 
00203 
00204     class Robot: public PhysicalObject
00205     {
00206     protected:
00208         std::vector<LocalInteraction *> localInteractions;
00210         std::vector<GlobalInteraction *> globalInteractions;
00211         
00212     public:
00214         Robot();
00215         
00217         void addLocalInteraction(LocalInteraction *li);
00219         void addGlobalInteraction(GlobalInteraction *gi) {globalInteractions.push_back(gi);}
00221         virtual void initLocalInteractions();
00223         virtual void doLocalInteractions(World *w, PhysicalObject *po, double dt, bool firstInteraction);
00225         virtual void doLocalWallsInteraction(World *w);
00227         virtual void finalizeLocalInteractions(double dt);
00228         
00230         virtual void doGlobalInteractions(World *w, double dt);
00232         void sortLocalInteractions(void);
00233     };
00234 
00236 
00239     class World
00240     {
00241     protected:
00243         bool collideEven;
00244 
00245     public:
00247         std::vector<PhysicalObject *> objects;
00249         bool useWalls;
00251         const double w;
00253         const double h;
00255         An::Texture wallTextures[4];
00256 
00258         bool getCollideEven() {return collideEven;}
00260         void collideCircleWithBS(PhysicalObject *circle, PhysicalObject *objectBS, const An::Polygone &bs);
00262         void collideObjects(PhysicalObject *object1, PhysicalObject *object2);
00264         void collideWithWalls(PhysicalObject *object);
00266         bool isPointInside(const An::Point &p, const An::Point &c, const An::Polygone &bs, An::Vector *distVector);
00267 
00268     public:
00270         World(double width, double height);
00272         ~World();
00274         void step(double dt);
00276         void addObject(PhysicalObject *o);
00278         void removeObject(PhysicalObject *o);
00280         void setRandomSeed(unsigned long seed);
00281     };
00282     
00284     extern An::FastRandom random;
00285 }
00286 
00287 #endif

Generated on Mon Oct 24 17:33:58 2005 for Enki by  doxygen 1.4.2