Open Dynamics Engine

objects.h

00001 /*************************************************************************
00002  *                                                                       *
00003  * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith.       *
00004  * All rights reserved.  Email: russ@q12.org   Web: www.q12.org          *
00005  *                                                                       *
00006  * This library is free software; you can redistribute it and/or         *
00007  * modify it under the terms of EITHER:                                  *
00008  *   (1) The GNU Lesser General Public License as published by the Free  *
00009  *       Software Foundation; either version 2.1 of the License, or (at  *
00010  *       your option) any later version. The text of the GNU Lesser      *
00011  *       General Public License is included with this library in the     *
00012  *       file LICENSE.TXT.                                               *
00013  *   (2) The BSD-style license that is included with this library in     *
00014  *       the file LICENSE-BSD.TXT.                                       *
00015  *                                                                       *
00016  * This library is distributed in the hope that it will be useful,       *
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files    *
00019  * LICENSE.TXT and LICENSE-BSD.TXT for more details.                     *
00020  *                                                                       *
00021  *************************************************************************/
00022 
00023 // object, body, and world structs.
00024 
00025 
00026 #ifndef _ODE_OBJECT_H_
00027 #define _ODE_OBJECT_H_
00028 
00029 #include <ode/common.h>
00030 #include <ode/memory.h>
00031 #include <ode/mass.h>
00032 #include "array.h"
00033 
00034 class dxStepWorkingMemory;
00035 
00036 // some body flags
00037 
00038 enum {
00039   dxBodyFlagFiniteRotation =        1,  // use finite rotations
00040   dxBodyFlagFiniteRotationAxis =    2,  // use finite rotations only along axis
00041   dxBodyDisabled =                  4,  // body is disabled
00042   dxBodyNoGravity =                 8,  // body is not influenced by gravity
00043   dxBodyAutoDisable =               16, // enable auto-disable on body
00044   dxBodyLinearDamping =             32, // use linear damping
00045   dxBodyAngularDamping =            64, // use angular damping
00046   dxBodyMaxAngularSpeed =           128,// use maximum angular speed
00047   dxBodyGyroscopic =                256,// use gyroscopic term
00048 };
00049 
00050 
00051 // base class that does correct object allocation / deallocation
00052 
00053 struct dBase {
00054   void *operator new (size_t size) { return dAlloc (size); }
00055   void *operator new (size_t size, void *p) { return p; }
00056   void operator delete (void *ptr, size_t size) { dFree (ptr,size); }
00057   void *operator new[] (size_t size) { return dAlloc (size); }
00058   void operator delete[] (void *ptr, size_t size) { dFree (ptr,size); }
00059 };
00060 
00061 
00062 // base class for bodies and joints
00063 
00064 struct dObject : public dBase {
00065   dxWorld *world;    // world this object is in
00066   dObject *next;     // next object of this type in list
00067   dObject **tome;    // pointer to previous object's next ptr
00068   int tag;        // used by dynamics algorithms
00069   void *userdata;    // user settable data
00070   dObject(dxWorld *w);
00071   virtual ~dObject() { }
00072 };
00073 
00074 
00075 // auto disable parameters
00076 struct dxAutoDisable {
00077   dReal idle_time;      // time the body needs to be idle to auto-disable it
00078   int idle_steps;    // steps the body needs to be idle to auto-disable it
00079   dReal linear_average_threshold;   // linear (squared) average velocity threshold
00080   dReal angular_average_threshold;  // angular (squared) average velocity threshold
00081   unsigned int average_samples;     // size of the average_lvel and average_avel buffers
00082 };
00083 
00084 
00085 // damping parameters
00086 struct dxDampingParameters {
00087   dReal linear_scale;  // multiply the linear velocity by (1 - scale)
00088   dReal angular_scale; // multiply the angular velocity by (1 - scale)
00089   dReal linear_threshold;   // linear (squared) average speed threshold
00090   dReal angular_threshold;  // angular (squared) average speed threshold
00091 };
00092 
00093 
00094 // quick-step parameters
00095 struct dxQuickStepParameters {
00096   int num_iterations;      // number of SOR iterations to perform
00097   dReal w;        // the SOR over-relaxation parameter
00098 };
00099 
00100 
00101 // contact generation parameters
00102 struct dxContactParameters {
00103   dReal max_vel;     // maximum correcting velocity
00104   dReal min_depth;      // thickness of 'surface layer'
00105 };
00106 
00107 // position vector and rotation matrix for geometry objects that are not
00108 // connected to bodies.
00109 struct dxPosR {
00110   dVector3 pos;
00111   dMatrix3 R;
00112 };
00113 
00114 struct dxBody : public dObject {
00115   dxJointNode *firstjoint; // list of attached joints
00116   unsigned flags;       // some dxBodyFlagXXX flags
00117   dGeomID geom;         // first collision geom associated with body
00118   dMass mass;        // mass parameters about POR
00119   dMatrix3 invI;     // inverse of mass.I
00120   dReal invMass;     // 1 / mass.mass
00121   dxPosR posr;       // position and orientation of point of reference
00122   dQuaternion q;     // orientation quaternion
00123   dVector3 lvel,avel;      // linear and angular velocity of POR
00124   dVector3 facc,tacc;      // force and torque accumulators
00125   dVector3 finite_rot_axis;   // finite rotation axis, unit length or 0=none
00126 
00127   // auto-disable information
00128   dxAutoDisable adis;      // auto-disable parameters
00129   dReal adis_timeleft;     // time left to be idle
00130   int adis_stepsleft;      // steps left to be idle
00131   dVector3* average_lvel_buffer;      // buffer for the linear average velocity calculation
00132   dVector3* average_avel_buffer;      // buffer for the angular average velocity calculation
00133   unsigned int average_counter;      // counter/index to fill the average-buffers
00134   int average_ready;            // indicates ( with = 1 ), if the Body's buffers are ready for average-calculations
00135 
00136   void (*moved_callback)(dxBody*); // let the user know the body moved
00137   dxDampingParameters dampingp; // damping parameters, depends on flags
00138   dReal max_angular_speed;      // limit the angular velocity to this magnitude
00139 
00140   dxBody(dxWorld *w);
00141 };
00142 
00143 
00144 struct dxWorld : public dBase {
00145   dxBody *firstbody;    // body linked list
00146   dxJoint *firstjoint;     // joint linked list
00147   int nb,nj;         // number of bodies and joints in lists
00148   dVector3 gravity;     // gravity vector (m/s/s)
00149   dReal global_erp;     // global error reduction parameter
00150   dReal global_cfm;     // global constraint force mixing parameter
00151   dxAutoDisable adis;      // auto-disable parameters
00152   int body_flags;               // flags for new bodies
00153   dxStepWorkingMemory *wmem; // Working memory object for dWorldStep/dWorldQuickStep
00154 
00155   dxQuickStepParameters qs;
00156   dxContactParameters contactp;
00157   dxDampingParameters dampingp; // damping parameters
00158   dReal max_angular_speed;      // limit the angular velocity to this magnitude
00159 };
00160 
00161 
00162 #endif