From: <dan...@us...> - 2007-12-11 18:37:54
|
Revision: 1325 http://opende.svn.sourceforge.net/opende/?rev=1325&view=rev Author: danielosmari Date: 2007-12-11 10:37:57 -0800 (Tue, 11 Dec 2007) Log Message: ----------- damping functions, maxangularvel function, some-const-correctness, updated odecpp.h Modified Paths: -------------- trunk/CHANGELOG.txt trunk/include/ode/objects.h trunk/include/ode/odecpp.h trunk/ode/demo/demo_boxstack.cpp trunk/ode/src/objects.h trunk/ode/src/ode.cpp trunk/ode/src/util.cpp Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2007-12-07 23:09:37 UTC (rev 1324) +++ trunk/CHANGELOG.txt 2007-12-11 18:37:57 UTC (rev 1325) @@ -9,6 +9,12 @@ ------------------------------------------------------------------------------ +12/11/07 Daniel K. O. + + * Added damping and MaxAngularVel() functions. + * Const-correctness: added const qualifier to some dWorldGet and dBodyGet functions. + * Updated the odecpp.h header. + 12/07/07 Daniel K. O. * Removed most of the compiler warnings from Drawstuff, ODE and Modified: trunk/include/ode/objects.h =================================================================== --- trunk/include/ode/objects.h 2007-12-07 23:09:37 UTC (rev 1324) +++ trunk/include/ode/objects.h 2007-12-11 18:37:57 UTC (rev 1325) @@ -79,7 +79,7 @@ * @brief Get the gravity vector for a given world. * @ingroup world */ -ODE_API void dWorldGetGravity (dWorldID, dVector3 gravity); +ODE_API void dWorldGetGravity (const dWorldID, dVector3 gravity); /** @@ -96,7 +96,7 @@ * @ingroup world * @return ERP value */ -ODE_API dReal dWorldGetERP (dWorldID); +ODE_API dReal dWorldGetERP (const dWorldID); /** @@ -113,7 +113,7 @@ * @ingroup world * @return CFM value */ -ODE_API dReal dWorldGetCFM (dWorldID); +ODE_API dReal dWorldGetCFM (const dWorldID); /** @@ -202,21 +202,21 @@ * @ingroup world * @return nr of iterations */ -ODE_API int dWorldGetQuickStepNumIterations (dWorldID); +ODE_API int dWorldGetQuickStepNumIterations (const dWorldID); /** * @brief Set the SOR over-relaxation parameter * @ingroup world * @param over_relaxation value to use by SOR */ -ODE_API void dWorldSetQuickStepW (dWorldID, dReal over_relaxation); +ODE_API void dWorldSetQuickStepW (const dWorldID, dReal over_relaxation); /** * @brief Get the SOR over-relaxation parameter * @ingroup world * @returns the over-relaxation setting */ -ODE_API dReal dWorldGetQuickStepW (dWorldID); +ODE_API dReal dWorldGetQuickStepW (const dWorldID); /* World contact parameter functions */ @@ -235,7 +235,7 @@ * to generated. * @ingroup world */ -ODE_API dReal dWorldGetContactMaxCorrectingVel (dWorldID); +ODE_API dReal dWorldGetContactMaxCorrectingVel (const dWorldID); /** * @brief Set the depth of the surface layer around all geometry objects. @@ -255,7 +255,7 @@ * @ingroup world * @returns the depth */ -ODE_API dReal dWorldGetContactSurfaceLayer (dWorldID); +ODE_API dReal dWorldGetContactSurfaceLayer (const dWorldID); /* StepFast1 functions */ @@ -270,6 +270,7 @@ /** * @defgroup disable Automatic Enabling and Disabling + * @ingroup world bodies * * Every body can be enabled or disabled. Enabled bodies participate in the * simulation, while disabled bodies are turned off and do not get updated @@ -309,14 +310,14 @@ * @brief Get the AutoEnableDepth parameter used by the StepFast1 algorithm. * @ingroup disable */ -ODE_API int dWorldGetAutoEnableDepthSF1(dWorldID); +ODE_API int dWorldGetAutoEnableDepthSF1(const dWorldID); /** * @brief Get auto disable linear threshold for newly created bodies. * @ingroup disable * @return the threshold */ -ODE_API dReal dWorldGetAutoDisableLinearThreshold (dWorldID); +ODE_API dReal dWorldGetAutoDisableLinearThreshold (const dWorldID); /** * @brief Set auto disable linear threshold for newly created bodies. @@ -330,7 +331,7 @@ * @ingroup disable * @return the threshold */ -ODE_API dReal dWorldGetAutoDisableAngularThreshold (dWorldID); +ODE_API dReal dWorldGetAutoDisableAngularThreshold (const dWorldID); /** * @brief Set auto disable angular threshold for newly created bodies. @@ -344,7 +345,7 @@ * @ingroup disable * @return the threshold */ -ODE_API dReal dWorldGetAutoDisableLinearAverageThreshold (dWorldID); +ODE_API dReal dWorldGetAutoDisableLinearAverageThreshold (const dWorldID); /** * @brief Set auto disable linear average threshold for newly created bodies. @@ -358,7 +359,7 @@ * @ingroup disable * @return the threshold */ -ODE_API dReal dWorldGetAutoDisableAngularAverageThreshold (dWorldID); +ODE_API dReal dWorldGetAutoDisableAngularAverageThreshold (const dWorldID); /** * @brief Set auto disable angular average threshold for newly created bodies. @@ -372,7 +373,7 @@ * @ingroup disable * @return number of samples used */ -ODE_API int dWorldGetAutoDisableAverageSamplesCount (dWorldID); +ODE_API int dWorldGetAutoDisableAverageSamplesCount (const dWorldID); /** * @brief Set auto disable average sample count for newly created bodies. @@ -387,7 +388,7 @@ * @ingroup disable * @return nr of steps */ -ODE_API int dWorldGetAutoDisableSteps (dWorldID); +ODE_API int dWorldGetAutoDisableSteps (const dWorldID); /** * @brief Set auto disable steps for newly created bodies. @@ -401,7 +402,7 @@ * @ingroup disable * @return nr of seconds */ -ODE_API dReal dWorldGetAutoDisableTime (dWorldID); +ODE_API dReal dWorldGetAutoDisableTime (const dWorldID); /** * @brief Set auto disable time for newly created bodies. @@ -415,7 +416,7 @@ * @ingroup disable * @return 0 or 1 */ -ODE_API int dWorldGetAutoDisableFlag (dWorldID); +ODE_API int dWorldGetAutoDisableFlag (const dWorldID); /** * @brief Set auto disable flag for newly created bodies. @@ -425,8 +426,143 @@ ODE_API void dWorldSetAutoDisableFlag (dWorldID, int do_auto_disable); +/** + * @defgroup damping Damping + * @ingroup bodies world + * + * Damping serves two purposes: reduce simulation instability, and to allow + * the bodies to come to rest (and possibly auto-disabling them). + * + * ODE's damping management works like this: + * + * @li Bodies obbey the world's damping scales. Until having their linear + * or angular damping scales set (they work independently), they will + * be affected by the world's current damping scales. + * @li Setting the linear (or angular) scale will make the body follow its + * own linear (or angular) scale parameter. It can use the world's + * damping scale parameters again by calling the reset functions. + * @li After updating the world's damping scale, all bodies that did not + * have their scale set will use the new world scale. + * + * The thresholds are shared between the auto-disable functions. The damping + * functions are meant to be used either alone or together with the auto-disable + * functions, but not independently; you should use the damping to help + * disabling the bodies. Damping is not a good substitute for proper + * (air) friction simulation. + * + * Here is how it is done: after every time step linear and angular + * velocities are tested against the corresponding thresholds. If they + * are above, they are multiplied by (1 - scale). So a negative value + * will actually increase the speed, and values greater than one will + * make the object oscilate every step; both can make the simulation unstable. + * + * You can also limit the maximum angular velocity. In contrast to the damping + * functions, the angular velocity is capped before the body is moved. + * That means that it will introduce errors in joints that are forcing the body + * to rotate too fast. Some bodies have naturally high angular velocities + * (like cars' wheels), so you may want to give them a very high (like the default, + * dInfinity) limit. + * + * @note The velocities are damped after the stepper function has moved the + * object. Otherwise the damping could introduce errors in joints. First the + * joint constraints are processed by the stepper, then the damping is applied. + * + * @note The damping happens right after the moved callback is called; this way + * it still possible use the exact velocities the body has acquired during the + * step. You can even use the callback to create your own customized damping. + */ /** + * @brief Get the world's linear damping threshold. It just calls the + * corresponding auto-disable function. + * @ingroup damping + */ +ODE_API dReal dWorldGetLinearDampingThreshold(const dWorldID w); + +/** + * @brief Set the world's linear damping threshold. It just calls the + * corresponding auto-disable function. + * @param threshold The damping won't be applied if the linear speed is + * below this threshold. Default is 0.01. + * @ingroup damping + */ +ODE_API void dWorldSetLinearDampingThreshold(dWorldID w, dReal threshold); + +/** + * @brief Get the world's angular damping threshold. It just calls the + * corresponding auto-disable function. + * @ingroup damping + */ +ODE_API dReal dWorldGetAngularDampingThreshold(const dWorldID w); + +/** + * @brief Set the world's angular damping threshold. It just calls the + * corresponding auto-disable function. + * @param threshold The damping won't be applied if the angular speed is + * below this threshold. Default is 0.01. + * @ingroup damping + */ +ODE_API void dWorldSetAngularDampingThreshold(dWorldID w, dReal threshold); + +/** + * @brief Get the world's linear damping scale. + * @ingroup damping + */ +ODE_API dReal dWorldGetLinearDamping(const dWorldID w); + +/** + * @brief Set the world's linear damping scale. + * @param scale The linear damping scale that is to be applied to bodies. + * Default is 0 (no damping). Should be in the interval [0, 1]. + * @ingroup damping + */ +ODE_API void dWorldSetLinearDamping(dWorldID w, dReal scale); + +/** + * @brief Get the world's angular damping scale. + * @ingroup damping + */ +ODE_API dReal dWorldGetAngularDamping(const dWorldID w); + +/** + * @brief Set the world's angular damping scale. + * @param scale The angular damping scale that is to be applied to bodies. + * Default is 0 (no damping). Should be in the interval [0, 1]. + * @ingroup damping + */ +ODE_API void dWorldSetAngularDamping(dWorldID w, dReal scale); + +/** + * @brief Convenience function to set body linear and angular scales. + * @param linear_scale The linear damping scale that is to be applied to bodies. + * @param angular_scale The angular damping scale that is to be applied to bodies. + * @ingroup damping + */ +ODE_API void dWorldSetDamping(dWorldID w, + dReal linear_scale, + dReal angular_scale); + +/** + * @brief Get the world's maximum angular velocity. + * @ingroup damping + * Every body with no specific maximum angular velocity will use + * this limit. + * @sa dBodyGetMaxAngularVel() + */ +ODE_API dReal dWorldGetMaxAngularVel(const dWorldID w); + + +/** + * @brief Set the world's maximum angular velocity. + * @ingroup damping + * Each body can have its own maximum angular velocity set. + * @sa dBodySetMaxAngularVel() + */ +ODE_API void dWorldSetMaxAngularVel(const dWorldID w, dReal max_velocity); + + + +/** * @defgroup bodies Rigid Bodies * * A rigid body has various properties from the point of view of the @@ -462,42 +598,42 @@ /** * @brief Get auto disable linear average threshold. - * @ingroup bodies + * @ingroup bodies disable * @return the threshold */ -ODE_API dReal dBodyGetAutoDisableLinearThreshold (dBodyID); +ODE_API dReal dBodyGetAutoDisableLinearThreshold (const dBodyID); /** * @brief Set auto disable linear average threshold. - * @ingroup bodies + * @ingroup bodies disable * @return the threshold */ ODE_API void dBodySetAutoDisableLinearThreshold (dBodyID, dReal linear_average_threshold); /** * @brief Get auto disable angular average threshold. - * @ingroup bodies + * @ingroup bodies disable * @return the threshold */ -ODE_API dReal dBodyGetAutoDisableAngularThreshold (dBodyID); +ODE_API dReal dBodyGetAutoDisableAngularThreshold (const dBodyID); /** * @brief Set auto disable angular average threshold. - * @ingroup bodies + * @ingroup bodies disable * @return the threshold */ ODE_API void dBodySetAutoDisableAngularThreshold (dBodyID, dReal angular_average_threshold); /** * @brief Get auto disable average size (samples count). - * @ingroup bodies + * @ingroup bodies disable * @return the nr of steps/size. */ -ODE_API int dBodyGetAutoDisableAverageSamplesCount (dBodyID); +ODE_API int dBodyGetAutoDisableAverageSamplesCount (const dBodyID); /** * @brief Set auto disable average buffer size (average steps). - * @ingroup bodies + * @ingroup bodies disable * @param average_samples_count the nr of samples to review. */ ODE_API void dBodySetAutoDisableAverageSamplesCount (dBodyID, unsigned int average_samples_count); @@ -505,42 +641,42 @@ /** * @brief Get auto steps a body must be thought of as idle to disable - * @ingroup bodies + * @ingroup bodies disable * @return the nr of steps */ -ODE_API int dBodyGetAutoDisableSteps (dBodyID); +ODE_API int dBodyGetAutoDisableSteps (const dBodyID); /** * @brief Set auto disable steps. - * @ingroup bodies + * @ingroup bodies disable * @param steps the nr of steps. */ ODE_API void dBodySetAutoDisableSteps (dBodyID, int steps); /** * @brief Get auto disable time. - * @ingroup bodies + * @ingroup bodies disable * @return nr of seconds */ -ODE_API dReal dBodyGetAutoDisableTime (dBodyID); +ODE_API dReal dBodyGetAutoDisableTime (const dBodyID); /** * @brief Set auto disable time. - * @ingroup bodies + * @ingroup bodies disable * @param time nr of seconds. */ ODE_API void dBodySetAutoDisableTime (dBodyID, dReal time); /** * @brief Get auto disable flag. - * @ingroup bodies + * @ingroup bodies disable * @return 0 or 1 */ -ODE_API int dBodyGetAutoDisableFlag (dBodyID); +ODE_API int dBodyGetAutoDisableFlag (const dBodyID); /** * @brief Set auto disable flag. - * @ingroup bodies + * @ingroup bodies disable * @param do_auto_disable 0 or 1 */ ODE_API void dBodySetAutoDisableFlag (dBodyID, int do_auto_disable); @@ -549,7 +685,7 @@ * @brief Set auto disable defaults. * @remarks * Set the values for the body to those set as default for the world. - * @ingroup bodies + * @ingroup bodies disable */ ODE_API void dBodySetAutoDisableDefaults (dBodyID); @@ -560,7 +696,7 @@ * * @ingroup bodies */ -ODE_API dWorldID dBodyGetWorld (dBodyID); +ODE_API dWorldID dBodyGetWorld (const dBodyID); /** * @brief Create a body in given world. @@ -592,7 +728,7 @@ * @ingroup bodies * @return a pointer to the user's data. */ -ODE_API void *dBodyGetData (dBodyID); +ODE_API void *dBodyGetData (const dBodyID); /** * @brief Set position of a body. @@ -645,7 +781,7 @@ * system structure. * @sa dBodyCopyPosition */ -ODE_API const dReal * dBodyGetPosition (dBodyID); +ODE_API const dReal * dBodyGetPosition (const dBodyID); /** @@ -663,7 +799,7 @@ * @ingroup bodies * @return pointer to a 4x3 rotation matrix. */ -ODE_API const dReal * dBodyGetRotation (dBodyID); +ODE_API const dReal * dBodyGetRotation (const dBodyID); /** @@ -681,7 +817,7 @@ * @ingroup bodies * @return pointer to 4 scalars that represent the quaternion. */ -ODE_API const dReal * dBodyGetQuaternion (dBodyID); +ODE_API const dReal * dBodyGetQuaternion (const dBodyID); /** @@ -698,13 +834,13 @@ * @brief Get the linear velocity of a body. * @ingroup bodies */ -ODE_API const dReal * dBodyGetLinearVel (dBodyID); +ODE_API const dReal * dBodyGetLinearVel (const dBodyID); /** * @brief Get the angular velocity of a body. * @ingroup bodies */ -ODE_API const dReal * dBodyGetAngularVel (dBodyID); +ODE_API const dReal * dBodyGetAngularVel (const dBodyID); /** * @brief Set the mass of a body. @@ -716,7 +852,7 @@ * @brief Get the mass of a body. * @ingroup bodies */ -ODE_API void dBodyGetMass (dBodyID, dMass *mass); +ODE_API void dBodyGetMass (const dBodyID, dMass *mass); /** * @brief Add force at centre of mass of body in absolute coordinates. @@ -776,7 +912,7 @@ * body system. * @ingroup bodies */ -ODE_API const dReal * dBodyGetForce (dBodyID); +ODE_API const dReal * dBodyGetForce (const dBodyID); /** * @brief Return the current accumulated torque vector. @@ -787,7 +923,7 @@ * body system. * @ingroup bodies */ -ODE_API const dReal * dBodyGetTorque (dBodyID); +ODE_API const dReal * dBodyGetTorque (const dBodyID); /** * @brief Set the body force accumulation vector. @@ -816,7 +952,7 @@ */ ODE_API void dBodyGetRelPointPos ( - dBodyID, dReal px, dReal py, dReal pz, + const dBodyID, dReal px, dReal py, dReal pz, dVector3 result ); @@ -827,7 +963,7 @@ */ ODE_API void dBodyGetRelPointVel ( - dBodyID, dReal px, dReal py, dReal pz, + const dBodyID, dReal px, dReal py, dReal pz, dVector3 result ); @@ -839,7 +975,7 @@ */ ODE_API void dBodyGetPointVel ( - dBodyID, dReal px, dReal py, dReal pz, + const dBodyID, dReal px, dReal py, dReal pz, dVector3 result ); @@ -853,7 +989,7 @@ */ ODE_API void dBodyGetPosRelPoint ( - dBodyID, dReal px, dReal py, dReal pz, + const dBodyID, dReal px, dReal py, dReal pz, dVector3 result ); @@ -921,21 +1057,21 @@ * @ingroup bodies * @return the mode 0 (infitesimal) or 1 (finite). */ -ODE_API int dBodyGetFiniteRotationMode (dBodyID); +ODE_API int dBodyGetFiniteRotationMode (const dBodyID); /** * @brief Get the finite rotation axis. * @param result will contain the axis. * @ingroup bodies */ -ODE_API void dBodyGetFiniteRotationAxis (dBodyID, dVector3 result); +ODE_API void dBodyGetFiniteRotationAxis (const dBodyID, dVector3 result); /** * @brief Get the number of joints that are attached to this body. * @ingroup bodies * @return nr of joints */ -ODE_API int dBodyGetNumJoints (dBodyID b); +ODE_API int dBodyGetNumJoints (const dBodyID b); /** * @brief Return a joint attached to this body, given by index. @@ -943,7 +1079,7 @@ * @param index valid range is 0 to n-1 where n is the value returned by * dBodyGetNumJoints(). */ -ODE_API dJointID dBodyGetJoint (dBodyID, int index); +ODE_API dJointID dBodyGetJoint (const dBodyID, int index); /** * @brief Manually enable a body. @@ -982,7 +1118,7 @@ * @ingroup bodies * @return nonzero means gravity affects this body. */ -ODE_API int dBodyGetGravityMode (dBodyID b); +ODE_API int dBodyGetGravityMode (const dBodyID b); /** * @brief Set the 'moved' callback of a body. @@ -1009,7 +1145,7 @@ * @return the first geom attached to this body, or 0. * @ingroup bodies */ -ODE_API dGeomID dBodyGetFirstGeom(dBodyID b); +ODE_API dGeomID dBodyGetFirstGeom(const dBodyID b); /** @@ -1019,11 +1155,135 @@ * @sa dBodyGetFirstGeom * @ingroup bodies */ -ODE_API dGeomID dBodyGetNextGeom(dGeomID g); +ODE_API dGeomID dBodyGetNextGeom(const dGeomID g); +/** + * @brief Get the body's linear damping scale. + * @ingroup bodies damping + * @remarks If the body's linear damping scale was not set, this function + * returns the world's linear damping scale. + */ +ODE_API dReal dBodyGetLinearDamping(const dBodyID b); /** + * @brief Set the body's linear damping scale. + * @param scale The linear damping scale. Should be in the interval [0, 1]. + * @ingroup bodies damping + * @remarks From now on the body will not use the world's linear damping + * scale until dBodyResetLinearDamping() is called. + * @sa dBodyResetLinearDamping() + */ +ODE_API void dBodySetLinearDamping(dBodyID b, dReal scale); + +/** + * @brief Get the body's angular damping scale. + * @ingroup bodies damping + * @remarks If the body's angular damping scale was not set, this function + * returns the world's angular damping scale. + */ +ODE_API dReal dBodyGetAngularDamping(const dBodyID b); + +/** + * @brief Set the body's angular damping scale. + * @param scale The angular damping scale. Should be in the interval [0, 1]. + * @ingroup bodies damping + * @remarks From now on the body will not use the world's angular damping + * scale until dBodyResetAngularDamping() is called. + * @sa dBodyResetAngularDamping() + */ +ODE_API void dBodySetAngularDamping(dBodyID b, dReal scale); + +/** + * @brief Convenience function tp set linear and angular scales at once. + * @param linear_scale The linear damping scale. Should be in the interval [0, 1]. + * @param angular_scale The angular damping scale. Should be in the interval [0, 1]. + * @ingroup bodies damping + * @sa dBodySetLinearDamping() dBodySetAngularDamping() + */ +ODE_API void dBodySetDamping(dBodyID b, dReal linear_scale, dReal angular_scale); + +/** + * @brief Makes the body use the world's linear damping scale again. + * @ingroup bodies damping + */ +ODE_API void dBodyResetLinearDamping(dBodyID b); + +/** + * @brief Makes the body use the world's angular damping scale again. + * @ingroup bodies damping + */ +ODE_API void dBodyResetAngularDamping(dBodyID b); + +/** + * @brief Get the body's linear damping threshold. + * @ingroup bodies damping + * @sa dBodyGetAutoDisableLinearThreshold() + * @remarks This just returns the auto-disable linear threshold. + */ +ODE_API dReal dBodyGetLinearDampingThreshold(const dBodyID b); + +/** + * @brief Set the body's linear damping threshold. + * @param threshold The linear threshold to be used. Damping + * is only applied if the linear speed is above this limit. + * @ingroup bodies damping + * @sa dBodySetAutoDisableLinearThreshold() + * @remarks This just sets the auto-disable linear threshold. + */ +ODE_API void dBodySetLinearDampingThreshold(dBodyID b, dReal threshold); + +/** + * @brief Get the body's angular damping threshold. + * @ingroup bodies damping + * @sa dBodyGetAutoDisableAngularThreshold() + * @remarks This just returns the auto-disable angular threshold. + */ +ODE_API dReal dBodyGetAngularDampingThreshold(const dBodyID b); + +/** + * @brief Set the body's angular damping threshold. + * @param threshold The angular threshold to be used. Damping is + * only used if the angular speed is above this limit. + * @ingroup bodies damping + * @sa dBodySetAutoDisableAngularThreshold() + * @remarks This just sets the auto-disable angular threshold. + */ +ODE_API void dBodySetAngularDampingThreshold(dBodyID b, dReal threshold); + +/** + * @brief Get the body's maximum angular velocity. + * @ingroup damping bodies + * @sa dWorldGetMaxAngularVel() + */ +ODE_API dReal dBodyGetMaxAngularVel(const dBodyID b); + + +/** + * @brief Set the body's maximum angular velocity. + * @ingroup damping bodies + * @sa dWorldSetMaxAngularVel() dBodyResetMaxAngularVel() + * The default value is dInfinity, but it's a good idea to limit + * it at less than 500 if you build ODE with the gyroscopic term + * enabled. + */ +ODE_API void dBodySetMaxAngularVel(dBodyID b, dReal max_velocity); + + +/** + * @brief Reset the body's maximum angular velocity to use the world's value + * @ingroup damping bodies + * @sa dBodySetMaxAngularVel() + */ +ODE_API void dBodyResetMaxAngularVel(dBodyID b); + + + + + + + +/** * @defgroup joints Joints * * In real life a joint is something like a hinge, that is used to connect two Modified: trunk/include/ode/odecpp.h =================================================================== --- trunk/include/ode/odecpp.h 2007-12-07 23:09:37 UTC (rev 1324) +++ trunk/include/ode/odecpp.h 2007-12-11 18:37:57 UTC (rev 1325) @@ -70,30 +70,69 @@ { dWorldStepFast1 (_id,stepsize,maxiterations); } void setAutoEnableDepthSF1(dWorldID, int depth) { dWorldSetAutoEnableDepthSF1 (_id, depth); } - int getAutoEnableDepthSF1(dWorldID) + int getAutoEnableDepthSF1(dWorldID) const { return dWorldGetAutoEnableDepthSF1 (_id); } + void quickStep(dReal stepsize) + { dWorldQuickStep (_id, stepsize); } + void setQuickStepNumIterations(int num) + { dWorldSetQuickStepNumIterations (_id, num); } + int getQuickStepNumIterations() const + { return dWorldGetQuickStepNumIterations (_id); } + void setQuickStepW(dReal over_relaxation) + { dWorldSetQuickStepW (_id, over_relaxation); } + dReal getQuickStepW() const + { return dWorldGetQuickStepW (_id); } + void setAutoDisableLinearThreshold (dReal threshold) { dWorldSetAutoDisableLinearThreshold (_id,threshold); } - dReal getAutoDisableLinearThreshold() + dReal getAutoDisableLinearThreshold() const { return dWorldGetAutoDisableLinearThreshold (_id); } void setAutoDisableAngularThreshold (dReal threshold) { dWorldSetAutoDisableAngularThreshold (_id,threshold); } - dReal getAutoDisableAngularThreshold() + dReal getAutoDisableAngularThreshold() const { return dWorldGetAutoDisableAngularThreshold (_id); } void setAutoDisableSteps (int steps) { dWorldSetAutoDisableSteps (_id,steps); } - int getAutoDisableSteps() + int getAutoDisableSteps() const { return dWorldGetAutoDisableSteps (_id); } void setAutoDisableTime (dReal time) { dWorldSetAutoDisableTime (_id,time); } - dReal getAutoDisableTime() + dReal getAutoDisableTime() const { return dWorldGetAutoDisableTime (_id); } void setAutoDisableFlag (int do_auto_disable) { dWorldSetAutoDisableFlag (_id,do_auto_disable); } - int getAutoDisableFlag() + int getAutoDisableFlag() const { return dWorldGetAutoDisableFlag (_id); } + dReal getLinearDampingThreshold() const + { return dWorldGetLinearDampingThreshold(_id); } + void setLinearDampingThreshold(dReal threshold) + { dWorldSetLinearDampingThreshold(_id, threshold); } + dReal getAngularDampingThreshold() const + { return dWorldGetAngularDampingThreshold(_id); } + void setAngularDampingThreshold(dReal threshold) + { dWorldSetAngularDampingThreshold(_id, threshold); } + dReal getLinearDamping() const + { return dWorldGetLinearDamping(_id); } + void setLinearDamping(dReal scale) + { dWorldSetLinearDamping(_id, scale); } + dReal getAngularDamping() const + { return dWorldGetAngularDamping(_id); } + void setAngularDamping(dReal scale) + { dWorldSetAngularDamping(_id, scale); } + void setDamping(dReal linear_scale, dReal angular_scale) + { dWorldSetDamping(_id, linear_scale, angular_scale); } + dReal getMaxAngularVel() const + { return dWorldGetMaxAngularVel(_id); } + void setMaxAngularVel(dReal max_velocity) + { dWorldSetMaxAngularVel(_id, max_velocity); } + + void setContactSurfaceLayer(dReal depth) + { dWorldSetContactSurfaceLayer (_id, depth); } + dReal getContactSurfaceLayer() const + { return dWorldGetContactSurfaceLayer (_id); } + void impulseToForce (dReal stepsize, dReal ix, dReal iy, dReal iz, dVector3 force) { dWorldImpulseToForce (_id,stepsize,ix,iy,iz,force); } @@ -232,24 +271,55 @@ void setAutoDisableLinearThreshold (dReal threshold) { dBodySetAutoDisableLinearThreshold (_id,threshold); } - dReal getAutoDisableLinearThreshold() + dReal getAutoDisableLinearThreshold() const { return dBodyGetAutoDisableLinearThreshold (_id); } void setAutoDisableAngularThreshold (dReal threshold) { dBodySetAutoDisableAngularThreshold (_id,threshold); } - dReal getAutoDisableAngularThreshold() + dReal getAutoDisableAngularThreshold() const { return dBodyGetAutoDisableAngularThreshold (_id); } void setAutoDisableSteps (int steps) { dBodySetAutoDisableSteps (_id,steps); } - int getAutoDisableSteps() + int getAutoDisableSteps() const { return dBodyGetAutoDisableSteps (_id); } void setAutoDisableTime (dReal time) { dBodySetAutoDisableTime (_id,time); } - dReal getAutoDisableTime() + dReal getAutoDisableTime() const { return dBodyGetAutoDisableTime (_id); } void setAutoDisableFlag (int do_auto_disable) { dBodySetAutoDisableFlag (_id,do_auto_disable); } - int getAutoDisableFlag() + int getAutoDisableFlag() const { return dBodyGetAutoDisableFlag (_id); } + + dReal getLinearDamping() const + { return dBodyGetLinearDamping(_id); } + void setLinearDamping(dReal scale) + { dBodySetLinearDamping(_id, scale); } + dReal getAngularDamping() const + { return dBodyGetAngularDamping(_id); } + void setAngularDamping(dReal scale) + { dBodySetAngularDamping(_id, scale); } + void setDamping(dReal linear_scale, dReal angular_scale) + { dBodySetDamping(_id, linear_scale, angular_scale); } + void resetLinearDamping() + { dBodyResetLinearDamping(_id); } + void resetAngularDamping() + { dBodyResetAngularDamping(_id); } + dReal getLinearDampingThreshold() const + { return dBodyGetLinearDampingThreshold(_id); } + void setLinearDampingThreshold(dReal threshold) const + { dBodySetLinearDampingThreshold(_id, threshold); } + dReal getAngularDampingThreshold() const + { return dBodyGetAngularDampingThreshold(_id); } + void setAngularDampingThreshold(dReal threshold) + { dBodySetAngularDampingThreshold(_id, threshold); } + + dReal getMaxAngularVel() const + { return dBodyGetMaxAngularVel(_id); } + void setMaxAngularVel(dReal max_velocity) + { dBodySetMaxAngularVel(_id, max_velocity); } + void resetMaxAngularVel() + { dBodyResetMaxAngularVel(_id); } + }; Modified: trunk/ode/demo/demo_boxstack.cpp =================================================================== --- trunk/ode/demo/demo_boxstack.cpp 2007-12-07 23:09:37 UTC (rev 1324) +++ trunk/ode/demo/demo_boxstack.cpp 2007-12-11 18:37:57 UTC (rev 1325) @@ -561,6 +561,9 @@ #endif + dWorldSetLinearDamping(world, 0.00001); + dWorldSetAngularDamping(world, 0.005); + dWorldSetMaxAngularVel(world, 200); dWorldSetContactMaxCorrectingVel (world,0.1); dWorldSetContactSurfaceLayer (world,0.001); Modified: trunk/ode/src/objects.h =================================================================== --- trunk/ode/src/objects.h 2007-12-07 23:09:37 UTC (rev 1324) +++ trunk/ode/src/objects.h 2007-12-11 18:37:57 UTC (rev 1325) @@ -39,7 +39,10 @@ dxBodyFlagFiniteRotationAxis = 2, // use finite rotations only along axis dxBodyDisabled = 4, // body is disabled dxBodyNoGravity = 8, // body is not influenced by gravity - dxBodyAutoDisable = 16 // enable auto-disable on body + dxBodyAutoDisable = 16, // enable auto-disable on body + dxBodyLinearDamping = 64, // using body's linear damping instead of world's + dxBodyAngularDamping = 32, // using body's angular damping insatead of world's + dxBodyMaxAngularVel = 64, // using body's maximum angular velocity }; @@ -74,6 +77,14 @@ }; +// damping parameters +struct dxDampingParameters { + dReal linear_scale; // multiply the linear velocity by (1 - scale) + dReal angular_scale; // multiply the angular velocity by (1 - scale) + dReal max_angular_vel; // limit the angular velocity to this magnitude +}; + + // quick-step parameters struct dxQuickStepParameters { int num_iterations; // number of SOR iterations to perform @@ -120,6 +131,7 @@ int average_ready; // indicates ( with = 1 ), if the Body's buffers are ready for average-calculations void (*moved_callback)(dxBody*); // let the user know the body moved + dxDampingParameters dampingp; // damping parameters, depends on flags }; @@ -134,6 +146,7 @@ int adis_flag; // auto-disable flag for new bodies dxQuickStepParameters qs; dxContactParameters contactp; + dxDampingParameters dampingp; // damping parameters }; Modified: trunk/ode/src/ode.cpp =================================================================== --- trunk/ode/src/ode.cpp 2007-12-07 23:09:37 UTC (rev 1324) +++ trunk/ode/src/ode.cpp 2007-12-11 18:37:57 UTC (rev 1325) @@ -221,7 +221,7 @@ //**************************************************************************** // body -dxWorld* dBodyGetWorld (dxBody* b) +dxWorld* dBodyGetWorld (const dxBody* b) { dAASSERT (b); return b->world; @@ -321,7 +321,7 @@ } -void *dBodyGetData (dBodyID b) +void *dBodyGetData (const dBodyID b) { dAASSERT (b); return b->userdata; @@ -393,7 +393,7 @@ } -const dReal * dBodyGetPosition (dBodyID b) +const dReal * dBodyGetPosition (const dBodyID b) { dAASSERT (b); return b->posr.pos; @@ -410,7 +410,7 @@ } -const dReal * dBodyGetRotation (dBodyID b) +const dReal * dBodyGetRotation (const dBodyID b) { dAASSERT (b); return b->posr.R; @@ -436,7 +436,7 @@ } -const dReal * dBodyGetQuaternion (dBodyID b) +const dReal * dBodyGetQuaternion (const dBodyID b) { dAASSERT (b); return b->q; @@ -454,14 +454,14 @@ } -const dReal * dBodyGetLinearVel (dBodyID b) +const dReal * dBodyGetLinearVel (const dBodyID b) { dAASSERT (b); return b->lvel; } -const dReal * dBodyGetAngularVel (dBodyID b) +const dReal * dBodyGetAngularVel (const dBodyID b) { dAASSERT (b); return b->avel; @@ -488,7 +488,7 @@ } -void dBodyGetMass (dBodyID b, dMass *mass) +void dBodyGetMass (const dBodyID b, dMass *mass) { dAASSERT (b && mass); memcpy (mass,&b->mass,sizeof(dMass)); @@ -625,14 +625,14 @@ } -const dReal * dBodyGetForce (dBodyID b) +const dReal * dBodyGetForce (const dBodyID b) { dAASSERT (b); return b->facc; } -const dReal * dBodyGetTorque (dBodyID b) +const dReal * dBodyGetTorque (const dBodyID b) { dAASSERT (b); return b->tacc; @@ -657,7 +657,7 @@ } -void dBodyGetRelPointPos (dBodyID b, dReal px, dReal py, dReal pz, +void dBodyGetRelPointPos (const dBodyID b, dReal px, dReal py, dReal pz, dVector3 result) { dAASSERT (b); @@ -673,7 +673,7 @@ } -void dBodyGetRelPointVel (dBodyID b, dReal px, dReal py, dReal pz, +void dBodyGetRelPointVel (const dBodyID b, dReal px, dReal py, dReal pz, dVector3 result) { dAASSERT (b); @@ -690,7 +690,7 @@ } -void dBodyGetPointVel (dBodyID b, dReal px, dReal py, dReal pz, +void dBodyGetPointVel (const dBodyID b, dReal px, dReal py, dReal pz, dVector3 result) { dAASSERT (b); @@ -706,7 +706,7 @@ } -void dBodyGetPosRelPoint (dBodyID b, dReal px, dReal py, dReal pz, +void dBodyGetPosRelPoint (const dBodyID b, dReal px, dReal py, dReal pz, dVector3 result) { dAASSERT (b); @@ -775,14 +775,14 @@ } -int dBodyGetFiniteRotationMode (dBodyID b) +int dBodyGetFiniteRotationMode (const dBodyID b) { dAASSERT (b); return ((b->flags & dxBodyFlagFiniteRotation) != 0); } -void dBodyGetFiniteRotationAxis (dBodyID b, dVector3 result) +void dBodyGetFiniteRotationAxis (const dBodyID b, dVector3 result) { dAASSERT (b); result[0] = b->finite_rot_axis[0]; @@ -791,7 +791,7 @@ } -int dBodyGetNumJoints (dBodyID b) +int dBodyGetNumJoints (const dBodyID b) { dAASSERT (b); int count=0; @@ -800,7 +800,7 @@ } -dJointID dBodyGetJoint (dBodyID b, int index) +dJointID dBodyGetJoint (const dBodyID b, int index) { dAASSERT (b); int i=0; @@ -843,7 +843,7 @@ } -int dBodyGetGravityMode (dBodyID b) +int dBodyGetGravityMode (const dBodyID b) { dAASSERT (b); return ((b->flags & dxBodyNoGravity) == 0); @@ -852,7 +852,7 @@ // body auto-disable functions -dReal dBodyGetAutoDisableLinearThreshold (dBodyID b) +dReal dBodyGetAutoDisableLinearThreshold (const dBodyID b) { dAASSERT(b); return dSqrt (b->adis.linear_average_threshold); @@ -866,7 +866,7 @@ } -dReal dBodyGetAutoDisableAngularThreshold (dBodyID b) +dReal dBodyGetAutoDisableAngularThreshold (const dBodyID b) { dAASSERT(b); return dSqrt (b->adis.angular_average_threshold); @@ -880,7 +880,7 @@ } -int dBodyGetAutoDisableAverageSamplesCount (dBodyID b) +int dBodyGetAutoDisableAverageSamplesCount (const dBodyID b) { dAASSERT(b); return b->adis.average_samples; @@ -918,7 +918,7 @@ } -int dBodyGetAutoDisableSteps (dBodyID b) +int dBodyGetAutoDisableSteps (const dBodyID b) { dAASSERT(b); return b->adis.idle_steps; @@ -932,7 +932,7 @@ } -dReal dBodyGetAutoDisableTime (dBodyID b) +dReal dBodyGetAutoDisableTime (const dBodyID b) { dAASSERT(b); return b->adis.idle_time; @@ -946,7 +946,7 @@ } -int dBodyGetAutoDisableFlag (dBodyID b) +int dBodyGetAutoDisableFlag (const dBodyID b) { dAASSERT(b); return ((b->flags & dxBodyAutoDisable) != 0); @@ -983,6 +983,104 @@ } +// body damping functions + +dReal dBodyGetLinearDamping(const dBodyID b) +{ + dAASSERT(b); + return (b->flags & dxBodyLinearDamping) ? + b->dampingp.linear_scale : + b->world->dampingp.linear_scale; +} + +void dBodySetLinearDamping(dBodyID b, dReal scale) +{ + dAASSERT(b); + b->flags |= dxBodyLinearDamping; + b->dampingp.linear_scale = scale; +} + +dReal dBodyGetAngularDamping(const dBodyID b) +{ + dAASSERT(b); + return (b->flags & dxBodyAngularDamping) ? + b->dampingp.angular_scale : + b->world->dampingp.angular_scale; +} + +void dBodySetAngularDamping(dBodyID b, dReal scale) +{ + dAASSERT(b); + b->flags |= dxBodyAngularDamping; + b->dampingp.angular_scale = scale; +} + +void dBodySetDamping(dBodyID b, dReal linear_scale, dReal angular_scale) +{ + dAASSERT(b); + dBodySetLinearDamping(b, linear_scale); + dBodySetAngularDamping(b, angular_scale); +} + +void dBodyResetLinearDamping(dBodyID b) +{ + dAASSERT(b); + b->flags &= ~dxBodyLinearDamping; +} + +void dBodyResetAngularDamping(dBodyID b) +{ + dAASSERT(b); + b->flags &= ~dxBodyAngularDamping; +} + +dReal dBodyGetLinearDampingThreshold(const dBodyID b) +{ + dAASSERT(b); + return dBodyGetAutoDisableLinearThreshold(b); +} + +void dBodySetLinearDampingThreshold(dBodyID b, dReal threshold) +{ + dAASSERT(b); + dBodySetAutoDisableLinearThreshold(b, threshold); +} + + +dReal dBodyGetAngularDampingThreshold(const dBodyID b) +{ + dAASSERT(b); + return dBodyGetAutoDisableAngularThreshold(b); +} + +void dBodySetAngularDampingThreshold(dBodyID b, dReal threshold) +{ + dAASSERT(b); + dBodySetAutoDisableAngularThreshold(b, threshold); +} + +dReal dBodyGetMaxAngularVel(const dBodyID b) +{ + dAASSERT(b); + return (b->flags & dxBodyMaxAngularVel) ? + b->dampingp.max_angular_vel: + b->world->dampingp.max_angular_vel; +} + +void dBodySetMaxAngularVel(dBodyID b, dReal max_velocity) +{ + dAASSERT(b); + b->flags |= dxBodyMaxAngularVel; + b->dampingp.max_angular_vel = max_velocity; +} + +void dBodyResetMaxAngularVel(dBodyID b) +{ + dAASSERT(b); + b->flags &= ~dxBodyMaxAngularVel; +} + + void dBodySetMovedCallback(dBodyID b, void (*callback)(dBodyID)) { dAASSERT(b); @@ -990,14 +1088,14 @@ } -dGeomID dBodyGetFirstGeom(dBodyID b) +dGeomID dBodyGetFirstGeom(const dBodyID b) { dAASSERT(b); return b->geom; } -dGeomID dBodyGetNextGeom(dGeomID geom) +dGeomID dBodyGetNextGeom(const dGeomID geom) { dAASSERT(geom); return dGeomGetBodyNext(geom); @@ -1391,6 +1489,10 @@ w->contactp.max_vel = dInfinity; w->contactp.min_depth = 0; + w->dampingp.linear_scale = 0; + w->dampingp.angular_scale = 0; + w->dampingp.max_angular_vel = dInfinity; + return w; } @@ -1445,7 +1547,7 @@ } -void dWorldGetGravity (dWorldID w, dVector3 g) +void dWorldGetGravity (const dWorldID w, dVector3 g) { dAASSERT (w); g[0] = w->gravity[0]; @@ -1461,7 +1563,7 @@ } -dReal dWorldGetERP (dWorldID w) +dReal dWorldGetERP (const dWorldID w) { dAASSERT (w); return w->global_erp; @@ -1475,7 +1577,7 @@ } -dReal dWorldGetCFM (dWorldID w) +dReal dWorldGetCFM (const dWorldID w) { dAASSERT (w); return w->global_cfm; @@ -1513,7 +1615,7 @@ // world auto-disable functions -dReal dWorldGetAutoDisableLinearThreshold (dWorldID w) +dReal dWorldGetAutoDisableLinearThreshold (const dWorldID w) { dAASSERT(w); return dSqrt (w->adis.linear_average_threshold); @@ -1527,7 +1629,7 @@ } -dReal dWorldGetAutoDisableAngularThreshold (dWorldID w) +dReal dWorldGetAutoDisableAngularThreshold (const dWorldID w) { dAASSERT(w); return dSqrt (w->adis.angular_average_threshold); @@ -1541,7 +1643,7 @@ } -int dWorldGetAutoDisableAverageSamplesCount (dWorldID w) +int dWorldGetAutoDisableAverageSamplesCount (const dWorldID w) { dAASSERT(w); return w->adis.average_samples; @@ -1555,7 +1657,7 @@ } -int dWorldGetAutoDisableSteps (dWorldID w) +int dWorldGetAutoDisableSteps (const dWorldID w) { dAASSERT(w); return w->adis.idle_steps; @@ -1569,7 +1671,7 @@ } -dReal dWorldGetAutoDisableTime (dWorldID w) +dReal dWorldGetAutoDisableTime (const dWorldID w) { dAASSERT(w); return w->adis.idle_time; @@ -1583,7 +1685,7 @@ } -int dWorldGetAutoDisableFlag (dWorldID w) +int dWorldGetAutoDisableFlag (const dWorldID w) { dAASSERT(w); return w->adis_flag; @@ -1597,6 +1699,76 @@ } +// world damping functions + +dReal dWorldGetLinearDampingThreshold(const dWorldID w) +{ + dAASSERT(w); + return dWorldGetAutoDisableLinearThreshold(w); +} + +void dWorldSetLinearDampingThreshold(dWorldID w, dReal threshold) +{ + dAASSERT(w); + dWorldSetAutoDisableLinearThreshold(w, threshold); +} + +dReal dWorldGetAngularDampingThreshold(const dWorldID w) +{ + dAASSERT(w); + return dWorldGetAutoDisableAngularThreshold(w); +} + +void dWorldSetAngularDampingThreshold(dWorldID w, dReal threshold) +{ + dAASSERT(w); + dWorldSetAutoDisableAngularThreshold(w, threshold); +} + +dReal dWorldGetLinearDamping(const dWorldID w) +{ + dAASSERT(w); + return w->dampingp.linear_scale; +} + +void dWorldSetLinearDamping(dWorldID w, dReal scale) +{ + dAASSERT(w); + w->dampingp.linear_scale = scale; +} + +dReal dWorldGetAngularDamping(const dWorldID w) +{ + dAASSERT(w); + return w->dampingp.angular_scale; +} + +void dWorldSetAngularDamping(dWorldID w, dReal scale) +{ + dAASSERT(w); + w->dampingp.angular_scale = scale; +} + +void dWorldSetDamping(dWorldID w, dReal linear_scale, dReal angular_scale) +{ + dAASSERT(w); + dWorldSetLinearDamping(w, linear_scale); + dWorldSetAngularDamping(w, angular_scale); +} + +dReal dWorldGetMaxAngularVel(const dWorldID w) +{ + dAASSERT(w); + return w->dampingp.max_angular_vel; +} + +void dWorldSetMaxAngularVel(dWorldID w, dReal max_velocity) +{ + dAASSERT(w); + w->dampingp.max_angular_vel = max_velocity; +} + + void dWorldSetQuickStepNumIterations (dWorldID w, int num) { dAASSERT(w); @@ -1604,7 +1776,7 @@ } -int dWorldGetQuickStepNumIterations (dWorldID w) +int dWorldGetQuickStepNumIterations (const dWorldID w) { dAASSERT(w); return w->qs.num_iterations; @@ -1618,7 +1790,7 @@ } -dReal dWorldGetQuickStepW (dWorldID w) +dReal dWorldGetQuickStepW (const dWorldID w) { dAASSERT(w); return w->qs.w; @@ -1632,7 +1804,7 @@ } -dReal dWorldGetContactMaxCorrectingVel (dWorldID w) +dReal dWorldGetContactMaxCorrectingVel (const dWorldID w) { dAASSERT(w); return w->contactp.max_vel; @@ -1646,7 +1818,7 @@ } -dReal dWorldGetContactSurfaceLayer (dWorldID w) +dReal dWorldGetContactSurfaceLayer (const dWorldID w) { dAASSERT(w); return w->contactp.min_depth; Modified: trunk/ode/src/util.cpp =================================================================== --- trunk/ode/src/util.cpp 2007-12-07 23:09:37 UTC (rev 1324) +++ trunk/ode/src/util.cpp 2007-12-11 18:37:57 UTC (rev 1325) @@ -188,6 +188,19 @@ void dxStepBody (dxBody *b, dReal h) { + // cap the angular velocity + const dReal aspeed = dDOT( b->avel, b->avel ); + const bool body_ang_max = b->flags & dxBodyMaxAngularVel; + const dReal max_ang_speed = body_ang_max ? + b->dampingp.max_angular_vel : + b->world->dampingp.max_angular_vel; + if (max_ang_speed != dInfinity && aspeed > max_ang_speed*max_ang_speed) { + const dReal coef = max_ang_speed/dSqrt(aspeed); + dOPEC(b->avel, *=, coef); + } + // end of angular velocity cap + + int j; // handle linear velocity @@ -262,6 +275,32 @@ // notify the user if (b->moved_callback) b->moved_callback(b); + + // damping + const dReal lspeed = dDOT( b->lvel, b->lvel ); + const bool lin_damping = b->flags & dxBodyLinearDamping; + if ( lspeed > + ( lin_damping ? + b->adis.linear_average_threshold : + b->world->adis.linear_average_threshold ) + ) { + const dReal scale = 1 - (lin_damping ? + b->dampingp.linear_scale : + b->world->dampingp.linear_scale); + dOPEC(b->lvel, *=, scale); + } + const bool ang_damping = b->flags & dxBodyAngularDamping; + if ( aspeed > + ( ang_damping ? + b->adis.angular_average_threshold : + b->world->adis.angular_average_threshold ) + ) { + const dReal scale = 1 - (ang_damping ? + b->dampingp.angular_scale : + b->world->dampingp.angular_scale); + dOPEC(b->avel, *=, scale); + } + } //**************************************************************************** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |