CBulletGenericObject.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2016, CHAI3D
5  (www.chai3d.org)
6 
7  All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions
11  are met:
12 
13  * Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 
16  * Redistributions in binary form must reproduce the above
17  copyright notice, this list of conditions and the following
18  disclaimer in the documentation and/or other materials provided
19  with the distribution.
20 
21  * Neither the name of CHAI3D nor the names of its contributors may
22  be used to endorse or promote products derived from this software
23  without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  POSSIBILITY OF SUCH DAMAGE.
37 
38  \author <http://www.chai3d.org>
39  \author Francois Conti
40  \version 3.2.0 $Rev: 2126 $
41 */
42 //==============================================================================
43 
44 //------------------------------------------------------------------------------
45 #ifndef CBulletGenericObjectH
46 #define CBulletGenericObjectH
47 //------------------------------------------------------------------------------
48 #include "chai3d.h"
49 //------------------------------------------------------------------------------
50 #include "btBulletDynamicsCommon.h"
51 //------------------------------------------------------------------------------
52 
53 //------------------------------------------------------------------------------
54 namespace chai3d {
55 //------------------------------------------------------------------------------
56 
57 //==============================================================================
65 //==============================================================================
66 
67 //------------------------------------------------------------------------------
68 class cBulletWorld;
69 //------------------------------------------------------------------------------
72 {
78 };
79 //------------------------------------------------------------------------------
80 
81 //==============================================================================
92 //==============================================================================
94 {
95  //--------------------------------------------------------------------------
96  // CONSTRUCTOR & DESTRUCTOR:
97  //--------------------------------------------------------------------------
98 
99 public:
100 
103 
105  virtual ~cBulletGenericObject();
106 
107 
108  //--------------------------------------------------------------------------
109  // PUBLIC METHODS - TRANSLATION AND ORIENTATION:
110  //--------------------------------------------------------------------------
111 
112 public:
113 
115  virtual void updateBodyPosition(void) {}
116 
117 
118  //--------------------------------------------------------------------------
119  // PUBLIC METHODS - DYNAMIC PROPERTIES:
120  //--------------------------------------------------------------------------
121 
122 public:
123 
125  virtual void setMass(const double a_mass);
126 
128  double getMass() const { return (m_mass); }
129 
131  virtual void setInertia(const cVector3d& a_inertia);
132 
135 
137  virtual void setMassInertia(const double a_mass, const cVector3d& a_inertia);
138 
140  virtual void estimateInertia();
141 
143  virtual void setStatic(bool a_static);
144 
146  virtual bool getStatic() const { return (m_static); }
147 
149  virtual void buildDynamicModel();
150 
152  virtual void updatePositionFromDynamics() {}
153 
154 
155  //--------------------------------------------------------------------------
156  // PUBLIC METHODS - FRICTION PROPERTIES:
157  //--------------------------------------------------------------------------
158 
159 public:
160 
162  void setSurfaceFriction(const double a_friction);
163 
165  double getSurfaceFriction();
166 
167 
168  //--------------------------------------------------------------------------
169  // PUBLIC METHODS - EXTERNAL FORCES:
170  //--------------------------------------------------------------------------
171 
172 public:
173 
175  void addExternalForce(const cVector3d& a_force);
176 
178  void addExternalTorque(const cVector3d& a_torque);
179 
181  void addExternalForceAtPoint(const cVector3d& a_force,
182  const cVector3d& a_relativePos);
183 
184 
185  //--------------------------------------------------------------------------
186  // PUBLIC METHODS - DAMPING:
187  //--------------------------------------------------------------------------
188 
189 public:
190 
192  void setDamping(const double& a_dampingLin, const double& a_dampingAng);
193 
195  double getDampingLin();
196 
198  double getDampingAng();
199 
200 
201  //--------------------------------------------------------------------------
202  // PUBLIC MEMBERS:
203  //--------------------------------------------------------------------------
204 
205 public:
206 
209 
211  btRigidBody* m_bulletRigidBody;
212 
214  btCollisionShape* m_bulletCollisionShape;
215 
217  btDefaultMotionState* m_bulletMotionState;
218 
219 
220  //--------------------------------------------------------------------------
221  // PROTECTED METHODS:
222  //--------------------------------------------------------------------------
223 
224 protected:
225 
227  virtual void initialize(cBulletWorld* a_world);
228 
229 
230  //--------------------------------------------------------------------------
231  // PROTECTED MEMBERS:
232  //--------------------------------------------------------------------------
233 
234 protected:
235 
237  bool m_static;
238 
240  double m_mass;
241 
244 };
245 
246 //------------------------------------------------------------------------------
247 } // namespace chai3d
248 //------------------------------------------------------------------------------
249 
250 //------------------------------------------------------------------------------
251 #endif
252 //------------------------------------------------------------------------------
Definition: CBulletGenericObject.h:75
double getDampingLin()
This method returns the linear damping term for this object.
Definition: CBulletGenericObject.cpp:288
bool m_static
If true then object is static and does not move, false otherwise.
Definition: CBulletGenericObject.h:237
double getDampingAng()
This method returns the angular damping term for this object.
Definition: CBulletGenericObject.cpp:307
cVector3d getInertia()
This method returns the inertia properties of this object.
Definition: CBulletGenericObject.h:134
cBulletDynamicModelType
Bullet geometry used for dynamic collision computation.
Definition: CBulletGenericObject.h:71
Definition: CBulletGenericObject.h:73
double getMass() const
This method returns the mass value for this object.
Definition: CBulletGenericObject.h:128
void addExternalForce(const cVector3d &a_force)
This method applies an external force at the center of mass of this object.
Definition: CBulletGenericObject.cpp:238
virtual void updatePositionFromDynamics()
This method updates the CHAI3D position representation from the Bullet dynamics engine.
Definition: CBulletGenericObject.h:152
virtual bool getStatic() const
This method returns true if the object is static, false otherwise.
Definition: CBulletGenericObject.h:146
cVector3d m_inertia
Inertia properties.
Definition: CBulletGenericObject.h:243
void setDamping(const double &a_dampingLin, const double &a_dampingAng)
This method assigns a linear and angular damping term to the object.
Definition: CBulletGenericObject.cpp:271
void addExternalForceAtPoint(const cVector3d &a_force, const cVector3d &a_relativePos)
This method applies an external force at a given position described in global coordinates to this obj...
Definition: CBulletGenericObject.cpp:221
cBulletGenericObject(cBulletWorld *a_world)
Constructor of cBulletGenericBody.
Definition: CBulletGenericObject.h:102
This class implements an Bullet dynamic world.
Definition: CBulletWorld.h:81
virtual void setMass(const double a_mass)
This method assigns a mass value to this object.
Definition: CBulletGenericObject.cpp:112
virtual void estimateInertia()
This method estimates the inertia properties for this object.
Definition: CBulletGenericObject.cpp:152
double getSurfaceFriction()
This method returns the coefficient of friction for this object.
Definition: CBulletGenericObject.cpp:342
Definition: CBulletGenericObject.h:76
virtual void setStatic(bool a_static)
This method enables of disables the object to be static in the world.
Definition: CBulletGenericObject.cpp:178
btDefaultMotionState * m_bulletMotionState
Bullet motion state.
Definition: CBulletGenericObject.h:217
virtual void buildDynamicModel()
This method builds a dynamic representation of the object in the Bullet world.
Definition: CBulletGenericObject.cpp:193
Definition: CBulletGenericObject.h:93
void addExternalTorque(const cVector3d &a_torque)
This method applies an external torque at the center of mass of of this object.
Definition: CBulletGenericObject.cpp:254
virtual void setMassInertia(const double a_mass, const cVector3d &a_inertia)
This method assigns a mass and an inertia to this object.
Definition: CBulletGenericObject.cpp:139
virtual ~cBulletGenericObject()
Destructor of cBulletGenericBody.
Definition: CBulletGenericObject.cpp:88
cBulletWorld * m_dynamicWorld
Bullet world.
Definition: CBulletGenericObject.h:208
Definition: CBulletGenericObject.h:77
virtual void setInertia(const cVector3d &a_inertia)
This method assigns an inertia properties to this object.
Definition: CBulletGenericObject.cpp:125
virtual void updateBodyPosition(void)
This method updates the position and orientation from the Bullet model to CHAI3D model.
Definition: CBulletGenericObject.h:115
double m_mass
Mass property.
Definition: CBulletGenericObject.h:240
virtual void initialize(cBulletWorld *a_world)
This method initializes the Bullet object.
Definition: CBulletGenericObject.cpp:61
btCollisionShape * m_bulletCollisionShape
Bullet collision shape.
Definition: CBulletGenericObject.h:214
btRigidBody * m_bulletRigidBody
Bullet rigid body.
Definition: CBulletGenericObject.h:211
Definition: CBulletGenericObject.h:74
void setSurfaceFriction(const double a_friction)
This method assign a coefficient of friction to this object.
Definition: CBulletGenericObject.cpp:325