Open Dynamics Engine
ode/src/objects.h
1 /*************************************************************************
2  * *
3  * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4  * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5  * *
6  * This library is free software; you can redistribute it and/or *
7  * modify it under the terms of EITHER: *
8  * (1) The GNU Lesser General Public License as published by the Free *
9  * Software Foundation; either version 2.1 of the License, or (at *
10  * your option) any later version. The text of the GNU Lesser *
11  * General Public License is included with this library in the *
12  * file LICENSE.TXT. *
13  * (2) The BSD-style license that is included with this library in *
14  * the file LICENSE-BSD.TXT. *
15  * *
16  * This library is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19  * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
20  * *
21  *************************************************************************/
22 
23 // object, body, and world structs.
24 
25 
26 #ifndef _ODE__PRIVATE_OBJECTS_H_
27 #define _ODE__PRIVATE_OBJECTS_H_
28 
29 #include <ode/common.h>
30 #include <ode/memory.h>
31 #include <ode/mass.h>
32 #include "error.h"
33 #include "array.h"
34 #include "threading_base.h"
35 
36 
39 
40 // some body flags
41 
42 enum {
43  dxBodyFlagFiniteRotation = 1, // use finite rotations
44  dxBodyFlagFiniteRotationAxis = 2, // use finite rotations only along axis
45  dxBodyDisabled = 4, // body is disabled
46  dxBodyNoGravity = 8, // body is not influenced by gravity
47  dxBodyAutoDisable = 16, // enable auto-disable on body
48  dxBodyLinearDamping = 32, // use linear damping
49  dxBodyAngularDamping = 64, // use angular damping
50  dxBodyMaxAngularSpeed = 128,// use maximum angular speed
51  dxBodyGyroscopic = 256 // use gyroscopic term
52 };
53 
54 
55 // base class that does correct object allocation / deallocation
56 
57 struct dBase {
58  void *operator new (size_t size) { return dAlloc (size); }
59  void *operator new (size_t, void *p) { return p; }
60  void operator delete (void *ptr, size_t size) { dFree (ptr,size); }
61  void *operator new[] (size_t size) { return dAlloc (size); }
62  void operator delete[] (void *ptr, size_t size) { dFree (ptr,size); }
63 };
64 
65 
66 // base class for bodies and joints
67 
68 struct dObject : public dBase {
69  dxWorld *world; // world this object is in
70  dObject *next; // next object of this type in list
71  dObject **tome; // pointer to previous object's next ptr
72  int tag; // used by dynamics algorithms
73  void *userdata; // user settable data
74 
75  explicit dObject(dxWorld *w): world(w), next(NULL), tome(NULL), tag(0), userdata(NULL) {}
76  virtual ~dObject();
77 };
78 
79 
80 // auto disable parameters
81 struct dxAutoDisable {
82  dReal idle_time; // time the body needs to be idle to auto-disable it
83  int idle_steps; // steps the body needs to be idle to auto-disable it
84  unsigned int average_samples; // size of the average_lvel and average_avel buffers
85  dReal linear_average_threshold; // linear (squared) average velocity threshold
86  dReal angular_average_threshold; // angular (squared) average velocity threshold
87 
88  dxAutoDisable() {}
89  explicit dxAutoDisable(void *);
90 };
91 
92 
93 // damping parameters
95  dReal linear_scale; // multiply the linear velocity by (1 - scale)
96  dReal angular_scale; // multiply the angular velocity by (1 - scale)
97  dReal linear_threshold; // linear (squared) average speed threshold
98  dReal angular_threshold; // angular (squared) average speed threshold
99 
101  explicit dxDampingParameters(void *);
102 };
103 
104 
105 // quick-step parameters
107  int num_iterations; // number of SOR iterations to perform
108  dReal w; // the SOR over-relaxation parameter
109 
111  explicit dxQuickStepParameters(void *);
112 };
113 
114 
115 // contact generation parameters
117  dReal max_vel; // maximum correcting velocity
118  dReal min_depth; // thickness of 'surface layer'
119 
121  explicit dxContactParameters(void *);
122 };
123 
124 // position vector and rotation matrix for geometry objects that are not
125 // connected to bodies.
126 struct dxPosR {
127  dVector3 pos;
128  dMatrix3 R;
129 };
130 
131 struct dxBody : public dObject {
132  dxJointNode *firstjoint; // list of attached joints
133  unsigned flags; // some dxBodyFlagXXX flags
134  dGeomID geom; // first collision geom associated with body
135  dMass mass; // mass parameters about POR
136  dMatrix3 invI; // inverse of mass.I
137  dReal invMass; // 1 / mass.mass
138  dxPosR posr; // position and orientation of point of reference
139  dQuaternion q; // orientation quaternion
140  dVector3 lvel,avel; // linear and angular velocity of POR
141  dVector3 facc,tacc; // force and torque accumulators
142  dVector3 finite_rot_axis; // finite rotation axis, unit length or 0=none
143 
144  // auto-disable information
145  dxAutoDisable adis; // auto-disable parameters
146  dReal adis_timeleft; // time left to be idle
147  int adis_stepsleft; // steps left to be idle
148  dVector3* average_lvel_buffer; // buffer for the linear average velocity calculation
149  dVector3* average_avel_buffer; // buffer for the angular average velocity calculation
150  unsigned int average_counter; // counter/index to fill the average-buffers
151  int average_ready; // indicates ( with = 1 ), if the Body's buffers are ready for average-calculations
152 
153  void (*moved_callback)(dxBody*); // let the user know the body moved
154  dxDampingParameters dampingp; // damping parameters, depends on flags
155  dReal max_angular_speed; // limit the angular velocity to this magnitude
156 
157  dxBody(dxWorld *w);
158 };
159 
160 
162  dxBody *firstbody; // body linked list
163  dxJoint *firstjoint; // joint linked list
164  int nb,nj; // number of bodies and joints in lists
165  dVector3 gravity; // gravity vector (m/s/s)
166  dReal global_erp; // global error reduction parameter
167  dReal global_cfm; // global constraint force mixing parameter
168  dxAutoDisable adis; // auto-disable parameters
169  int body_flags; // flags for new bodies
170  unsigned islands_max_threads; // maximum threads to allocate for island processing
171  dxStepWorkingMemory *wmem; // Working memory object for dWorldStep/dWorldQuickStep
172 
174  dxContactParameters contactp;
175  dxDampingParameters dampingp; // damping parameters
176  dReal max_angular_speed; // limit the angular velocity to this magnitude
177 
178 
179  dxWorld();
180  virtual ~dxWorld(); // Compilers emit warnings if a class with virtual methods does not have a virtual destructor :(
181 
182  static bool InitializeDefaultThreading();
183  static void FinalizeDefaultThreading();
184 
185  void AssignThreadingImpl(const dxThreadingFunctionsInfo *functions_info, dThreadingImplementationID threading_impl);
186  unsigned GetThreadingIslandsMaxThreadsCount(unsigned *out_active_thread_count_ptr=NULL) const;
187  dxWorldProcessContext *UnsafeGetWorldProcessingContext() const;
188 
189 private: // dxIThreadingDefaultImplProvider
190  virtual const dxThreadingFunctionsInfo *RetrieveThreadingDefaultImpl(dThreadingImplementationID &out_default_impl);
191 };
192 
193 
194 #endif // #ifndef _ODE__PRIVATE_OBJECTS_H_
Definition: ode/src/objects.h:116
Definition: threading_base.h:49
Definition: util.h:369
Definition: util.h:210
Definition: ode/src/objects.h:57
Definition: mass.h:88
Definition: ode/src/objects.h:161
Definition: ode/src/objects.h:94
Definition: ode/src/objects.h:81
Definition: ode/src/objects.h:131
Definition: ode/src/objects.h:106
Definition: ode/src/objects.h:68
Definition: ode/src/objects.h:126
Definition: collision_kernel.h:96
Definition: threading_base.h:42
An interface structure with function pointers to be provided by threading implementation.
Definition: threading.h:370