Image Component Library (ICL)
PhysicsObject.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2014 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLPhysics/src/ICLPhysics/PhysicsObject.h **
10 ** Module : ICLPhysics **
11 ** Author : Christof Elbrechter, Matthias Esau **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 #pragma once
31 
32 #include <ICLGeom/SceneObject.h>
33 #include <ICLUtils/Uncopyable.h>
34 #include <ICLUtils/Mutex.h>
35 #include <ICLUtils/Function.h>
36 class btCollisionObject;
37 
38 namespace icl {
39  namespace physics{
40 
41  class PhysicsWorld;
42 
48  btCollisionObject *m_physicalObject;
51  protected:
54 
56 
57  std::string m_id;
58 
59  public:
61  PhysicsObject():m_world(0), m_physicalObject(0),m_collisionGroup(0), m_stateChanged(true), m_id("") {
62  setLockingEnabled(true);
63  //create an empty default callback
64  struct defaultCallback {
65  static void callback(PhysicsObject* self, PhysicsObject* other, geom::Vec pos) {}
66  };
67  m_collisionCallback = utils::function(&defaultCallback::callback);
68  }
69 
71  virtual ~PhysicsObject();
72 
74  void setPhysicalObject(btCollisionObject *obj);
75 
77  void forgetPhysicalObject(bool removeFromWorld=true);
78 
80 
81  virtual btCollisionObject *getCollisionObject() {
82  return m_physicalObject;
83  }
84 
86  virtual const btCollisionObject *getCollisionObject() const{
87  return m_physicalObject;
88  }
89 
91  virtual void updateSceneObject();
92 
94  virtual void prepareForRendering() {
95  lock();
96  updateSceneObject();
97  unlock();
98  }
99 
101  virtual void setTransformation(const geom::Mat &m);
103  virtual void transform(const geom::Mat &m);
105  geom::Mat getTransformation();
106 
107  void setScale(geom::Vec scale);
108  geom::Vec getScale();
109 
111  void setCollisionMargin(float margin);
112 
114  void setFriction(float friction);
115 
117  void setRollingFriction(float friction);
118 
120  void setCollisionGroup(int group);
121 
123  int getCollisionGroup();
124 
126  void setContactResponse(bool response);
127 
129  bool hasContactResponse();
130 
132  void setRestitution(float restitution);
133 
135  void activate(bool forceActivation = false);
136 
137  int getCollisionObjectType();
138 
139  void setCollisionObjectType(int type);
140 
141  int getCollisionFlags();
142 
143  void setCollisionFlags(int flags);
144 
146  void stateChanged();
147 
149  void setCurrentPhysicsWorld(PhysicsWorld *world);
150 
152  void setCollisionCallback(utils::Function<void,PhysicsObject*,PhysicsObject*, geom::Vec> collisionCallback);
153 
155  void collisionCallback(PhysicsObject* self, PhysicsObject* other, geom::Vec pos);
156 
158  void setObjectID(std::string const &id);
159 
161  std::string getObjectID();
162 
164  std::string getObjectID() const;
165  };
166  }
167 }
btCollisionObject * m_physicalObject
internal physical object
Definition: PhysicsObject.h:48
The General Function Template.
Definition: Function.h:284
undocument this line if you encounter any issues!
Definition: Any.h:37
Class interface for un-copyable classes.
Definition: Uncopyable.h:64
bool m_stateChanged
is true if the physical state of the object has changed since the last updateSceneObject()
Definition: PhysicsObject.h:53
Function< R, A, B, C > function(Object &obj, R(Object::*method)(A, B, C))
Create Function instances from member functions.
Definition: Function.h:376
A physical world that handles physical objects.
Definition: PhysicsWorld.h:56
utils::Function< void, PhysicsObject *, PhysicsObject *, geom::Vec > m_collisionCallback
Definition: PhysicsObject.h:55
virtual const btCollisionObject * getCollisionObject() const
Definition: PhysicsObject.h:86
std::string m_id
Definition: PhysicsObject.h:57
#define ICLPhysics_API
Definition: CompatMacros.h:181
virtual void prepareForRendering()
called by the scene before it's rendered (calling purely virtual updateSceneObject)
Definition: PhysicsObject.h:94
virtual btCollisionObject * getCollisionObject()
returns internal physical object as collision object
Definition: PhysicsObject.h:81
static void scale(const int deg, xcomplex *P)
Definition: PolynomialSolver.h:133
PhysicsWorld * m_world
physicsworld this object has been added to
Definition: PhysicsObject.h:46
Definition: FixedVector.h:40
PhysicsObject()
Default constructor (initializint m_physicalObject with 0)
Definition: PhysicsObject.h:61
This class combines an physical object and it's graphical representation in ICL.
Definition: PhysicsObject.h:44
The SceneObject class defines visible objects in scenes or scene graph nodes.
Definition: SceneObject.h:140
int m_collisionGroup
collisionGroup this object belongs to
Definition: PhysicsObject.h:50