• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdeedu
  • Sitemap
  • Contact Us
 

step/stepcore

collisionsolver.h

Go to the documentation of this file.
00001 /* This file is part of StepCore library.
00002    Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
00003 
00004    StepCore library is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 2 of the License, or
00007    (at your option) any later version.
00008 
00009    StepCore library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with StepCore; if not, write to the Free Software
00016    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017 */
00018 
00023 #ifndef STEPCORE_COLLISIONSOLVER_H
00024 #define STEPCORE_COLLISIONSOLVER_H
00025 
00026 #include "object.h"
00027 #include "world.h"
00028 #include "vector.h"
00029 #include "solver.h"
00030 
00031 namespace StepCore
00032 {
00033 
00034 class BasePolygon;
00035 class Body;
00036 
00040 struct Contact {
00041     enum {
00042         Unknown = 0,    
00044         Separated,      
00045         Separating,     
00046         Contacted,      
00047         Colliding,      
00048         Intersected     
00049     };
00050     enum {
00051         UnknownType,
00052         PolygonPolygonType,
00053         PolygonDiskType,
00054         PolygonParticleType,
00055         DiskDiskType,
00056         DiskParticleType
00057     };
00058     int      type;          
00059     Body*    body0;         
00060     Body*    body1;         
00061     int      state;         
00062     double   distance;      
00063     Vector2d normal;        
00064     Vector2d normalDerivative; 
00065     int      pointsCount;   
00066     int      pointsState[2];
00067     Vector2d points[2];     
00068     double   vrel[2];       
00070     // Cached values from previous run
00071     // TODO: move it to GJK-specific derived struct
00072     int _w1[2];
00073 };
00074 
00080 class CollisionSolver : public Object
00081 {
00082     STEPCORE_OBJECT(CollisionSolver)
00083 
00084 public:
00085     CollisionSolver(): _toleranceAbs(0.001), _localError(0) {}
00086     virtual ~CollisionSolver() {}
00087 
00089     double toleranceAbs() const { return _toleranceAbs; }
00091     virtual void setToleranceAbs(double toleranceAbs) { _toleranceAbs = toleranceAbs; }
00093     double localError() const { return _localError; }
00094 
00099     //virtual int checkContact(Contact* contact) = 0;
00100 
00106     virtual int checkContacts(BodyList& bodies,
00107             ConstraintsInfo* info, bool collisions = false) = 0;
00108 
00109     // TODO: add errors
00112     virtual int solveCollisions(BodyList& bodies) = 0;
00113 
00117     virtual void resetCaches() {}
00118 
00119     virtual void bodyAdded(BodyList&, Body*) {}
00120     virtual void bodyRemoved(BodyList&, Body*) {}
00121 
00122 public:
00123     enum {
00124         InternalError = Solver::CollisionError
00125     };
00126 
00127 protected:
00128     double _toleranceAbs;
00129     //double _toleranceRel;
00130     double _localError;
00131 };
00132 
00133 typedef std::vector<Contact> ContactValueList;
00134 
00144 class GJKCollisionSolver : public CollisionSolver
00145 {
00146     STEPCORE_OBJECT(GJKCollisionSolver)
00147 
00148 public:
00149     GJKCollisionSolver() : _contactsIsValid(false) {}
00150 
00151     // TODO: proper copying of the cache !
00152     GJKCollisionSolver(const GJKCollisionSolver& solver)
00153         : CollisionSolver(solver), _contactsIsValid(false) {}
00154     GJKCollisionSolver& operator=(const GJKCollisionSolver&) {
00155         _contactsIsValid = false; return *this; }
00156 
00157     /*
00158     enum {
00159         OK = 0,
00160         CollisionDetected = 4096,
00161         PenetrationDetected = 4097
00162     };*/
00163 
00164     //int checkContact(Contact* contact);
00165     int checkContacts(BodyList& bodies, ConstraintsInfo* info, bool collisions = false);
00166     //int findClosestPoints(const BasePolygon* polygon1, const BasePolygon* polygon2);
00167 
00168     int solveCollisions(BodyList& bodies);
00169     //int solveConstraints(BodyList& bodies);
00170 
00171     void resetCaches();
00172     void bodyAdded(BodyList& bodies, Body* body);
00173     void bodyRemoved(BodyList& bodies, Body* body);
00174 
00175 protected:
00176     int checkContact(Contact* contact);
00177 
00178     int checkPolygonPolygon(Contact* contact);
00179     int solvePolygonPolygon(Contact* contact);
00180 
00181     int checkPolygonParticle(Contact* contact);
00182     int solvePolygonParticle(Contact* contact);
00183 
00184     int checkPolygonDisk(Contact* contact);
00185     int solvePolygonDisk(Contact* contact);
00186 
00187     int checkDiskDisk(Contact* contact);
00188     int solveDiskDisk(Contact* contact);
00189 
00190     int checkDiskParticle(Contact* contact);
00191     int solveDiskParticle(Contact* contact);
00192 
00193     void addContact(Body* body0, Body* body1);
00194     void checkCache(BodyList& bodies);
00195 
00196 protected:
00197     ContactValueList _contacts;
00198     bool             _contactsIsValid;
00199 };
00200 
00201 } // namespace StepCore
00202 
00203 #endif
00204 

step/stepcore

Skip menu "step/stepcore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeedu

Skip menu "kdeedu"
  • kalzium
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  •   docs
  •   src
  • parley
  •   stepcore
Generated for kdeedu by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal