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

step/stepcore

  • sources
  • kde-4.12
  • kdeedu
  • step
  • stepcore
collisionsolver.h
Go to the documentation of this file.
1 /* This file is part of StepCore library.
2  Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
3 
4  StepCore library is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  StepCore library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with StepCore; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
23 #ifndef STEPCORE_COLLISIONSOLVER_H
24 #define STEPCORE_COLLISIONSOLVER_H
25 
26 #include "object.h"
27 #include "world.h"
28 #include "vector.h"
29 #include "solver.h"
30 
31 #define EIGEN_USE_NEW_STDVECTOR
32 #include <Eigen/StdVector>
33 
34 namespace StepCore
35 {
36 
37 class BasePolygon;
38 class Body;
39 
43 struct Contact {
44  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
45 
46  enum {
47  Unknown = 0,
49  Separated,
50  Separating,
51  Contacted,
52  Colliding,
53  Intersected
54  };
55  enum {
56  UnknownType,
57  PolygonPolygonType,
58  PolygonDiskType,
59  PolygonParticleType,
60  DiskDiskType,
61  DiskParticleType
62  };
63  int type;
64  Body* body0;
65  Body* body1;
66  int state;
67  double distance;
68  Vector2d normal;
69  Vector2d normalDerivative;
70  int pointsCount;
71  int pointsState[2];
72  Vector2d points[2];
73  double vrel[2];
75  // Cached values from previous run
76  // TODO: move it to GJK-specific derived struct
77  int _w1[2];
78 };
79 
85 class CollisionSolver : public Object
86 {
87  STEPCORE_OBJECT(CollisionSolver)
88 
89 public:
90  CollisionSolver(): _toleranceAbs(0.001), _localError(0) {}
91  virtual ~CollisionSolver() {}
92 
94  double toleranceAbs() const { return _toleranceAbs; }
96  virtual void setToleranceAbs(double toleranceAbs) { _toleranceAbs = toleranceAbs; }
98  double localError() const { return _localError; }
99 
104  //virtual int checkContact(Contact* contact) = 0;
105 
111  virtual int checkContacts(BodyList& bodies, bool collisions = false, int* count = NULL) = 0;
112 
116  virtual void getContactsInfo(ConstraintsInfo& info, bool collisions = false) = 0;
117 
118  // TODO: add errors
121  virtual int solveCollisions(BodyList& bodies) = 0;
122 
126  virtual void resetCaches() {}
127 
128  virtual void bodyAdded(BodyList&, Body*) {}
129  virtual void bodyRemoved(BodyList&, Body*) {}
130 
131 public:
132  enum {
133  InternalError = Solver::CollisionError
134  };
135 
136 protected:
137  double _toleranceAbs;
138  //double _toleranceRel;
139  double _localError;
140 };
141 
142 typedef std::vector<Contact, Eigen::aligned_allocator<Contact> >
143  ContactValueList;
144 
154 class GJKCollisionSolver : public CollisionSolver
155 {
156  STEPCORE_OBJECT(GJKCollisionSolver)
157 
158 public:
159  GJKCollisionSolver() : _contactsIsValid(false) {}
160 
161  // TODO: proper copying of the cache !
162  GJKCollisionSolver(const GJKCollisionSolver& solver)
163  : CollisionSolver(solver), _contactsIsValid(false) {}
164  GJKCollisionSolver& operator=(const GJKCollisionSolver&) {
165  _contactsIsValid = false; return *this; }
166 
167  /*
168  enum {
169  OK = 0,
170  CollisionDetected = 4096,
171  PenetrationDetected = 4097
172  };*/
173 
174  int checkContacts(BodyList& bodies, bool collisions = false, int* count = NULL);
175  void getContactsInfo(ConstraintsInfo& info, bool collisions = false);
176  //int findClosestPoints(const BasePolygon* polygon1, const BasePolygon* polygon2);
177 
178  int solveCollisions(BodyList& bodies);
179  //int solveConstraints(BodyList& bodies);
180 
181  void resetCaches();
182  void bodyAdded(BodyList& bodies, Body* body);
183  void bodyRemoved(BodyList& bodies, Body* body);
184 
185 protected:
186  int checkContact(Contact* contact);
187 
188  int checkPolygonPolygon(Contact* contact);
189  int solvePolygonPolygon(Contact* contact);
190 
191  int checkPolygonParticle(Contact* contact);
192  int solvePolygonParticle(Contact* contact);
193 
194  int checkPolygonDisk(Contact* contact);
195  int solvePolygonDisk(Contact* contact);
196 
197  int checkDiskDisk(Contact* contact);
198  int solveDiskDisk(Contact* contact);
199 
200  int checkDiskParticle(Contact* contact);
201  int solveDiskParticle(Contact* contact);
202 
203  void addContact(Body* body0, Body* body1);
204  void checkCache(BodyList& bodies);
205 
206 protected:
207  ContactValueList _contacts;
208  bool _contactsIsValid;
209 };
210 
211 } // namespace StepCore
212 
213 #endif
214 
StepCore::GJKCollisionSolver::solveCollisions
int solveCollisions(BodyList &bodies)
Solve the collisions between bodies.
Definition: collisionsolver.cc:1173
StepCore::Contact::body0
Body * body0
Body0.
Definition: collisionsolver.h:64
StepCore::Contact::PolygonDiskType
Definition: collisionsolver.h:58
StepCore::Body
Interface for bodies.
Definition: world.h:138
StepCore::CollisionSolver::toleranceAbs
double toleranceAbs() const
Get absolute allowed tolerance.
Definition: collisionsolver.h:94
StepCore::Contact::state
int state
Contact state (maximum of pointsState if pointsCount > 0)
Definition: collisionsolver.h:66
StepCore::Contact
Description of contact between two bodies.
Definition: collisionsolver.h:43
StepCore::GJKCollisionSolver::resetCaches
void resetCaches()
Reset internal caches of collision information.
Definition: collisionsolver.cc:1285
StepCore::GJKCollisionSolver::bodyAdded
void bodyAdded(BodyList &bodies, Body *body)
Definition: collisionsolver.cc:1225
StepCore::GJKCollisionSolver::solvePolygonParticle
int solvePolygonParticle(Contact *contact)
Definition: collisionsolver.cc:1083
StepCore::Vector2d
Eigen::Vector2d Vector2d
Two-dimensional vector with double components.
Definition: vector.h:29
StepCore::GJKCollisionSolver::checkDiskParticle
int checkDiskParticle(Contact *contact)
Definition: collisionsolver.cc:769
StepCore::Object
Root of the StepCore classes hierarchy.
Definition: object.h:57
StepCore::Contact::DiskParticleType
Definition: collisionsolver.h:61
StepCore::Contact::Contacted
Bodies are contacted but resting.
Definition: collisionsolver.h:51
StepCore::CollisionSolver::InternalError
Definition: collisionsolver.h:133
StepCore::Contact::Separating
Bodies are contacted but moving apart.
Definition: collisionsolver.h:50
StepCore::Contact::Intersected
Bodies are interpenetrating.
Definition: collisionsolver.h:53
StepCore::CollisionSolver::getContactsInfo
virtual void getContactsInfo(ConstraintsInfo &info, bool collisions=false)=0
Fill the constraint info structure with the contacts computed by checkContacts()
StepCore::GJKCollisionSolver::addContact
void addContact(Body *body0, Body *body1)
Definition: collisionsolver.cc:1248
world.h
Item, Body, Force and Tool interfaces, World class.
StepCore::GJKCollisionSolver::GJKCollisionSolver
GJKCollisionSolver()
Definition: collisionsolver.h:159
StepCore::GJKCollisionSolver::solvePolygonDisk
int solvePolygonDisk(Contact *contact)
Definition: collisionsolver.cc:1035
StepCore::Contact::Colliding
Bodies are collising.
Definition: collisionsolver.h:52
StepCore::GJKCollisionSolver
Discrete collision solver using Gilbert-Johnson-Keerthi distance algorithm.
Definition: collisionsolver.h:154
StepCore::GJKCollisionSolver::checkCache
void checkCache(BodyList &bodies)
Definition: collisionsolver.cc:1209
StepCore::CollisionSolver::localError
double localError() const
Get error estimation from last step.
Definition: collisionsolver.h:98
StepCore::Contact::UnknownType
Definition: collisionsolver.h:56
StepCore::CollisionSolver::bodyRemoved
virtual void bodyRemoved(BodyList &, Body *)
Definition: collisionsolver.h:129
StepCore::GJKCollisionSolver::bodyRemoved
void bodyRemoved(BodyList &bodies, Body *body)
Definition: collisionsolver.cc:1234
StepCore::Contact::pointsCount
int pointsCount
Count of contact points (either one or two)
Definition: collisionsolver.h:70
StepCore::GJKCollisionSolver::solveDiskDisk
int solveDiskDisk(Contact *contact)
Definition: collisionsolver.cc:1131
StepCore::Contact::points
Vector2d points[2]
Contact point coordinated.
Definition: collisionsolver.h:72
StepCore::Solver::CollisionError
Definition: solver.h:148
StepCore::CollisionSolver::_toleranceAbs
double _toleranceAbs
Definition: collisionsolver.h:137
StepCore::BodyList
std::vector< Body * > BodyList
List of pointers to Body.
Definition: world.h:300
StepCore::GJKCollisionSolver::checkPolygonParticle
int checkPolygonParticle(Contact *contact)
Definition: collisionsolver.cc:541
StepCore::GJKCollisionSolver::_contacts
ContactValueList _contacts
Definition: collisionsolver.h:207
StepCore::Contact::PolygonParticleType
Definition: collisionsolver.h:59
StepCore::ContactValueList
std::vector< Contact, Eigen::aligned_allocator< Contact > > ContactValueList
Definition: collisionsolver.h:143
StepCore::Contact::normal
Vector2d normal
Contact normal (pointing from body0 to body1)
Definition: collisionsolver.h:68
StepCore::GJKCollisionSolver::checkContact
int checkContact(Contact *contact)
Definition: collisionsolver.cc:828
StepCore::CollisionSolver
Collision solver interface.
Definition: collisionsolver.h:85
StepCore::Contact::Unknown
Contact state was not (can not) be determined (if state == Unknown all other fields are not used) ...
Definition: collisionsolver.h:47
StepCore::CollisionSolver::~CollisionSolver
virtual ~CollisionSolver()
Definition: collisionsolver.h:91
solver.h
Solver interface.
StepCore::GJKCollisionSolver::checkPolygonDisk
int checkPolygonDisk(Contact *contact)
Definition: collisionsolver.cc:347
StepCore::GJKCollisionSolver::_contactsIsValid
bool _contactsIsValid
Definition: collisionsolver.h:208
StepCore::Contact::DiskDiskType
Definition: collisionsolver.h:60
StepCore::CollisionSolver::bodyAdded
virtual void bodyAdded(BodyList &, Body *)
Definition: collisionsolver.h:128
StepCore::GJKCollisionSolver::checkDiskDisk
int checkDiskDisk(Contact *contact)
Definition: collisionsolver.cc:732
object.h
Object, MetaObject and MetaProperty classes.
vector.h
StepCore::GJKCollisionSolver::checkPolygonPolygon
int checkPolygonPolygon(Contact *contact)
Definition: collisionsolver.cc:39
StepCore::Contact::normalDerivative
Vector2d normalDerivative
Time derivative of contact normal (only if state == Contacted)
Definition: collisionsolver.h:69
StepCore::CollisionSolver::CollisionSolver
CollisionSolver()
Definition: collisionsolver.h:90
StepCore::Contact::pointsState
int pointsState[2]
Contact point states.
Definition: collisionsolver.h:71
StepCore::CollisionSolver::checkContacts
virtual int checkContacts(BodyList &bodies, bool collisions=false, int *count=NULL)=0
Check (and update) state of the contact.
StepCore::GJKCollisionSolver::GJKCollisionSolver
GJKCollisionSolver(const GJKCollisionSolver &solver)
Definition: collisionsolver.h:162
StepCore::Contact::PolygonPolygonType
Definition: collisionsolver.h:57
StepCore::CollisionSolver::setToleranceAbs
virtual void setToleranceAbs(double toleranceAbs)
Set absolute allowed tolerance.
Definition: collisionsolver.h:96
StepCore::Contact::_w1
int _w1[2]
Definition: collisionsolver.h:77
StepCore::Contact::type
int type
Contact type (used internally)
Definition: collisionsolver.h:63
StepCore::GJKCollisionSolver::solvePolygonPolygon
int solvePolygonPolygon(Contact *contact)
Definition: collisionsolver.cc:974
StepCore::GJKCollisionSolver::operator=
GJKCollisionSolver & operator=(const GJKCollisionSolver &)
Definition: collisionsolver.h:164
STEPCORE_OBJECT
#define STEPCORE_OBJECT(_className)
Definition: object.h:49
StepCore::GJKCollisionSolver::checkContacts
int checkContacts(BodyList &bodies, bool collisions=false, int *count=NULL)
Check (and update) state of the contact.
Definition: collisionsolver.cc:839
StepCore::Contact::Separated
Bodies are far away.
Definition: collisionsolver.h:49
StepCore::Contact::vrel
double vrel[2]
Relative velocities at contact points.
Definition: collisionsolver.h:73
StepCore::CollisionSolver::resetCaches
virtual void resetCaches()
Reset internal caches of collision information.
Definition: collisionsolver.h:126
StepCore::CollisionSolver::_localError
double _localError
Definition: collisionsolver.h:139
StepCore::Contact::body1
Body * body1
Body1.
Definition: collisionsolver.h:65
StepCore::CollisionSolver::solveCollisions
virtual int solveCollisions(BodyList &bodies)=0
Solve the collisions between bodies.
StepCore::ConstraintsInfo
Constraints information structure XXX: Move it to constraintsolver.h.
Definition: world.h:216
StepCore::Contact::distance
double distance
Distance between bodies.
Definition: collisionsolver.h:67
StepCore::GJKCollisionSolver::getContactsInfo
void getContactsInfo(ConstraintsInfo &info, bool collisions=false)
Fill the constraint info structure with the contacts computed by checkContacts()
Definition: collisionsolver.cc:862
StepCore::GJKCollisionSolver::solveDiskParticle
int solveDiskParticle(Contact *contact)
Definition: collisionsolver.cc:1152
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:43:06 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

step/stepcore

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal