My Project
Loading...
Searching...
No Matches
CBulletGenericObject.h
Go to the documentation of this file.
1//==============================================================================
2/*
3 Software License Agreement (BSD License)
4 Copyright (c) 2003-2024, 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 1.0.0
41*/
42//==============================================================================
43
44//------------------------------------------------------------------------------
45#ifndef CBulletGenericObjectH
46#define CBulletGenericObjectH
47//------------------------------------------------------------------------------
48#include "chai3d.h"
49//------------------------------------------------------------------------------
50#include "btBulletDynamicsCommon.h"
51//------------------------------------------------------------------------------
52
53//------------------------------------------------------------------------------
54namespace chai3d {
55//------------------------------------------------------------------------------
56
57//==============================================================================
65//==============================================================================
66
67//------------------------------------------------------------------------------
68class cBulletWorld;
69//------------------------------------------------------------------------------
79//------------------------------------------------------------------------------
80
81//==============================================================================
92//==============================================================================
94{
95 //--------------------------------------------------------------------------
96 // CONSTRUCTOR & DESTRUCTOR:
97 //--------------------------------------------------------------------------
98
99public:
100
103
105 virtual ~cBulletGenericObject();
106
107
108 //--------------------------------------------------------------------------
109 // PUBLIC METHODS - TRANSLATION AND ORIENTATION:
110 //--------------------------------------------------------------------------
111
112public:
113
115 virtual void updateBodyPosition(void) {}
116
117
118 //--------------------------------------------------------------------------
119 // PUBLIC METHODS - DYNAMIC PROPERTIES:
120 //--------------------------------------------------------------------------
121
122public:
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
153
154
155 //--------------------------------------------------------------------------
156 // PUBLIC METHODS - FRICTION PROPERTIES:
157 //--------------------------------------------------------------------------
158
159public:
160
162 void setSurfaceFriction(const double a_friction);
163
165 double getSurfaceFriction();
166
167
168 //--------------------------------------------------------------------------
169 // PUBLIC METHODS - EXTERNAL FORCES:
170 //--------------------------------------------------------------------------
171
172public:
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
189public:
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
205public:
206
209
211 btRigidBody* m_bulletRigidBody;
212
214 btCollisionShape* m_bulletCollisionShape;
215
217 btDefaultMotionState* m_bulletMotionState;
218
219
220 //--------------------------------------------------------------------------
221 // PROTECTED METHODS:
222 //--------------------------------------------------------------------------
223
224protected:
225
227 virtual void initialize(cBulletWorld* a_world);
228
229
230 //--------------------------------------------------------------------------
231 // PROTECTED MEMBERS:
232 //--------------------------------------------------------------------------
233
234protected:
235
238
240 double m_mass;
241
244};
245
246//------------------------------------------------------------------------------
247} // namespace chai3d
248//------------------------------------------------------------------------------
249
250//------------------------------------------------------------------------------
251#endif
252//------------------------------------------------------------------------------
Definition CBulletGenericObject.h:94
btDefaultMotionState * m_bulletMotionState
Bullet motion state.
Definition CBulletGenericObject.h:217
virtual void updateBodyPosition(void)
This method updates the position and orientation from the Bullet model to CHAI3D model.
Definition CBulletGenericObject.h:115
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
virtual void buildDynamicModel()
This method builds a dynamic representation of the object in the Bullet world.
Definition CBulletGenericObject.cpp:193
virtual void updatePositionFromDynamics()
This method updates the CHAI3D position representation from the Bullet dynamics engine.
Definition CBulletGenericObject.h:152
virtual void setMass(const double a_mass)
This method assigns a mass value to this object.
Definition CBulletGenericObject.cpp:112
double getSurfaceFriction()
This method returns the coefficient of friction for this object.
Definition CBulletGenericObject.cpp:342
virtual void initialize(cBulletWorld *a_world)
This method initializes the Bullet object.
Definition CBulletGenericObject.cpp:61
cBulletGenericObject(cBulletWorld *a_world)
Constructor of cBulletGenericBody.
Definition CBulletGenericObject.h:102
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
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
virtual ~cBulletGenericObject()
Destructor of cBulletGenericBody.
Definition CBulletGenericObject.cpp:88
cVector3d m_inertia
Inertia properties.
Definition CBulletGenericObject.h:243
double getMass() const
This method returns the mass value for this object.
Definition CBulletGenericObject.h:128
virtual void setStatic(bool a_static)
This method enables of disables the object to be static in the world.
Definition CBulletGenericObject.cpp:178
virtual void setInertia(const cVector3d &a_inertia)
This method assigns an inertia properties to this object.
Definition CBulletGenericObject.cpp:125
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
btRigidBody * m_bulletRigidBody
Bullet rigid body.
Definition CBulletGenericObject.h:211
virtual bool getStatic() const
This method returns true if the object is static, false otherwise.
Definition CBulletGenericObject.h:146
virtual void estimateInertia()
This method estimates the inertia properties for this object.
Definition CBulletGenericObject.cpp:152
double getDampingLin()
This method returns the linear damping term for this object.
Definition CBulletGenericObject.cpp:288
void setSurfaceFriction(const double a_friction)
This method assign a coefficient of friction to this object.
Definition CBulletGenericObject.cpp:325
cVector3d getInertia()
This method returns the inertia properties of this object.
Definition CBulletGenericObject.h:134
void addExternalForce(const cVector3d &a_force)
This method applies an external force at the center of mass of this object.
Definition CBulletGenericObject.cpp:238
cBulletWorld * m_dynamicWorld
Bullet world.
Definition CBulletGenericObject.h:208
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
btCollisionShape * m_bulletCollisionShape
Bullet collision shape.
Definition CBulletGenericObject.h:214
double m_mass
Mass property.
Definition CBulletGenericObject.h:240
This class implements an Bullet dynamic world.
Definition CBulletWorld.h:82
cBulletDynamicModelType
Bullet geometry used for dynamic collision computation.
Definition CBulletGenericObject.h:72
@ BULLET_MODEL_PLANE
Definition CBulletGenericObject.h:76
@ BULLET_MODEL_CYLINDER
Definition CBulletGenericObject.h:75
@ BULLET_MODEL_SPHERE
Definition CBulletGenericObject.h:74
@ BULLET_MODEL_BOX
Definition CBulletGenericObject.h:73
@ BULLET_MODEL_TRIMESH
Definition CBulletGenericObject.h:77