From: <dan...@us...> - 2008-07-24 22:18:32
|
Revision: 1536 http://opende.svn.sourceforge.net/opende/?rev=1536&view=rev Author: danielosmari Date: 2008-07-24 22:18:40 +0000 (Thu, 24 Jul 2008) Log Message: ----------- applied patch 'Per body gyroscopic term' (2019242) and added missing methods to dMass Modified Paths: -------------- trunk/CHANGELOG.txt trunk/build/demos.lua trunk/configure.in trunk/include/ode/mass.h trunk/include/ode/objects.h trunk/include/ode/odecpp.h trunk/ode/demo/Makefile.am trunk/ode/src/objects.h trunk/ode/src/ode.cpp trunk/ode/src/quickstep.cpp trunk/ode/src/step.cpp trunk/ode/src/stepfast.cpp Added Paths: ----------- trunk/ode/demo/demo_gyroscopic.cpp Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2008-07-24 14:39:54 UTC (rev 1535) +++ trunk/CHANGELOG.txt 2008-07-24 22:18:40 UTC (rev 1536) @@ -8,7 +8,11 @@ * keep the format consistent (79 char width, M/D/Y date format). ------------------------------------------------------------------------------ -0715/08 Remi Ricard (papaDoc) +07/24/08 Daniel K. O. + * New functions: dBodyGetGyroscopicMode and dBodySetGyroscopicMode + (patch #2019242). + +07/15/08 Remi Ricard (papaDoc) * Add a new define ODE_API_DEPRECATED to mark function as deprecated when necessary. Modified: trunk/build/demos.lua =================================================================== --- trunk/build/demos.lua 2008-07-24 14:39:54 UTC (rev 1535) +++ trunk/build/demos.lua 2008-07-24 22:18:40 UTC (rev 1536) @@ -11,7 +11,8 @@ "crash", "cylvssphere", "feedback", - "friction", + "friction", + "gyroscopic", "heightfield", "hinge", "I", Modified: trunk/configure.in =================================================================== --- trunk/configure.in 2008-07-24 14:39:54 UTC (rev 1535) +++ trunk/configure.in 2008-07-24 22:18:40 UTC (rev 1536) @@ -142,19 +142,6 @@ AC_SUBST(ODE_PRECISION) -AC_MSG_CHECKING(if gyroscopic term should be used) -AC_ARG_ENABLE(gyroscopic, - AS_HELP_STRING([--disable-gyroscopic], - [Configure ODE to work without gyroscopic term (may improve stability)] - ), - gyroscopic=$enableval,gyroscopic=yes) -AC_MSG_RESULT($gyroscopic) -if test x"$gyroscopic" = xyes -then - AC_DEFINE(dGYROSCOPIC,1,[Use gyroscopic terms]) -fi - - AC_ARG_WITH([drawstuff],AS_HELP_STRING([--with-drawstuff=X11|Win32|OSX|none],[force a particular drawstuff implementation or disable it.]), [drawstuff=$withval],[drawstuff=]) @@ -451,7 +438,6 @@ echo " Demos enabled: $enable_demos" echo " Use OPCODE: $opcode" echo " Use GIMPACT: $gimpact" -echo " Use gyroscopic term: $gyroscopic" echo " Is target a Pentium: $pentium" echo " Is target x86-64: $cpu64" echo " Use new opcode trimesh collider: $new_trimesh" Modified: trunk/include/ode/mass.h =================================================================== --- trunk/include/ode/mass.h 2008-07-24 14:39:54 UTC (rev 1535) +++ trunk/include/ode/mass.h 2008-07-24 22:18:40 UTC (rev 1536) @@ -79,11 +79,17 @@ ODE_API void dMassAdd (dMass *a, const dMass *b); + // Backwards compatible API -#define dMassSetCappedCylinder dMassSetCapsule -#define dMassSetCappedCylinderTotal dMassSetCapsuleTotal +ODE_API_DEPRECATED static void dMassSetCappedCylinder( + dMass *a, dReal b, int c, dReal d, dReal e) +{ return dMassSetCapsule(a,b,c,d,e); } +ODE_API_DEPRECATED static void dMassSetCappedCylinderTotal( + dMass *a, dReal b, int c, dReal d, dReal e) +{ return dMassSetCapsuleTotal(a,b,c,d,e); } + struct dMass { dReal mass; dVector4 c; @@ -98,14 +104,32 @@ dReal I11, dReal I22, dReal I33, dReal I12, dReal I13, dReal I23) { dMassSetParameters (this,themass,cgx,cgy,cgz,I11,I22,I33,I12,I13,I23); } + void setSphere (dReal density, dReal radius) { dMassSetSphere (this,density,radius); } - void setCapsule (dReal density, int direction, dReal a, dReal b) - { dMassSetCappedCylinder (this,density,direction,a,b); } - void setCappedCylinder (dReal density, int direction, dReal a, dReal b) - { setCapsule(density, direction, a, b); } + void setSphereTotal (dReal total, dReal radius) + { dMassSetSphereTotal (this,total,radius); } + + void setCapsule (dReal density, int direction, dReal radius, dReal length) + { dMassSetCapsule (this,density,direction,radius,length); } + void setCapsuleTotal (dReal total, int direction, dReal radius, dReal length) + { dMassSetCapsule (this,total,direction,radius,length); } + + void setCylinder(dReal density, int direction, dReal radius, dReal length) + { dMassSetCylinder (this,density,direction,radius,length); } + void setCylinderTotal(dReal total, int direction, dReal radius, dReal length) + { dMassSetCylinderTotal (this,total,direction,radius,length); } + void setBox (dReal density, dReal lx, dReal ly, dReal lz) { dMassSetBox (this,density,lx,ly,lz); } + void setBoxTotal (dReal total, dReal lx, dReal ly, dReal lz) + { dMassSetBoxTotal (this,total,lx,ly,lz); } + + void setTrimesh(dReal density, dGeomID g) + { dMassSetTrimesh (this, density, g); } + void setTrimeshTotal(dReal total, dGeomID g) + { dMassSetTrimeshTotal (this, total, g); } + void adjust (dReal newmass) { dMassAdjust (this,newmass); } void translate (dReal x, dReal y, dReal z) Modified: trunk/include/ode/objects.h =================================================================== --- trunk/include/ode/objects.h 2008-07-24 14:39:54 UTC (rev 1535) +++ trunk/include/ode/objects.h 2008-07-24 22:18:40 UTC (rev 1536) @@ -1231,17 +1231,39 @@ * @ingroup damping bodies * @sa dWorldSetMaxAngularSpeed() dBodyResetMaxAngularSpeed() * 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 + * it at less than 500 if the body has the gyroscopic term * enabled. */ ODE_API void dBodySetMaxAngularSpeed(dBodyID b, dReal max_speed); +/** + * @brief Get the body's gyroscopic state. + * + * @return nonzero if gyroscopic term computation is enabled (default), + * zero otherwise. + * @ingroup bodies + */ +ODE_API int dBodyGetGyroscopicMode(dBodyID b); +/** + * @brief Enable/disable the body's gyroscopic term. + * + * Disabling the gyroscopic term of a body usually improves + * stability. It also helps turning spining objects, like cars' + * wheels. + * + * @param enabled nonzero (default) to enable gyroscopic term, 0 + * to disable. + * @ingroup bodies + */ +ODE_API void dBodySetGyroscopicMode(dBodyID b, int enabled); + + /** * @defgroup joints Joints * Modified: trunk/include/ode/odecpp.h =================================================================== --- trunk/include/ode/odecpp.h 2008-07-24 14:39:54 UTC (rev 1535) +++ trunk/include/ode/odecpp.h 2008-07-24 22:18:40 UTC (rev 1536) @@ -363,22 +363,27 @@ { dBodySetAngularDamping(_id, scale); } void setDamping(dReal linear_scale, dReal angular_scale) { dBodySetDamping(_id, linear_scale, angular_scale); } - dReal getLinearDampingThreshold() const + dReal getLinearDampingThreshold() const { return dBodyGetLinearDampingThreshold(_id); } - void setLinearDampingThreshold(dReal threshold) const + void setLinearDampingThreshold(dReal threshold) const { dBodySetLinearDampingThreshold(_id, threshold); } - dReal getAngularDampingThreshold() const + dReal getAngularDampingThreshold() const { return dBodyGetAngularDampingThreshold(_id); } - void setAngularDampingThreshold(dReal threshold) + void setAngularDampingThreshold(dReal threshold) { dBodySetAngularDampingThreshold(_id, threshold); } - void setDampingDefaults() + void setDampingDefaults() { dBodySetDampingDefaults(_id); } - dReal getMaxAngularSpeed() const + dReal getMaxAngularSpeed() const { return dBodyGetMaxAngularSpeed(_id); } - void setMaxAngularSpeed(dReal max_speed) + void setMaxAngularSpeed(dReal max_speed) { dBodySetMaxAngularSpeed(_id, max_speed); } + bool getGyroscopicMode() const + { return dBodyGetGyroscopicMode(_id) != 0; } + void setGyroscopicMode(bool mode) + { dBodySetGyroscopicMode(_id, mode); } + }; Modified: trunk/ode/demo/Makefile.am =================================================================== --- trunk/ode/demo/Makefile.am 2008-07-24 14:39:54 UTC (rev 1535) +++ trunk/ode/demo/Makefile.am 2008-07-24 22:18:40 UTC (rev 1536) @@ -22,6 +22,7 @@ demo_cylvssphere \ demo_feedback \ demo_friction \ + demo_gyroscopic \ demo_heightfield \ demo_hinge \ demo_I \ @@ -50,6 +51,7 @@ demo_cylvssphere_SOURCES = demo_cylvssphere.cpp demo_feedback_SOURCES = demo_feedback.cpp demo_friction_SOURCES = demo_friction.cpp +demo_gyroscopic_SOURCES = demo_gyroscopic.cpp demo_heightfield_SOURCES = demo_heightfield.cpp demo_hinge_SOURCES = demo_hinge.cpp demo_I_SOURCES = demo_I.cpp Added: trunk/ode/demo/demo_gyroscopic.cpp =================================================================== --- trunk/ode/demo/demo_gyroscopic.cpp (rev 0) +++ trunk/ode/demo/demo_gyroscopic.cpp 2008-07-24 22:18:40 UTC (rev 1536) @@ -0,0 +1,237 @@ +#include <ode/ode.h> +#include <drawstuff/drawstuff.h> +#include "texturepath.h" + +#ifdef _MSC_VER +#pragma warning(disable:4244 4305) // for VC++, no precision loss complaints +#endif + +// select correct drawing functions + +#ifdef dDOUBLE +#define dsDrawBox dsDrawBoxD +#define dsDrawSphere dsDrawSphereD +#define dsDrawCylinder dsDrawCylinderD +#define dsDrawCapsule dsDrawCapsuleD +#define dsDrawConvex dsDrawConvexD +#endif + +bool write_world = false; +bool show_contacts = false; +dWorld * world; +dBody *top1, *top2; +dSpace *space; +dJointGroup contactgroup; + +const dReal pinradius = 0.05f; +const dReal pinlength = 1.5f; +const dReal topradius = 1.0f; +const dReal toplength = 0.25f; +const dReal topmass = 1.0f; + +#define MAX_CONTACTS 4 + +static void nearCallback (void *data, dGeomID o1, dGeomID o2) +{ + // for drawing the contact points + dMatrix3 RI; + dRSetIdentity (RI); + const dReal ss[3] = {0.02,0.02,0.02}; + + int i; + dBodyID b1 = dGeomGetBody(o1); + dBodyID b2 = dGeomGetBody(o2); + + dContact contact[MAX_CONTACTS]; + int numc = dCollide (o1,o2,MAX_CONTACTS,&contact[0].geom, + sizeof(dContact)); + + for (i=0; i<numc; i++) { + contact[i].surface.mode = dContactApprox1; + contact[i].surface.mu = 2; + + dJointID c = dJointCreateContact (*world,contactgroup,contact+i); + dJointAttach (c,b1,b2); + if (show_contacts) + dsDrawBox (contact[i].geom.pos, RI, ss); + + } +} + + +// start simulation - set viewpoint + +static void start() +{ + static float xyz[3] = {4.777f, -2.084f, 2.18f}; + static float hpr[3] = {153.0f, -14.5f, 0.0f}; + dsSetViewpoint (xyz,hpr); + printf ("SPACE to reset\n"); + printf ("A to tilt the tops.\n"); + printf ("T to toggle showing the contact points.\n"); + printf ("1 to save the current state to 'state.dif'.\n"); +} + + +char locase (char c) +{ + if (c >= 'A' && c <= 'Z') return c - ('a'-'A'); + else return c; +} + + +// called when a key pressed +static void reset(); +static void tilt(); + +static void command (int cmd) +{ + cmd = locase (cmd); + if (cmd == ' ') + { + reset(); + } + else if (cmd == 'a') { + tilt(); + } + else if (cmd == 't') { + show_contacts = !show_contacts; + } + else if (cmd == '1') { + write_world = true; + } +} + +// simulation loop + +static void simLoop (int pause) +{ + dsSetColor (0,0,2); + space->collide(0,&nearCallback); + if (!pause) + //world->quickStep(0.02); + world->step(0.02); + + if (write_world) { + FILE *f = fopen ("state.dif","wt"); + if (f) { + dWorldExportDIF (*world,f,"X"); + fclose (f); + } + write_world = false; + } + + // remove all contact joints + dJointGroupEmpty (contactgroup); + + dsSetTexture (DS_WOOD); + + dsSetColor (1,0.5f,0); + dsDrawCylinder(top1->getPosition(), + top1->getRotation(), + toplength, topradius); + dsDrawCapsule(top1->getPosition(), + top1->getRotation(), + pinlength, pinradius); + + dsSetColor (0.5f,1,0); + dsDrawCylinder(top2->getPosition(), + top2->getRotation(), + toplength, topradius); + dsDrawCapsule(top2->getPosition(), + top2->getRotation(), + pinlength, pinradius); + +} + + +static void reset() +{ + dMatrix3 R; + dRSetIdentity(R); + + top1->setRotation(R); + top2->setRotation(R); + + top1->setPosition(0.8f, -2, 2); + top2->setPosition(0.8f, 2, 2); + + top1->setAngularVel(0,0,5); + top2->setAngularVel(0,0,5); + + top1->setLinearVel(0,0.2f,0); + top2->setLinearVel(0,0.2f,0); +} + +static void tilt() +{ + top1->addTorque(0, 10, 0); + top2->addTorque(0, 10, 0); +} + +int main (int argc, char **argv) +{ + // setup pointers to drawstuff callback functions + dsFunctions fn; + fn.version = DS_VERSION; + fn.start = &start; + fn.step = &simLoop; + fn.command = &command; + fn.stop = 0; + fn.path_to_textures = DRAWSTUFF_TEXTURE_PATH; + if(argc==2) + { + fn.path_to_textures = argv[1]; + } + + + // create world + dInitODE(); + world = new dWorld(); + world->setGravity(0,0,-0.5f); + world->setCFM(1e-5f); + world->setLinearDamping(0.00001f); + world->setAngularDamping(0.0001f); + + space = new dSimpleSpace(0); + + dPlane *floor = new dPlane(*space, 0,0,1,0); + + top1 = new dBody(*world); + top2 = new dBody(*world); + + dMass m; + m.setCylinderTotal(1, 3, topradius, toplength); + top1->setMass(m); + top2->setMass(m); + + dGeom *g1, *g2, *pin1, *pin2; + g1 = new dCylinder(*space, topradius, toplength); + g1->setBody(*top1); + g2 = new dCylinder(*space, topradius, toplength); + g2->setBody(*top2); + + pin1 = new dCapsule(*space, pinradius, pinlength); + pin1->setBody(*top1); + pin2 = new dCapsule(*space, pinradius, pinlength); + pin2->setBody(*top2); + + top2->setGyroscopicMode(false); + + reset(); + + // run simulation + dsSimulationLoop (argc,argv,512,384,&fn); + + delete g1; + delete g2; + delete pin1; + delete pin2; + delete floor; + contactgroup.empty(); + delete top1; + delete top2; + delete space; + delete world; + dCloseODE(); +} Property changes on: trunk/ode/demo/demo_gyroscopic.cpp ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ode/src/objects.h =================================================================== --- trunk/ode/src/objects.h 2008-07-24 14:39:54 UTC (rev 1535) +++ trunk/ode/src/objects.h 2008-07-24 22:18:40 UTC (rev 1536) @@ -35,14 +35,15 @@ // some body flags enum { - dxBodyFlagFiniteRotation = 1, // use finite rotations - 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 - dxBodyLinearDamping = 32, // using linear damping - dxBodyAngularDamping = 64, // using angular damping - dxBodyMaxAngularSpeed = 128, // using maximum angular speed + dxBodyFlagFiniteRotation = 1, // use finite rotations + 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 + dxBodyLinearDamping = 32, // use linear damping + dxBodyAngularDamping = 64, // use angular damping + dxBodyMaxAngularSpeed = 128,// use maximum angular speed + dxBodyGyroscopic = 256,// use gyroscopic term }; @@ -114,7 +115,7 @@ struct dxBody : public dObject { dxJointNode *firstjoint; // list of attached joints - int flags; // some dxBodyFlagXXX flags + unsigned flags; // some dxBodyFlagXXX flags dGeomID geom; // first collision geom associated with body dMass mass; // mass parameters about POR dMatrix3 invI; // inverse of mass.I Modified: trunk/ode/src/ode.cpp =================================================================== --- trunk/ode/src/ode.cpp 2008-07-24 14:39:54 UTC (rev 1535) +++ trunk/ode/src/ode.cpp 2008-07-24 22:18:40 UTC (rev 1536) @@ -286,6 +286,8 @@ b->flags |= w->body_flags & dxBodyMaxAngularSpeed; b->max_angular_speed = w->max_angular_speed; + b->flags |= dxBodyGyroscopic; + return b; } @@ -1075,7 +1077,7 @@ dWorldID w = b->world; dAASSERT(w); b->dampingp = w->dampingp; - int mask = dxBodyLinearDamping | dxBodyAngularDamping; + const unsigned mask = dxBodyLinearDamping | dxBodyAngularDamping; b->flags &= ~mask; // zero them b->flags |= w->body_flags & mask; } @@ -1117,6 +1119,23 @@ } +int dBodyGetGyroscopicMode(dBodyID b) +{ + dAASSERT(b); + return b->flags & dxBodyGyroscopic; +} + +void dBodySetGyroscopicMode(dBodyID b, int enabled) +{ + dAASSERT(b); + if (enabled) + b->flags |= dxBodyGyroscopic; + else + b->flags &= ~dxBodyGyroscopic; +} + + + //**************************************************************************** // joints @@ -1990,13 +2009,9 @@ REGISTER_EXTENSION( ODE_EXT_no_debug ) #endif // dNODEBUG -#ifdef dGYROSCOPIC -REGISTER_EXTENSION( ODE_EXT_gyroscopic ) -#endif // dGYROSCOPIC - #ifdef dUSE_MALLOC_FOR_ALLOCA REGISTER_EXTENSION( ODE_EXT_malloc_not_alloca ) -#endif // dGYROSCOPIC +#endif #if dTRIMESH_ENABLED REGISTER_EXTENSION( ODE_EXT_trimesh ) Modified: trunk/ode/src/quickstep.cpp =================================================================== --- trunk/ode/src/quickstep.cpp 2008-07-24 14:39:54 UTC (rev 1535) +++ trunk/ode/src/quickstep.cpp 2008-07-24 22:18:40 UTC (rev 1536) @@ -595,15 +595,16 @@ // compute inverse inertia tensor in global frame dMULTIPLY2_333 (tmp,body[i]->invI,body[i]->posr.R); dMULTIPLY0_333 (invI+i*12,body[i]->posr.R,tmp); -#ifdef dGYROSCOPIC - dMatrix3 I; - // compute inertia tensor in global frame - dMULTIPLY2_333 (tmp,body[i]->mass.I,body[i]->posr.R); - dMULTIPLY0_333 (I,body[i]->posr.R,tmp); - // compute rotational force - dMULTIPLY0_331 (tmp,I,body[i]->avel); - dCROSS (body[i]->tacc,-=,body[i]->avel,tmp); -#endif + + if (body[i]->flags & dxBodyGyroscopic) { + dMatrix3 I; + // compute inertia tensor in global frame + dMULTIPLY2_333 (tmp,body[i]->mass.I,body[i]->posr.R); + dMULTIPLY0_333 (I,body[i]->posr.R,tmp); + // compute rotational force + dMULTIPLY0_331 (tmp,I,body[i]->avel); + dCROSS (body[i]->tacc,-=,body[i]->avel,tmp); + } } // add the gravity force to all bodies Modified: trunk/ode/src/step.cpp =================================================================== --- trunk/ode/src/step.cpp 2008-07-24 14:39:54 UTC (rev 1535) +++ trunk/ode/src/step.cpp 2008-07-24 22:18:40 UTC (rev 1536) @@ -629,13 +629,8 @@ // for all bodies, compute the inertia tensor and its inverse in the global // frame, and compute the rotational force and add it to the torque - // accumulator. I and invI are vertically stacked 3x4 matrices, one per body. + // accumulator. invI are vertically stacked 3x4 matrices, one per body. // @@@ check computation of rotational force. -#ifdef dGYROSCOPIC - ALLOCA(dReal,I,3*nb*4*sizeof(dReal)); -#else - dReal *I = NULL; -#endif // for dGYROSCOPIC ALLOCA(dReal,invI,3*nb*4*sizeof(dReal)); @@ -647,15 +642,18 @@ // compute inverse inertia tensor in global frame dMULTIPLY2_333 (tmp,body[i]->invI,body[i]->posr.R); dMULTIPLY0_333 (invI+i*12,body[i]->posr.R,tmp); -#ifdef dGYROSCOPIC - // compute inertia tensor in global frame - dMULTIPLY2_333 (tmp,body[i]->mass.I,body[i]->posr.R); - dMULTIPLY0_333 (I+i*12,body[i]->posr.R,tmp); - // compute rotational force - dMULTIPLY0_331 (tmp,I+i*12,body[i]->avel); - dCROSS (body[i]->tacc,-=,body[i]->avel,tmp); -#endif + if (body[i]->flags & dxBodyGyroscopic) { + dMatrix3 I; + + // compute inertia tensor in global frame + dMULTIPLY2_333 (tmp,body[i]->mass.I,body[i]->posr.R); + dMULTIPLY0_333 (I,body[i]->posr.R,tmp); + + // compute rotational force + dMULTIPLY0_331 (tmp,I,body[i]->avel); + dCROSS (body[i]->tacc,-=,body[i]->avel,tmp); + } } // add the gravity force to all bodies Modified: trunk/ode/src/stepfast.cpp =================================================================== --- trunk/ode/src/stepfast.cpp 2008-07-24 14:39:54 UTC (rev 1535) +++ trunk/ode/src/stepfast.cpp 2008-07-24 22:18:40 UTC (rev 1536) @@ -812,11 +812,13 @@ for (i = 0; i < 4; i++) body->tacc[i] = saveTacc[b * 4 + i]; -#ifdef dGYROSCOPIC - // compute rotational force - dMULTIPLY0_331 (tmp, globalI + b * 12, body->avel); - dCROSS (body->tacc, -=, body->avel, tmp); -#endif + + if (body->flags & dxBodyGyroscopic) { + // DanielKO: this doesn't look right/efficient, but anyways... + // compute rotational force + dMULTIPLY0_331 (tmp, globalI + b * 12, body->avel); + dCROSS (body->tacc, -=, body->avel, tmp); + } // add the gravity force to all bodies if ((body->flags & dxBodyNoGravity) == 0) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2008-08-07 21:14:10
|
Revision: 1537 http://opende.svn.sourceforge.net/opende/?rev=1537&view=rev Author: danielosmari Date: 2008-08-07 21:14:19 +0000 (Thu, 07 Aug 2008) Log Message: ----------- removed static functions, to fix static build issues with drawstuff Modified Paths: -------------- trunk/include/ode/mass.h trunk/ode/src/mass.cpp Modified: trunk/include/ode/mass.h =================================================================== --- trunk/include/ode/mass.h 2008-07-24 22:18:40 UTC (rev 1536) +++ trunk/include/ode/mass.h 2008-08-07 21:14:19 UTC (rev 1537) @@ -81,15 +81,10 @@ // Backwards compatible API -ODE_API_DEPRECATED static void dMassSetCappedCylinder( - dMass *a, dReal b, int c, dReal d, dReal e) -{ return dMassSetCapsule(a,b,c,d,e); } +ODE_API ODE_API_DEPRECATED void dMassSetCappedCylinder(dMass *a, dReal b, int c, dReal d, dReal e); +ODE_API ODE_API_DEPRECATED void dMassSetCappedCylinderTotal(dMass *a, dReal b, int c, dReal d, dReal e); -ODE_API_DEPRECATED static void dMassSetCappedCylinderTotal( - dMass *a, dReal b, int c, dReal d, dReal e) -{ return dMassSetCapsuleTotal(a,b,c,d,e); } - struct dMass { dReal mass; dVector4 c; Modified: trunk/ode/src/mass.cpp =================================================================== --- trunk/ode/src/mass.cpp 2008-07-24 22:18:40 UTC (rev 1536) +++ trunk/ode/src/mass.cpp 2008-08-07 21:14:19 UTC (rev 1537) @@ -539,3 +539,16 @@ a->mass += b->mass; for (i=0; i<12; i++) a->I[i] += b->I[i]; } + + +// Backwards compatible API +void dMassSetCappedCylinder(dMass *a, dReal b, int c, dReal d, dReal e) +{ + return dMassSetCapsule(a,b,c,d,e); +} + +void dMassSetCappedCylinderTotal(dMass *a, dReal b, int c, dReal d, dReal e) +{ + return dMassSetCapsuleTotal(a,b,c,d,e); +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2008-08-08 01:10:34
|
Revision: 1538 http://opende.svn.sourceforge.net/opende/?rev=1538&view=rev Author: danielosmari Date: 2008-08-08 01:10:42 +0000 (Fri, 08 Aug 2008) Log Message: ----------- fixed strict aliasing issue that was breaking the new trimesh collider Modified Paths: -------------- trunk/CHANGELOG.txt trunk/ode/demo/demo_moving_trimesh.cpp trunk/ode/src/collision_trimesh_trimesh_new.cpp Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2008-08-07 21:14:19 UTC (rev 1537) +++ trunk/CHANGELOG.txt 2008-08-08 01:10:42 UTC (rev 1538) @@ -8,6 +8,9 @@ * keep the format consistent (79 char width, M/D/Y date format). ------------------------------------------------------------------------------ +08/07/08 Daniel K. O. + * Fixed strict aliasing issue that was breaking the new trimesh collider. + 07/24/08 Daniel K. O. * New functions: dBodyGetGyroscopicMode and dBodySetGyroscopicMode (patch #2019242). Modified: trunk/ode/demo/demo_moving_trimesh.cpp =================================================================== --- trunk/ode/demo/demo_moving_trimesh.cpp 2008-08-07 21:14:19 UTC (rev 1537) +++ trunk/ode/demo/demo_moving_trimesh.cpp 2008-08-08 01:10:42 UTC (rev 1538) @@ -399,7 +399,7 @@ dSpaceCollide (space,0,&nearCallback); -#if 0 +#if 1 // What is this for??? - Bram if (!pause) { Modified: trunk/ode/src/collision_trimesh_trimesh_new.cpp =================================================================== --- trunk/ode/src/collision_trimesh_trimesh_new.cpp 2008-08-07 21:14:19 UTC (rev 1537) +++ trunk/ode/src/collision_trimesh_trimesh_new.cpp 2008-08-08 01:10:42 UTC (rev 1538) @@ -70,12 +70,9 @@ // static void GetTriangleGeometryCallback(udword, VertexPointers&, udword); -- not used inline void dMakeMatrix4(const dVector3 Position, const dMatrix3 Rotation, dMatrix4 &B); -static void dInvertMatrix4( dMatrix4& B, dMatrix4& Binv ); -static int IntersectLineSegmentRay(dVector3, dVector3, dVector3, dVector3, dVector3); +//static void dInvertMatrix4( dMatrix4& B, dMatrix4& Binv ); +//static int IntersectLineSegmentRay(dVector3, dVector3, dVector3, dVector3, dVector3); static void ClipConvexPolygonAgainstPlane( const dVector3, dReal, LineContactSet& ); -static int RayTriangleIntersect(const dVector3 orig, const dVector3 dir, - const dVector3 vert0, const dVector3 vert1,const dVector3 vert2, - dReal *t,dReal *u,dReal *v); ///returns the penetration depth @@ -84,18 +81,7 @@ const dVector3 plane_normal, dReal plane_dist, LineContactSet & deep_points); -///returns the penetration depth -static dReal FindMostDeepPointsInTetra( - LineContactSet contact_points, - const dVector3 sourcetri[3],///triangle which contains contact_points - const dVector3 tetra[4], - const dVector4 tetraplanes[4], - dVector3 separating_normal, - LineContactSet deep_points); -static bool ClipTriByTetra(const dVector3 tri[3], - const dVector3 tetra[4], - LineContactSet& Contacts); static bool TriTriContacts(const dVector3 tr1[3], const dVector3 tr2[3], dxGeom* g1, dxGeom* g2, int Flags, @@ -163,8 +149,6 @@ #define CONTACT_POS_HASH_QUOTIENT REAL(10000.0) #define dSQRT3 REAL(1.7320508075688773) - - void UpdateContactKey(CONTACT_KEY & key, dContactGeom * contact) { key.m_contact = contact; @@ -177,14 +161,18 @@ { dReal coord = contact->pos[i]; coord = dFloor(coord * CONTACT_POS_HASH_QUOTIENT); - - unsigned int hash_input = ((unsigned int *)&coord)[0]; - if (sizeof(dReal) / sizeof(unsigned int) != 1) - { - dIASSERT(sizeof(dReal) / sizeof(unsigned int) == 2); - hash_input ^= ((unsigned int *)&coord)[1]; - } - + + union { + dReal r; + struct { + unsigned u[ sizeof(dReal) / sizeof(unsigned) ]; + }; + } ru; + ru.r = coord; + unsigned hash_input = 0; + for (unsigned i=0; i<sizeof(dReal)/sizeof(unsigned); ++i) + hash_input ^= ru.u[i]; + hash = (( hash << 4 ) + (hash_input >> 24)) ^ ( hash >> 28 ); hash = (( hash << 4 ) + ((hash_input >> 16) & 0xFF)) ^ ( hash >> 28 ); hash = (( hash << 4 ) + ((hash_input >> 8) & 0xFF)) ^ ( hash >> 28 ); @@ -480,8 +468,8 @@ dxTriMesh* TriMesh1 = (dxTriMesh*) g1; dxTriMesh* TriMesh2 = (dxTriMesh*) g2; - dReal * TriNormals1 = (dReal *) TriMesh1->Data->Normals; - dReal * TriNormals2 = (dReal *) TriMesh2->Data->Normals; + //dReal * TriNormals1 = (dReal *) TriMesh1->Data->Normals; + //dReal * TriNormals2 = (dReal *) TriMesh2->Data->Normals; const dVector3& TLPosition1 = *(const dVector3*) dGeomGetPosition(TriMesh1); // TLRotation1 = column-major order @@ -639,7 +627,7 @@ B14 = 0.0; B24 = 0.0; B34 = 0.0; B44 = 1.0; } - +#if 0 static void dInvertMatrix4( dMatrix4& B, dMatrix4& Binv ) { @@ -671,9 +659,9 @@ Binv43 = (dReal) (det * (B41*(B13*B22 - B12*B23) + B42*(B11*B23 - B13*B21) + B43*(B12*B21 - B11*B22))); Binv44 = 1.0f; } +#endif - // Find the intersectiojn point between a coplanar line segement, // defined by X1 and X2, and a ray defined by X3 and direction N. // @@ -687,6 +675,7 @@ // c = x3 - x1 // x1 and x2 are the edges of the triangle, and x3 is CoplanarPt // and x4 is (CoplanarPt - n) +#if 0 static int IntersectLineSegmentRay(dVector3 x1, dVector3 x2, dVector3 x3, dVector3 n, dVector3 out_pt) @@ -728,9 +717,9 @@ else return 0; } +#endif - void PlaneClipSegment( const dVector3 s1, const dVector3 s2, const dVector3 N, dReal C, dVector3 clipped) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2008-08-23 00:30:54
|
Revision: 1541 http://opende.svn.sourceforge.net/opende/?rev=1541&view=rev Author: danielosmari Date: 2008-08-23 00:31:01 +0000 (Sat, 23 Aug 2008) Log Message: ----------- added pkg-config support contributed by Miko Rasa Modified Paths: -------------- trunk/Makefile.am trunk/configure.in trunk/ode-config.in Modified: trunk/Makefile.am =================================================================== --- trunk/Makefile.am 2008-08-09 21:00:29 UTC (rev 1540) +++ trunk/Makefile.am 2008-08-23 00:31:01 UTC (rev 1541) @@ -31,3 +31,5 @@ EXTRA_DIST = autogen.sh build tools \ CHANGELOG.txt INSTALL.txt README.txt LICENSE.TXT +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = ode.pc Modified: trunk/configure.in =================================================================== --- trunk/configure.in 2008-08-09 21:00:29 UTC (rev 1540) +++ trunk/configure.in 2008-08-23 00:31:01 UTC (rev 1541) @@ -422,6 +422,7 @@ tests/UnitTest++/src/Posix/Makefile tests/UnitTest++/src/Win32/Makefile ode-config + ode.pc ]) AC_OUTPUT Modified: trunk/ode-config.in =================================================================== --- trunk/ode-config.in 2008-08-09 21:00:29 UTC (rev 1540) +++ trunk/ode-config.in 2008-08-23 00:31:01 UTC (rev 1541) @@ -5,7 +5,7 @@ exec_prefix_set=no usage="\ -Usage: ode-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs] [--shared-libs]" +Usage: ode-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs]" if test $# -eq 0; then echo "${usage}" 1>&2 @@ -44,9 +44,6 @@ --libs) echo -L@libdir@ -lode ;; - --shared-libs) - echo -L@prefix@/lib -lode@so_ext@ - ;; *) echo "${usage}" 1>&2 exit 1 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2008-08-31 17:52:14
|
Revision: 1546 http://opende.svn.sourceforge.net/opende/?rev=1546&view=rev Author: danielosmari Date: 2008-08-31 17:52:21 +0000 (Sun, 31 Aug 2008) Log Message: ----------- applied patch 2080674: Improved dBodySetRotation Modified Paths: -------------- trunk/CHANGELOG.txt trunk/ode/src/ode.cpp trunk/ode/src/util.cpp trunk/ode/src/util.h trunk/tests/Makefile.am trunk/tests/odemath.cpp Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2008-08-31 03:00:59 UTC (rev 1545) +++ trunk/CHANGELOG.txt 2008-08-31 17:52:21 UTC (rev 1546) @@ -8,6 +8,10 @@ * keep the format consistent (79 char width, M/D/Y date format). ------------------------------------------------------------------------------ +38/31/08 Daniel K. O. + * Applied patch 2080674: Improved dBodySetRotation; now exact rotation + matrices are preserved until the next simulation step. + 08/07/08 Daniel K. O. * Fixed strict aliasing issue that was breaking the new trimesh collider. Modified: trunk/ode/src/ode.cpp =================================================================== --- trunk/ode/src/ode.cpp 2008-08-31 03:00:59 UTC (rev 1545) +++ trunk/ode/src/ode.cpp 2008-08-31 17:52:21 UTC (rev 1546) @@ -366,15 +366,12 @@ void dBodySetRotation (dBodyID b, const dMatrix3 R) { dAASSERT (b && R); - dQuaternion q; - dRtoQ (R,q); - dNormalize4 (q); - b->q[0] = q[0]; - b->q[1] = q[1]; - b->q[2] = q[2]; - b->q[3] = q[3]; - dQtoR (b->q,b->posr.R); + memcpy(b->posr.R, R, sizeof(dMatrix3)); + dOrthogonalizeR(b->posr.R); + dRtoQ (R, b->q); + dNormalize4 (b->q); + // notify all attached geoms that this body has moved for (dxGeom *geom = b->geom; geom; geom = dGeomGetBodyNext (geom)) dGeomMoved (geom); Modified: trunk/ode/src/util.cpp =================================================================== --- trunk/ode/src/util.cpp 2008-08-31 03:00:59 UTC (rev 1545) +++ trunk/ode/src/util.cpp 2008-08-31 17:52:21 UTC (rev 1546) @@ -408,3 +408,37 @@ } # endif } + + + + +/* + * This takes what is supposed to be a rotation matrix, + * and make sure it is correct. + * Note: this operates on rows, not columns, because for rotations + * both ways give equivalent results. + */ +void +dOrthogonalizeR(dMatrix3 m) +{ + dReal n0 = dLENGTHSQUARED(m); + if (n0 != 1) + dSafeNormalize3(m); + + // project row[0] on row[1], should be zero + dReal proj = dDOT(m, m+4); + if (proj != 0) { + // Gram-Schmidt step on row[1] + m[4] -= proj * m[0]; + m[5] -= proj * m[1]; + m[6] -= proj * m[2]; + } + dReal n1 = dLENGTHSQUARED(m+4); + if (n1 != 1) + dSafeNormalize3(m+4); + + /* just overwrite row[2], this makes sure the matrix is not + a reflection */ + dCROSS(m+8, =, m, m+4); + m[3] = m[4+3] = m[8+3] = 0; +} Modified: trunk/ode/src/util.h =================================================================== --- trunk/ode/src/util.h 2008-08-31 03:00:59 UTC (rev 1545) +++ trunk/ode/src/util.h 2008-08-31 17:52:21 UTC (rev 1546) @@ -67,4 +67,9 @@ void dxProcessIslands (dxWorld *world, dReal stepsize, dstepper_fn_t stepper); + +/* Makes sure the matrix is a proper rotation */ +void dOrthogonalizeR(dMatrix3 m); + + #endif Modified: trunk/tests/Makefile.am =================================================================== --- trunk/tests/Makefile.am 2008-08-31 03:00:59 UTC (rev 1545) +++ trunk/tests/Makefile.am 2008-08-31 17:52:21 UTC (rev 1546) @@ -1,13 +1,16 @@ SUBDIRS = UnitTest++ -AM_CPPFLAGS = -I $(srcdir)/UnitTest++/src -I $(top_srcdir)/include +AM_CPPFLAGS = -I $(srcdir)/UnitTest++/src \ + -I $(top_srcdir)/include \ + -I $(top_srcdir)/ode/src +LDADD = $(builddir)/UnitTest++/src/libunittestpp.la \ + $(top_builddir)/ode/src/libode.la + check_PROGRAMS = tests TESTS = tests -tests_SOURCES = main.cpp joint.cpp odemath.cpp joints/fixed.cpp joints/hinge.cpp joints/slider.cpp +tests_SOURCES = main.cpp joint.cpp odemath.cpp \ + joints/fixed.cpp joints/hinge.cpp joints/slider.cpp -tests_LDFLAGS = $(builddir)/UnitTest++/src/libunittestpp.la \ - $(top_builddir)/ode/src/libode.la - Modified: trunk/tests/odemath.cpp =================================================================== --- trunk/tests/odemath.cpp 2008-08-31 03:00:59 UTC (rev 1545) +++ trunk/tests/odemath.cpp 2008-08-31 17:52:21 UTC (rev 1546) @@ -25,9 +25,10 @@ #include <UnitTest++.h> #include <ode/ode.h> #include "ode/odemath.h" +#include "util.h" // internal header + + - - TEST(test_dNormalization3) { const dVector3 x = {1,0,0,0}; @@ -139,3 +140,63 @@ CHECK_EQUAL(dLENGTH(v), REAL(1.0)); } + + +TEST(test_dOrthogonalizeR) +{ + { + dMatrix3 r1 = { 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0 }; + dMatrix3 r2; + memcpy(r2, r1, sizeof(dMatrix3)); + dOrthogonalizeR(r2); + CHECK_ARRAY_EQUAL(r1, r2, 12); + } + { + dMatrix3 r1 = { 0, 1, 0, 0, + 0, 0, 1, 0, + 1, 0, 0, 0 }; + dMatrix3 r2; + memcpy(r2, r1, sizeof(dMatrix3)); + dOrthogonalizeR(r2); + CHECK_ARRAY_EQUAL(r1, r2, 12); + } + { + dMatrix3 r1 = { 0, 0, 1, 0, + 1, 0, 0, 0, + 0, 1, 0, 0 }; + dMatrix3 r2; + memcpy(r2, r1, sizeof(dMatrix3)); + dOrthogonalizeR(r2); + CHECK_ARRAY_EQUAL(r1, r2, 12); + } + { + dMatrix3 r1 = { -1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, -1, 0 }; + dMatrix3 r2; + memcpy(r2, r1, sizeof(dMatrix3)); + dOrthogonalizeR(r2); + CHECK_ARRAY_EQUAL(r1, r2, 12); + } + { + dMatrix3 r1 = { 0, -1, 0, 0, + 0, 0, 1, 0, + -1, 0, 0, 0 }; + dMatrix3 r2; + memcpy(r2, r1, sizeof(dMatrix3)); + dOrthogonalizeR(r2); + CHECK_ARRAY_EQUAL(r1, r2, 12); + } + { + dMatrix3 r1 = { 0, 0, -1, 0, + 0, -1, 0, 0, + -1, 0, 0, 0 }; + dMatrix3 r2; + memcpy(r2, r1, sizeof(dMatrix3)); + dOrthogonalizeR(r2); + CHECK_ARRAY_EQUAL(r1, r2, 12); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kw...@us...> - 2008-10-02 21:00:37
|
Revision: 1553 http://opende.svn.sourceforge.net/opende/?rev=1553&view=rev Author: kwizatz Date: 2008-10-02 20:59:35 +0000 (Thu, 02 Oct 2008) Log Message: ----------- Convex-Convex is finally stable. Modified Paths: -------------- trunk/CHANGELOG.txt trunk/build/demos.lua trunk/ode/demo/demo_convex_cd.cpp trunk/ode/src/convex.cpp Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2008-10-01 23:46:57 UTC (rev 1552) +++ trunk/CHANGELOG.txt 2008-10-02 20:59:35 UTC (rev 1553) @@ -8,7 +8,10 @@ * keep the format consistent (79 char width, M/D/Y date format). ------------------------------------------------------------------------------ -38/31/08 Daniel K. O. +10/01/08 Rodrigo Hernandez (Kwizatz) + * Convex-Convex collision detection code is finally stable. + +08/31/08 Daniel K. O. * Applied patch 2080674: Improved dBodySetRotation; now exact rotation matrices are preserved until the next simulation step. Modified: trunk/build/demos.lua =================================================================== --- trunk/build/demos.lua 2008-10-01 23:46:57 UTC (rev 1552) +++ trunk/build/demos.lua 2008-10-02 20:59:35 UTC (rev 1553) @@ -10,6 +10,7 @@ "collision", "crash", "cylvssphere", + "convex_cd", "feedback", "friction", "gyroscopic", Modified: trunk/ode/demo/demo_convex_cd.cpp =================================================================== --- trunk/ode/demo/demo_convex_cd.cpp 2008-10-01 23:46:57 UTC (rev 1552) +++ trunk/ode/demo/demo_convex_cd.cpp 2008-10-02 20:59:35 UTC (rev 1553) @@ -67,7 +67,7 @@ -0.25f,0.25f,-0.25f,// point 5 0.25f,-0.25f,-0.25f,// point 6 - -0.25f,-0.25f,-0.25f,// point 7 + -0.25f,-0.25f,-0.25f,// point 7 }; const unsigned int pointcount=8; unsigned int polygons[] = //Polygons for a cube (6 squares) @@ -92,7 +92,7 @@ dSpaceID space; dWorldID world; dJointGroupID contactgroup; -/* +/* glRotate Matrix: ( xx(1-c)+c xy(1-c)-zs xz(1-c)+ys 0 ) | | @@ -110,7 +110,8 @@ bool DumpInfo=true; int drawmode = DS_WIREFRAME; - + +#if 0 const dReal fixed_pos_0[]={0.703704,-0.748281,0.249495}; const dReal fixed_rot_0[]={0.996994,-0.001009,-0.077468,0.000000, -0.077468,-0.000117,-0.996995,0.000000, @@ -120,7 +121,16 @@ const dReal fixed_rot_1[]={-0.999461, 0.032777,0.001829,0.000000, -0.032777,-0.999463,0.000033,0.000000, 0.001829,-0.000027,0.999998,0.000000}; - + +#else +// for EDGE-EDGE test +const dReal fixed_pos_0[]={0.0,0.0,0.25}; +const dReal fixed_rot_0[]={ 1,0,0,0,0,1,0,0,0,0,1,0 }; +const dReal fixed_pos_1[]={0.000000,0.450000,0.600000}; +const dReal fixed_rot_1[]={0.708311,-0.705472,-0.000000,0.000000, + 0.516939,0.519297,-0.679785,0.000000, + 0.480067,0.481293,0.733034,0.000000}; +#endif void start() { // adjust the starting viewpoint a bit @@ -275,59 +285,87 @@ { // note: 0.0174532925 radians = 1 degree dQuaternion q; - dMatrix3 m; + dMatrix3 m; + bool changed = false; switch(cmd) { case 'w': - geom1pos[0]+=0.05; + geom1pos[0]+=0.05; + changed = true; break; case 'a': geom1pos[1]-=0.05; + changed = true; break; case 's': geom1pos[0]-=0.05; + changed = true; break; case 'd': geom1pos[1]+=0.05; + changed = true; break; case 'e': geom1pos[2]-=0.05; + changed = true; break; case 'q': geom1pos[2]+=0.05; + changed = true; break; case 'i': dQFromAxisAndAngle (q, 0, 0, 1,0.0174532925); dQMultiply0(geom1quat,geom1quat,q); + changed = true; break; case 'j': dQFromAxisAndAngle (q, 1, 0, 0,0.0174532925); dQMultiply0(geom1quat,geom1quat,q); + changed = true; break; case 'k': dQFromAxisAndAngle (q, 0, 0, 1,-0.0174532925); dQMultiply0(geom1quat,geom1quat,q); + changed = true; break; case 'l': dQFromAxisAndAngle (q, 1, 0, 0,-0.0174532925); dQMultiply0(geom1quat,geom1quat,q); + changed = true; break; case 'm': (drawmode!=DS_POLYFILL)? drawmode=DS_POLYFILL:drawmode=DS_WIREFRAME; break; case 'n': - (geoms!=convex)? geoms=convex:geoms=boxes; + (geoms!=convex)? geoms=convex:geoms=boxes; + if(geoms==convex) + { + printf("CONVEX------------------------------------------------------>\n"); + } + else + { + printf("BOX--------------------------------------------------------->\n"); + } break; default: - dsPrint ("received command %d (`%c')\n",cmd,cmd); + dsPrint ("received command %d (`%c')\n",cmd,cmd); } -#if 0 - dGeomSetPosition (geoms[1], +#if 0 + dGeomSetPosition (geoms[1], geom1pos[0], geom1pos[1], geom1pos[2]); - dQtoR (geom1quat, m); - dGeomSetRotation (geoms[1],m); + dQtoR (geom1quat, m); + dGeomSetRotation(geoms[1],m); + if(changed) + { + + printf("POS: %f,%f,%f\n",geom1pos[0],geom1pos[1],geom1pos[2]); + printf("ROT:\n%f,%f,%f,%f\n%f,%f,%f,%f\n%f,%f,%f,%f\n", + m[0],m[1],m[2],m[3], + m[4],m[5],m[6],m[7], + m[8],m[9],m[10],m[11]); + } #endif DumpInfo=true; } Modified: trunk/ode/src/convex.cpp =================================================================== --- trunk/ode/src/convex.cpp 2008-10-01 23:46:57 UTC (rev 1552) +++ trunk/ode/src/convex.cpp 2008-10-02 20:59:35 UTC (rev 1553) @@ -324,11 +324,13 @@ dVector3& q1, dVector3& p2, dVector3& q2, - float &s, - float &t, dVector3& c1, dVector3& c2) { + // s & t were originaly part of the output args, but since + // we don't really need them, we'll just declare them in here + float s; + float t; dVector3 d1 = {q1[0] - p1[0], q1[1] - p1[1], q1[2] - p1[2]}; @@ -914,7 +916,7 @@ int depth_type; dVector4 plane; dVector3 dist; // distance from center to center, from cvx1 to cvx2 - dVector3 e1a,e1b,e2a,e2b; + dVector3 e1a,e1b,e2a,e2b; // e1a to e1b = edge in cvx1,e2a to e2b = edge in cvx2. }; /*! \brief Does an axis separation test using cvx1 planes on cvx1 and cvx2, returns true for a collision false for no collision @@ -1027,9 +1029,7 @@ { dVector3Copy(plane,ccso.plane); ccso.min_depth=depth; - //ccso.g1=&cvx2; - //ccso.g2=&cvx1; - ccso.depth_type = 2; // 2 = edge-edge + ccso.depth_type = 2; // 2 means edge-edge // use cached values, add position dVector3Copy(e1a,ccso.e1a); dVector3Copy(e1b,ccso.e1b); @@ -1112,10 +1112,8 @@ dContactGeom *contact, int skip) { ConvexConvexSATOutput ccso; -// ccso.side_index = -1; // no side ccso.min_depth=dInfinity; // Min not min at all ccso.depth_type=0; // no type -// ccso.g1=ccso.g2=NULL; // precompute distance vector ccso.dist[0] = cvx2.final_posr->pos[0]-cvx1.final_posr->pos[0]; ccso.dist[1] = cvx2.final_posr->pos[1]-cvx1.final_posr->pos[1]; @@ -1124,7 +1122,6 @@ dIASSERT(maxc != 0); dVector3 i1,i2,r1,r2; // edges of incident and reference faces respectively int contacts=0; - unsigned int i; if(!CheckSATConvexFaces(cvx1,cvx2,ccso)) { return 0; @@ -1134,12 +1131,10 @@ { return 0; } - /* else if(!CheckSATConvexEdges(cvx1,cvx2,ccso)) { return 0; } - */ // If we get here, there was a collision if(ccso.depth_type==1) // face-face { @@ -1185,7 +1180,6 @@ pIncidentPoly+=pIncidentPoly[0]+1; } pIncidentPoints = pIncidentPoly+1; -#if 1 // Get the first point of the incident face dMULTIPLY0_331(i2,cvx2.final_posr->R,&cvx2.points[(pIncidentPoints[0]*3)]); dVector3Add(i2,cvx2.final_posr->pos,i2); @@ -1262,7 +1256,6 @@ rplane[3]; if(d>0) { -#if 1 dVector3Copy(p,SAFECONTACT(flags, contact, contacts, skip)->pos); dVector3Copy(rplane,SAFECONTACT(flags, contact, contacts, skip)->normal); SAFECONTACT(flags, contact, contacts, skip)->g1=&cvx1; @@ -1270,7 +1263,6 @@ SAFECONTACT(flags, contact, contacts, skip)->depth=d; ++contacts; if (contacts==maxc) return contacts; -#endif } } } @@ -1301,15 +1293,15 @@ // plane and test them for inclusion in the reference plane as well. // We already have computed intersections so, skip those. - // Get Incident plane, we need it for projection - // Rotate + /* Get Incident plane, we need it for projection */ + /* Rotate */ dMULTIPLY0_331(iplane,cvx2.final_posr->R,cvx2.planes+(incident_side*4)); dNormalize3(iplane); - // Translate + /* Translate */ iplane[3]= - (cvx2.planes[(incident_side*4)+3])+ + (cvx2.planes[(incident_side*4)+3]) + ((iplane[0] * cvx2.final_posr->pos[0]) + - (iplane[1] * cvx2.final_posr->pos[1]) + + (iplane[1] * cvx2.final_posr->pos[1]) + (iplane[2] * cvx2.final_posr->pos[2])); // get reference face for(unsigned int i=0;i<reference_side;++i) @@ -1376,57 +1368,21 @@ } } } -#else - // Keeping this code just for debuging purposes - for(unsigned int i=0;i<pIncidentPoly[0];++i) - { - dMULTIPLY0_331(i2,cvx2.final_posr->R,&cvx2.points[(pIncidentPoints[i]*3)]); - dVector3Add(cvx2.final_posr->pos,i2,i2); - dVector3Copy(i2,SAFECONTACT(flags, contact, contacts, skip)->pos); - SAFECONTACT(flags, contact, contacts, skip)->g1=&cvx1; - SAFECONTACT(flags, contact, contacts, skip)->g2=&cvx2; - ++contacts; - if (contacts==maxc) return contacts; - } - for(unsigned int i=0;i<reference_side;++i) - { - pReferencePoly+=pReferencePoly[0]+1; - } - pReferencePoints = pReferencePoly+1; - for(unsigned int i=0;i<pReferencePoly[0];++i) - { - dMULTIPLY0_331(i1,cvx1.final_posr->R,&cvx1.points[(pReferencePoints[i]*3)]); - dVector3Add(cvx1.final_posr->pos,i1,i1); - dVector3Copy(i1,SAFECONTACT(flags, contact, contacts, skip)->pos); - SAFECONTACT(flags, contact, contacts, skip)->g1=&cvx1; - SAFECONTACT(flags, contact, contacts, skip)->g2=&cvx2; - ++contacts; - if (contacts==maxc) return contacts; - } -#endif } else if(ccso.depth_type==2) // edge-edge { - // Some parts borrowed from dBoxBox - dVector3 ua,ub,pa,pb; - dReal alpha,beta; - // Get direction of first edge - for (i=0; i<3; i++) ua[i] = ccso.e1b[i]-ccso.e1a[i]; - dNormalize3(ua); // normalization shouldn't be necesary but dLineClosestApproach requires it - // Get direction of second edge - for (i=0; i<3; i++) ub[i] = ccso.e2b[i]-ccso.e2a[i]; - dNormalize3(ub); // same as with ua normalization - // Get closest points between edges (one at each) - dLineClosestApproach (ccso.e1a,ua,ccso.e2a,ub,&alpha,&beta); - for (i=0; i<3; i++) pa[i] = ccso.e1a[i]+(ua[i]*alpha); - for (i=0; i<3; i++) pb[i] = ccso.e2a[i]+(ub[i]*beta); - // Set the contact point as halfway between the 2 closest points - for (i=0; i<3; i++) SAFECONTACT(flags, contact, contacts, skip)->pos[i] = REAL(0.5)*(pa[i]+pb[i]); + dVector3 c1,c2; + //float s,t; + SAFECONTACT(flags, contact, contacts, skip)->depth = + dSqrt(ClosestPointBetweenSegments(ccso.e1a,ccso.e1b,ccso.e2a,ccso.e2b,c1,c2)); SAFECONTACT(flags, contact, contacts, skip)->g1=&cvx1; SAFECONTACT(flags, contact, contacts, skip)->g2=&cvx2; - dVector3Copy(ccso.plane,SAFECONTACT(flags, contact, contacts, skip)->normal); - SAFECONTACT(flags, contact, contacts, skip)->depth=ccso.min_depth; - ++contacts; + dVector3Copy(c1,SAFECONTACT(flags, contact, contacts, skip)->pos); + SAFECONTACT(flags, contact, contacts, skip)->normal[0] = c2[0]-c1[0]; + SAFECONTACT(flags, contact, contacts, skip)->normal[1] = c2[1]-c1[1]; + SAFECONTACT(flags, contact, contacts, skip)->normal[2] = c2[2]-c1[2]; + dNormalize3(SAFECONTACT(flags, contact, contacts, skip)->normal); + contacts++; } return contacts; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kw...@us...> - 2008-10-03 18:55:36
|
Revision: 1555 http://opende.svn.sourceforge.net/opende/?rev=1555&view=rev Author: kwizatz Date: 2008-10-03 18:55:21 +0000 (Fri, 03 Oct 2008) Log Message: ----------- Added initial script to export Convex geometry from Blender to tools, replaced box convex with Blender Icosahedron sphere in demo_boxstack.cpp. Modified Paths: -------------- trunk/ode/demo/demo_boxstack.cpp Added Paths: ----------- trunk/tools/ode_convex_export.py Modified: trunk/ode/demo/demo_boxstack.cpp =================================================================== --- trunk/ode/demo/demo_boxstack.cpp 2008-10-02 21:17:06 UTC (rev 1554) +++ trunk/ode/demo/demo_boxstack.cpp 2008-10-03 18:55:21 UTC (rev 1555) @@ -29,6 +29,218 @@ #endif +//<---- Icosahedron ----> +unsigned int Sphere_pointcount = 42; +unsigned int Sphere_planecount = 80; +dReal Sphere_points[126]={ +0.000000,0.000000,-0.300000, +0.217080,-0.157716,-0.134164, +-0.082915,-0.255192,-0.134164, +-0.268327,0.000000,-0.134164, +-0.082915,0.255192,-0.134164, +0.217080,0.157716,-0.134164, +0.082915,-0.255192,0.134164, +-0.217080,-0.157716,0.134164, +-0.217080,0.157716,0.134164, +0.082915,0.255192,0.134164, +0.268327,0.000000,0.134164, +0.000000,0.000000,0.300000, +0.127597,-0.092703,-0.255196, +-0.048737,-0.149999,-0.255196, +0.078861,-0.242703,-0.157721, +0.127597,0.092703,-0.255196, +0.255194,0.000000,-0.157721, +-0.157719,0.000000,-0.255195, +-0.206457,-0.149999,-0.157721, +-0.048737,0.149999,-0.255196, +-0.206457,0.149999,-0.157721, +0.078861,0.242703,-0.157721, +0.285317,0.092704,0.000000, +0.285317,-0.092704,0.000000, +0.176336,-0.242705,0.000000, +0.000000,-0.300000,0.000000, +-0.176336,-0.242705,0.000000, +-0.285317,-0.092704,0.000000, +-0.285317,0.092704,0.000000, +-0.176336,0.242705,0.000000, +0.000000,0.300000,0.000000, +0.176336,0.242705,0.000000, +0.206457,-0.149999,0.157721, +-0.078861,-0.242703,0.157721, +-0.255194,0.000000,0.157721, +-0.078861,0.242703,0.157721, +0.206457,0.149999,0.157721, +0.157719,0.000000,0.255195, +0.048737,-0.149999,0.255196, +-0.127597,-0.092703,0.255196, +-0.127597,0.092703,0.255196, +0.048737,0.149999,0.255196 +}; +unsigned int Sphere_polygons[]={ +3,14,12,1, +3,12,14,13, +3,2,13,14, +3,13,0,12, +3,16,1,12, +3,12,15,16, +3,5,16,15, +3,12,0,15, +3,18,13,2, +3,13,18,17, +3,3,17,18, +3,17,0,13, +3,20,17,3, +3,17,20,19, +3,4,19,20, +3,19,0,17, +3,21,19,4, +3,19,21,15, +3,5,15,21, +3,15,0,19, +3,23,1,16, +3,16,22,23, +3,10,23,22, +3,22,16,5, +3,25,2,14, +3,14,24,25, +3,6,25,24, +3,24,14,1, +3,27,3,18, +3,18,26,27, +3,7,27,26, +3,26,18,2, +3,29,4,20, +3,20,28,29, +3,8,29,28, +3,28,20,3, +3,31,5,21, +3,21,30,31, +3,9,31,30, +3,30,21,4, +3,32,23,10, +3,23,32,24, +3,6,24,32, +3,24,1,23, +3,33,25,6, +3,25,33,26, +3,7,26,33, +3,26,2,25, +3,34,27,7, +3,27,34,28, +3,8,28,34, +3,28,3,27, +3,35,29,8, +3,29,35,30, +3,9,30,35, +3,30,4,29, +3,36,31,9, +3,31,36,22, +3,10,22,36, +3,22,5,31, +3,38,6,32, +3,32,37,38, +3,11,38,37, +3,37,32,10, +3,39,7,33, +3,33,38,39, +3,11,39,38, +3,38,33,6, +3,40,8,34, +3,34,39,40, +3,11,40,39, +3,39,34,7, +3,41,9,35, +3,35,40,41, +3,11,41,40, +3,40,35,8, +3,37,10,36, +3,36,41,37, +3,11,37,41, +3,41,36,9, +}; +dReal Sphere_planes[]={ +0.471317,-0.583121,-0.661687,0.283056, +0.187594,-0.577345,-0.794658,0.280252, +-0.038547,-0.748789,-0.661687,0.283056, +0.102381,-0.315090,-0.943523,0.283057, +0.700228,-0.268049,-0.661688,0.283056, +0.607060,0.000000,-0.794656,0.280252, +0.700228,0.268049,-0.661688,0.283056, +0.331305,0.000000,-0.943524,0.283057, +-0.408939,-0.628443,-0.661686,0.283056, +-0.491119,-0.356821,-0.794657,0.280252, +-0.724044,-0.194735,-0.661694,0.283057, +-0.268034,-0.194737,-0.943523,0.283057, +-0.724044,0.194735,-0.661694,0.283057, +-0.491119,0.356821,-0.794657,0.280252, +-0.408939,0.628443,-0.661686,0.283056, +-0.268034,0.194737,-0.943523,0.283057, +-0.038547,0.748789,-0.661687,0.283056, +0.187594,0.577345,-0.794658,0.280252, +0.471317,0.583121,-0.661687,0.283056, +0.102381,0.315090,-0.943523,0.283057, +0.904981,-0.268049,-0.330393,0.283056, +0.982246,0.000000,-0.187599,0.280252, +0.992077,0.000000,0.125631,0.283057, +0.904981,0.268049,-0.330393,0.283056, +0.024726,-0.943519,-0.330396,0.283056, +0.303531,-0.934171,-0.187598,0.280251, +0.306568,-0.943519,0.125651,0.283056, +0.534590,-0.777851,-0.330395,0.283056, +-0.889698,-0.315092,-0.330386,0.283056, +-0.794656,-0.577348,-0.187595,0.280251, +-0.802607,-0.583125,0.125648,0.283055, +-0.574584,-0.748793,-0.330397,0.283055, +-0.574584,0.748793,-0.330397,0.283055, +-0.794656,0.577348,-0.187595,0.280251, +-0.802607,0.583125,0.125648,0.283055, +-0.889698,0.315092,-0.330386,0.283056, +0.534590,0.777851,-0.330395,0.283056, +0.303531,0.934171,-0.187598,0.280251, +0.306568,0.943519,0.125651,0.283056, +0.024726,0.943519,-0.330396,0.283056, +0.889698,-0.315092,0.330386,0.283056, +0.794656,-0.577348,0.187595,0.280251, +0.574584,-0.748793,0.330397,0.283055, +0.802607,-0.583125,-0.125648,0.283055, +-0.024726,-0.943519,0.330396,0.283055, +-0.303531,-0.934171,0.187598,0.280251, +-0.534590,-0.777851,0.330395,0.283056, +-0.306568,-0.943519,-0.125651,0.283056, +-0.904981,-0.268049,0.330393,0.283056, +-0.982246,0.000000,0.187599,0.280252, +-0.904981,0.268049,0.330393,0.283056, +-0.992077,0.000000,-0.125631,0.283057, +-0.534590,0.777851,0.330395,0.283056, +-0.303531,0.934171,0.187598,0.280251, +-0.024726,0.943519,0.330396,0.283055, +-0.306568,0.943519,-0.125651,0.283056, +0.574584,0.748793,0.330397,0.283055, +0.794656,0.577348,0.187595,0.280251, +0.889698,0.315092,0.330386,0.283056, +0.802607,0.583125,-0.125648,0.283055, +0.408939,-0.628443,0.661686,0.283056, +0.491119,-0.356821,0.794657,0.280252, +0.268034,-0.194737,0.943523,0.283057, +0.724044,-0.194735,0.661694,0.283057, +-0.471317,-0.583121,0.661687,0.283056, +-0.187594,-0.577345,0.794658,0.280252, +-0.102381,-0.315090,0.943523,0.283057, +0.038547,-0.748789,0.661687,0.283056, +-0.700228,0.268049,0.661688,0.283056, +-0.607060,0.000000,0.794656,0.280252, +-0.331305,0.000000,0.943524,0.283057, +-0.700228,-0.268049,0.661688,0.283056, +0.038547,0.748789,0.661687,0.283056, +-0.187594,0.577345,0.794658,0.280252, +-0.102381,0.315090,0.943523,0.283057, +-0.471317,0.583121,0.661687,0.283056, +0.724044,0.194735,0.661694,0.283057, +0.491119,0.356821,0.794657,0.280252, +0.268034,0.194737,0.943523,0.283057, +0.408939,0.628443,0.661686,0.283056, +}; + //<---- Convex Object dReal planes[]= // planes for a cube, these should coincide with the face array { @@ -275,12 +487,21 @@ else if (cmd == 'v') { dMassSetBox (&m,DENSITY,0.25,0.25,0.25); +#if 0 obj[i].geom[0] = dCreateConvex (space, planes, planecount, points, pointcount, polygons); +#else + obj[i].geom[0] = dCreateConvex (space, + Sphere_planes, + Sphere_planecount, + Sphere_points, + Sphere_pointcount, + Sphere_polygons); +#endif } //----> Convex Object else if (cmd == 'y') { @@ -478,12 +699,20 @@ //<---- Convex Object else if (type == dConvexClass) { - //dVector3 sides={0.50,0.50,0.50}; +#if 0 dsDrawConvex(pos,R,planes, planecount, points, pointcount, polygons); +#else + dsDrawConvex(pos,R, + Sphere_planes, + Sphere_planecount, + Sphere_points, + Sphere_pointcount, + Sphere_polygons); +#endif } //----> Convex Object else if (type == dCylinderClass) { Added: trunk/tools/ode_convex_export.py =================================================================== --- trunk/tools/ode_convex_export.py (rev 0) +++ trunk/tools/ode_convex_export.py 2008-10-03 18:55:21 UTC (rev 1555) @@ -0,0 +1,61 @@ +#!BPY +""" +Name: 'ODE Convex...' +Blender: 244 +Group: 'Export' +Tooltip: 'Export to Open Dynamics.' +""" +__author__ = "Rodrigo Hernandez" +__url__ = ("http://www.ode.org") +__version__ = "0.1" +__bpydoc__ = """\ +ODE Convex Exporter +This script Exports a Blender scene as a series of ODE Convex Geom data stored in a C header file. +""" +import Blender +import bpy +#import struct + +def WriteMesh(file,ob): + mesh = ob.getData(mesh=1) + # Write Point Count + file.write("unsigned int %s_pointcount = %d;\n" % (ob.getName(),len(mesh.verts))) + # Write Plane Count + file.write("unsigned int %s_planecount = %d;\n" % (ob.getName(),len(mesh.faces))) + # Write Points + file.write("dReal %s_points[%d]={\n" % (ob.getName(),(len(mesh.verts)*3))) + for vert in mesh.verts: + if vert.index==(len(mesh.verts)-1): + file.write("%f,%f,%f\n};\n" % (vert.co[0],vert.co[1],vert.co[2])) + else: + file.write("%f,%f,%f,\n" % (vert.co[0],vert.co[1],vert.co[2])) + # Write Polygons + file.write("unsigned int %s_polygons[]={\n" % ob.getName()) + for face in mesh.faces: + file.write("%d," % len(face.verts)) + for vert in face.verts: + file.write("%d," % vert.index) + if face.index==(len(mesh.faces)-1): + file.write("\n};\n"); + else: + file.write("\n"); + # Write Planes + file.write("dReal %s_planes[]={\n" % ob.getName()) + for face in mesh.faces: + # d calculated separatelly for code readability + d = face.no[0]*face.verts[0].co[0]+face.no[1]*face.verts[0].co[1]+face.no[2]*face.verts[0].co[2] + file.write("%f,%f,%f,%f,\n" % (face.no[0],face.no[1],face.no[2],d)) + file.write("};\n"); + +# Entry Point +sce = bpy.data.scenes.active +in_editmode = Blender.Window.EditMode() +if in_editmode: Blender.Window.EditMode(0) +file = open("convex.h",mode='wt') +for ob in sce.objects: + if ob.getType()=='Mesh': + WriteMesh(file,ob) +file.close() +if in_editmode: + Blender.Window.EditMode(1) +print "ODE Export Done" \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2008-10-10 14:26:37
|
Revision: 1557 http://opende.svn.sourceforge.net/opende/?rev=1557&view=rev Author: papaDoc Date: 2008-10-10 14:26:25 +0000 (Fri, 10 Oct 2008) Log Message: ----------- * Fix bug in dJointGetPUAxis2. The axis was not multiplier with the the rotation matrix of the good body. * Fix bug if there is only one body on the PU joint the axis returned was not the right one. * Add unit test to verify previous bug. Modified Paths: -------------- trunk/CHANGELOG.txt trunk/ode/src/joints/pu.cpp trunk/tests/Makefile.am Added Paths: ----------- trunk/tests/joints/pu.cpp Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2008-10-03 18:58:33 UTC (rev 1556) +++ trunk/CHANGELOG.txt 2008-10-10 14:26:25 UTC (rev 1557) @@ -8,6 +8,13 @@ * keep the format consistent (79 char width, M/D/Y date format). ------------------------------------------------------------------------------ +10/10/08 Remi Ricard (papaDoc) + * Fix bug in dJointGetPUAxis2. The axis was not multiplier with the + the rotation matrix of the good body. + * Fix bug if there is only one body on the PU joint the axis returned + was not the right one. + * Add unit test to verify previous bug. + 10/03/08 Rodrigo Hernandez (Kwizatz) * Added Blender script to create ODE convex geoms under tools. Modified: trunk/ode/src/joints/pu.cpp =================================================================== --- trunk/ode/src/joints/pu.cpp 2008-10-03 18:58:33 UTC (rev 1556) +++ trunk/ode/src/joints/pu.cpp 2008-10-10 14:26:25 UTC (rev 1557) @@ -638,7 +638,10 @@ dUASSERT( joint, "bad joint argument" ); dUASSERT( result, "bad result argument" ); checktype( joint, PU ); - getAxis( joint, result, joint->axis1 ); + if ( joint->flags & dJOINT_REVERSE ) + getAxis2( joint, result, joint->axis2 ); + else + getAxis( joint, result, joint->axis1 ); } void dJointGetPUAxis2( dJointID j, dVector3 result ) @@ -647,7 +650,10 @@ dUASSERT( joint, "bad joint argument" ); dUASSERT( result, "bad result argument" ); checktype( joint, PU ); - getAxis( joint, result, joint->axis2 ); + if ( joint->flags & dJOINT_REVERSE ) + getAxis( joint, result, joint->axis1 ); + else + getAxis2( joint, result, joint->axis2 ); } /** Modified: trunk/tests/Makefile.am =================================================================== --- trunk/tests/Makefile.am 2008-10-03 18:58:33 UTC (rev 1556) +++ trunk/tests/Makefile.am 2008-10-10 14:26:25 UTC (rev 1557) @@ -12,5 +12,8 @@ TESTS = tests tests_SOURCES = main.cpp joint.cpp odemath.cpp \ - joints/fixed.cpp joints/hinge.cpp joints/slider.cpp + joints/fixed.cpp \ + joints/hinge.cpp \ + joints/pu.cpp \ + joints/slider.cpp Added: trunk/tests/joints/pu.cpp =================================================================== --- trunk/tests/joints/pu.cpp (rev 0) +++ trunk/tests/joints/pu.cpp 2008-10-10 14:26:25 UTC (rev 1557) @@ -0,0 +1,118 @@ +/************************************************************************* + * * + * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. * + * All rights reserved. Email: ru...@q1... Web: www.q12.org * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of EITHER: * + * (1) The GNU Lesser General Public License as published by the Free * + * Software Foundation; either version 2.1 of the License, or (at * + * your option) any later version. The text of the GNU Lesser * + * General Public License is included with this library in the * + * file LICENSE.TXT. * + * (2) The BSD-style license that is included with this library in * + * the file LICENSE-BSD.TXT. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * + * LICENSE.TXT and LICENSE-BSD.TXT for more details. * + * * + *************************************************************************/ +//234567890123456789012345678901234567890123456789012345678901234567890123456789 +// 1 2 3 4 5 6 7 + +//////////////////////////////////////////////////////////////////////////////// +// This file create unit test for some of the functions found in: +// ode/src/joinst/pu.cpp +// +// +//////////////////////////////////////////////////////////////////////////////// + +#include <UnitTest++.h> +#include <ode/ode.h> + +#include "../../ode/src/joints/pu.h" + +SUITE (TestdxJointPU) +{ + // The 2 bodies are positionned at (0, 0, 0), and (0, 0, 0) + // The second body has a rotation of 27deg around X axis. + // The joint is a PU Joint + // Axis is along the X axis + // Anchor at (0, 0, 0) + struct Fixture_dxJointPU_B1_and_B2_At_Zero_Axis_Along_X + { + Fixture_dxJointPU_B1_and_B2_At_Zero_Axis_Along_X() + { + wId = dWorldCreate(); + + bId1 = dBodyCreate (wId); + dBodySetPosition (bId1, 0, 0, 0); + + bId2 = dBodyCreate (wId); + dBodySetPosition (bId2, 0, 0, 0); + + dMatrix3 R; + + dRFromAxisAndAngle (R, 1, 0, 0, REAL(0.47123)); // 27deg + dBodySetRotation (bId2, R); + + jId = dJointCreatePU (wId, 0); + joint = (dxJointPU*) jId; + + + dJointAttach (jId, bId1, bId2); + } + + ~Fixture_dxJointPU_B1_and_B2_At_Zero_Axis_Along_X() + { + dWorldDestroy (wId); + } + + dWorldID wId; + + dBodyID bId1; + dBodyID bId2; + + + dJointID jId; + dxJointPU* joint; + }; + + // Test is dJointSetPUAxis and dJointGetPUAxis return same value + TEST_FIXTURE (Fixture_dxJointPU_B1_and_B2_At_Zero_Axis_Along_X, + test_dJointSetGetPUAxis) + { + dVector3 axisOrig, axis; + + + dJointGetPUAxis1 (jId, axisOrig); + dJointGetPUAxis1 (jId, axis); + dJointSetPUAxis1 (jId, axis[0], axis[1], axis[2]); + dJointGetPUAxis1 (jId, axis); + CHECK_CLOSE (axis[0], axisOrig[0] , 1e-4); + CHECK_CLOSE (axis[1], axisOrig[1] , 1e-4); + CHECK_CLOSE (axis[2], axisOrig[2] , 1e-4); + + + dJointGetPUAxis2 (jId, axisOrig); + dJointGetPUAxis2(jId, axis); + dJointSetPUAxis2 (jId, axis[0], axis[1], axis[2]); + dJointGetPUAxis2 (jId, axis); + CHECK_CLOSE (axis[0], axisOrig[0] , 1e-4); + CHECK_CLOSE (axis[1], axisOrig[1] , 1e-4); + CHECK_CLOSE (axis[2], axisOrig[2] , 1e-4); + + + dJointGetPUAxis3 (jId, axisOrig); + dJointGetPUAxis3(jId, axis); + dJointSetPUAxis3 (jId, axis[0], axis[1], axis[2]); + dJointGetPUAxis3 (jId, axis); + CHECK_CLOSE (axis[0], axisOrig[0] , 1e-4); + CHECK_CLOSE (axis[1], axisOrig[1] , 1e-4); + CHECK_CLOSE (axis[2], axisOrig[2] , 1e-4); + } + +} // End of SUITE TestdxJointPU + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2008-10-15 16:48:02
|
Revision: 1561 http://opende.svn.sourceforge.net/opende/?rev=1561&view=rev Author: papaDoc Date: 2008-10-15 15:57:14 +0000 (Wed, 15 Oct 2008) Log Message: ----------- - For tests/odemath.cpp and joint.cpp - Pass astyle and set svn:eol-style to native - Add unit test to check if using directly a joint or using after setting with default values is the same. - This is not the case so add function setRelativeValues called in dJointAttach for all joints. - ode/src/joints/hinge2.cpp - Change a macro to a function - Reuse setAxes instead of copy paste same code. - ode/src/joints/slider.cpp - Create computeOffset function instead of copy and paste same code at several places. Modified Paths: -------------- trunk/CHANGELOG.txt trunk/ode/src/joints/ball.cpp trunk/ode/src/joints/ball.h trunk/ode/src/joints/hinge.cpp trunk/ode/src/joints/hinge.h trunk/ode/src/joints/hinge2.cpp trunk/ode/src/joints/hinge2.h trunk/ode/src/joints/joint.h trunk/ode/src/joints/piston.cpp trunk/ode/src/joints/piston.h trunk/ode/src/joints/pr.cpp trunk/ode/src/joints/pr.h trunk/ode/src/joints/pu.cpp trunk/ode/src/joints/pu.h trunk/ode/src/joints/slider.cpp trunk/ode/src/joints/slider.h trunk/ode/src/joints/universal.cpp trunk/ode/src/joints/universal.h trunk/ode/src/ode.cpp trunk/tests/Makefile.am trunk/tests/joint.cpp trunk/tests/joints/fixed.cpp trunk/tests/joints/hinge.cpp trunk/tests/joints/piston.cpp trunk/tests/joints/pu.cpp trunk/tests/joints/slider.cpp trunk/tests/main.cpp trunk/tests/odemath.cpp Added Paths: ----------- trunk/tests/joints/ball.cpp trunk/tests/joints/hinge2.cpp trunk/tests/joints/pr.cpp trunk/tests/joints/universal.cpp Property Changed: ---------------- trunk/tests/joint.cpp trunk/tests/joints/fixed.cpp trunk/tests/joints/hinge.cpp trunk/tests/joints/piston.cpp trunk/tests/joints/pu.cpp trunk/tests/joints/slider.cpp trunk/tests/odemath.cpp Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/CHANGELOG.txt 2008-10-15 15:57:14 UTC (rev 1561) @@ -8,12 +8,18 @@ * keep the format consistent (79 char width, M/D/Y date format). ------------------------------------------------------------------------------ +10/15/08 Remi Ricard (papaDoc) + * Add unit test to check if using directly a joint + or using after setting with default values is the same. + * Add function setRelativeValues called in dJointAttach for + all joints. + 10/10/08 Remi Ricard (papaDoc) - * Fix bug in dJointGetPUAxis2. The axis was not multiplier with the - the rotation matrix of the good body. - * Fix bug if there is only one body on the PU joint the axis returned - was not the right one. - * Add unit test to verify previous bug. + * Fix bug in dJointGetPUAxis2. The axis was not multiplier with the + the rotation matrix of the good body. + * Fix bug if there is only one body on the PU joint the axis returned + was not the right one. + * Add unit test to verify previous bug. 10/03/08 Rodrigo Hernandez (Kwizatz) * Added Blender script to create ODE convex geoms under tools. Modified: trunk/ode/src/joints/ball.cpp =================================================================== --- trunk/ode/src/joints/ball.cpp 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/ode/src/joints/ball.cpp 2008-10-15 15:57:14 UTC (rev 1561) @@ -163,4 +163,13 @@ return sizeof( *this ); } +void +dxJointBall::setRelativeValues() +{ + dVector3 anchor; + dJointGetBallAnchor(this, anchor); + setAnchors( this, anchor[0], anchor[1], anchor[2], anchor1, anchor2 ); +} + + Modified: trunk/ode/src/joints/ball.h =================================================================== --- trunk/ode/src/joints/ball.h 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/ode/src/joints/ball.h 2008-10-15 15:57:14 UTC (rev 1561) @@ -41,6 +41,8 @@ virtual void getInfo2( Info2* info ); virtual dJointType type() const; virtual size_t size() const; + + virtual void setRelativeValues(); }; Modified: trunk/ode/src/joints/hinge.cpp =================================================================== --- trunk/ode/src/joints/hinge.cpp 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/ode/src/joints/hinge.cpp 2008-10-15 15:57:14 UTC (rev 1561) @@ -352,6 +352,19 @@ } +void +dxJointHinge::setRelativeValues() +{ + dVector3 vec; + dJointGetHingeAnchor(this, vec); + setAnchors( this, vec[0], vec[1], vec[2], anchor1, anchor2 ); + + dJointGetHingeAxis(this, vec); + setAxes( this, vec[0], vec[1], vec[2], axis1, axis2 ); + computeInitialRelativeRotation(); +} + + /// Compute initial relative rotation body1 -> body2, or env -> body1 void dxJointHinge::computeInitialRelativeRotation() Modified: trunk/ode/src/joints/hinge.h =================================================================== --- trunk/ode/src/joints/hinge.h 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/ode/src/joints/hinge.h 2008-10-15 15:57:14 UTC (rev 1561) @@ -43,6 +43,8 @@ virtual dJointType type() const; virtual size_t size() const; + virtual void setRelativeValues(); + void computeInitialRelativeRotation(); }; Modified: trunk/ode/src/joints/hinge2.cpp =================================================================== --- trunk/ode/src/joints/hinge2.cpp 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/ode/src/joints/hinge2.cpp 2008-10-15 15:57:14 UTC (rev 1561) @@ -91,19 +91,29 @@ } -// macro that computes ax1,ax2 = axis 1 and 2 in global coordinates (they are -// relative to body 1 and 2 initially) and then computes the constrained -// rotational axis as the cross product of ax1 and ax2. -// the sin and cos of the angle between axis 1 and 2 is computed, this comes -// from dot and cross product rules. - -#define HINGE2_GET_AXIS_INFO(axis,sin_angle,cos_angle) \ - dVector3 ax1,ax2; \ - dMULTIPLY0_331 (ax1, joint->node[0].body->posr.R, joint->axis1); \ - dMULTIPLY0_331 (ax2, joint->node[1].body->posr.R, joint->axis2); \ - dCROSS (axis,=,ax1,ax2); \ - sin_angle = dSqrt (axis[0]*axis[0] + axis[1]*axis[1] + axis[2]*axis[2]); \ +//////////////////////////////////////////////////////////////////////////////// +/// Function that computes ax1,ax2 = axis 1 and 2 in global coordinates (they are +/// relative to body 1 and 2 initially) and then computes the constrained +/// rotational axis as the cross product of ax1 and ax2. +/// the sin and cos of the angle between axis 1 and 2 is computed, this comes +/// from dot and cross product rules. +/// +/// @param ax1 Will contain the joint axis1 in world frame +/// @param ax2 Will contain the joint axis2 in world frame +/// @param axis Will contain the cross product of ax1 x ax2 +/// @param sin_angle +/// @param cos_angle +//////////////////////////////////////////////////////////////////////////////// +void +dxJointHinge2::getAxisInfo(dVector3 ax1, dVector3 ax2, dVector3 axCross, + dReal &sin_angle, dReal &cos_angle) const +{ + dMULTIPLY0_331 (ax1, node[0].body->posr.R, axis1); + dMULTIPLY0_331 (ax2, node[1].body->posr.R, axis2); + dCROSS (axCross,=,ax1,ax2); + sin_angle = dSqrt (axCross[0]*axCross[0] + axCross[1]*axCross[1] + axCross[2]*axCross[2]); cos_angle = dDOT (ax1,ax2); +} void @@ -113,7 +123,9 @@ dReal s, c; dVector3 q; const dxJointHinge2 *joint = this; - HINGE2_GET_AXIS_INFO( q, s, c ); + + dVector3 ax1, ax2; + joint->getAxisInfo( ax1, ax2, q, s, c ); dNormalize3( q ); // @@@ quicker: divide q by s ? // set the three ball-and-socket rows (aligned to the suspension axis ax1) @@ -208,18 +220,11 @@ checktype( joint, Hinge2 ); if ( joint->node[0].body ) { - dReal q[4]; - q[0] = x; - q[1] = y; - q[2] = z; - q[3] = 0; - dNormalize3( q ); - dMULTIPLY1_331( joint->axis1, joint->node[0].body->posr.R, q ); - joint->axis1[3] = 0; + setAxes(joint, x, y, z, joint->axis1, NULL); // compute the sin and cos of the angle between axis 1 and axis 2 - dVector3 ax; - HINGE2_GET_AXIS_INFO( ax, joint->s0, joint->c0 ); + dVector3 ax1, ax2, ax; + joint->getAxisInfo( ax1, ax2, ax, joint->s0, joint->c0 ); } joint->makeV1andV2(); } @@ -232,18 +237,12 @@ checktype( joint, Hinge2 ); if ( joint->node[1].body ) { - dReal q[4]; - q[0] = x; - q[1] = y; - q[2] = z; - q[3] = 0; - dNormalize3( q ); - dMULTIPLY1_331( joint->axis2, joint->node[1].body->posr.R, q ); - joint->axis1[3] = 0; + setAxes(joint, x, y, z, NULL, joint->axis2); + // compute the sin and cos of the angle between axis 1 and axis 2 - dVector3 ax; - HINGE2_GET_AXIS_INFO( ax, joint->s0, joint->c0 ); + dVector3 ax1, ax2, ax;; + joint->getAxisInfo( ax1, ax2, ax, joint->s0, joint->c0 ); } joint->makeV1andV2(); } @@ -417,3 +416,29 @@ } +void +dxJointHinge2::setRelativeValues() +{ + dVector3 anchor; + dJointGetHinge2Anchor(this, anchor); + setAnchors( this, anchor[0], anchor[1], anchor[2], anchor1, anchor2 ); + + dVector3 axis; + + if ( node[0].body ) + { + dJointGetHinge2Axis1(this, axis); + setAxes( this, axis[0],axis[1],axis[2], axis1, NULL ); + } + + if ( node[0].body ) + { + dJointGetHinge2Axis2(this, axis); + setAxes( this, axis[0],axis[1],axis[2], NULL, axis2 ); + } + + dVector3 ax1, ax2; + getAxisInfo( ax1, ax2, axis, s0, c0 ); + + makeV1andV2(); +} Modified: trunk/ode/src/joints/hinge2.h =================================================================== --- trunk/ode/src/joints/hinge2.h 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/ode/src/joints/hinge2.h 2008-10-15 15:57:14 UTC (rev 1561) @@ -43,13 +43,19 @@ dReal measureAngle() const; void makeV1andV2(); + void getAxisInfo(dVector3 ax1, dVector3 ax2, dVector3 axis, + dReal &sin_angle, dReal &cos_Angle) const; + dxJointHinge2( dxWorld *w ); + virtual void getInfo1( Info1* info ); virtual void getInfo2( Info2* info ); virtual dJointType type() const; virtual size_t size() const; + + virtual void setRelativeValues(); }; Modified: trunk/ode/src/joints/joint.h =================================================================== --- trunk/ode/src/joints/joint.h 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/ode/src/joints/joint.h 2008-10-15 15:57:14 UTC (rev 1561) @@ -122,6 +122,10 @@ virtual void getInfo2( Info2* info ) = 0; virtual dJointType type() const = 0; virtual size_t size() const = 0; + + /// Set values which are relative with respect to bodies. + /// Each dxJoint should redefined it if need be. + virtual void setRelativeValues() {}; }; Modified: trunk/ode/src/joints/piston.cpp =================================================================== --- trunk/ode/src/joints/piston.cpp 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/ode/src/joints/piston.cpp 2008-10-15 15:57:14 UTC (rev 1561) @@ -227,9 +227,9 @@ // 2 bodies anchor is center of body 2 // 1 bodies anchor is origin dVector3 lanchor2= - { - 0,0,0 - }; + { + 0,0,0 + }; pos1 = node[0].body->posr.pos; R1 = node[0].body->posr.R; @@ -387,26 +387,6 @@ limotR.addLimot ( this, info, row, ax1, 1 ); } -void -dxJointPiston::computeInitialRelativeRotation() -{ - if ( node[0].body ) - { - if ( node[1].body ) - { - dQMultiply1 ( qrel, node[0].body->q, node[1].body->q ); - } - else - { - // set joint->qrel to the transpose of the first body q - qrel[0] = node[0].body->q[0]; - for ( int i = 1; i < 4; i++ ) - qrel[i] = -node[0].body->q[i]; - // WARNING do we need the - in -joint->node[0].body->q[i]; or not - } - } -} - void dJointSetPistonAnchor ( dJointID j, dReal x, dReal y, dReal z ) { dxJointPiston* joint = ( dxJointPiston* ) j; @@ -664,3 +644,39 @@ } + +void +dxJointPiston::setRelativeValues() +{ + dVector3 vec; + dJointGetPistonAnchor(this, vec); + setAnchors( this, vec[0], vec[1], vec[2], anchor1, anchor2 ); + + dJointGetPistonAxis(this, vec); + setAxes( this, vec[0], vec[1], vec[2], axis1, axis2 ); + + computeInitialRelativeRotation(); +} + + + + +void +dxJointPiston::computeInitialRelativeRotation() +{ + if ( node[0].body ) + { + if ( node[1].body ) + { + dQMultiply1 ( qrel, node[0].body->q, node[1].body->q ); + } + else + { + // set joint->qrel to the transpose of the first body q + qrel[0] = node[0].body->q[0]; + for ( int i = 1; i < 4; i++ ) + qrel[i] = -node[0].body->q[i]; + // WARNING do we need the - in -joint->node[0].body->q[i]; or not + } + } +} Modified: trunk/ode/src/joints/piston.h =================================================================== --- trunk/ode/src/joints/piston.h 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/ode/src/joints/piston.h 2008-10-15 15:57:14 UTC (rev 1561) @@ -91,15 +91,15 @@ /// part of the joint dxJointLimitMotor limotR; - - void computeInitialRelativeRotation(); - - dxJointPiston( dxWorld *w ); virtual void getInfo1( Info1* info ); virtual void getInfo2( Info2* info ); virtual dJointType type() const; virtual size_t size() const; + + virtual void setRelativeValues(); + + void computeInitialRelativeRotation(); }; Modified: trunk/ode/src/joints/pr.cpp =================================================================== --- trunk/ode/src/joints/pr.cpp 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/ode/src/joints/pr.cpp 2008-10-15 15:57:14 UTC (rev 1561) @@ -498,6 +498,24 @@ } +void +dxJointPR::setRelativeValues() +{ + dVector3 anchor; + dJointGetPRAnchor(this, anchor); + setAnchors( this, anchor[0], anchor[1], anchor[2], offset, anchor2 ); + dVector3 axis; + dJointGetPRAxis1(this, axis); + setAxes( this, axis[0], axis[1], axis[2], axisP1, 0 ); + dJointGetPRAxis2(this, axis); + setAxes( this, axis[0], axis[1], axis[2], axisR1, axisR2 ); + computeInitialRelativeRotation(); +} + + + + + Modified: trunk/ode/src/joints/pr.h =================================================================== --- trunk/ode/src/joints/pr.h 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/ode/src/joints/pr.h 2008-10-15 15:57:14 UTC (rev 1561) @@ -46,28 +46,34 @@ struct dxJointPR : public dxJoint { - dVector3 anchor2; ///< @brief Position of the rotoide articulation - ///< w.r.t second body. - ///< @note Position of body 2 in world frame + - ///< anchor2 in world frame give the position - ///< of the rotoide articulation - dVector3 axisR1; ///< axis of the rotoide articulation w.r.t first body. - ///< @note This is considered as axis1 from the parameter - ///< view. - dVector3 axisR2; ///< axis of the rotoide articulation w.r.t second body. - ///< @note This is considered also as axis1 from the - ///< parameter view - dVector3 axisP1; ///< axis for the prismatic articulation w.r.t first body. - ///< @note This is considered as axis2 in from the parameter - ///< view + /// @brief Position of the rotoide articulation w.r.t second body. + /// @note Position of body 2 in world frame + anchor2 in world frame give + /// the position of the rotoide articulation + dVector3 anchor2; + + + /// axis of the rotoide articulation w.r.t first body. + /// @note This is considered as axis1 from the parameter view. + dVector3 axisR1; + + /// axis of the rotoide articulation w.r.t second body. + /// @note This is considered also as axis1 from the parameter view + dVector3 axisR2; + + /// axis for the prismatic articulation w.r.t first body. + /// @note This is considered as axis2 in from the parameter view + dVector3 axisP1; + + dQuaternion qrel; ///< initial relative rotation body1 -> body2. - dVector3 offset; ///< @brief vector between the body1 and the rotoide - ///< articulation. - ///< - ///< Going from the first to the second in the frame - ///< of body1. - ///< That should be aligned with body1 center along axisP - ///< This is calculated when the axis are set. + + + /// @brief vector between the body1 and the rotoide articulation. + /// + /// Going from the first to the second in the frame of body1. + /// That should be aligned with body1 center along axisP. + /// This is calculated when the axis are set. + dVector3 offset; dxJointLimitMotor limotR; ///< limit and motor information for the rotoide articulation. dxJointLimitMotor limotP; ///< limit and motor information for the prismatic articulation. @@ -80,6 +86,8 @@ virtual void getInfo2( Info2* info ); virtual dJointType type() const; virtual size_t size() const; + + virtual void setRelativeValues(); }; Modified: trunk/ode/src/joints/pu.cpp =================================================================== --- trunk/ode/src/joints/pu.cpp 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/ode/src/joints/pu.cpp 2008-10-15 15:57:14 UTC (rev 1561) @@ -715,3 +715,32 @@ } +void +dxJointPU::setRelativeValues() +{ + dVector3 anchor; + dJointGetPUAnchor(this, anchor); + setAnchors( this, anchor[0], anchor[1], anchor[2], anchor1, anchor2 ); + + dVector3 ax1, ax2, ax3; + dJointGetPUAxis1(this, ax1); + dJointGetPUAxis2(this, ax2); + dJointGetPUAxis3(this, ax3); + + if ( flags & dJOINT_REVERSE ) + { + setAxes( this, ax1[0], ax1[1], ax1[2], NULL, axis2 ); + setAxes( this, ax2[0], ax2[1], ax2[2], axis1, NULL ); + } + else + { + setAxes( this, ax1[0], ax1[1], ax1[2], axis1, NULL ); + setAxes( this, ax2[0], ax2[1], ax2[2], NULL, axis2 ); + } + + + setAxes( this, ax3[0], ax3[1], ax3[2], NULL, axisP1 ); + + computeInitialRelativeRotations(); +} + Modified: trunk/ode/src/joints/pu.h =================================================================== --- trunk/ode/src/joints/pu.h 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/ode/src/joints/pu.h 2008-10-15 15:57:14 UTC (rev 1561) @@ -61,9 +61,11 @@ */ struct dxJointPU : public dxJointUniversal { - dVector3 axisP1; ///< @brief Axis for the prismatic articulation w.r.t first body. - ///< @note This is considered as axis2 from the parameter - ///< view + + /// @brief Axis for the prismatic articulation w.r.t first body. + /// @note This is considered as axis2 from the parameter view + dVector3 axisP1; + dxJointLimitMotor limotP; ///< limit and motor information for the prismatic articulation. @@ -72,6 +74,9 @@ virtual void getInfo2( Info2* info ); virtual dJointType type() const; virtual size_t size() const; + + + virtual void setRelativeValues(); }; Modified: trunk/ode/src/joints/slider.cpp =================================================================== --- trunk/ode/src/joints/slider.cpp 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/ode/src/joints/slider.cpp 2008-10-15 15:57:14 UTC (rev 1561) @@ -66,7 +66,8 @@ q[2] = joint->node[0].body->posr.pos[2] - joint->offset[2]; if ( joint->flags & dJOINT_REVERSE ) - { // N.B. it could have been simplier to only inverse the sign of + { + // N.B. it could have been simplier to only inverse the sign of // the dDot result but this case is exceptional and doing // the check for all case can decrease the performance. ax1[0] = -ax1[0]; @@ -221,19 +222,7 @@ checktype ( joint, Slider ); setAxes ( joint, x, y, z, joint->axis1, 0 ); - // compute initial relative rotation body1 -> body2, or env -> body1 - // also compute center of body1 w.r.t body 2 - if ( joint->node[1].body ) - { - dVector3 c; - for ( i = 0; i < 3; i++ ) - c[i] = joint->node[0].body->posr.pos[i] - joint->node[1].body->posr.pos[i]; - dMULTIPLY1_331 ( joint->offset, joint->node[1].body->posr.R, c ); - } - else - { - for ( i = 0; i < 3; i++ ) joint->offset[i] = joint->node[0].body->posr.pos[i]; - } + joint->computeOffset(); joint->computeInitialRelativeRotation(); } @@ -247,21 +236,16 @@ checktype ( joint, Slider ); setAxes ( joint, x, y, z, joint->axis1, 0 ); + joint->computeOffset(); + // compute initial relative rotation body1 -> body2, or env -> body1 // also compute center of body1 w.r.t body 2 - if ( joint->node[1].body ) + if ( !(joint->node[1].body) ) { - dVector3 c; - for ( i = 0; i < 3; i++ ) - c[i] = joint->node[0].body->posr.pos[i] - joint->node[1].body->posr.pos[i]; - dMULTIPLY1_331 ( joint->offset, joint->node[1].body->posr.R, c ); + joint->offset[0] += dx; + joint->offset[1] += dy; + joint->offset[2] += dz; } - else - { - joint->offset[0] = joint->node[0].body->posr.pos[0] + dx; - joint->offset[1] = joint->node[0].body->posr.pos[1] + dy; - joint->offset[2] = joint->node[0].body->posr.pos[2] + dz; - } joint->computeInitialRelativeRotation(); } @@ -350,6 +334,15 @@ } +void +dxJointSlider::setRelativeValues() +{ + computeOffset(); + computeInitialRelativeRotation(); +} + + + /// Compute initial relative rotation body1 -> body2, or env -> body1 void dxJointSlider::computeInitialRelativeRotation() @@ -372,3 +365,25 @@ } } } + + +/// Compute center of body1 w.r.t body 2 +void +dxJointSlider::computeOffset() +{ + if ( node[1].body ) + { + dVector3 c; + c[0] = node[0].body->posr.pos[0] - node[1].body->posr.pos[0]; + c[1] = node[0].body->posr.pos[1] - node[1].body->posr.pos[1]; + c[2] = node[0].body->posr.pos[2] - node[1].body->posr.pos[2]; + + dMULTIPLY1_331 ( offset, node[1].body->posr.R, c ); + } + else if ( node[0].body ) + { + offset[0] = node[0].body->posr.pos[0]; + offset[1] = node[0].body->posr.pos[1]; + offset[2] = node[0].body->posr.pos[2]; + } +} Modified: trunk/ode/src/joints/slider.h =================================================================== --- trunk/ode/src/joints/slider.h 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/ode/src/joints/slider.h 2008-10-15 15:57:14 UTC (rev 1561) @@ -43,7 +43,11 @@ virtual dJointType type() const; virtual size_t size() const; + virtual void setRelativeValues(); + void computeInitialRelativeRotation(); + + void computeOffset(); }; Modified: trunk/ode/src/joints/universal.cpp =================================================================== --- trunk/ode/src/joints/universal.cpp 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/ode/src/joints/universal.cpp 2008-10-15 15:57:14 UTC (rev 1561) @@ -628,3 +628,29 @@ } + +void +dxJointUniversal::setRelativeValues() +{ + dVector3 anchor; + dJointGetUniversalAnchor(this, anchor); + setAnchors( this, anchor[0], anchor[1], anchor[2], anchor1, anchor2 ); + + dVector3 ax1,ax2; + dJointGetUniversalAxis1(this, ax1); + dJointGetUniversalAxis2(this, ax2); + + if ( flags & dJOINT_REVERSE ) + { + setAxes( this, ax1[0],ax1[1],ax1[2], NULL, axis2 ); + setAxes( this, ax2[0],ax2[1],ax2[2], axis1, NULL ); + } + else + { + setAxes( this, ax1[0],ax1[1],ax1[2], axis1, NULL ); + setAxes( this, ax2[0],ax2[1],ax2[2], NULL, axis2 ); + } + + computeInitialRelativeRotations(); +} + Modified: trunk/ode/src/joints/universal.h =================================================================== --- trunk/ode/src/joints/universal.h 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/ode/src/joints/universal.h 2008-10-15 15:57:14 UTC (rev 1561) @@ -51,6 +51,8 @@ virtual void getInfo2( Info2* info ); virtual dJointType type() const; virtual size_t size() const; + + virtual void setRelativeValues(); }; Modified: trunk/ode/src/ode.cpp =================================================================== --- trunk/ode/src/ode.cpp 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/ode/src/ode.cpp 2008-10-15 15:57:14 UTC (rev 1561) @@ -1369,6 +1369,10 @@ else { joint->node[0].next = 0; } + + // Since the bodies are now set. + // Calculate the values depending on the bodies + joint->setRelativeValues(); } Modified: trunk/tests/Makefile.am =================================================================== --- trunk/tests/Makefile.am 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/tests/Makefile.am 2008-10-15 15:57:14 UTC (rev 1561) @@ -12,8 +12,13 @@ TESTS = tests tests_SOURCES = main.cpp joint.cpp odemath.cpp \ + joints/ball.cpp \ joints/fixed.cpp \ - joints/hinge.cpp \ - joints/pu.cpp \ - joints/slider.cpp + joints/hinge.cpp \ + joints/hinge2.cpp \ + joints/piston.cpp \ + joints/pr.cpp \ + joints/pu.cpp \ + joints/slider.cpp \ + joints/universal.cpp Modified: trunk/tests/joint.cpp =================================================================== --- trunk/tests/joint.cpp 2008-10-14 04:19:45 UTC (rev 1560) +++ trunk/tests/joint.cpp 2008-10-15 15:57:14 UTC (rev 1561) @@ -1,2920 +1,2978 @@ -/************************************************************************* - * * - * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. * - * All rights reserved. Email: ru...@q1... Web: www.q12.org * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of EITHER: * - * (1) The GNU Lesser General Public License as published by the Free * - * Software Foundation; either version 2.1 of the License, or (at * - * your option) any later version. The text of the GNU Lesser * - * General Public License is included with this library in the * - * file LICENSE.TXT. * - * (2) The BSD-style license that is included with this library in * - * the file LICENSE-BSD.TXT. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * - * LICENSE.TXT and LICENSE-BSD.TXT for more details. * - * * - *************************************************************************/ -//234567890123456789012345678901234567890123456789012345678901234567890123456789 -// 1 2 3 4 5 6 7 - -//////////////////////////////////////////////////////////////////////////////// -// This file create unit test for some of the functions found in: -// ode/src/joint.cpp -// -// -//////////////////////////////////////////////////////////////////////////////// -#include <UnitTest++.h> -#include <ode/ode.h> -#include "../ode/src/joints/joints.h" - - -//////////////////////////////////////////////////////////////////////////////// -// Testing the Hinge2 Joint -// -SUITE(JointHinge2) -{ - - struct Hinge2GetInfo1_Fixture_1 { - Hinge2GetInfo1_Fixture_1() { - wId = dWorldCreate(); - - bId1 = dBodyCreate(wId); - dBodySetPosition(bId1, 0, -1, 0); - - bId2 = dBodyCreate(wId); - dBodySetPosition(bId2, 0, 1, 0); - - - jId = dJointCreateHinge2(wId, 0); - joint = (dxJointHinge2*)jId; - - dJointAttach(jId, bId1, bId2); - - dJointSetHinge2Anchor (jId, REAL(0.0), REAL(0.0), REAL(0.0)); - } - - ~Hinge2GetInfo1_Fixture_1() { - dWorldDestroy(wId); - } - - dJointID jId; - dxJointHinge2* joint; - - dWorldID wId; - - dBodyID bId1; - dBodyID bId2; - - dxJoint::Info1 info; - }; - -TEST_FIXTURE(Hinge2GetInfo1_Fixture_1, test_hinge2GetInfo1) -{ - // ^Y - // |---| HiStop - // | | ^Y / - // |B_2| | / - // |---| | / - // | ----- | / - // Z <-- * Z<--|B_2|--* - // / | \ ----- | \ - // /|---|\ |---| \ - // / | | \ | | \ - // / |B_1| \ |B_1| \ - // / |---| \ |---| \ - //LoStop HiStop LoStop - // - // - // - // - dMatrix3 R; - - dJointSetHinge2Param(jId, dParamLoStop, -M_PI/4.0); - dJointSetHinge2Param(jId, dParamHiStop, M_PI/4.0); - - dxJoint::Info1 info; - - - dxJointHinge2* joint = (dxJointHinge2*)jId; - - // Original position inside the limits - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot1.limit); - CHECK_EQUAL(4, info.m); - - // Move the body outside the Lo limits - dBodySetPosition (bId2, 0, 0, 1); - dRFromAxisAndAngle (R, 1, 0, 0, M_PI/2.0); - dBodySetRotation (bId2, R); - joint->getInfo1(&info); - CHECK_EQUAL(1, joint->limot1.limit); - CHECK_EQUAL(5, info.m); - - - // Return to original position - // Keep the limits - dBodySetPosition (bId2, 0, 1, 0); - dRFromAxisAndAngle (R, 1, REAL(0.0), REAL(0.0), REAL(0.0)); - dBodySetRotation (bId2, R); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot1.limit); - CHECK_EQUAL(4, info.m); - - - // Move the body outside the Lo limits - dBodySetPosition (bId2, 0, 0, 1); - dRFromAxisAndAngle (R, 1, 0, 0, M_PI/2.0); - dBodySetRotation (bId2, R); - joint->getInfo1(&info); - CHECK_EQUAL(1, joint->limot1.limit); - CHECK_EQUAL(5, info.m); - - - - // Return to original position - // and remove the limits - dBodySetPosition (bId2, 0, 1, 0); - dRFromAxisAndAngle (R, 1, REAL(0.0), REAL(0.0), REAL(0.0)); - dBodySetRotation (bId2, R); - dJointSetHinge2Param(jId, dParamLoStop, -2*M_PI); - dJointSetHinge2Param(jId, dParamHiStop, 2*M_PI); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot1.limit); - CHECK_EQUAL(4, info.m); - - - // Set the limits - // Move pass the Hi limits - dJointSetHinge2Param(jId, dParamLoStop, -M_PI/4.0); - dJointSetHinge2Param(jId, dParamHiStop, M_PI/4.0); - dBodySetPosition (bId2, 0, 0, 1); - dRFromAxisAndAngle (R, 1, 0, 0, -M_PI/2.0); - dBodySetRotation (bId2, R); - joint->getInfo1(&info); - CHECK_EQUAL(2, joint->limot1.limit); - CHECK_EQUAL(5, info.m); - - - // Return to original position - // Keep the limits - dBodySetPosition (bId2, 0, 1, 0); - dRFromAxisAndAngle (R, 1, REAL(0.0), REAL(0.0), REAL(0.0)); - dBodySetRotation (bId2, R); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot1.limit); - CHECK_EQUAL(4, info.m); - - - // Move the pass the Hi limit - dBodySetPosition (bId2, 0, 0, 1); - dRFromAxisAndAngle (R, 1, 0, 0, -M_PI/2.0); - dBodySetRotation (bId2, R); - joint->getInfo1(&info); - CHECK_EQUAL(2, joint->limot1.limit); - CHECK_EQUAL(5, info.m); - - - // Return to original position - // and remove the limits - dBodySetPosition (bId2, 0, 1, 0); - dRFromAxisAndAngle (R, 1, 0, 0, -M_PI/2.0); - dBodySetRotation (bId2, R); - dJointSetHinge2Param(jId, dParamLoStop, -2*M_PI); - dJointSetHinge2Param(jId, dParamHiStop, 2*M_PI); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot1.limit); - CHECK_EQUAL(4, info.m); - - - /// Motorize the first joint angle - dJointSetHinge2Param(jId, dParamFMax, 2); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot1.limit); - CHECK_EQUAL(5, info.m); - - - /// Motorize the second joint angle - dJointSetHinge2Param(jId, dParamFMax2, 2); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot1.limit); - CHECK_EQUAL(6, info.m); - - /// Unmotorize the first joint angle - dJointSetHinge2Param(jId, dParamFMax, 0); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot1.limit); - CHECK_EQUAL(5, info.m); -} -} // End of SUITE(JointHinge2) - - -//////////////////////////////////////////////////////////////////////////////// -// Testing the Universal Joint -// -SUITE(JointUniversal) -{ - - struct UniversalGetInfo1_Fixture_1 { - UniversalGetInfo1_Fixture_1() { - wId = dWorldCreate(); - - bId1 = dBodyCreate(wId); - dBodySetPosition(bId1, 0, -1, 0); - - bId2 = dBodyCreate(wId); - dBodySetPosition(bId2, 0, 1, 0); - - - jId = dJointCreateUniversal(wId, 0); - joint = (dxJointUniversal*)jId; - - dJointAttach(jId, bId1, bId2); - - dJointSetUniversalAnchor (jId, REAL(0.0), REAL(0.0), REAL(0.0)); - } - - ~UniversalGetInfo1_Fixture_1() { - dWorldDestroy(wId); - } - - dJointID jId; - dxJointUniversal* joint; - - dWorldID wId; - - dBodyID bId1; - dBodyID bId2; - - dxJoint::Info1 info; - }; - -TEST_FIXTURE(UniversalGetInfo1_Fixture_1, test_hinge2GetInfo1_RotAroundX) -{ - // ^Y - // |---| HiStop - // | | ^Y / - // |B_2| | / - // |---| | / - // | ----- | / - // Z <-- * Z<--|B_2|--* - // / | \ ----- | \ - // /|---|\ |---| \ - // / | | \ | | \ - // / |B_1| \ |B_1| \ - // / |---| \ |---| \ - //LoStop HiStop LoStop - // - // - // - // - dMatrix3 R; - - dJointSetUniversalParam(jId, dParamLoStop, -M_PI/4.0); - dJointSetUniversalParam(jId, dParamHiStop, M_PI/4.0); - dJointSetUniversalParam(jId, dParamLoStop2, -M_PI/4.0); - dJointSetUniversalParam(jId, dParamHiStop2, M_PI/4.0); - - dxJoint::Info1 info; - - - dxJointUniversal* joint = (dxJointUniversal*)jId; - - // Original position inside the limits - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot1.limit); - CHECK_EQUAL(4, info.m); - - // Move the body outside the Lo limits - dBodySetPosition (bId2, 0, 0, 1); - dRFromAxisAndAngle (R, 1, 0, 0, M_PI/2.0); - dBodySetRotation (bId2, R); - joint->getInfo1(&info); - CHECK_EQUAL(1, joint->limot1.limit); - CHECK_EQUAL(5, info.m); - - - // Return to original position - // Keep the limits - dBodySetPosition (bId2, 0, 1, 0); - dRFromAxisAndAngle (R, 1, REAL(0.0), REAL(0.0), REAL(0.0)); - dBodySetRotation (bId2, R); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot1.limit); - CHECK_EQUAL(4, info.m); - - - // Move the body outside the Lo limits - dBodySetPosition (bId2, 0, 0, 1); - dRFromAxisAndAngle (R, 1, 0, 0, M_PI/2.0); - dBodySetRotation (bId2, R); - joint->getInfo1(&info); - CHECK_EQUAL(1, joint->limot1.limit); - CHECK_EQUAL(5, info.m); - - - - // Return to original position - // and remove the limits - dBodySetPosition (bId2, 0, 1, 0); - dRFromAxisAndAngle (R, 1, REAL(0.0), REAL(0.0), REAL(0.0)); - dBodySetRotation (bId2, R); - dJointSetUniversalParam(jId, dParamLoStop, -2*M_PI); - dJointSetUniversalParam(jId, dParamHiStop, 2*M_PI); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot1.limit); - CHECK_EQUAL(4, info.m); - - - // Set the limits - // Move pass the Hi limits - dJointSetUniversalParam(jId, dParamLoStop, -M_PI/4.0); - dJointSetUniversalParam(jId, dParamHiStop, M_PI/4.0); - dBodySetPosition (bId2, 0, 0, 1); - dRFromAxisAndAngle (R, 1, 0, 0, -M_PI/2.0); - dBodySetRotation (bId2, R); - joint->getInfo1(&info); - CHECK_EQUAL(2, joint->limot1.limit); - CHECK_EQUAL(5, info.m); - - - // Return to original position - // Keep the limits - dBodySetPosition (bId2, 0, 1, 0); - dRFromAxisAndAngle (R, 1, REAL(0.0), REAL(0.0), REAL(0.0)); - dBodySetRotation (bId2, R); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot1.limit); - CHECK_EQUAL(4, info.m); - - - // Move the pass the Hi limit - dBodySetPosition (bId2, 0, 0, 1); - dRFromAxisAndAngle (R, 1, 0, 0, -M_PI/2.0); - dBodySetRotation (bId2, R); - joint->getInfo1(&info); - CHECK_EQUAL(2, joint->limot1.limit); - CHECK_EQUAL(5, info.m); - - - // Return to original position - // and remove the limits - dBodySetPosition (bId2, 0, 1, 0); - dRFromAxisAndAngle (R, 1, 0, 0, -M_PI/2.0); - dBodySetRotation (bId2, R); - dJointSetUniversalParam(jId, dParamLoStop, -2*M_PI); - dJointSetUniversalParam(jId, dParamHiStop, 2*M_PI); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot1.limit); - CHECK_EQUAL(4, info.m); - - - /// Motorize the first joint angle - dJointSetUniversalParam(jId, dParamFMax, 2); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot1.limit); - CHECK_EQUAL(5, info.m); - - - /// Motorize the second joint angle - dJointSetUniversalParam(jId, dParamFMax2, 2); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot1.limit); - CHECK_EQUAL(6, info.m); - - /// Unmotorize the first joint angle - dJointSetUniversalParam(jId, dParamFMax, 0); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot1.limit); - CHECK_EQUAL(5, info.m); -} - -TEST_FIXTURE(UniversalGetInfo1_Fixture_1, test_hinge2GetInfo1_RotAroundY) -{ - // ^Y - // |---| HiStop - // | | ^Y / - // |B_2| | / - // |---| | / - // | ----- | / - // Z <-- * Z<--|B_2|--* - // / | \ ----- | \ - // /|---|\ |---| \ - // / | | \ | | \ - // / |B_1| \ |B_1| \ - // / |---| \ |---| \ - //LoStop HiStop LoStop - // - // - // - // - dMatrix3 R; - - dJointSetUniversalParam(jId, dParamLoStop, -M_PI/4.0); - dJointSetUniversalParam(jId, dParamHiStop, M_PI/4.0); - dJointSetUniversalParam(jId, dParamLoStop2, -M_PI/4.0); - dJointSetUniversalParam(jId, dParamHiStop2, M_PI/4.0); - - dxJoint::Info1 info; - - - dxJointUniversal* joint = (dxJointUniversal*)jId; - - // Original position inside the limits - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot1.limit); - CHECK_EQUAL(4, info.m); - - // Move the body outside the Lo limits - dBodySetPosition (bId2, 0, 0, 1); - dRFromAxisAndAngle (R, 0, 1, 0, M_PI/2.0); - dBodySetRotation (bId2, R); - joint->getInfo1(&info); - CHECK_EQUAL(1, joint->limot2.limit); - CHECK_EQUAL(5, info.m); - - - // Return to original position - // Keep the limits - dBodySetPosition (bId2, 0, 1, 0); - dRFromAxisAndAngle (R, 0, 1, 0, 0); - dBodySetRotation (bId2, R); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot2.limit); - CHECK_EQUAL(4, info.m); - - - // Move the body outside the Lo limits - dBodySetPosition (bId2, 0, 0, 1); - dRFromAxisAndAngle (R, 0, 1, 0, M_PI/2.0); - dBodySetRotation (bId2, R); - joint->getInfo1(&info); - CHECK_EQUAL(1, joint->limot2.limit); - CHECK_EQUAL(5, info.m); - - - - // Return to original position - // and remove the limits - dBodySetPosition (bId2, 0, 1, 0); - dRFromAxisAndAngle (R, 0, 1, 0, 0); - dBodySetRotation (bId2, R); - dJointSetUniversalParam(jId, dParamLoStop2, -2*M_PI); - dJointSetUniversalParam(jId, dParamHiStop2, 2*M_PI); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot2.limit); - CHECK_EQUAL(4, info.m); - - - // Set the limits - // Move pass the Hi limits - dJointSetUniversalParam(jId, dParamLoStop2, -M_PI/4.0); - dJointSetUniversalParam(jId, dParamHiStop2, M_PI/4.0); - dBodySetPosition (bId2, 0, 0, 1); - dRFromAxisAndAngle (R, 0, 1, 0, -M_PI/2.0); - dBodySetRotation (bId2, R); - joint->getInfo1(&info); - CHECK_EQUAL(2, joint->limot2.limit); - CHECK_EQUAL(5, info.m); - - - // Return to original position - // Keep the limits - dBodySetPosition (bId2, 0, 1, 0); - dRFromAxisAndAngle (R, 0, 1, 0, 0); - dBodySetRotation (bId2, R); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot2.limit); - CHECK_EQUAL(4, info.m); - - - // Move the pass the Hi limit - dBodySetPosition (bId2, 0, 0, 1); - dRFromAxisAndAngle (R, 0, 1, 0, -M_PI/2.0); - dBodySetRotation (bId2, R); - joint->getInfo1(&info); - CHECK_EQUAL(2, joint->limot2.limit); - CHECK_EQUAL(5, info.m); - - - // Return to original position - // and remove the limits - dBodySetPosition (bId2, 0, 1, 0); - dRFromAxisAndAngle (R, 0, 1, 0, -M_PI/2.0); - dBodySetRotation (bId2, R); - dJointSetUniversalParam(jId, dParamLoStop2, -2*M_PI); - dJointSetUniversalParam(jId, dParamHiStop2, 2*M_PI); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot2.limit); - CHECK_EQUAL(4, info.m); - - - /// Motorize the first joint angle - dJointSetUniversalParam(jId, dParamFMax, 2); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot2.limit); - CHECK_EQUAL(5, info.m); - - - /// Motorize the second joint angle - dJointSetUniversalParam(jId, dParamFMax2, 2); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot2.limit); - CHECK_EQUAL(6, info.m); - - /// Unmotorize the first joint angle - dJointSetUniversalParam(jId, dParamFMax, 0); - joint->getInfo1(&info); - CHECK_EQUAL(0, joint->limot2.limit); - CHECK_EQUAL(5, info.m); -} -} // End of SUITE(JointUniversal) - - - -// // // -// Testing the PR Joint -// -SUITE(JointPR) -{ - struct PRGetInfo1_Fixture_1 { - PRGetInfo1_Fixture_1() { - wId = dWorldCreate(); - - bId1 = dBodyCreate(wId); - dBodySetPosition(bId1, 0, -1, 0); - - bId2 = dBodyCreate(wId); - dBodySetPosition(bId2, 0, 1, 0); - - - jId = dJointCreatePR(wId, 0); - joint = (dxJointPR*)jId; - - dJointAttach(jId, bId1, bId2); - - dJointSetPRAnchor (jId, REAL(0.0), REAL(0.0), REAL(0.0)); - } - - ~PRGetInfo1_Fixture_1() { - dWorldDestroy(wId); - } - - dJointID jId; - dxJointPR* joint; - - dWorldID wId; - - dBodyID bId1; - dBodyID bId2; - - dxJoint::Info1 info; - }; - - -//////////////////////////////////////////////////////////////////////////////// -// Test when there is no limits. -// The 2 bodies stay aligned. -// -// Default value for axisR1 = 1,0,0 -// Default value for axisP1 = 0,1,0 -//////////////////////////////////////////////////////////////////////////////// - TEST_FIXTURE(PRGetInfo1_Fixture_1, test1_PRGetInfo1_) - { - dJointSetPRParam(jId, dParamLoStop, -dInfinity); - dJointSetPRParam(jId, dParamHiStop, dInfinity); - dJointSetPRParam(jId, dParamLoStop2, -M_PI); - dJointSetPRParam(jId, dParamHiStop2, M_PI); - - joint->getInfo1(&info); - - CHECK_EQUAL(0, joint->limotP.limit); - CHECK_EQUAL(0, joint->limotR.limit); - CHECK_EQUAL(4, info.m); - } - - -//////////////////////////////////////////////////////////////////////////////// -// Test when there is limits for the prismatic at -10 and 10 -// The Body 2 is moved -100 unit then at 100 -// -// Default value for axisR1 = 1,0,0 -// Default value for axisP1 = 0,1,0 -//////////////////////////////////////////////////////////////////////////////// - TEST_FIXTURE(PRGetInfo1_Fixture_1, test2_PRGetInfo1) - { - dJointSetPRParam(jId, dParamLoStop, -10); - dJointSetPRParam(jId, dParamHiStop, 10); - dJointSetPRParam(jId, dParamLoStop2, -M_PI); - dJointSetPRParam(jId, dParamHiStop2, M_PI); - - - dBodySetPosition(bId2, 0, -100, 0); - - joint->getInfo1(&info); - - CHECK_EQUAL(2, joint->limotP.limit); - CHECK_EQUAL(0, joint->limotR.limit); - CHECK_EQUAL(5, info.m); - - - dBodySetPosition(bId2, 0, 100, 0); - - joint->getInfo1(&info); - - CHECK_EQUAL(1, joint->limotP.limit); - CHECK_EQUAL(0, joint->limotR.limit); - CHECK_EQUAL(5, info.m); - - // Reset Position and test - dBodySetPosition(bId2, 0, 1, 0); - dMatrix3 R_final = { 1,0,0,0, - 0,1,0,0, - 0,0,1,0 }; - dBodySetRotation (bId2, R_final); - - joint->getInfo1(&info); - - CHECK_EQUAL(0, joint->limotP.limit); - CHECK_EQUAL(0, joint->limotR.limit); - CHECK_EQUAL(4, info.m); - } - -//////////////////////////////////////////////////////////////////////////////// -// Test when there is limits for the prismatic at -10 and 10 -// and for the rotoide at -45deg and 45deg. -// The Body 2 is only rotated by 90deg since the rotoide limits are not -// used this should not change the limit value. -// -// Default value for axisR1 = 1,0,0 -// Default value for axisP1 = 0,1,0 -// -//////////////////////////////////////////////////////////////////////////////// - TEST_FIXTURE(PRGetInfo1_Fixture_1, test3_PRGetInfo1) - { - dJointSetPRParam(jId, dParamLoStop, -10); - dJointSetPRParam(jId, dParamHiStop, 10); - dJointSetPRParam(jId, dParamLoStop2, -M_PI/4.0); - dJointSetPRParam(jId, dParamHiStop2, M_PI/4.0); - - - dMatrix3 R; - dBodySetPosition (bId2, 0, 0, 1); - dRFromAxisAndAngle (R, 1, 0, 0, M_PI/2.0); - dBodySetRotation (bId2, R); - - joint->getInfo1(&info); - - CHECK_EQUAL(0, joint->limotP.limit); - CHECK_EQUAL(0, joint->limotR.limit); - CHECK_EQUAL(4, info.m); - - // Reset Position and test - dBodySetPosition(bId2, 0, 1, 0); - dMatrix3 R_final = { 1,0,0,0, - 0,1,0,0, - 0,0,1,0 }; - dBodySetRotation (bId2, R_final); - - joint->getInfo1(&info); - - CHECK_EQUAL(0, joint->limotP.limit); - CHECK_EQUAL(0, joint->limotR.limit); - CHECK_EQUAL(4, info.m); - } - - -// The joint is now powered. (i.e. info->fmax > 0 - struct PRGetInfo1_Fixture_2 { - PRGetInfo1_Fixture_2() { - wId = dWorldCreate(); - - bId1 = dBodyCreate(wId); - dBodySetPosition(bId1, 0, -1, 0); - - bId2 = dBodyCreate(wId); - dBodySetPosition(bId2, 0, 1, 0); - - - jId = dJointCreatePR(wId, 0); - joint = (dxJointPR*)jId; - - dJointAttach(jId, bId1, bId2); - dJointSetPRAnchor (jId, REAL(0.0), REAL(0.0), REAL(0.0)); - - joint->limotP.fmax = 1; - } - - ~PRGetInfo1_Fixture_2() { - dWorldDestroy(wId); - } - - dJointID jId; - dxJointPR* joint; - - dWorldID wId; - - dBodyID bId1; - dBodyID bId2; - - dxJoint::Info1 info; - }; - - - -//////////////////////////////////////////////////////////////////////////////// -// Test when there is no limits. -// The 2 bodies stay align. -// -// Default value for axisR1 = 1,0,0 -// Default value for axisP1 = 0,1,0 -// -//////////////////////////////////////////////////////////////////////////////// - TEST_FIXTURE(PRGetInfo1_Fixture_2, test1_PRGetInfo1) - { - dJointSetPRParam(jId, dParamLoStop, -dInfinity); - dJointSetPRParam(jId, dParamHiStop, dInfinity); - dJointSetPRParam(jId, dParamLoStop2, -M_PI); - dJointSetPRParam(jId, dParamHiStop2, M_PI); - - joint->getInfo1(&info); - - CHECK_EQUAL(0, joint->limotP.limit); - CHECK_EQUAL(0, joint->limotR.limit); - CHECK_EQUAL(5, info.m); - } - - -//////////////////////////////////////////////////////////////////////////////// -// Test when there is limits for the prismatic at -10 and 10 -// The Body 2 is moved -100 unit then at 100 -// -// Default value for axisR1 = 1,0,0 -// Default value for axisP1 = 0,1,0 -// -//////////////////////////////////////////////////////////////////////////////// - TEST_FIXTURE(PRGetInfo1_Fixture_2, test2_PRGetInfo1) - { - - dJointSetPRParam(jId, dParamLoStop, -10); - dJointSetPRParam(jId, dParamHiStop, 10); - dJointSetPRParam(jId, dParamLoStop2, -M_PI); - dJointSetPRParam(jId, dParamHiStop2, M_PI); - - - dBodySetPosition(bId2, 0, -100, 0); - - joint->getInfo1(&info); - - CHECK_EQUAL(2, joint->limotP.limit); - CHECK_EQUAL(0, joint->limotR.limit); - CHECK_EQUAL(5, info.m); - - - dBodySetPosition(bId2, 0, 100, 0); - - joint->getInfo1(&info); - - CHECK_EQUAL(1, joint->limotP.limit); - CHECK_EQUAL(0, joint->limotR.limit); - CHECK_EQUAL(5, info.m); - - // Reset Position and test - dBodySetPosition(bId2, 0, 1, 0); - dMatrix3 R_final = { 1,0,0,0, - 0,1,0,0, - 0,0,1,0 }; - dBodySetRotation (bId2, R_final); - - joint->getInfo1(&info); - - CHECK_EQUAL(0, joint->limotP.limit); - CHECK_EQUAL(0, joint->limotR.limit); - CHECK_EQUAL(5, info.m); - } - -//////////////////////////////////////////////////////////////////////////////// -// Test when there is limits for the prismatic at -10 and 10 -// and for the rotoide at -45deg and 45deg -// The Body 2 is only rotated by 90deg since the rotoide limits are not -// used this should not change the limit value. -// -// Default value for axisR1 = 1,0,0 -// Default value for axisP1 = 0,1,0 -// -//////////////////////////////////////////////////////////////////////////////// - TEST_FIXTURE(PRGetInfo1_Fixture_2, test3_PRGetInfo1) - { - - dJointSetPRParam(jId, dParamLoStop, -10); - dJointSetPRParam(jId, dParamHiStop, 10); - dJointSetPRParam(jId, dParamLoStop2, -M_PI/4.0); - dJointSetPRParam(jId, dParamHiStop2, M_PI/4.0); - - - dMatrix3 R; - dBodySetPosition (bId2, 0, 0, 100); - dRFromAxisAndAngle (R, 1, 0, 0, M_PI/2.0); - dBodySetRotation (bId2, R); - - joint->getInfo1(&info); - - CHECK_EQUAL(0, joint->limotP.limit); - CHECK_EQUAL(0, joint->limotR.limit); - CHECK_EQUAL(5, info.m); - - // Reset Position and test - dBodySetPosition(bId2, 0, 1, 0); - dMatrix3 R_final = { 1,0,0,0, - 0,1,0,0, - 0,0,1,0 }; - dBodySetRotation (bId2, R_final); - - joint->getInfo1(&info); - - CHECK_EQUAL(0, joint->limotP.limit); - CHECK_EQUAL(0, joint->limotR.limit); - CHECK_EQUAL(5, info.m); - } - - -//////////////////////////////////////////////////////////////////////////////// -// Test the setting and getting of parameters -//////////////////////////////////////////////////////////////////////////////// - TEST_FIXTURE(PRGetInfo1_Fixture_1, test_SetPRParam) - { - dJointSetPRParam(jId, dParamHiStop, REAL(5.0) ); - CHECK_EQUAL(REAL(5.0), joint->limotP.histop); - - dJointSetPRParam(jId, dParamVel, REAL(7.0) ); - CHECK_EQUAL(REAL(7.0), joint->limotP.vel); - -#ifdef dParamFudgeFactor1 - dJointSetPRParam(jId, dParamFudgeFactor1, REAL(5.5) ); - CHECK_EQUAL(REAL(5.5), joint->limotP.dParamFudgeFactor); -#endif - - dJointSetPRParam(jId, dParamCFM2, REAL(9.0) ); - CHECK_EQUAL(REAL(9.0), joint->limotR.normal_cfm); - - dJointSetPRParam(jId, dParamStopERP2, REAL(11.0) ); - CHECK_EQUAL(REAL(11.0), joint->limotR.stop_erp); - } - - TEST_FIXTURE(PRGetInfo1_Fixture_1, test_GetPRParam) - { - joint->limotP.histop = REAL(5.0); - CHECK_EQUAL(joint->limotP.histop, - dJointGetPRParam(jId, dParamHiStop) ); - - joint->limotP.vel = REAL(7.0); - - CHECK_EQUAL(joint->limotP.vel, - dJointGetPRParam(jId, dParamVel) ); - -#ifdef dParamFudgeFactor1 - joint->limotP.dParamFudgeFactor = REAL(5.5); - - CHECK_EQUAL(joint->limotP.dParamFudgeFactor, - dJointGetPRParam(jId, dParamFudgeFactor1) ); -#endif - - joint->limotR.normal_cfm = REAL(9.0); - CHECK_EQUAL(joint->limotR.normal_cfm, - dJointGetPRParam(jId, dParamCFM2) ); - - joint->limotR.stop_erp = REAL(11.0); - CHECK_EQUAL(joint->limotR.stop_erp, - dJointGetPRParam(jId, dParamStopERP2) ); - } - - - -//////////////////////////////////////////////////////////////////////////////// -// Fixture for testing the PositionRate -// -// Default Position -// ^Z -// | -// | -// -// Body2 R Body1 -// +---------+ _ - +-----------+ -// | |--------(_)----|-----| | ----->Y -// +---------+ - +-----------+ -// -// N.B. X is comming out of the page -//////////////////////////////////////////////////////////////////////////////// - struct PRGetInfo1_Fixture_3 { - PRGetInfo1_Fixture_3() { - wId = dWorldCreate(); - - bId1 = dBodyCreate(wId); - dBodySetPosition(bId1, 0, 1, 0); - - bId2 = dBodyCreate(wId); - dBodySetPosition(bId2, 0, -1, 0); - - - jId = dJointCreatePR(wId, 0); - joint = (dxJointPR*)jId; - - dJointAttach(jId, bId1, bId2); - dJointSetPRAnchor (jId, REAL(0.0), REAL(0.0), REAL(0.0)); - - dBodySetLinearVel (bId1, REAL(0.0), REAL(0.0), REAL(0.0)); - dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0)); - - dBodySetLinearVel (bId2, REAL(0.0), REAL(0.0), REAL(0.0)); - dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0)); - - } - - ~PRGetInfo1_Fixture_3() { - dWorldDestroy(wId); - } - - dJointID jId; - dxJointPR* joint; - - dWorldID wId; - - dBodyID bId1; - dBodyID bId2; - - dxJoint::Info1 info; - }; - -//////////////////////////////////////////////////////////////////////////////// -// Position Body1 [0, 1, 0] -// Position Body2 [0, -1, 0] -// Axis of the prismatic [0, 1, 0] -// Axis of the rotoide [1, 0, ]0 -// -// Move at the same speed -//////////////////////////////////////////////////////////////////////////////// - TEST_FIXTURE(PRGetInfo1_Fixture_3, test_GetPRPositionRate_1) - { - // They move with the same linear speed - // Angular speed == 0 - dBodySetLinearVel(bId1, REAL(0.0), REAL(3.33), REAL(0.0)); - dBodySetLinearVel(bId2, REAL(0.0), REAL(3.33), REAL(0.0)); - CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) ); - - dBodySetLinearVel(bId1, REAL(1.11), REAL(3.33), REAL(0.0)); - dBodySetLinearVel(bId2, REAL(1.11), REAL(3.33), REAL(0.0)); - CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) ); - - dBodySetLinearVel(bId1, REAL(1.11), REAL(3.33), REAL(2.22)); - dBodySetLinearVel(bId2, REAL(1.11), REAL(3.33), REAL(2.22)); - CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) ); - - - // Reset for the next set of test. - dBodySetLinearVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0)); - dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0)); - - dBodySetLinearVel(bId2, REAL(0.0), REAL(0.0), REAL(0.0)); - dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0)); - - - // They move with the same angular speed - // linear speed == 0 - - dBodySetAngularVel(bId1, REAL(1.22), REAL(0.0), REAL(0.0)); - dBodySetAngularVel(bId2, REAL(1.22), REAL(0.0), REAL(0.0)); - CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) ); - - dBodySetAngularVel(bId1, REAL(1.22), REAL(2.33), REAL(0.0)); - dBodySetAngularVel(bId2, REAL(1.22), REAL(2.33), REAL(0.0)); - CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) ); - - dBodySetAngularVel(bId1, REAL(1.22), REAL(2.33), REAL(3.44)); - dBodySetAngularVel(bId2, REAL(1.22), REAL(2.33), REAL(3.44)); - CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) ); - } - - -//////////////////////////////////////////////////////////////////////////////// -// Position Body1 [0, 1, 0] -// Position Body2 [0, -1, 0] -// Axis of the prismatic [0, 1, 0] -// Axis of the rotoide [1, 0, ]0 -// -// Only the first body moves -//////////////////////////////////////////////////////////////////////////////// - TEST_FIXTURE(PRGetInfo1_Fixture_3, GetPRPositionRate_Bodies_in_line_B1_moves) - { - dBodySetLinearVel(bId1, REAL(3.33), REAL(0.0), REAL(0.0)); // This is impossible but ... - CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) ); - - dBodySetLinearVel(bId1, REAL(0.0), REAL(3.33), REAL(0.0)); - CHECK_EQUAL(REAL(3.33), dJointGetPRPositionRate (jId) ); - - dBodySetLinearVel(bId1, REAL(0.0), REAL(0.0), REAL(3.33)); // This is impossible but ... - CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) ); - - - // Only the first body as angular velocity - dBodySetAngularVel(bId1, REAL(1.22), REAL(0.0), REAL(0.0)); - CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) ); - - dBodySetAngularVel(bId1, REAL(0.0), REAL(2.33), REAL(0.0)); - CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) ); - - dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(5.55)); - CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) ); - } - -//////////////////////////////////////////////////////////////////////////////// -// Position Body1 [0, 1, 0] -// Position Body2 [0, -1, 0] -// Axis of the prismatic [0, 1, 0] -// Axis of the rotoide [1, 0, ]0 -// -// Only the second body moves -//////////////////////////////////////////////////////////////////////////////// - TEST_FIXTURE(PRGetInfo1_Fixture_3, GetPRPositionRate_Bodies_in_line_B2_moves) - { - dBodySetLinearVel(bId2, REAL(3.33), REAL(0.0), REAL(0.0)); // This is impossible but ... - CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) ); - - // The length was at zero and this will give an negative length - dBodySetLinearVel(bId2, REAL(0.0), REAL(3.33), REAL(0.0)); - CHECK_EQUAL(REAL(-3.33), dJointGetPRPositionRate (jId) ); - - dBodySetLinearVel(bId2, REAL(0.0), REAL(0.0), REAL(3.33)); // This is impossible but ... - CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) ); - - - // Only angular velocity - dBodySetAngularVel(bId2, REAL(1.22), REAL(0.0), REAL(0.0)); - CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) ); - - dBodySetAngularVel(bId2, REAL(0.0), REAL(2.33), REAL(0.0)); - CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) ); - - dBodySetAngularVel(bId2, REAL(0.0), REAL(0.0), REAL(5.55)); - CHECK_EQUAL(REAL(0.0), dJointGetPRPositionRate (jId) ); - } - - -//////////////////////////////////////////////////////////////////////////////// -// Fixture for testing the PositionRate -// -// The second body is at 90deg w.r.t. the first body -// -// -// Default Position -// ^Z -// | -// | -// -// +---+ -// | |Body2 -// | | -// | | -// +---+ -// | -// | -// | -// | Body1 -// R _ - +-----------+ -// (_)----|-----| | ----->Y -// - +-----------+ -// -// N.B. X is comming out of the page -//////////////////////////////////////////////////////////////////////////////// - struct PRGetInfo1_Fixture_4 { - PRGetInfo1_Fixture_4() { - wId = dWorldCreate(); - - bId1 = dBodyCreate(wId); - dBodySetPosition(bId1, 0, 1, 0); - - bId2 = dBodyCreate(wId); - dBodySetPosition(bId2, 0, 0, 1); - - dMatrix3 R; - dRFromAxisAndAngle (R, 1, 0, 0, -M_PI/2.0); - dBodySetRotation (bId2, R); - - - jId = dJointCreatePR(wId, 0); - joint = (dxJointPR*)jId; - - dJointAttach(jId, bId1, bId2); - dJointSetPRAnchor (jId, REAL(0.0), REAL(0.0), REAL(0.0)); - - dBodySetLinearVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0)); - dBodySetAngularVel(bId1, REAL(0.0), REAL(0.0), REAL(0.0)); -... [truncated message content] |
From: <pa...@us...> - 2008-10-15 19:23:02
|
Revision: 1562 http://opende.svn.sourceforge.net/opende/?rev=1562&view=rev Author: papaDoc Date: 2008-10-15 19:22:50 +0000 (Wed, 15 Oct 2008) Log Message: ----------- - Enable the motor on the rotoide part of the PR joint Modified Paths: -------------- trunk/CHANGELOG.txt trunk/ode/demo/demo_jointPR.cpp trunk/ode/src/joints/pr.cpp trunk/tests/joint.cpp Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2008-10-15 15:57:14 UTC (rev 1561) +++ trunk/CHANGELOG.txt 2008-10-15 19:22:50 UTC (rev 1562) @@ -9,6 +9,9 @@ ------------------------------------------------------------------------------ 10/15/08 Remi Ricard (papaDoc) + * Enable the motor on the Rotoide part of the PR joint + +10/15/08 Remi Ricard (papaDoc) * Add unit test to check if using directly a joint or using after setting with default values is the same. * Add function setRelativeValues called in dJointAttach for Modified: trunk/ode/demo/demo_jointPR.cpp =================================================================== --- trunk/ode/demo/demo_jointPR.cpp 2008-10-15 15:57:14 UTC (rev 1561) +++ trunk/ode/demo/demo_jointPR.cpp 2008-10-15 19:22:50 UTC (rev 1562) @@ -46,7 +46,7 @@ // physics parameters -#define BOX1_LENGTH 2 // Size along the X axis +#define BOX1_LENGTH 2 // Size along the X axis #define BOX1_WIDTH 1 // Size along the Y axis #define BOX1_HEIGHT 0.4 // Size along the Z axis (up) since gravity is (0,0,-10) #define BOX2_LENGTH 0.2 @@ -80,42 +80,48 @@ //collision detection static void nearCallback (void *data, dGeomID o1, dGeomID o2) { - int i,n; + int i,n; - dBodyID b1 = dGeomGetBody(o1); - dBodyID b2 = dGeomGetBody(o2); - if (b1 && b2 && dAreConnectedExcluding (b1,b2,dJointTypeContact)) return; - const int N = 10; - dContact contact[N]; - n = dCollide (o1,o2,N,&contact[0].geom,sizeof(dContact)); - if (n > 0) - { - for (i=0; i<n; i++) - { - contact[i].surface.mode = dContactSlip1 | dContactSlip2 | - dContactSoftERP | dContactSoftCFM | dContactApprox1; - contact[i].surface.mu = 0.1; - contact[i].surface.slip1 = 0.02; - contact[i].surface.slip2 = 0.02; - contact[i].surface.soft_erp = 0.1; - contact[i].surface.soft_cfm = 0.0001; - dJointID c = dJointCreateContact (world,contactgroup,&contact[i]); - dJointAttach (c,dGeomGetBody(contact[i].geom.g1),dGeomGetBody(contact[i].geom.g2)); - } - } + dBodyID b1 = dGeomGetBody(o1); + dBodyID b2 = dGeomGetBody(o2); + if (b1 && b2 && dAreConnectedExcluding (b1,b2,dJointTypeContact)) return; + const int N = 10; + dContact contact[N]; + n = dCollide (o1,o2,N,&contact[0].geom,sizeof(dContact)); + if (n > 0) + { + for (i=0; i<n; i++) + { + contact[i].surface.mode = dContactSlip1 | dContactSlip2 | + dContactSoftERP | dContactSoftCFM | dContactApprox1; + contact[i].surface.mu = 0.1; + contact[i].surface.slip1 = 0.02; + contact[i].surface.slip2 = 0.02; + contact[i].surface.soft_erp = 0.1; + contact[i].surface.soft_cfm = 0.0001; + dJointID c = dJointCreateContact (world,contactgroup,&contact[i]); + dJointAttach (c,dGeomGetBody(contact[i].geom.g1),dGeomGetBody(contact[i].geom.g2)); + } + } } // start simulation - set viewpoint static void start() { - dAllocateODEDataForThread(dAllocateMaskAll); + dAllocateODEDataForThread(dAllocateMaskAll); - dsSetViewpoint (xyz,hpr); - printf ("Press 'd' to add force along positive x direction.\nPress 'a' to add force along negative x direction.\n"); - printf ("Press 'w' to add force along positive y direction.\nPress 's' to add force along negative y direction.\n"); - printf ("Press 'e' to add torque around positive z direction.\nPress 'q' to add torque around negative z direction.\n"); - printf ("Press 'o' to add force around positive x direction \n"); + dsSetViewpoint (xyz,hpr); + printf ("Press 'd' to add force along positive x direction.\nPress 'a' to add force along negative x direction.\n"); + printf ("Press 'w' to add force along positive y direction.\nPress 's' to add force along negative y direction.\n"); + printf ("Press 'e' to add torque around positive z direction.\nPress 'q' to add torque around negative z direction.\n"); + printf ("Press 'o' to add force around positive x direction \n"); + + printf("Press 'v' to give a defined velocity and add a FMax to the rotoide axis\n"); + printf("Press 'c' to set the velocity to zero and remove the FMax\n"); + + printf("Press 'l' to add limits (-0.5 to 0.5rad) on the rotoide axis\n"); + printf("Press 'k' to remove the limits on the rotoide axis\n"); } // function to update camera position at each step. @@ -136,245 +142,277 @@ // called when a key pressed static void command (int cmd) { - switch(cmd) - { - case 'w': case 'W': - dBodyAddForce(box2_body[0],0,500,0); - std::cout<<(dBodyGetPosition(box2_body[0])[1]-dBodyGetPosition(box1_body[0])[1])<<'\n'; - break; - case 's': case 'S': - dBodyAddForce(box2_body[0],0,-500,0); - std::cout<<(dBodyGetPosition(box2_body[0])[1]-dBodyGetPosition(box1_body[0])[1])<<'\n'; - break; - case 'd': case 'D': - dBodyAddForce(box2_body[0],500,0,0); - std::cout<<(dBodyGetPosition(box2_body[0])[0]-dBodyGetPosition(box1_body[0])[0])<<'\n'; - break; - case 'a': case 'A': - dBodyAddForce(box2_body[0],-500,0,0); - std::cout<<(dBodyGetPosition(box2_body[0])[0]-dBodyGetPosition(box1_body[0])[0])<<'\n'; - break; - case 'e': case 'E': - dBodyAddRelTorque(box2_body[0],0,0,200); - break; - case 'q': case 'Q': - dBodyAddRelTorque(box2_body[0],0,0,-200); - break; - case 'o': case 'O': - dBodyAddForce(box1_body[0],10000,0,0); - break; - } + switch (cmd) + { + case 'w': + case 'W': + dBodyAddForce(box2_body[0],0,500,0); + std::cout<<(dBodyGetPosition(box2_body[0])[1]-dBodyGetPosition(box1_body[0])[1])<<'\n'; + break; + case 's': + case 'S': + dBodyAddForce(box2_body[0],0,-500,0); + std::cout<<(dBodyGetPosition(box2_body[0])[1]-dBodyGetPosition(box1_body[0])[1])<<'\n'; + break; + case 'd': + case 'D': + dBodyAddForce(box2_body[0],500,0,0); + std::cout<<(dBodyGetPosition(box2_body[0])[0]-dBodyGetPosition(box1_body[0])[0])<<'\n'; + break; + case 'a': + case 'A': + dBodyAddForce(box2_body[0],-500,0,0); + std::cout<<(dBodyGetPosition(box2_body[0])[0]-dBodyGetPosition(box1_body[0])[0])<<'\n'; + break; + case 'e': + case 'E': + dBodyAddRelTorque(box2_body[0],0,0,200); + break; + case 'q': + case 'Q': + dBodyAddRelTorque(box2_body[0],0,0,-200); + break; + case 'o': + case 'O': + dBodyAddForce(box1_body[0],10000,0,0); + break; + + case 'v': + case 'V': + dJointSetPRParam(joint[0], dParamVel2, 2); + dJointSetPRParam(joint[0], dParamFMax2, 200); + break; + + case 'c': + case 'C': + dJointSetPRParam(joint[0], dParamVel2, 0); + dJointSetPRParam(joint[0], dParamFMax2, 0); + break; + + case 'l': + case 'L': + dJointSetPRParam(joint[0], dParamLoStop2, -0.5); + dJointSetPRParam(joint[0], dParamHiStop2, 0.5); + break; + + case 'k': + case 'K': + dJointSetPRParam(joint[0], dParamLoStop2, -dInfinity); + dJointSetPRParam(joint[0], dParamHiStop2, dInfinity); + break; + + } } // simulation loop static void simLoop (int pause) { - if (!pause) - { - //draw 2 boxes - dVector3 ss; - dsSetTexture (DS_WOOD); + if (!pause) + { + //draw 2 boxes + dVector3 ss; + dsSetTexture (DS_WOOD); - const dReal *posBox2 = dGeomGetPosition(box2[0]); - const dReal *rotBox2 = dGeomGetRotation(box2[0]); - dsSetColor (1,1,0); - dGeomBoxGetLengths (box2[0],ss); - dsDrawBox (posBox2, rotBox2, ss); + const dReal *posBox2 = dGeomGetPosition(box2[0]); + const dReal *rotBox2 = dGeomGetRotation(box2[0]); + dsSetColor (1,1,0); + dGeomBoxGetLengths (box2[0],ss); + dsDrawBox (posBox2, rotBox2, ss); - const dReal *posBox1 = dGeomGetPosition(box1[0]); - const dReal *rotBox1 = dGeomGetRotation(box1[0]); - dsSetColor (1,1,2); - dGeomBoxGetLengths (box1[0], ss); - dsDrawBox (posBox1, rotBox1, ss); + const dReal *posBox1 = dGeomGetPosition(box1[0]); + const dReal *rotBox1 = dGeomGetRotation(box1[0]); + dsSetColor (1,1,2); + dGeomBoxGetLengths (box1[0], ss); + dsDrawBox (posBox1, rotBox1, ss); - dVector3 anchorPos; - dJointGetPRAnchor (joint[0], anchorPos); + dVector3 anchorPos; + dJointGetPRAnchor (joint[0], anchorPos); - // Draw the axisP - if (ROTOIDE_ONLY != flag ) - { - dsSetColor (1,0,0); - dVector3 sizeP = {0, 0.1, 0.1}; - for (int i=0; i<3; ++i) - sizeP[0] += (anchorPos[i] - posBox1[i])*(anchorPos[i] - posBox1[i]); - sizeP[0] = sqrt(sizeP[0]); - dVector3 posAxisP; - for (int i=0; i<3; ++i) - posAxisP[i] = posBox1[i] + (anchorPos[i] - posBox1[i])/2.0; - dsDrawBox (posAxisP, rotBox1, sizeP); - } - + // Draw the axisP + if (ROTOIDE_ONLY != flag ) + { + dsSetColor (1,0,0); + dVector3 sizeP = {0, 0.1, 0.1}; + for (int i=0; i<3; ++i) + sizeP[0] += (anchorPos[i] - posBox1[i])*(anchorPos[i] - posBox1[i]); + sizeP[0] = sqrt(sizeP[0]); + dVector3 posAxisP; + for (int i=0; i<3; ++i) + posAxisP[i] = posBox1[i] + (anchorPos[i] - posBox1[i])/2.0; + dsDrawBox (posAxisP, rotBox1, sizeP); + } - // Draw the axisR - if (PRISMATIC_ONLY != flag ) - { - dsSetColor (0,1,0); - dVector3 sizeR = {0, 0.1, 0.1}; - for (int i=0; i<3; ++i) - sizeR[0] += (anchorPos[i] - posBox2[i])*(anchorPos[i] - posBox2[i]); - sizeR[0] = sqrt(sizeR[0]); - dVector3 posAxisR; - for (int i=0; i<3; ++i) - posAxisR[i] = posBox2[i] + (anchorPos[i] - posBox2[i])/2.0; - dsDrawBox (posAxisR, rotBox2, sizeR); - } - dSpaceCollide (space,0,&nearCallback); - dWorldQuickStep (world,0.0001); - update(); - dJointGroupEmpty (contactgroup); - } + // Draw the axisR + if (PRISMATIC_ONLY != flag ) + { + dsSetColor (0,1,0); + dVector3 sizeR = {0, 0.1, 0.1}; + for (int i=0; i<3; ++i) + sizeR[0] += (anchorPos[i] - posBox2[i])*(anchorPos[i] - posBox2[i]); + sizeR[0] = sqrt(sizeR[0]); + dVector3 posAxisR; + for (int i=0; i<3; ++i) + posAxisR[i] = posBox2[i] + (anchorPos[i] - posBox2[i])/2.0; + dsDrawBox (posAxisR, rotBox2, sizeR); + } + + dSpaceCollide (space,0,&nearCallback); + dWorldQuickStep (world,0.0001); + update(); + dJointGroupEmpty (contactgroup); + } } void Help(char **argv) { - printf("%s ", argv[0]); - printf(" -h | --help : print this help\n"); - printf(" -b | --both : Display how the complete joint works\n"); - printf(" Default behavior\n"); - printf(" -p | --prismatic-only : Display how the prismatic part works\n"); - printf(" The anchor pts is set at the center of body 2\n"); - printf(" -r | --rotoide-only : Display how the rotoide part works\n"); - printf(" The anchor pts is set at the center of body 1\n"); - printf(" -t | --texture-path path : Path to the texture.\n"); - printf(" Default = %s\n", DRAWSTUFF_TEXTURE_PATH); - printf("--------------------------------------------------\n"); - printf("Hit any key to continue:"); - getchar(); + printf("%s ", argv[0]); + printf(" -h | --help : print this help\n"); + printf(" -b | --both : Display how the complete joint works\n"); + printf(" Default behavior\n"); + printf(" -p | --prismatic-only : Display how the prismatic part works\n"); + printf(" The anchor pts is set at the center of body 2\n"); + printf(" -r | --rotoide-only : Display how the rotoide part works\n"); + printf(" The anchor pts is set at the center of body 1\n"); + printf(" -t | --texture-path path : Path to the texture.\n"); + printf(" Default = %s\n", DRAWSTUFF_TEXTURE_PATH); + printf("--------------------------------------------------\n"); + printf("Hit any key to continue:"); + getchar(); - exit(0); + exit(0); } int main (int argc, char **argv) { - // setup pointers to drawstuff callback functions - dsFunctions fn; - fn.version = DS_VERSION; - fn.start = &start; - fn.step = &simLoop; - fn.command = &command; - fn.stop = 0; - fn.path_to_textures = DRAWSTUFF_TEXTURE_PATH; - - if (argc >= 2 ) - { - for (int i=1; i < argc; ++i) + // setup pointers to drawstuff callback functions + dsFunctions fn; + fn.version = DS_VERSION; + fn.start = &start; + fn.step = &simLoop; + fn.command = &command; + fn.stop = 0; + fn.path_to_textures = DRAWSTUFF_TEXTURE_PATH; + + if (argc >= 2 ) { - if( 0 == strcmp("-h", argv[i]) || 0 == strcmp("--help", argv[i]) ) - Help(argv); - - if(!flag && (0 == strcmp("-p", argv[i]) ||0 == strcmp("--prismatic-only", argv[i])) ) - flag = PRISMATIC_ONLY; - - if(!flag && (0 == strcmp("-r", argv[i]) || 0 == strcmp("--rotoide-only", argv[i])) ) - flag = ROTOIDE_ONLY; - - if(0 == strcmp("-t", argv[i]) || 0 == strcmp("--texture-path", argv[i])) - { - int j = i+1; - if ( j+1 > argc || // Check if we have enough arguments - argv[j] == '\0' || // We should have a path here - argv[j][0] == '-' ) // We should have a path not a command line - Help(argv); - else - fn.path_to_textures = argv[++i]; // Increase i since we use this argument - } + for (int i=1; i < argc; ++i) + { + if ( 0 == strcmp("-h", argv[i]) || 0 == strcmp("--help", argv[i]) ) + Help(argv); + + if (!flag && (0 == strcmp("-p", argv[i]) ||0 == strcmp("--prismatic-only", argv[i])) ) + flag = PRISMATIC_ONLY; + + if (!flag && (0 == strcmp("-r", argv[i]) || 0 == strcmp("--rotoide-only", argv[i])) ) + flag = ROTOIDE_ONLY; + + if (0 == strcmp("-t", argv[i]) || 0 == strcmp("--texture-path", argv[i])) + { + int j = i+1; + if ( j+1 > argc || // Check if we have enough arguments + argv[j] == '\0' || // We should have a path here + argv[j][0] == '-' ) // We should have a path not a command line + Help(argv); + else + fn.path_to_textures = argv[++i]; // Increase i since we use this argument + } + } } - } - - dInitODE2(0); - // create world - world = dWorldCreate(); - space = dHashSpaceCreate (0); - contactgroup = dJointGroupCreate (0); - dWorldSetGravity (world,0,0,-10); - ground = dCreatePlane (space,0,0,1,0); - - //create two boxes - dMass m; - box1_body[0] = dBodyCreate (world); - dMassSetBox (&m,1,BOX1_LENGTH,BOX1_WIDTH,BOX1_HEIGHT); - dMassAdjust (&m,Mass1); - dBodySetMass (box1_body[0],&m); - box1[0] = dCreateBox (0,BOX1_LENGTH,BOX1_WIDTH,BOX1_HEIGHT); - dGeomSetBody (box1[0],box1_body[0]); - - box2_body[0] = dBodyCreate (world); - dMassSetBox (&m,10,BOX2_LENGTH,BOX2_WIDTH,BOX2_HEIGHT); - dMassAdjust (&m,Mass2); - dBodySetMass (box2_body[0],&m); - box2[0] = dCreateBox (0,BOX2_LENGTH,BOX2_WIDTH,BOX2_HEIGHT); - dGeomSetBody (box2[0],box2_body[0]); - - //set the initial positions of body1 and body2 - dMatrix3 R; - dRSetIdentity(R); - dBodySetPosition (box1_body[0],0,0,BOX1_HEIGHT/2.0); - dBodySetRotation (box1_body[0], R); - - dBodySetPosition (box2_body[0], - 2.1, - 0.0, - BOX2_HEIGHT/2.0); - dBodySetRotation (box2_body[0], R); - - - //set PR joint - joint[0] = dJointCreatePR(world,0); - dJointAttach (joint[0],box1_body[0],box2_body[0]); - switch (flag) - { + dInitODE2(0); + + // create world + world = dWorldCreate(); + space = dHashSpaceCreate (0); + contactgroup = dJointGroupCreate (0); + dWorldSetGravity (world,0,0,-10); + ground = dCreatePlane (space,0,0,1,0); + + //create two boxes + dMass m; + box1_body[0] = dBodyCreate (world); + dMassSetBox (&m,1,BOX1_LENGTH,BOX1_WIDTH,BOX1_HEIGHT); + dMassAdjust (&m,Mass1); + dBodySetMass (box1_body[0],&m); + box1[0] = dCreateBox (0,BOX1_LENGTH,BOX1_WIDTH,BOX1_HEIGHT); + dGeomSetBody (box1[0],box1_body[0]); + + box2_body[0] = dBodyCreate (world); + dMassSetBox (&m,10,BOX2_LENGTH,BOX2_WIDTH,BOX2_HEIGHT); + dMassAdjust (&m,Mass2); + dBodySetMass (box2_body[0],&m); + box2[0] = dCreateBox (0,BOX2_LENGTH,BOX2_WIDTH,BOX2_HEIGHT); + dGeomSetBody (box2[0],box2_body[0]); + + //set the initial positions of body1 and body2 + dMatrix3 R; + dRSetIdentity(R); + dBodySetPosition (box1_body[0],0,0,BOX1_HEIGHT/2.0); + dBodySetRotation (box1_body[0], R); + + dBodySetPosition (box2_body[0], + 2.1, + 0.0, + BOX2_HEIGHT/2.0); + dBodySetRotation (box2_body[0], R); + + + //set PR joint + joint[0] = dJointCreatePR(world,0); + dJointAttach (joint[0],box1_body[0],box2_body[0]); + switch (flag) + { case PRISMATIC_ONLY: - dJointSetPRAnchor (joint[0], - 2.1, - 0.0, - BOX2_HEIGHT/2.0); - dJointSetPRParam (joint[0],dParamLoStop, -0.5); - dJointSetPRParam (joint[0],dParamHiStop, 1.5); - break; - + dJointSetPRAnchor (joint[0], + 2.1, + 0.0, + BOX2_HEIGHT/2.0); + dJointSetPRParam (joint[0],dParamLoStop, -0.5); + dJointSetPRParam (joint[0],dParamHiStop, 1.5); + break; + case ROTOIDE_ONLY: - dJointSetPRAnchor (joint[0], - 0.0, - 0.0, - BOX2_HEIGHT/2.0); - dJointSetPRParam (joint[0],dParamLoStop, 0.0); - dJointSetPRParam (joint[0],dParamHiStop, 0.0); - break; - + dJointSetPRAnchor (joint[0], + 0.0, + 0.0, + BOX2_HEIGHT/2.0); + dJointSetPRParam (joint[0],dParamLoStop, 0.0); + dJointSetPRParam (joint[0],dParamHiStop, 0.0); + break; + default: - dJointSetPRAnchor (joint[0], - 1.1, - 0.0, - BOX2_HEIGHT/2.0); - dJointSetPRParam (joint[0],dParamLoStop, -0.5); - dJointSetPRParam (joint[0],dParamHiStop, 1.5); - break; - } - - dJointSetPRAxis1(joint[0],1,0,0); - dJointSetPRAxis2(joint[0],0,0,1); + dJointSetPRAnchor (joint[0], + 1.1, + 0.0, + BOX2_HEIGHT/2.0); + dJointSetPRParam (joint[0],dParamLoStop, -0.5); + dJointSetPRParam (joint[0],dParamHiStop, 1.5); + break; + } + + dJointSetPRAxis1(joint[0],1,0,0); + dJointSetPRAxis2(joint[0],0,0,1); // We position the 2 body // The position of the rotoide joint is on the second body so it can rotate on itself // and move along the X axis. -// With this anchor +// With this anchor // - A force in X will move only the body 2 inside the low and hi limit // of the prismatic // - A force in Y will make the 2 bodies to rotate around on the plane - - box1_space = dSimpleSpaceCreate (space); - dSpaceSetCleanup (box1_space,0); - dSpaceAdd(box1_space,box1[0]); - - // run simulation - dsSimulationLoop (argc,argv,400,300,&fn); - dJointGroupDestroy (contactgroup); - dSpaceDestroy (space); - dWorldDestroy (world); - dCloseODE(); - return 0; + + box1_space = dSimpleSpaceCreate (space); + dSpaceSetCleanup (box1_space,0); + dSpaceAdd(box1_space,box1[0]); + + // run simulation + dsSimulationLoop (argc,argv,400,300,&fn); + dJointGroupDestroy (contactgroup); + dSpaceDestroy (space); + dWorldDestroy (world); + dCloseODE(); + return 0; } Modified: trunk/ode/src/joints/pr.cpp =================================================================== --- trunk/ode/src/joints/pr.cpp 2008-10-15 15:57:14 UTC (rev 1561) +++ trunk/ode/src/joints/pr.cpp 2008-10-15 19:22:50 UTC (rev 1562) @@ -144,6 +144,22 @@ // powered needs an extra constraint row if ( limotP.limit || limotP.fmax > 0 ) info->m++; + + + // see if we're at a joint limit. + limotR.limit = 0; + if (( limotR.lostop >= -M_PI || limotR.histop <= M_PI ) && + limotR.lostop <= limotR.histop ) + { + dReal angle = getHingeAngle( node[0].body, + node[1].body, + axisR1, qrel ); + limotR.testRotationalLimit( angle ); + } + + // powered morit or at limits needs an extra constraint row + if ( limotR.limit || limotR.fmax > 0 ) info->m++; + } @@ -342,7 +358,8 @@ info->c[2] = k * dDOT( ax1, err ); info->c[3] = k * dDOT( q, err ); - limotP.addLimot( this, info, 4, axP, 0 ); + int row = 4 + limotP.addLimot( this, info, 4, axP, 0 ); + limotR.addLimot ( this, info, row, ax1, 1 ); } Modified: trunk/tests/joint.cpp =================================================================== --- trunk/tests/joint.cpp 2008-10-15 15:57:14 UTC (rev 1561) +++ trunk/tests/joint.cpp 2008-10-15 19:22:50 UTC (rev 1562) @@ -680,8 +680,8 @@ joint->getInfo1(&info); CHECK_EQUAL(0, joint->limotP.limit); - CHECK_EQUAL(0, joint->limotR.limit); - CHECK_EQUAL(4, info.m); + CHECK_EQUAL(1, joint->limotR.limit); + CHECK_EQUAL(5, info.m); // Reset Position and test dBodySetPosition(bId2, 0, 1, 0); @@ -839,8 +839,8 @@ joint->getInfo1(&info); CHECK_EQUAL(0, joint->limotP.limit); - CHECK_EQUAL(0, joint->limotR.limit); - CHECK_EQUAL(5, info.m); + CHECK_EQUAL(1, joint->limotR.limit); + CHECK_EQUAL(6, info.m); // Reset Position and test dBodySetPosition(bId2, 0, 1, 0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2008-10-16 16:56:49
|
Revision: 1567 http://opende.svn.sourceforge.net/opende/?rev=1567&view=rev Author: papaDoc Date: 2008-10-16 16:56:47 +0000 (Thu, 16 Oct 2008) Log Message: ----------- - Add function dJointGetPRAngle and dJointGetPRAngleRate Modified Paths: -------------- trunk/CHANGELOG.txt trunk/include/ode/objects.h trunk/ode/demo/demo_jointPR.cpp trunk/ode/src/joints/pr.cpp Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2008-10-15 21:19:01 UTC (rev 1566) +++ trunk/CHANGELOG.txt 2008-10-16 16:56:47 UTC (rev 1567) @@ -9,7 +9,7 @@ ------------------------------------------------------------------------------ 10/15/08 Remi Ricard (papaDoc) - * Enable the motor on the Rotoide part of the PR joint + * Enable the motor on the rotoide part of the PR joint 10/15/08 Remi Ricard (papaDoc) * Add unit test to check if using directly a joint Modified: trunk/include/ode/objects.h =================================================================== --- trunk/include/ode/objects.h 2008-10-15 21:19:01 UTC (rev 1566) +++ trunk/include/ode/objects.h 2008-10-16 16:56:47 UTC (rev 1567) @@ -2284,6 +2284,23 @@ /** + * @brief Get the PR angular position (i.e. the twist between the 2 bodies) + * + * When the axis is set, the current position of the attached bodies is + * examined and that position will be the zero position. + * @ingroup joints + */ +ODE_API dReal dJointGetPRAngle (dJointID); + +/** + * @brief Get the PR angular position's time derivative + * + * @ingroup joints + */ +ODE_API dReal dJointGetPRAngleRate (dJointID); + + +/** * @brief Get the prismatic axis * @ingroup joints */ Modified: trunk/ode/demo/demo_jointPR.cpp =================================================================== --- trunk/ode/demo/demo_jointPR.cpp 2008-10-15 21:19:01 UTC (rev 1566) +++ trunk/ode/demo/demo_jointPR.cpp 2008-10-16 16:56:47 UTC (rev 1567) @@ -122,6 +122,8 @@ printf("Press 'l' to add limits (-0.5 to 0.5rad) on the rotoide axis\n"); printf("Press 'k' to remove the limits on the rotoide axis\n"); + + printf("Press 'i' to get joint info\n"); } // function to update camera position at each step. @@ -179,28 +181,42 @@ case 'v': case 'V': - dJointSetPRParam(joint[0], dParamVel2, 2); - dJointSetPRParam(joint[0], dParamFMax2, 200); - break; + dJointSetPRParam(joint[0], dParamVel2, 2); + dJointSetPRParam(joint[0], dParamFMax2, 500); + break; case 'c': case 'C': - dJointSetPRParam(joint[0], dParamVel2, 0); - dJointSetPRParam(joint[0], dParamFMax2, 0); - break; + dJointSetPRParam(joint[0], dParamVel2, 0); + dJointSetPRParam(joint[0], dParamFMax2, 0); + break; case 'l': case 'L': - dJointSetPRParam(joint[0], dParamLoStop2, -0.5); - dJointSetPRParam(joint[0], dParamHiStop2, 0.5); - break; + dJointSetPRParam(joint[0], dParamLoStop2, -0.5); + dJointSetPRParam(joint[0], dParamHiStop2, 0.5); + break; case 'k': case 'K': - dJointSetPRParam(joint[0], dParamLoStop2, -dInfinity); - dJointSetPRParam(joint[0], dParamHiStop2, dInfinity); - break; + dJointSetPRParam(joint[0], dParamLoStop2, -dInfinity); + dJointSetPRParam(joint[0], dParamHiStop2, dInfinity); + break; + case 'i': + case 'I': + dVector3 anchor; + dJointGetPRAnchor(joint[0], anchor); + dReal angle = dJointGetPRAngle(joint[0]); + dReal w = dJointGetPRAngleRate(joint[0]); + + dReal l = dJointGetPRPosition(joint[0]); + dReal v = dJointGetPRPositionRate(joint[0]); + + printf("Anchor: [%6.4lf, %6.4lf, %6.4lf]\n", anchor[0], anchor[1], anchor[2]); + printf("Position: %7.4lf, Rate: %7.4lf\n", l, v); + printf("Angle: %7.4lf, Rate: %7.4lf\n", angle, w); + break; } } Modified: trunk/ode/src/joints/pr.cpp =================================================================== --- trunk/ode/src/joints/pr.cpp 2008-10-15 21:19:01 UTC (rev 1566) +++ trunk/ode/src/joints/pr.cpp 2008-10-16 16:56:47 UTC (rev 1567) @@ -125,6 +125,47 @@ +dReal dJointGetPRAngle( dJointID j ) +{ + dxJointPR* joint = ( dxJointPR* )j; + dAASSERT( joint ); + checktype( joint, PR ); + if ( joint->node[0].body ) + { + dReal ang = getHingeAngle( joint->node[0].body, + joint->node[1].body, + joint->axisR1, + joint->qrel ); + if ( joint->flags & dJOINT_REVERSE ) + return -ang; + else + return ang; + } + else return 0; +} + + + +dReal dJointGetPRAngleRate( dJointID j ) +{ + dxJointPR* joint = ( dxJointPR* )j; + dAASSERT( joint ); + checktype( joint, PR ); + if ( joint->node[0].body ) + { + dVector3 axis; + dMULTIPLY0_331( axis, joint->node[0].body->posr.R, joint->axisR1 ); + dReal rate = dDOT( axis, joint->node[0].body->avel ); + if ( joint->node[1].body ) rate -= dDOT( axis, joint->node[1].body->avel ); + if ( joint->flags & dJOINT_REVERSE ) rate = -rate; + return rate; + } + else return 0; +} + + + + void dxJointPR::getInfo1( dxJoint::Info1 *info ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2008-10-16 17:59:53
|
Revision: 1568 http://opende.svn.sourceforge.net/opende/?rev=1568&view=rev Author: papaDoc Date: 2008-10-16 17:59:43 +0000 (Thu, 16 Oct 2008) Log Message: ----------- - Applying patch #2158425 64-bit GIMPACT provided by Mark William. This patch makeis GIMPACT works on 64-bit machine. Modified Paths: -------------- trunk/CHANGELOG.txt trunk/GIMPACT/include/GIMPACT/gim_boxpruning.h trunk/GIMPACT/include/GIMPACT/gim_contact.h trunk/GIMPACT/include/GIMPACT/gim_geometry.h trunk/GIMPACT/include/GIMPACT/gim_math.h trunk/GIMPACT/include/GIMPACT/gim_memory.h trunk/GIMPACT/include/GIMPACT/gim_radixsort.h trunk/GIMPACT/include/GIMPACT/gim_tri_collision.h trunk/GIMPACT/include/GIMPACT/gim_trimesh.h trunk/GIMPACT/src/gim_boxpruning.cpp trunk/GIMPACT/src/gim_contact.cpp trunk/GIMPACT/src/gim_memory.cpp trunk/GIMPACT/src/gim_trimesh.cpp trunk/GIMPACT/src/gim_trimesh_capsule_collision.cpp trunk/GIMPACT/src/gim_trimesh_ray_collision.cpp trunk/GIMPACT/src/gim_trimesh_sphere_collision.cpp trunk/GIMPACT/src/gim_trimesh_trimesh_collision.cpp trunk/ode/src/collision_cylinder_trimesh.cpp trunk/ode/src/collision_trimesh_box.cpp trunk/ode/src/collision_trimesh_gimpact.cpp trunk/ode/src/collision_trimesh_internal.h Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2008-10-16 16:56:47 UTC (rev 1567) +++ trunk/CHANGELOG.txt 2008-10-16 17:59:43 UTC (rev 1568) @@ -9,6 +9,14 @@ ------------------------------------------------------------------------------ 10/15/08 Remi Ricard (papaDoc) + * Applying patch #2158425 64-bit GIMPACT provided by Mark + William. This patch enable make the GIMPACT works on 64-bit machine. + + +10/15/08 Remi Ricard (papaDoc) + * Add function dJointGetPRAngle and dJointGetPRAngleRate + +10/15/08 Remi Ricard (papaDoc) * Enable the motor on the rotoide part of the PR joint 10/15/08 Remi Ricard (papaDoc) Modified: trunk/GIMPACT/include/GIMPACT/gim_boxpruning.h =================================================================== --- trunk/GIMPACT/include/GIMPACT/gim_boxpruning.h 2008-10-16 16:56:47 UTC (rev 1567) +++ trunk/GIMPACT/include/GIMPACT/gim_boxpruning.h 2008-10-16 17:59:43 UTC (rev 1568) @@ -53,18 +53,18 @@ //! Overlapping pair struct GIM_PAIR { - GUINT m_index1; - GUINT m_index2; + GUINT32 m_index1; + GUINT32 m_index2; }; //typedef struct _GIM_PAIR GIM_PAIR; //! Box container struct GIM_AABB_SET { - GUINT m_count; + GUINT32 m_count; aabb3f m_global_bound;//!< Global calculated bound of all boxes aabb3f * m_boxes; - GUINT * m_maxcoords;//!<Upper corners of the boxes, in integer representation + GUINT32 * m_maxcoords;//!<Upper corners of the boxes, in integer representation GIM_RSORT_TOKEN * m_sorted_mincoords;//!< sorted min coords (lower corners), with their coord value as the m_key and m_value as the box index char m_shared;//!< if m_shared == 0 then the memory is allocated and the set must be destroyed, else the pointers are shared and the set should't be destroyed }; @@ -76,7 +76,7 @@ #define GIM_DESTROY_PAIR_SET(dynarray) GIM_DYNARRAY_DESTROY(dynarray) //! Allocate memory for all aabb set. -void gim_aabbset_alloc(GIM_AABB_SET * aabbset, GUINT count); +void gim_aabbset_alloc(GIM_AABB_SET * aabbset, GUINT32 count); //! Destroys the aabb set. void gim_aabbset_destroy(GIM_AABB_SET * aabbset); @@ -219,7 +219,7 @@ ///Function for create Box collision result set -#define GIM_CREATE_BOXQUERY_LIST(dynarray) GIM_DYNARRAY_CREATE(GUINT,dynarray,G_ARRAY_GROW_SIZE) +#define GIM_CREATE_BOXQUERY_LIST(dynarray) GIM_DYNARRAY_CREATE(GUINT32,dynarray,G_ARRAY_GROW_SIZE) //! Finds intersections between a box and a set. Return the colliding boxes of the set /*! @@ -269,8 +269,8 @@ */ #define GIM_CONVERT_VEC3F_GUINT_XZ(vx,vz,uint_key)\ {\ - GUINT _z = ((GUINT)(vz*ERROR_AABB))+32768;\ - uint_key = ((GUINT)(vx*ERROR_AABB))+32768;\ + GUINT32 _z = ((GUINT32)(vz*ERROR_AABB))+32768;\ + uint_key = ((GUINT32)(vx*ERROR_AABB))+32768;\ uint_key = (uint_key<<16) + _z;\ }\ @@ -282,8 +282,8 @@ */ #define GIM_CONVERT_VEC3F_GUINT_XZ_UPPER(vx,vz,uint_key)\ {\ - GUINT _z = ((GUINT)ceilf(vz*ERROR_AABB))+32768;\ - uint_key = ((GUINT)ceilf(vx*ERROR_AABB))+32768;\ + GUINT32 _z = ((GUINT32)ceilf(vz*ERROR_AABB))+32768;\ + uint_key = ((GUINT32)ceilf(vx*ERROR_AABB))+32768;\ uint_key = (uint_key<<16) + _z;\ }\ @@ -298,8 +298,8 @@ {\ GREAL _cx = CLAMP(vx,-MAX_AABB_SIZE,MAX_AABB_SIZE);\ GREAL _cz = CLAMP(vz,-MAX_AABB_SIZE,MAX_AABB_SIZE);\ - GUINT _z = ((GUINT)(_cz*ERROR_AABB))+32768;\ - uint_key = ((GUINT)(_cx*ERROR_AABB))+32768;\ + GUINT32 _z = ((GUINT32)(_cz*ERROR_AABB))+32768;\ + uint_key = ((GUINT32)(_cx*ERROR_AABB))+32768;\ uint_key = (uint_key<<16) + _z;\ }\ @@ -313,8 +313,8 @@ {\ GREAL _cx = CLAMP(vx,-MAX_AABB_SIZE,MAX_AABB_SIZE);\ GREAL _cz = CLAMP(vz,-MAX_AABB_SIZE,MAX_AABB_SIZE);\ - GUINT _z = ((GUINT)ceilf(_cz*ERROR_AABB))+32768;\ - uint_key = ((GUINT)ceilf(_cx*ERROR_AABB))+32768;\ + GUINT32 _z = ((GUINT32)ceilf(_cz*ERROR_AABB))+32768;\ + uint_key = ((GUINT32)ceilf(_cx*ERROR_AABB))+32768;\ uint_key = (uint_key<<16) + _z;\ }\ Modified: trunk/GIMPACT/include/GIMPACT/gim_contact.h =================================================================== --- trunk/GIMPACT/include/GIMPACT/gim_contact.h 2008-10-16 16:56:47 UTC (rev 1567) +++ trunk/GIMPACT/include/GIMPACT/gim_contact.h 2008-10-16 17:59:43 UTC (rev 1568) @@ -54,8 +54,8 @@ GREAL m_depth;//Positive value indicates interpenetration void * m_handle1; void * m_handle2; - GUINT m_feature1;//Face number - GUINT m_feature2;//Face number + GUINT32 m_feature1;//Face number + GUINT32 m_feature2;//Face number }; //typedef struct _GIM_CONTACT GIM_CONTACT; @@ -63,9 +63,9 @@ #define GIM_CALC_KEY_CONTACT(pos,hash)\ {\ - GINT _coords[] = {(GINT)(pos[0]*1000.0f+1.0f),(GINT)(pos[1]*1333.0f),(GINT)(pos[2]*2133.0f+3.0f)};\ - GUINT _hash=0;\ - GUINT *_uitmp = (GUINT *)(&_coords[0]);\ + GINT32 _coords[] = {(GINT32)(pos[0]*1000.0f+1.0f),(GINT32)(pos[1]*1333.0f),(GINT32)(pos[2]*2133.0f+3.0f)};\ + GUINT32 _hash=0;\ + GUINT32 *_uitmp = (GUINT32 *)(&_coords[0]);\ _hash = *_uitmp;\ _uitmp++;\ _hash += (*_uitmp)<<4;\ Modified: trunk/GIMPACT/include/GIMPACT/gim_geometry.h =================================================================== --- trunk/GIMPACT/include/GIMPACT/gim_geometry.h 2008-10-16 16:56:47 UTC (rev 1567) +++ trunk/GIMPACT/include/GIMPACT/gim_geometry.h 2008-10-16 17:59:43 UTC (rev 1568) @@ -41,11 +41,11 @@ //! @{ //! Integer vector 2D -typedef GINT vec2i[2]; +typedef GINT32 vec2i[2]; //! Integer vector 3D -typedef GINT vec3i[3]; +typedef GINT32 vec3i[3]; //! Integer vector 4D -typedef GINT vec4i[4]; +typedef GINT32 vec4i[4]; //! Float vector 2D typedef GREAL vec2f[2]; @@ -1582,7 +1582,7 @@ {\ GREAL _dis;\ outside = 0;\ - GUINT _i = 0;\ + GUINT32 _i = 0;\ do\ {\ _dis = DISTANCE_PLANE_POINT(planes[_i],point);\ Modified: trunk/GIMPACT/include/GIMPACT/gim_math.h =================================================================== --- trunk/GIMPACT/include/GIMPACT/gim_math.h 2008-10-16 16:56:47 UTC (rev 1567) +++ trunk/GIMPACT/include/GIMPACT/gim_math.h 2008-10-16 17:59:43 UTC (rev 1568) @@ -31,9 +31,15 @@ ----------------------------------------------------------------------------- */ +#include "config.h" #include <math.h> #include <float.h> +#if HAVE_SYS_TYPES_H +#include <sys/types.h> +#else +#error "GIMPACT: Must define int32_t and uint32_t" +#endif /*! \defgroup BASIC_TYPES @@ -45,11 +51,14 @@ //! @{ /*! Types */ #define GREAL float -#define GINT long -#define GUINT unsigned long +#define GINT32 int32_t +#define GUINT32 u_int32_t + +#define GPTR void* + /*! Constants for integers*/ -#define GUINT_BIT_COUNT 32 -#define GUINT_EXPONENT 5 +#define GUINT32_BIT_COUNT 32 +#define GUINT32_EXPONENT 5 #define G_FASTMATH 1 #define G_PI 3.14159265358979f @@ -74,10 +83,10 @@ #define G_RADTODEG(X) ((X)*180.0f/3.1415926f) //! Integer representation of a floating-point value. -#define IR(x) ((GUINT&)(x)) +#define IR(x) ((GUINT32&)(x)) //! Signed integer representation of a floating-point value. -#define SIR(x) ((GINT&)(x)) +#define SIR(x) ((GINT32&)(x)) //! Absolute integer representation of a floating-point value #define AIR(x) (IR(x)&0x7fffffff) @@ -116,7 +125,7 @@ else\ {\ GREAL _x = (va) * 0.5f;\ - GUINT _y = 0x5f3759df - ( IR(va) >> 1);\ + GUINT32 _y = 0x5f3759df - ( IR(va) >> 1);\ (isva) = FR(_y);\ (isva) = (isva) * ( 1.5f - ( _x * (isva) * (isva) ) );\ }\ Modified: trunk/GIMPACT/include/GIMPACT/gim_memory.h =================================================================== --- trunk/GIMPACT/include/GIMPACT/gim_memory.h 2008-10-16 16:56:47 UTC (rev 1567) +++ trunk/GIMPACT/include/GIMPACT/gim_memory.h 2008-10-16 17:59:43 UTC (rev 1568) @@ -60,7 +60,7 @@ //! @{ #define GIM_COPY_ARRAYS(dest_array, source_array, element_count)\ {\ - GUINT _i_;\ + GUINT32 _i_;\ for (_i_ = 0; _i_ < (element_count); _i_++)\ {\ (dest_array)[_i_] = (source_array)[_i_];\ @@ -69,7 +69,7 @@ #define GIM_COPY_ARRAYS_1(dest_array, source_array, element_count, copy_macro)\ {\ - GUINT _i_;\ + GUINT32 _i_;\ for (_i_=0; _i_ < (element_count); _i_++)\ {\ copy_macro((dest_array)[_i_], (source_array)[_i_]);\ @@ -79,7 +79,7 @@ #define GIM_ZERO_ARRAY(array, element_count)\ {\ - GUINT _i_;\ + GUINT32 _i_;\ for (_i_=0; _i_ < (element_count); _i_++)\ {\ (array)[_i_] = 0;\ @@ -88,7 +88,7 @@ #define GIM_CONSTANT_ARRAY(array, element_count, constant)\ {\ - GUINT _i_;\ + GUINT32 _i_;\ for (_i_ = 0; _i_ < (element_count); _i_++)\ {\ (array)[_i_] = (constant);\ @@ -155,8 +155,8 @@ struct GDYNAMIC_ARRAY { char * m_pdata; - GUINT m_size; - GUINT m_reserve_size; + GUINT32 m_size; + GUINT32 m_reserve_size; }; //typedef struct _GDYNAMIC_ARRAY GDYNAMIC_ARRAY; @@ -275,46 +275,46 @@ //! @{ //! Creates a bitset -#define GIM_BITSET_CREATE(array_data) GIM_DYNARRAY_CREATE(GUINT, array_data, G_ARRAY_GROW_SIZE) +#define GIM_BITSET_CREATE(array_data) GIM_DYNARRAY_CREATE(GUINT32, array_data, G_ARRAY_GROW_SIZE) //! Creates a bitset, with their bits set to 0. #define GIM_BITSET_CREATE_SIZED(array_data, bits_count) \ { \ - GUINT array_size = (bits_count) / GUINT_BIT_COUNT + 1; \ - GIM_DYNARRAY_CREATE(GUINT, array_data, array_size); \ - GUINT * _pt = GIM_DYNARRAY_POINTER(GUINT, array_data); \ - memset(_pt, 0, sizeof(GUINT) * ((array_data).m_size)); \ + GUINT32 array_size = (bits_count) / GUINT32_BIT_COUNT + 1; \ + GIM_DYNARRAY_CREATE(GUINT32, array_data, array_size); \ + GUINT32 * _pt = GIM_DYNARRAY_POINTER(GUINT32, array_data); \ + memset(_pt, 0, sizeof(GUINT32) * ((array_data).m_size)); \ } \ //! Gets the bitset bit count. -#define GIM_BITSET_SIZE(array_data) ((array_data).m_size * GUINT_BIT_COUNT) +#define GIM_BITSET_SIZE(array_data) ((array_data).m_size * GUINT32_BIT_COUNT) //! Resizes a bitset, with their bits set to 0. #define GIM_BITSET_RESIZE(array_data, new_bits_count) \ { \ - GUINT _oldsize = (array_data).m_size; \ - (array_data).m_size = (new_bits_count) / GUINT_BIT_COUNT + 1; \ + GUINT32 _oldsize = (array_data).m_size; \ + (array_data).m_size = (new_bits_count) / GUINT32_BIT_COUNT + 1; \ if (_oldsize < (array_data).m_size) \ { \ if ((array_data).m_size > (array_data).m_reserve_size) \ { \ - GIM_DYNARRAY_RESERVE_SIZE(GUINT, array_data, _oldsize, (array_data).m_size + G_ARRAY_GROW_SIZE); \ + GIM_DYNARRAY_RESERVE_SIZE(GUINT32, array_data, _oldsize, (array_data).m_size + G_ARRAY_GROW_SIZE); \ } \ - GUINT * _pt = GIM_DYNARRAY_POINTER(GUINT, array_data); \ - memset(&_pt[_oldsize], 0, sizeof(GUINT) * ((array_data).m_size - _oldsize)); \ + GUINT32 * _pt = GIM_DYNARRAY_POINTER(GUINT32, array_data); \ + memset(&_pt[_oldsize], 0, sizeof(GUINT32) * ((array_data).m_size - _oldsize)); \ } \ } \ //! Sets all bitset bit to 0. #define GIM_BITSET_CLEAR_ALL(array_data) \ { \ - memset((array_data).m_pdata, 0, sizeof(GUINT) * (array_data).m_size); \ + memset((array_data).m_pdata, 0, sizeof(GUINT32) * (array_data).m_size); \ } \ //! Sets all bitset bit to 1. #define GIM_BITSET_SET_ALL(array_data) \ { \ - memset((array_data).m_pdata, 0xFF, sizeof(GUINT) * (array_data).m_size); \ + memset((array_data).m_pdata, 0xFF, sizeof(GUINT32) * (array_data).m_size); \ } \ ///Sets the desired bit to 1 @@ -324,8 +324,8 @@ { \ GIM_BITSET_RESIZE(array_data, bit_index); \ } \ - GUINT * _pt = GIM_DYNARRAY_POINTER(GUINT, array_data); \ - _pt[(bit_index) >> GUINT_EXPONENT] |= (1 << ((bit_index) & (GUINT_BIT_COUNT - 1))); \ + GUINT32 * _pt = GIM_DYNARRAY_POINTER(GUINT32, array_data); \ + _pt[(bit_index) >> GUINT32_EXPONENT] |= (1 << ((bit_index) & (GUINT32_BIT_COUNT - 1))); \ } \ ///Return 0 or 1 @@ -337,8 +337,8 @@ } \ else \ { \ - GUINT * _pt = GIM_DYNARRAY_POINTER(GUINT, array_data); \ - (get_value) = _pt[(bit_index) >> GUINT_EXPONENT] & (1 << ((bit_index) & (GUINT_BIT_COUNT - 1))); \ + GUINT32 * _pt = GIM_DYNARRAY_POINTER(GUINT32, array_data); \ + (get_value) = _pt[(bit_index) >> GUINT32_EXPONENT] & (1 << ((bit_index) & (GUINT32_BIT_COUNT - 1))); \ } \ } \ @@ -347,8 +347,8 @@ { \ if ((bit_index) < GIM_BITSET_SIZE(array_data)) \ { \ - GUINT * _pt = GIM_DYNARRAY_POINTER(GUINT, array_data); \ - _pt[(bit_index) >> GUINT_EXPONENT] &= ~(1 << ((bit_index) & (GUINT_BIT_COUNT - 1))); \ + GUINT32 * _pt = GIM_DYNARRAY_POINTER(GUINT32, array_data); \ + _pt[(bit_index) >> GUINT32_EXPONENT] &= ~(1 << ((bit_index) & (GUINT32_BIT_COUNT - 1))); \ } \ } \ //! @} @@ -432,22 +432,22 @@ //! Buffer handle. struct GBUFFER_ID { - GBUFFER_MANAGER_DATA * m_bm_data; - GUINT m_buffer_id; + GBUFFER_MANAGER_DATA * m_bm_data; + GUINT32 m_buffer_id; }; //typedef struct _GBUFFER_ID GBUFFER_ID; //! Buffer internal data struct GBUFFER_DATA { - GUINT m_buffer_handle;//!< if 0, buffer doesn't exists - GUINT m_size; - GUINT m_usage; - GINT m_access; - GUINT m_lock_count; + GPTR m_buffer_handle;//!< if 0, buffer doesn't exists + GUINT32 m_size; + GUINT32 m_usage; + GINT32 m_access; + GUINT32 m_lock_count; char * m_mapped_pointer; GBUFFER_ID m_shadow_buffer; - GUINT m_refcount;//! Reference counting for safe garbage collection + GUINT32 m_refcount;//! Reference counting for safe garbage collection }; //typedef struct _GBUFFER_DATA GBUFFER_DATA; //! @} @@ -460,41 +460,41 @@ //! @{ //! Returns a Buffer handle -typedef GUINT gim_buffer_alloc_function(GUINT size,int usage); +typedef GPTR gim_buffer_alloc_function(GUINT32 size,int usage); //! Returns a Buffer handle, and copies the pdata to the buffer -typedef GUINT gim_buffer_alloc_data_function(const void * pdata,GUINT size,int usage); +typedef GPTR gim_buffer_alloc_data_function(const void * pdata,GUINT32 size,int usage); //! Changes the size of the buffer preserving the content, and returns the new buffer id -typedef GUINT gim_buffer_realloc_function(GUINT buffer_handle,GUINT oldsize,int old_usage,GUINT newsize,int new_usage); +typedef GPTR gim_buffer_realloc_function(GPTR buffer_handle,GUINT32 oldsize,int old_usage,GUINT32 newsize,int new_usage); //! It changes the m_buffer_handle member to 0/0 -typedef void gim_buffer_free_function(GUINT buffer_handle,GUINT size); +typedef void gim_buffer_free_function(GPTR buffer_handle,GUINT32 size); //! It maps the m_mapped_pointer. Returns a pointer -typedef char * gim_lock_buffer_function(GUINT buffer_handle,int access); +typedef char * gim_lock_buffer_function(GPTR buffer_handle,int access); //! It sets the m_mapped_pointer to 0 -typedef void gim_unlock_buffer_function(GUINT buffer_handle); +typedef void gim_unlock_buffer_function(GPTR buffer_handle); typedef void gim_download_from_buffer_function( - GUINT source_buffer_handle, - GUINT source_pos, + GPTR source_buffer_handle, + GUINT32 source_pos, void * destdata, - GUINT copysize); + GUINT32 copysize); typedef void gim_upload_to_buffer_function( - GUINT dest_buffer_handle, - GUINT dest_pos, + GPTR dest_buffer_handle, + GUINT32 dest_pos, void * sourcedata, - GUINT copysize); + GUINT32 copysize); typedef void gim_copy_buffers_function( - GUINT source_buffer_handle, - GUINT source_pos, - GUINT dest_buffer_handle, - GUINT dest_pos, - GUINT copysize); + GPTR source_buffer_handle, + GUINT32 source_pos, + GPTR dest_buffer_handle, + GUINT32 dest_pos, + GUINT32 copysize); //! @} @@ -524,20 +524,20 @@ GDYNAMIC_ARRAY m_buffer_array;//!< Array of GBUFFER_DATA objects GDYNAMIC_ARRAY m_free_positions;//!< Array of GUINT elements. Free positions const GBUFFER_MANAGER_PROTOTYPE *m_prototype;//!< Prototype of functions - GUINT m_buffer_manager_id;//!< Buffer manager id + GUINT32 m_buffer_manager_id;//!< Buffer manager id }; //typedef struct _GBUFFER_MANAGER_DATA GBUFFER_MANAGER_DATA; //! Checks if buffer manager is used int gim_is_buffer_manager_active(GBUFFER_MANAGER_DATA buffer_managers[], - GUINT buffer_manager_id); + GUINT32 buffer_manager_id); //! Adds a buffer Manager to the Memory Singleton void gim_create_buffer_manager(GBUFFER_MANAGER_DATA buffer_managers[], - GUINT buffer_manager_id); + GUINT32 buffer_manager_id); //! Destroys a buffer manager -void gim_destroy_buffer_manager(GBUFFER_MANAGER_DATA buffer_managers[], GUINT buffer_manager_id); +void gim_destroy_buffer_manager(GBUFFER_MANAGER_DATA buffer_managers[], GUINT32 buffer_manager_id); void gim_get_buffer_manager_data(GBUFFER_MANAGER_DATA buffer_managers[], - GUINT buffer_manager_id,GBUFFER_MANAGER_DATA ** pbm_data); + GUINT32 buffer_manager_id,GBUFFER_MANAGER_DATA ** pbm_data); void gim_init_buffer_managers(GBUFFER_MANAGER_DATA buffer_managers[]); void gim_terminate_buffer_managers(GBUFFER_MANAGER_DATA buffer_managers[]); @@ -557,10 +557,10 @@ \return An error code. 0 if success. \post m_refcount = 0 */ -GUINT gim_create_buffer( +GUINT32 gim_create_buffer( GBUFFER_MANAGER_DATA buffer_managers[], - GUINT buffer_manager_id, - GUINT buffer_size, + GUINT32 buffer_manager_id, + GUINT32 buffer_size, int usage, GBUFFER_ID * buffer_id); @@ -574,27 +574,27 @@ \return An error code. 0 if success. \post m_refcount = 0 */ -GUINT gim_create_buffer_from_data( +GUINT32 gim_create_buffer_from_data( GBUFFER_MANAGER_DATA buffer_managers[], - GUINT buffer_manager_id, + GUINT32 buffer_manager_id, const void * pdata, - GUINT buffer_size, + GUINT32 buffer_size, int usage, GBUFFER_ID * buffer_id); //!Allocates on the G_BUFFER_MANAGER_SYSTEM -GUINT gim_create_common_buffer(GBUFFER_MANAGER_DATA buffer_managers[], - GUINT buffer_size, GBUFFER_ID * buffer_id); +GUINT32 gim_create_common_buffer(GBUFFER_MANAGER_DATA buffer_managers[], + GUINT32 buffer_size, GBUFFER_ID * buffer_id); //!Allocates on the G_BUFFER_MANAGER_SYSTEM, and copies the data -GUINT gim_create_common_buffer_from_data(GBUFFER_MANAGER_DATA buffer_managers[], - const void * pdata, GUINT buffer_size, GBUFFER_ID * buffer_id); +GUINT32 gim_create_common_buffer_from_data(GBUFFER_MANAGER_DATA buffer_managers[], + const void * pdata, GUINT32 buffer_size, GBUFFER_ID * buffer_id); //!Creates a buffer with shared data -GUINT gim_create_shared_buffer_from_data(GBUFFER_MANAGER_DATA buffer_managers[], - const void * pdata, GUINT buffer_size, GBUFFER_ID * buffer_id); +GUINT32 gim_create_shared_buffer_from_data(GBUFFER_MANAGER_DATA buffer_managers[], + const void * pdata, GUINT32 buffer_size, GBUFFER_ID * buffer_id); //! Add reference counting to buffer. -GINT gim_buffer_add_ref(GBUFFER_ID * buffer_id); +GINT32 gim_buffer_add_ref(GBUFFER_ID * buffer_id); //! Function for resize buffer, preserving the content /*! @@ -603,13 +603,13 @@ \return An error code. 0 if success. \post If m_refcount>0 then it decrements it. */ -GINT gim_buffer_realloc(GBUFFER_ID * buffer_id,GUINT newsize); +GINT32 gim_buffer_realloc(GBUFFER_ID * buffer_id,GUINT32 newsize); //! Eliminates the buffer. /*! If the buffer reference counting is <= 1 and is unlocked, then it eliminates the buffer. */ -GINT gim_buffer_free(GBUFFER_ID * buffer_id); +GINT32 gim_buffer_free(GBUFFER_ID * buffer_id); //! Locks the buffer for memory access. /*! @@ -618,38 +618,38 @@ \param map_pointer Dest Pointer of the memory address from buffer. \post m_lock_count increases. */ -GINT gim_lock_buffer(GBUFFER_ID * buffer_id,int access,char ** map_pointer); +GINT32 gim_lock_buffer(GBUFFER_ID * buffer_id,int access,char ** map_pointer); //! Unlocks the buffer for memory access. -GINT gim_unlock_buffer(GBUFFER_ID * buffer_id); +GINT32 gim_unlock_buffer(GBUFFER_ID * buffer_id); //! Gets the buffer size in bytes -GINT gim_get_buffer_size(GBUFFER_ID * buffer_id,GUINT * buffer_size); +GINT32 gim_get_buffer_size(GBUFFER_ID * buffer_id,GUINT32 * buffer_size); //! Determines if the buffer is locked -GINT gim_get_buffer_is_locked(GBUFFER_ID * buffer_id,GUINT * lock_count); +GINT32 gim_get_buffer_is_locked(GBUFFER_ID * buffer_id,GUINT32 * lock_count); //! Copies the content of the buffer to a dest pointer -GINT gim_download_from_buffer( +GINT32 gim_download_from_buffer( GBUFFER_ID * buffer_id, - GUINT source_pos, + GUINT32 source_pos, void * destdata, - GUINT copysize); + GUINT32 copysize); //! Copies the content of a memory pointer to the buffer -GINT gim_upload_to_buffer( +GINT32 gim_upload_to_buffer( GBUFFER_ID * buffer_id, - GUINT dest_pos, + GUINT32 dest_pos, void * sourcedata, - GUINT copysize); + GUINT32 copysize); //! Copies two buffers. -GINT gim_copy_buffers( +GINT32 gim_copy_buffers( GBUFFER_ID * source_buffer_id, - GUINT source_pos, + GUINT32 source_pos, GBUFFER_ID * dest_buffer_id, - GUINT dest_pos, - GUINT copysize); + GUINT32 dest_pos, + GUINT32 copysize); //! @} @@ -720,8 +720,8 @@ GBUFFER_ID m_buffer_id; char * m_buffer_data; char m_byte_stride; - GUINT m_byte_offset; - GUINT m_element_count; + GUINT32 m_byte_offset; + GUINT32 m_element_count; }; //typedef struct _GBUFFER_ARRAY GBUFFER_ARRAY; @@ -758,7 +758,7 @@ { \ if ((reserve_size) > (array_data).m_element_count) \ { \ - GUINT _buffer_size, _newarray_size; \ + GUINT32 _buffer_size, _newarray_size; \ gim_get_buffer_size(&(array_data).m_buffer_id, _buffer_size); \ _newarray_size = (reserve_size) * (array_data).m_byte_stride; \ if(_newarray_size > _buffer_size) \ @@ -906,14 +906,14 @@ \param access A constant for access to the buffer. can be G_MA_READ_ONLY,G_MA_WRITE_ONLY or G_MA_READ_WRITE \return an Buffer error code */ -GINT gim_buffer_array_lock(GBUFFER_ARRAY * array_data, int access); +GINT32 gim_buffer_array_lock(GBUFFER_ARRAY * array_data, int access); //! close the access to the array buffer through the m_buffer_data element /*! \param array_data Array structure to be locked \return an Buffer error code */ -GINT gim_buffer_array_unlock(GBUFFER_ARRAY * array_data); +GINT32 gim_buffer_array_unlock(GBUFFER_ARRAY * array_data); //! Copy an array by reference /*! @@ -928,7 +928,7 @@ */ void gim_buffer_array_copy_value(GBUFFER_ARRAY * source_data, GBUFFER_MANAGER_DATA dest_buffer_managers[],GBUFFER_ARRAY * dest_data, - GUINT buffer_manager_id,int usage); + GUINT32 buffer_manager_id,int usage); //! Destroys an GBUFFER_ARRAY object /*! @@ -951,7 +951,7 @@ } \ else \ { \ - GUINT _k_, _ecount_= (array_data).m_element_count; \ + GUINT32 _k_, _ecount_= (array_data).m_element_count; \ type * _source_vert_; \ type * _dest_vert_ = (dest_data); \ gim_buffer_array_lock(&(array_data), G_MA_READ_ONLY); \ @@ -980,7 +980,7 @@ } \ else \ { \ - GUINT _k_, _ecount_= (array_data).m_element_count; \ + GUINT32 _k_, _ecount_= (array_data).m_element_count; \ type * _source_vert_ = (source_data); \ type * _dest_vert_; \ gim_buffer_array_lock(&(array_data), G_MA_WRITE_ONLY); \ @@ -1022,7 +1022,7 @@ gim_buffer_array_lock(&(_src_array), G_MA_READ_ONLY); \ gim_buffer_array_lock(&(_dst_array), G_MA_WRITE_ONLY); \ \ - GUINT _i_, _count_=(_src_array).m_element_count; \ + GUINT32 _i_, _count_=(_src_array).m_element_count; \ \ _src_type * _source_vert_; \ _dst_type * _dest_vert_; \ Modified: trunk/GIMPACT/include/GIMPACT/gim_radixsort.h =================================================================== --- trunk/GIMPACT/include/GIMPACT/gim_radixsort.h 2008-10-16 16:56:47 UTC (rev 1567) +++ trunk/GIMPACT/include/GIMPACT/gim_radixsort.h 2008-10-16 17:59:43 UTC (rev 1568) @@ -41,8 +41,8 @@ //! @{ struct GIM_RSORT_TOKEN { - GUINT m_key; - GUINT m_value; + GUINT32 m_key; + GUINT32 m_value; }; //typedef struct _GIM_RSORT_TOKEN GIM_RSORT_TOKEN; @@ -61,9 +61,9 @@ //For the type of your array, you need to declare a macro for obtaining the key, like these: #define SIMPLE_GET_FLOAT32KEY(e,key) {key =(GREAL)(e);} -#define SIMPLE_GET_INTKEY(e,key) {key =(GINT)(e);} +#define SIMPLE_GET_INTKEY(e,key) {key =(GINT32)(e);} -#define SIMPLE_GET_UINTKEY(e,key) {key =(GUINT)(e);} +#define SIMPLE_GET_UINTKEY(e,key) {key =(GUINT32)(e);} //For the type of your array, you need to declare a macro for copy elements, like this: @@ -75,16 +75,16 @@ #define GIM_RADIX_SORT_RTOKENS(array,sorted,element_count)\ {\ - GUINT i;\ - GUINT b0[kHist * 3];\ - GUINT *b1 = b0 + kHist;\ - GUINT *b2 = b1 + kHist;\ + GUINT32 i;\ + GUINT32 b0[kHist * 3];\ + GUINT32 *b1 = b0 + kHist;\ + GUINT32 *b2 = b1 + kHist;\ for (i = 0; i < kHist * 3; i++)\ {\ b0[i] = 0;\ }\ - GUINT fi;\ - GUINT pos;\ + GUINT32 fi;\ + GUINT32 pos;\ for (i = 0; i < element_count; i++)\ {\ fi = array[i].m_key;\ @@ -93,8 +93,8 @@ b2[D11_2(fi)] ++;\ }\ {\ - GUINT sum0 = 0, sum1 = 0, sum2 = 0;\ - GUINT tsum;\ + GUINT32 sum0 = 0, sum1 = 0, sum2 = 0;\ + GUINT32 tsum;\ for (i = 0; i < kHist; i++)\ {\ tsum = b0[i] + sum0;\ @@ -138,7 +138,7 @@ #define GIM_RADIX_SORT_ARRAY_TOKENS(array, sorted_tokens, element_count, get_uintkey_macro)\ {\ GIM_RSORT_TOKEN * _unsorted = (GIM_RSORT_TOKEN *) gim_alloc(sizeof(GIM_RSORT_TOKEN )*element_count);\ - GUINT _i;\ + GUINT32 _i;\ for (_i=0;_i<element_count;_i++)\ {\ get_uintkey_macro(array[_i],_unsorted[_i].m_key);\ @@ -155,7 +155,7 @@ GIM_RADIX_SORT_ARRAY_TOKENS(array,_sorted,element_count,get_uintkey_macro);\ type * _original_array = (type *) gim_alloc(sizeof(type)*element_count); \ memcpy(_original_array,array,sizeof(type)*element_count);\ - GUINT _i;\ + GUINT32 _i;\ for (_i=0;_i<element_count;_i++)\ {\ copy_elements_macro(array[_i],_original_array[_sorted[_i].m_value]);\ @@ -167,9 +167,9 @@ /// Sorts array in place using quick sort #define GIM_QUICK_SORT_ARRAY(type, array, array_count, comp_macro, exchange_macro) \ {\ - GINT _i_, _j_, _p_, _stack_index_, _start_, _end_;\ - GINT _start_stack_[64]; \ - GINT _end_stack_[64];\ + GINT32 _i_, _j_, _p_, _stack_index_, _start_, _end_;\ + GINT32 _start_stack_[64]; \ + GINT32 _end_stack_[64];\ _start_stack_[0] = 0;\ _end_stack_[0] = (array_count);\ _stack_index_ = 1;\ @@ -253,6 +253,6 @@ (_array)[(_j)]= _e_tmp_;\ }\ -#define GIM_COMP_MACRO(x, y) ((GINT)((x) - (y))) +#define GIM_COMP_MACRO(x, y) ((GINT32)((x) - (y))) //! @} #endif // GIM_RADIXSORT_H_INCLUDED Modified: trunk/GIMPACT/include/GIMPACT/gim_tri_collision.h =================================================================== --- trunk/GIMPACT/include/GIMPACT/gim_tri_collision.h 2008-10-16 16:56:47 UTC (rev 1567) +++ trunk/GIMPACT/include/GIMPACT/gim_tri_collision.h 2008-10-16 17:59:43 UTC (rev 1568) @@ -42,7 +42,7 @@ #define PLANE_CLIP_POLYGON(plane,polygon_points,polygon_point_count,clipped,clipped_count,max_clipped) \ { \ clipped_count = 0; \ - GUINT _i, _vi, _prevclassif=32000, _classif; \ + GUINT32 _i, _vi, _prevclassif=32000, _classif; \ GREAL _d; \ for(_i=0;_i<=polygon_point_count;_i++) \ { \ @@ -116,7 +116,7 @@ struct GIM_TRIANGLE_CONTACT_DATA { GREAL m_penetration_depth; - GUINT m_point_count; + GUINT32 m_point_count; vec3f m_separating_normal; vec3f m_points[MAX_TRI_CLIPPING]; }; @@ -127,7 +127,7 @@ GREAL u; GREAL v; GREAL tparam; - GUINT m_face_id; + GUINT32 m_face_id; vec3f m_point; vec3f m_normal; }; @@ -190,7 +190,7 @@ VEC_DIFF(_axe1,vec2,vec1);\ VEC_DIFF(_axe2,vec3,vec1);\ VEC_DIFF(_vecproj,point,vec1);\ - GUINT _i1,_i2;\ + GUINT32 _i1,_i2;\ PLANE_MINOR_AXES(tri_plane, _i1, _i2);\ if(fabsf(_axe2[_i2])<G_EPSILON)\ {\ Modified: trunk/GIMPACT/include/GIMPACT/gim_trimesh.h =================================================================== --- trunk/GIMPACT/include/GIMPACT/gim_trimesh.h 2008-10-16 16:56:47 UTC (rev 1567) +++ trunk/GIMPACT/include/GIMPACT/gim_trimesh.h 2008-10-16 17:59:43 UTC (rev 1568) @@ -162,7 +162,7 @@ /// Info about mesh //! Return the trimesh triangle count -GUINT gim_trimesh_get_triangle_count(GIM_TRIMESH * trimesh); +GUINT32 gim_trimesh_get_triangle_count(GIM_TRIMESH * trimesh); //! Returns 1 if the m_transformed_vertex_buffer is a reply of m_source_vertex_buffer char gim_trimesh_has_tranformed_reply(GIM_TRIMESH * trimesh); @@ -204,8 +204,8 @@ \param transformed_reply If 1, then the m_transformed_vertices is a reply of the source vertices. Else it just be a reference to the original array. Use 1 if you will apply transformations to the trimesh. See \ref gim_trimesh_set_tranform(). */ void gim_trimesh_create_from_data(GBUFFER_MANAGER_DATA buffer_managers[], - GIM_TRIMESH * trimesh, vec3f * vertex_array, GUINT vertex_count,char copy_vertices, - GUINT * triindex_array, GUINT index_count,char copy_indices,char transformed_reply); + GIM_TRIMESH * trimesh, vec3f * vertex_array, GUINT32 vertex_count,char copy_vertices, + GUINT32 * triindex_array, GUINT32 index_count,char copy_indices,char transformed_reply); //! Clears auxiliary data and releases buffer arrays void gim_trimesh_destroy(GIM_TRIMESH * trimesh); @@ -265,13 +265,13 @@ /*! \pre gim_trimesh_locks_work_data must be called before */ -void gim_trimesh_get_triangle_data(GIM_TRIMESH * trimesh, GUINT triangle_index, GIM_TRIANGLE_DATA * tri_data); +void gim_trimesh_get_triangle_data(GIM_TRIMESH * trimesh, GUINT32 triangle_index, GIM_TRIANGLE_DATA * tri_data); //! Fetch triangle vertices /*! \pre gim_trimesh_locks_work_data must be called before */ -void gim_trimesh_get_triangle_vertices(GIM_TRIMESH * trimesh, GUINT triangle_index, vec3f v1,vec3f v2,vec3f v3); +void gim_trimesh_get_triangle_vertices(GIM_TRIMESH * trimesh, GUINT32 triangle_index, vec3f v1,vec3f v2,vec3f v3); //! Trimesh Trimesh Collisions /*! Modified: trunk/GIMPACT/src/gim_boxpruning.cpp =================================================================== --- trunk/GIMPACT/src/gim_boxpruning.cpp 2008-10-16 16:56:47 UTC (rev 1567) +++ trunk/GIMPACT/src/gim_boxpruning.cpp 2008-10-16 17:59:43 UTC (rev 1568) @@ -32,7 +32,7 @@ //! Allocate memory for all aabb set. -void gim_aabbset_alloc(GIM_AABB_SET * aabbset, GUINT count) +void gim_aabbset_alloc(GIM_AABB_SET * aabbset, GUINT32 count) { aabbset->m_count = count; aabbset->m_boxes = (aabb3f *)gim_alloc(sizeof(aabb3f)*count); @@ -44,7 +44,7 @@ } else { - aabbset->m_maxcoords = (GUINT *)gim_alloc(sizeof(GUINT)*aabbset->m_count ); + aabbset->m_maxcoords = (GUINT32 *)gim_alloc(sizeof(GUINT32)*aabbset->m_count ); aabbset->m_sorted_mincoords = (GIM_RSORT_TOKEN *)gim_alloc(sizeof(GIM_RSORT_TOKEN)*aabbset->m_count); } aabbset->m_shared = 0; @@ -72,7 +72,7 @@ aabb3f * globalbox = &aabbset->m_global_bound; AABB_COPY((*globalbox),(*paabb)); - GUINT count = aabbset->m_count-1; + GUINT32 count = aabbset->m_count-1; paabb++; while(count) { @@ -97,13 +97,13 @@ { if(aabbset->m_sorted_mincoords == 0) {//allocate - aabbset->m_maxcoords = (GUINT *)gim_alloc(sizeof(GUINT)*aabbset->m_count ); + aabbset->m_maxcoords = (GUINT32 *)gim_alloc(sizeof(GUINT32)*aabbset->m_count ); aabbset->m_sorted_mincoords = (GIM_RSORT_TOKEN *)gim_alloc(sizeof(GIM_RSORT_TOKEN)*aabbset->m_count); } - GUINT i, count = aabbset->m_count; + GUINT32 i, count = aabbset->m_count; aabb3f * paabb = aabbset->m_boxes; - GUINT * maxcoords = aabbset->m_maxcoords; + GUINT32 * maxcoords = aabbset->m_maxcoords; GIM_RSORT_TOKEN * sorted_tokens = aabbset->m_sorted_mincoords; if(count<860)//Calibrated on a Pentium IV @@ -170,7 +170,7 @@ pairset,\ push_pair_macro)\ {\ - GUINT _i = test_count;\ + GUINT32 _i = test_count;\ char _intersected;\ GIM_RSORT_TOKEN * _psorted_tokens = sorted_tokens;\ while(_i>0 && max_coord_uint >= _psorted_tokens->m_key)\ @@ -194,16 +194,16 @@ void gim_aabbset_self_intersections_sorted(GIM_AABB_SET * aabbset, GDYNAMIC_ARRAY * collision_pairs) { collision_pairs->m_size = 0; - GUINT count = aabbset->m_count; + GUINT32 count = aabbset->m_count; aabb3f * paabb = aabbset->m_boxes; - GUINT * maxcoords = aabbset->m_maxcoords; + GUINT32 * maxcoords = aabbset->m_maxcoords; GIM_RSORT_TOKEN * sorted_tokens = aabbset->m_sorted_mincoords; aabb3f test_aabb; while(count>1) { ///current cache variables - GUINT curr_index = sorted_tokens->m_value; - GUINT max_coord_uint = maxcoords[curr_index]; + GUINT32 curr_index = sorted_tokens->m_value; + GUINT32 max_coord_uint = maxcoords[curr_index]; AABB_COPY(test_aabb,paabb[curr_index]); ///next pairs @@ -222,8 +222,8 @@ void gim_aabbset_self_intersections_brute_force(GIM_AABB_SET * aabbset, GDYNAMIC_ARRAY * collision_pairs) { collision_pairs->m_size = 0; - GUINT i,j; - GUINT count = aabbset->m_count; + GUINT32 i,j; + GUINT32 count = aabbset->m_count; aabb3f * paabb = aabbset->m_boxes; char intersected; for (i=0;i< count-1 ;i++ ) @@ -254,19 +254,19 @@ AABBCOLLISION(intersected,aabbset1->m_global_bound,aabbset2->m_global_bound); if(intersected == 0) return; - GUINT count1 = aabbset1->m_count; + GUINT32 count1 = aabbset1->m_count; aabb3f * paabb1 = aabbset1->m_boxes; - GUINT * maxcoords1 = aabbset1->m_maxcoords; + GUINT32 * maxcoords1 = aabbset1->m_maxcoords; GIM_RSORT_TOKEN * sorted_tokens1 = aabbset1->m_sorted_mincoords; - GUINT count2 = aabbset2->m_count; + GUINT32 count2 = aabbset2->m_count; aabb3f * paabb2 = aabbset2->m_boxes; - GUINT * maxcoords2 = aabbset2->m_maxcoords; + GUINT32 * maxcoords2 = aabbset2->m_maxcoords; GIM_RSORT_TOKEN * sorted_tokens2 = aabbset2->m_sorted_mincoords; - GUINT curr_index; + GUINT32 curr_index; - GUINT max_coord_uint; + GUINT32 max_coord_uint; aabb3f test_aabb; //Classify boxes @@ -276,7 +276,7 @@ //Clasify set 1 GIM_RSORT_TOKEN * classified_tokens1 = (GIM_RSORT_TOKEN *) gim_alloc(sizeof(GIM_RSORT_TOKEN)*count1); - GUINT i,classified_count1 = 0,classified_count2 = 0; + GUINT32 i,classified_count1 = 0,classified_count2 = 0; for (i=0;i<count1;i++ ) @@ -367,14 +367,14 @@ //Find Set intersection BOXINTERSECTION(aabbset1->m_global_bound,aabbset2->m_global_bound, int_abbb); //Clasify set 1 - GUINT i,j; - GUINT classified_count = 0; + GUINT32 i,j; + GUINT32 classified_count = 0; - GUINT count = aabbset1->m_count; + GUINT32 count = aabbset1->m_count; aabb3f * paabb1 = aabbset1->m_boxes; aabb3f * paabb2 = aabbset2->m_boxes; - GUINT * classified = (GUINT *) gim_alloc(sizeof(GUINT)*count); + GUINT32 * classified = (GUINT32 *) gim_alloc(sizeof(GUINT32)*count); for (i=0;i<count;i++ ) { @@ -479,8 +479,8 @@ AABBCOLLISION(intersected,aabbset->m_global_bound,(*test_aabb)); if(intersected == 0) return; - GUINT i; - GUINT count = aabbset->m_count; + GUINT32 i; + GUINT32 count = aabbset->m_count; aabb3f * paabb = aabbset->m_boxes; aabb3f _testaabb; AABB_COPY(_testaabb,*test_aabb); @@ -490,7 +490,7 @@ AABBCOLLISION(intersected,paabb[i],_testaabb); if(intersected) { - GIM_DYNARRAY_PUSH_ITEM(GUINT,(*collided),i); + GIM_DYNARRAY_PUSH_ITEM(GUINT32,(*collided),i); } } } @@ -503,8 +503,8 @@ BOX_INTERSECTS_RAY(aabbset->m_global_bound, vorigin, vdir, tparam, tmax,intersected); if(intersected==0) return; - GUINT i; - GUINT count = aabbset->m_count; + GUINT32 i; + GUINT32 count = aabbset->m_count; aabb3f * paabb = aabbset->m_boxes; for (i=0;i< count;i++ ) @@ -512,7 +512,7 @@ BOX_INTERSECTS_RAY(paabb[i], vorigin, vdir, tparam, tmax,intersected); if(intersected) { - GIM_DYNARRAY_PUSH_ITEM(GUINT,(*collided),i); + GIM_DYNARRAY_PUSH_ITEM(GUINT32,(*collided),i); } } } Modified: trunk/GIMPACT/src/gim_contact.cpp =================================================================== --- trunk/GIMPACT/src/gim_contact.cpp 2008-10-16 16:56:47 UTC (rev 1567) +++ trunk/GIMPACT/src/gim_contact.cpp 2008-10-16 17:59:43 UTC (rev 1568) @@ -33,12 +33,12 @@ { dest_contacts->m_size = 0; - GUINT source_count = source_contacts->m_size; + GUINT32 source_count = source_contacts->m_size; GIM_CONTACT * psource_contacts = GIM_DYNARRAY_POINTER(GIM_CONTACT,(*source_contacts)); //create keys GIM_RSORT_TOKEN * keycontacts = (GIM_RSORT_TOKEN * )gim_alloc(sizeof(GIM_RSORT_TOKEN)*source_count); - GUINT i; + GUINT32 i; for(i=0;i<source_count;i++) { keycontacts[i].m_value = i; @@ -51,7 +51,7 @@ // Merge contacts GIM_CONTACT * pcontact = 0; GIM_CONTACT * scontact = 0; - GUINT key,last_key=0; + GUINT32 key,last_key=0; for(i=0;i<source_contacts->m_size;i++) { @@ -82,7 +82,7 @@ { dest_contacts->m_size = 0; //Traverse the source contacts - GUINT source_count = source_contacts->m_size; + GUINT32 source_count = source_contacts->m_size; if(source_count==0) return; GIM_CONTACT * psource_contacts = GIM_DYNARRAY_POINTER(GIM_CONTACT,(*source_contacts)); @@ -101,7 +101,7 @@ psource_contacts++; //Average the contacts - GUINT i; + GUINT32 i; for(i=1;i<source_count;i++) { VEC_SUM(pcontact->m_point,pcontact->m_point,psource_contacts->m_point); Modified: trunk/GIMPACT/src/gim_memory.cpp =================================================================== --- trunk/GIMPACT/src/gim_memory.cpp 2008-10-16 16:56:47 UTC (rev 1567) +++ trunk/GIMPACT/src/gim_memory.cpp 2008-10-16 17:59:43 UTC (rev 1568) @@ -174,46 +174,46 @@ //!** Basic buffer prototype functions -static GUINT _system_buffer_alloc_function(GUINT size,int usage) +static GPTR _system_buffer_alloc_function(GUINT32 size,int usage) { void * newdata = gim_alloc(size); memset(newdata,0,size); - return (GUINT)(newdata); + return (GPTR)newdata; } -static GUINT _system_buffer_alloc_data_function(const void * pdata,GUINT size,int usage) +static GPTR _system_buffer_alloc_data_function(const void * pdata,GUINT32 size,int usage) { void * newdata = gim_alloc(size); memcpy(newdata,pdata,size); - return (GUINT)(newdata); + return (GPTR)(newdata); } -static GUINT _system_buffer_realloc_function(GUINT buffer_handle,GUINT oldsize,int old_usage,GUINT newsize,int new_usage) +static GPTR _system_buffer_realloc_function(GPTR buffer_handle,GUINT32 oldsize,int old_usage,GUINT32 newsize,int new_usage) { - void * newdata = gim_realloc((void *)buffer_handle,oldsize,newsize); - return (GUINT)(newdata); + void * newdata = gim_realloc(buffer_handle,oldsize,newsize); + return (GPTR)(newdata); } -static void _system_buffer_free_function(GUINT buffer_handle,GUINT size) +static void _system_buffer_free_function(GPTR buffer_handle,GUINT32 size) { - gim_free((void*)buffer_handle,size); + gim_free(buffer_handle,size); } -static char * _system_lock_buffer_function(GUINT buffer_handle,int access) +static char * _system_lock_buffer_function(GPTR buffer_handle,int access) { return (char * )(buffer_handle); } -static void _system_unlock_buffer_function(GUINT buffer_handle) +static void _system_unlock_buffer_function(GPTR buffer_handle) { } static void _system_download_from_buffer_function( - GUINT source_buffer_handle, - GUINT source_pos, + GPTR source_buffer_handle, + GUINT32 source_pos, void * destdata, - GUINT copysize) + GUINT32 copysize) { char * pdata; pdata = (char *)source_buffer_handle; @@ -221,10 +221,10 @@ } static void _system_upload_to_buffer_function( - GUINT dest_buffer_handle, - GUINT dest_pos, + GPTR dest_buffer_handle, + GUINT32 dest_pos, void * sourcedata, - GUINT copysize) + GUINT32 copysize) { char * pdata; pdata = (char * )dest_buffer_handle; @@ -232,11 +232,11 @@ } static void _system_copy_buffers_function( - GUINT source_buffer_handle, - GUINT source_pos, - GUINT dest_buffer_handle, - GUINT dest_pos, - GUINT copysize) + GPTR source_buffer_handle, + GUINT32 source_pos, + GPTR dest_buffer_handle, + GUINT32 dest_pos, + GUINT32 copysize) { char * pdata1,*pdata2; pdata1 = (char *)source_buffer_handle; @@ -244,22 +244,22 @@ memcpy(pdata2+dest_pos,pdata1+source_pos,copysize); } -static GUINT _shared_buffer_alloc_function(GUINT size,int usage) +static GPTR _shared_buffer_alloc_function(GUINT32 size,int usage) { return 0; } -static GUINT _shared_buffer_alloc_data_function(const void * pdata,GUINT size,int usage) +static GPTR _shared_buffer_alloc_data_function(const void * pdata,GUINT32 size,int usage) { - return (GUINT)pdata; + return (GPTR)pdata; } -static GUINT _shared_buffer_realloc_function(GUINT buffer_handle,GUINT oldsize,int old_usage,GUINT newsize,int new_usage) +static GPTR _shared_buffer_realloc_function(GPTR buffer_handle,GUINT32 oldsize,int old_usage,GUINT32 newsize,int new_usage) { return 0; } -static void _shared_buffer_free_function(GUINT buffer_handle,GUINT size) +static void _shared_buffer_free_function(GPTR buffer_handle,GUINT32 size) { } @@ -301,7 +301,7 @@ }; int gim_is_buffer_manager_active(GBUFFER_MANAGER_DATA buffer_managers[], - GUINT buffer_manager_id) + GUINT32 buffer_manager_id) { GBUFFER_MANAGER_DATA * bm_data; bm_data = &buffer_managers[buffer_manager_id]; @@ -310,7 +310,7 @@ //!** Buffer manager operations void gim_create_buffer_manager(GBUFFER_MANAGER_DATA buffer_managers[], - GUINT buffer_manager_id) + GUINT32 buffer_manager_id) { GBUFFER_MANAGER_DATA * bm_data; bm_data = &buffer_managers[buffer_manager_id]; @@ -322,12 +322,12 @@ //CREATE ARRAYS GIM_DYNARRAY_CREATE(GBUFFER_DATA,bm_data->m_buffer_array,G_ARRAY_BUFFERMANAGER_INIT_SIZE); - GIM_DYNARRAY_CREATE(GUINT,bm_data->m_free_positions,G_ARRAY_BUFFERMANAGER_INIT_SIZE); + GIM_DYNARRAY_CREATE(GUINT32,bm_data->m_free_positions,G_ARRAY_BUFFERMANAGER_INIT_SIZE); bm_data->m_prototype = g_bm_prototypes + buffer_manager_id; bm_data->m_buffer_manager_id = buffer_manager_id; } -void gim_destroy_buffer_manager(GBUFFER_MANAGER_DATA buffer_managers[], GUINT buffer_manager_id) +void gim_destroy_buffer_manager(GBUFFER_MANAGER_DATA buffer_managers[], GUINT32 buffer_manager_id) { GBUFFER_MANAGER_DATA * bm_data; gim_get_buffer_manager_data(buffer_managers,buffer_manager_id,&bm_data); @@ -335,7 +335,7 @@ //Destroy all buffers GBUFFER_DATA * buffers = GIM_DYNARRAY_POINTER(GBUFFER_DATA,bm_data->m_buffer_array); - GUINT i, buffer_count = bm_data->m_buffer_array.m_size; + GUINT32 i, buffer_count = bm_data->m_buffer_array.m_size; for (i=0;i<buffer_count ;i++ ) { GBUFFER_DATA * current_buffer = buffers + i; @@ -352,7 +352,7 @@ GIM_DYNARRAY_DESTROY(bm_data->m_free_positions); } void gim_get_buffer_manager_data(GBUFFER_MANAGER_DATA buffer_managers[], - GUINT buffer_manager_id,GBUFFER_MANAGER_DATA ** pbm_data) + GUINT32 buffer_manager_id,GBUFFER_MANAGER_DATA ** pbm_data) { GBUFFER_MANAGER_DATA * bm_data; bm_data = &buffer_managers[buffer_manager_id]; @@ -369,7 +369,7 @@ void gim_init_buffer_managers(GBUFFER_MANAGER_DATA buffer_managers[]) { - GUINT i; + GUINT32 i; for (i=0;i<G_BUFFER_MANAGER__MAX;i++) { _init_buffer_manager_data(buffer_managers + i); @@ -386,7 +386,7 @@ void gim_terminate_buffer_managers(GBUFFER_MANAGER_DATA buffer_managers[]) { - GUINT i; + GUINT32 i; for (i=0;i<G_BUFFER_MANAGER__MAX;i++) { gim_destroy_buffer_manager(buffer_managers,i); @@ -395,11 +395,11 @@ //!** Buffer operations -void GET_AVALIABLE_BUFFER_ID(GBUFFER_MANAGER_DATA * buffer_manager, GUINT & buffer_id) +void GET_AVALIABLE_BUFFER_ID(GBUFFER_MANAGER_DATA * buffer_manager, GUINT32 & buffer_id) { if(buffer_manager->m_free_positions.m_size>0)\ { - GUINT * _pointer = GIM_DYNARRAY_POINTER(GUINT,buffer_manager->m_free_positions); + GUINT32 * _pointer = GIM_DYNARRAY_POINTER(GUINT32,buffer_manager->m_free_positions); buffer_id = _pointer[buffer_manager->m_free_positions.m_size-1]; GIM_DYNARRAY_POP_ITEM(buffer_manager->m_free_positions); } @@ -410,7 +410,7 @@ } } -GINT _validate_buffer_id(GBUFFER_ID * buffer_id,GBUFFER_DATA ** ppbuffer,GBUFFER_MANAGER_DATA ** pbm_data) +GINT32 _validate_buffer_id(GBUFFER_ID * buffer_id,GBUFFER_DATA ** ppbuffer,GBUFFER_MANAGER_DATA ** pbm_data) { VALIDATE_BUFFER_ID_PT(buffer_id) *ppbuffer = pbuffer; @@ -418,16 +418,16 @@ return G_BUFFER_OP_SUCCESS; } -GUINT gim_create_buffer( +GUINT32 gim_create_buffer( GBUFFER_MANAGER_DATA buffer_managers[], - GUINT buffer_manager_id, - GUINT buffer_size, + GUINT32 buffer_manager_id, + GUINT32 buffer_size, int usage, GBUFFER_ID * buffer_id) { VALIDATE_BUFFER_MANAGER(buffer_managers,buffer_manager_id) - GUINT newbufferhandle = bm_data->m_prototype->alloc_fn(buffer_size,usage); + GPTR newbufferhandle = bm_data->m_prototype->alloc_fn(buffer_size,usage); if(newbufferhandle==0) return G_BUFFER_OP_INVALID; GET_AVALIABLE_BUFFER_ID(bm_data,buffer_id->m_buffer_id); @@ -459,17 +459,17 @@ } -GUINT gim_create_buffer_from_data( +GUINT32 gim_create_buffer_from_data( GBUFFER_MANAGER_DATA buffer_managers[], - GUINT buffer_manager_id, + GUINT32 buffer_manager_id, const void * pdata, - GUINT buffer_size, + GUINT32 buffer_size, int usage, GBUFFER_ID * buffer_id) { VALIDATE_BUFFER_MANAGER(buffer_managers,buffer_manager_id) - GUINT newbufferhandle = bm_data->m_prototype->alloc_data_fn(pdata,buffer_size,usage); + GPTR newbufferhandle = bm_data->m_prototype->alloc_data_fn(pdata,buffer_size,usage); if(newbufferhandle==0) return G_BUFFER_OP_INVALID; GET_AVALIABLE_BUFFER_ID(bm_data,buffer_id->m_buffer_id); @@ -500,29 +500,29 @@ return G_BUFFER_OP_SUCCESS; } -GUINT gim_create_common_buffer(GBUFFER_MANAGER_DATA buffer_managers[], - GUINT buffer_size, GBUFFER_ID * buffer_id) +GUINT32 gim_create_common_buffer(GBUFFER_MANAGER_DATA buffer_managers[], + GUINT32 buffer_size, GBUFFER_ID * buffer_id) { return gim_create_buffer(buffer_managers,G_BUFFER_MANAGER_SYSTEM,buffer_size,G_MU_DYNAMIC_READ_WRITE,buffer_id); } -GUINT gim_create_common_buffer_from_data(GBUFFER_MANAGER_DATA buffer_managers[], - const void * pdata, GUINT buffer_size, GBUFFER_ID * buffer_id) +GUINT32 gim_create_common_buffer_from_data(GBUFFER_MANAGER_DATA buffer_managers[], + const void * pdata, GUINT32 buffer_size, GBUFFER_ID * buffer_id) { return gim_create_buffer_from_data(buffer_managers,G_BUFFER_MANAGER_SYSTEM,pdata,buffer_size,G_MU_DYNAMIC_READ_WRITE,buffer_id); } -GUINT gim_create_shared_buffer_from_data(GBUFFER_MANAGER_DATA buffer_managers[], - const void * pdata, GUINT buffer_size, GBUFFER_ID * buffer_id) +GUINT32 gim_create_shared_buffer_from_data(GBUFFER_MANAGER_DATA buffer_managers[], + const void * pdata, GUINT32 buffer_size, GBUFFER_ID * buffer_id) { return gim_create_buffer_from_data(buffer_managers,G_BUFFER_MANAGER_SHARED,pdata,buffer_size,G_MU_DYNAMIC_READ_WRITE,buffer_id); } -GINT gim_buffer_realloc(GBUFFER_ID * buffer_id,GUINT newsize) +GINT32 gim_buffer_realloc(GBUFFER_ID * buffer_id,GUINT32 newsize) { VALIDATE_BUFFER_ID_PT(buffer_id) if(pbuffer->m_lock_count>0) return G_BUFFER_OP_INVALID; - GUINT newhandle = buffer_id->m_bm_data->m_prototype->realloc_fn( + GPTR newhandle = buffer_id->m_bm_data->m_prototype->realloc_fn( pbuffer->m_buffer_handle,pbuffer->m_size,pbuffer->m_usage,newsize,pbuffer->m_usage); if(newhandle==0) return G_BUFFER_OP_INVALID; pbuffer->m_buffer_handle = newhandle; @@ -531,14 +531,14 @@ return G_BUFFER_OP_SUCCESS; } -GINT gim_buffer_add_ref(GBUFFER_ID * buffer_id) +GINT32 gim_buffer_add_ref(GBUFFER_ID * buffer_id) { VALIDATE_BUFFER_ID_PT(buffer_id) pbuffer->m_refcount++; return G_BUFFER_OP_SUCCESS; } -GINT gim_buffer_free(GBUFFER_ID * buffer_id) +GINT32 gim_buffer_free(GBUFFER_ID * buffer_id) { VALIDATE_BUFFER_ID_PT(buffer_id) if(pbuffer->m_lock_count>0) return G_BUFFER_OP_INVALID; @@ -550,7 +550,7 @@ //destroy shadow buffer if needed gim_buffer_free(&pbuffer->m_shadow_buffer); // Obtain a free slot index for a new buffer - GIM_DYNARRAY_PUSH_ITEM(GUINT,bm_data->m_free_positions,buffer_id->m_buffer_id); + GIM_DYNARRAY_PUSH_ITEM(GUINT32,bm_data->m_free_positions,buffer_id->m_buffer_id); pbuffer->m_buffer_handle = 0; pbuffer->m_size = 0; pbuffer->m_shadow_buffer.m_bm_data = 0; @@ -558,7 +558,7 @@ return G_BUFFER_OP_SUCCESS; } -GINT gim_lock_buffer(GBUFFER_ID * buffer_id,int access,char ** map_pointer) +GINT32 gim_lock_buffer(GBUFFER_ID * buffer_id,int access,char ** map_pointer) { VALIDATE_BUFFER_ID_PT(buffer_id) if(pbuffer->m_lock_count>0) @@ -571,7 +571,7 @@ pbuffer->m_access = access; - GUINT result; + GUINT32 result; if(pbuffer->m_usage==G_MU_STATIC_WRITE) { *map_pointer = 0;///no access @@ -646,7 +646,7 @@ return G_BUFFER_OP_SUCCESS; } -GINT gim_unlock_buffer(GBUFFER_ID * buffer_id) +GINT32 gim_unlock_buffer(GBUFFER_ID * buffer_id) { VALIDATE_BUFFER_ID_PT(buffer_id) if(pbuffer->m_lock_count==0) return G_BUFFER_OP_INVALID; @@ -658,7 +658,7 @@ } - GUINT result; + GUINT32 result; if(pbuffer->m_usage==G_MU_STATIC_WRITE) { pbuffer->m_mapped_pointer = 0; @@ -741,14 +741,14 @@ return G_BUFFER_OP_SUCCESS; } -GINT gim_get_buffer_size(GBUFFER_ID * buffer_id,GUINT * buffer_size) +GINT32 gim_get_buffer_size(GBUFFER_ID * buffer_id,GUINT32 * buffer_size) { VALIDATE_BUFFER_ID_PT(buffer_id) *buffer_size = pbuffer->m_size; return G_BUFFER_OP_SUCCESS; } -GINT gim_get_buffer_is_locked(GBUFFER_ID * buffer_id,GUINT * lock_count) +GINT32 gim_get_buffer_is_locked(GBUFFER_ID * buffer_id,GUINT32 * lock_count) { VALIDATE_BUFFER_ID_PT(buffer_id) *lock_count = pbuffer->m_lock_count; @@ -756,11 +756,11 @@ } -GINT gim_download_from_buffer( +GINT32 gim_download_from_buffer( GBUFFER_ID * buffer_id, - GUINT source_pos, + GUINT32 source_pos, void * destdata, - GUINT copysize) + GUINT32 copysize) { VALIDATE_BUFFER_ID_PT(buffer_id) buffer_id->m_bm_data->m_prototype->download_from_buffer_fn( @@ -768,11 +768,11 @@ return G_BUFFER_OP_SUCCESS; } -GINT gim_upload_to_buffer( +GINT32 gim_upload_to_buffer( GBUFFER_ID * buffer_id, - GUINT dest_pos, + GUINT32 dest_pos, void * sourcedata, - GUINT copysize) + GUINT32 copysize) { VALIDATE_BUFFER_ID_PT(buffer_id) buffer_id->m_bm_data->m_prototype->upload_to_buffer_fn( @@ -780,12 +780,12 @@ return G_BUFFER_OP_SUCCESS; } -GINT gim_copy_buffers( +GINT32 gim_copy_buffers( GBUFFER_ID * source_buffer_id, - GUINT source_pos, + GUINT32 source_pos, GBUFFER_ID * dest_buffer_id, - GUINT dest_pos, - GUINT copysize) + GUINT32 dest_pos, + GUINT32 copysize) { GBUFFER_MANAGER_DATA * bm_data1,* bm_data2; GBUFFER_DATA * pbuffer1, * pbuffer2; @@ -828,19 +828,19 @@ return G_BUFFER_OP_SUCCESS; } -GINT gim_buffer_array_lock(GBUFFER_ARRAY * array_data, int access) +GINT32 gim_buffer_array_lock(GBUFFER_ARRAY * array_data, int access) { if(array_data->m_buffer_data != 0) return G_BUFFER_OP_SUCCESS; - GINT result = gim_lock_buffer(&array_data->m_buffer_id,access,&array_data->m_buffer_data); + GINT32 result = gim_lock_buffer(&array_data->m_buffer_id,access,&array_data->m_buffer_data); if(result!= G_BUFFER_OP_SUCCESS) return result; array_data->m_buffer_data += array_data->m_byte_offset; return result; } -GINT gim_buffer_array_unlock(GBUFFER_ARRAY * array_data) +GINT32 gim_buffer_array_unlock(GBUFFER_ARRAY * array_data) { if(array_data->m_buffer_data == 0) return G_BUFFER_OP_SUCCESS; - GINT result = gim_unlock_buffer(&array_data->m_buffer_id); + GINT32 result = gim_unlock_buffer(&array_data->m_buffer_id); if(result!= G_BUFFER_OP_SUCCESS) return result; array_data->m_buffer_data = 0; return result; @@ -859,10 +859,10 @@ void gim_buffer_array_copy_value(GBUFFER_ARRAY * source_data, GBUFFER_MANAGER_DATA dest_buffer_managers[],GBUFFER_ARRAY * dest_data, - GUINT buffer_manager_id,int usage) + GUINT32 buffer_manager_id,int usage) { //Create new buffer - GUINT buffsize = source_data->m_element_count*source_data->m_byte_stride; + GUINT32 buffsize = source_data->m_element_count*source_data->m_byte_stride; gim_create_buffer(dest_buffer_managers,buffer_manager_id,buffsize,usage,&dest_data->m_buffer_id); //copy ref data Modified: trunk/GIMPACT/src/gim_trimesh.cpp =================================================================== --- trunk/GIMPACT/src/gim_trimesh.cpp 2008-10-16 16:56:47 UTC (rev 1567) +++ trunk/GIMPACT/src/gim_trimesh.cpp 2008-10-16 17:59:43 UTC (rev 1568) @@ -30,7 +30,7 @@ #include <assert.h> #include "GIMPACT/gim_trimesh.h" -GUINT gim_trimesh_get_triangle_count(GIM_TRIMESH * trimesh) +GUINT32 gim_trimesh_get_triangle_count(GIM_TRIMESH * trimesh) { return trimesh->m_tri_index_buffer.m_element_count/3; } @@ -66,7 +66,7 @@ gim_buffer_array_copy_ref(vertex_array,&trimesh->m_transformed_vertex_buffer); } //create the box set - GUINT facecount = gim_trimesh_get_triangle_count(trimesh); + GUINT32 facecount = gim_trimesh_get_triangle_count(trimesh); gim_aabbset_alloc(&trimesh->m_aabbset,facecount); //create the planes cache @@ -94,8 +94,8 @@ \param transformed_reply If , then the m_transformed_vertices is a reply of the source vertices. Else it just be a reference to the original array. */ void gim_trimesh_create_from_data(GBUFFER_MANAGER_DATA buffer_managers[], - GIM_TRIMESH * trimesh, vec3f * vertex_array, GUINT vertex_count,char copy_vertices, - GUINT * triindex_array, GUINT index_count,char copy_indices,char transformed_reply) + GIM_TRIMESH * trimesh, vec3f * vertex_array, GUINT32 vertex_count,char copy_vertices, + GUINT32 * triindex_array, GUINT32 index_count,char copy_indices,char transformed_reply) { GBUFFER_ARRAY buffer_vertex_array; GBUFFER_ARRAY buffer_triindex_array; @@ -118,14 +118,14 @@ if(copy_indices == 1) { gim_create_common_buffer_from_data(buffer_managers, - triindex_array, index_count*sizeof(GUINT), &buffer_triindex_array.m_buffer_id); + triindex_array, index_count*sizeof(GUINT32), &buffer_triindex_array.m_buffer_id); } else//Create a shared buffer { gim_create_shared_buffer_from_data(buffer_managers, - triindex_array, index_count*sizeof(GUINT), &buffer_triindex_array.m_buffer_id); + triindex_array, index_count*sizeof(GUINT32), &buffer_triindex_array.m_buffer_id); } - GIM_BUFFER_ARRAY_INIT_TYPE(GUINT,buffer_triindex_array,buffer_triindex_array.m_buffer_id,index_count); + GIM_BUFFER_ARRAY_INIT_TYPE(GUINT32,buffer_triindex_array,buffer_triindex_array.m_buffer_id,index_count); gim_trimesh_create_from_arrays(buffer_managers, trimesh, &buffer_vertex_array, &buffer_triindex_array,transformed_reply); @@ -194,7 +194,7 @@ */ void gim_trimesh_locks_work_data(GIM_TRIMESH * trimesh) { - GINT res; + GINT32 res; res=gim_buffer_array_lock(&trimesh->m_tri_index_buffer,G_MA_READ_ONLY); assert(res==G_BUFFER_OP_SUCCESS); res=gim_buffer_array_lock(&trimesh->m_transformed_vertex_buffer,G_MA_READ_ONLY); @@ -267,13 +267,13 @@ vec3f * transformed_vertices = GIM_BUFFER_ARRAY_POINTER(vec3f,trimesh->m_transformed_vertex_buffer,0); assert(transformed_vertices); - GUINT * triangle_indices = GIM_BUFFER_ARRAY_POINTER(GUINT,trimesh->m_tri_index_buffer,0); + GUINT32 * triangle_indices = GIM_BUFFER_ARRAY_POINTER(GUINT32,trimesh->m_tri_index_buffer,0); assert(triangle_indices); // box set aabb3f * paabb = trimesh->m_aabbset.m_boxes; - GUINT triangle_count = gim_trimesh_get_triangle_count(trimesh); + GUINT32 triangle_count = gim_trimesh_get_triangle_count(trimesh); float * v1,*v2,*v3; - GUINT i; + GUINT32 i; for (i=0; i<triangle_count;i++) { v1 = &transformed_vertices[triangle_indices[0]][0]; @@ -310,7 +310,7 @@ GREAL diff = 0.0f; float * originaltrans = &trimesh->m_transform[0][0]; float * newtrans = &transform[0][0]; - GUINT i; + GUINT32 i; for (i=0;i<16;i++) { diff += fabs(originaltrans[i]-newtrans[i]); @@ -324,11 +324,11 @@ gim_trimesh_post_update(trimesh); } -void gim_trimesh_get_triangle_data(GIM_TRIMESH * trimesh, GUINT triangle_index, GIM_TRIANGLE_DATA * tri_data) +void gim_trimesh_get_triangle_data(GIM_TRIMESH * trimesh, GUINT32 triangle_index, GIM_TRIANGLE_DATA * tri_data) { vec3f * transformed_vertices = GIM_BUFFER_ARRAY_POINTER(vec3f,trimesh->m_transformed_vertex_buffer,0); - GUINT * triangle_indices = GIM_BUFFER_ARRAY_POINTER(GUINT,trimesh->m_tri_index_buffer,triangle_index*3); + GUINT32 * triangle_indices = GIM_BUFFER_ARRAY_POINTER(GUINT32,trimesh->m_tri_index_buffer,triangle_index*3); //Copy the vertices @@ -341,7 +341,7 @@ planes += triangle_index; //verify planes cache - GUINT bit_eval; + GUINT32 bit_eval; GIM_BITSET_GET(trimesh->m_planes_cache_bitset,triangle_index,bit_eval); if(bit_eval == 0)// Needs to calc the planes { @@ -367,11 +367,11 @@ VEC_COPY_4((tri_data->m_planes.m_planes[3]),(planes->m_planes[3]));//edge3 } -void gim_trimesh_get_triangle_vertices(GIM_TRIMESH * trimesh, GUINT triangle_index, vec3f v1,vec3f v2,vec3f v3) +void gim_trimesh_get_triangle_vertices(GIM_TRIMESH * trimesh, GUINT32 triangle_index, vec3f v1,vec3f v2,vec3f v3) { vec3f * transformed_vertices = GIM_BUFFER_ARRAY_POINTER(vec3f,trimesh->m_transformed_vertex_buffer,0); - GUINT * triangle_indices = GIM_BUFFER_ARRAY_POINTER(GUINT,trimesh->m_tri_index_buffer,triangle_index*3); + GUINT32 * triangle_indices = GIM_BUFFER_ARRAY_POINTER(GUINT32,trimesh->m_tri_index_buffer,triangle_index*3); //Copy the vertices VEC_COPY(v1,transformed_vertices[triangle_indices[0]]); Modified: trunk/GIMPACT/src/gim_trimesh_capsule_collision.cpp =================================================================== --- trunk/GIMPACT/src/gim_trimesh_capsule_collision.cpp 2008-10-16 16:56:47 UTC (rev 1567) +++ trunk/GIMPACT/src/gim_trimesh_capsule_collision.cpp 2008-10-16 17:59:43 UTC (rev 1568) @@ -42,7 +42,7 @@ { vec3f segment_points[4] = {{0}}; vec3f closest_points[2] = {{0}}; - GUINT intersection_type, out_edge= 10; + GUINT32 intersection_type, out_edge= 10; GREAL dis, dis_temp,perpend; vec4f sdiff; @@ -135... [truncated message content] |
From: <dan...@us...> - 2008-10-16 22:33:21
|
Revision: 1572 http://opende.svn.sourceforge.net/opende/?rev=1572&view=rev Author: danielosmari Date: 2008-10-16 22:33:17 +0000 (Thu, 16 Oct 2008) Log Message: ----------- removed svn:executable from some source files Property Changed: ---------------- trunk/include/ode/collision_trimesh.h trunk/include/ode/odeconfig.h trunk/ode/demo/convex_bunny_geom.h trunk/ode/demo/demo_moving_convex.cpp Property changes on: trunk/include/ode/collision_trimesh.h ___________________________________________________________________ Deleted: svn:executable - * Property changes on: trunk/include/ode/odeconfig.h ___________________________________________________________________ Deleted: svn:executable - * Property changes on: trunk/ode/demo/convex_bunny_geom.h ___________________________________________________________________ Deleted: svn:executable - * Property changes on: trunk/ode/demo/demo_moving_convex.cpp ___________________________________________________________________ Deleted: svn:executable - * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ole...@us...> - 2008-10-29 10:33:58
|
Revision: 1584 http://opende.svn.sourceforge.net/opende/?rev=1584&view=rev Author: oleh_derevenko Date: 2008-10-29 10:33:44 +0000 (Wed, 29 Oct 2008) Log Message: ----------- Changed: dOrthogonalizeR moved from utils.cpp to odemath.cpp Modified Paths: -------------- trunk/include/ode/odemath.h trunk/ode/src/odemath.cpp trunk/ode/src/util.cpp trunk/ode/src/util.h Modified: trunk/include/ode/odemath.h =================================================================== --- trunk/include/ode/odemath.h 2008-10-29 02:54:23 UTC (rev 1583) +++ trunk/include/ode/odemath.h 2008-10-29 10:33:44 UTC (rev 1584) @@ -349,7 +349,11 @@ */ ODE_API void dPlaneSpace (const dVector3 n, dVector3 p, dVector3 q); +/* Makes sure the matrix is a proper rotation */ +ODE_API void dOrthogonalizeR(dMatrix3 m); + + #ifdef __cplusplus } #endif Modified: trunk/ode/src/odemath.cpp =================================================================== --- trunk/ode/src/odemath.cpp 2008-10-29 02:54:23 UTC (rev 1583) +++ trunk/ode/src/odemath.cpp 2008-10-29 10:33:44 UTC (rev 1584) @@ -183,3 +183,34 @@ q[2] = a*k; } } + + +/* +* This takes what is supposed to be a rotation matrix, +* and make sure it is correct. +* Note: this operates on rows, not columns, because for rotations +* both ways give equivalent results. +*/ +void dOrthogonalizeR(dMatrix3 m) +{ + dReal n0 = dLENGTHSQUARED(m); + if (n0 != 1) + dSafeNormalize3(m); + + // project row[0] on row[1], should be zero + dReal proj = dDOT(m, m+4); + if (proj != 0) { + // Gram-Schmidt step on row[1] + m[4] -= proj * m[0]; + m[5] -= proj * m[1]; + m[6] -= proj * m[2]; + } + dReal n1 = dLENGTHSQUARED(m+4); + if (n1 != 1) + dSafeNormalize3(m+4); + + /* just overwrite row[2], this makes sure the matrix is not + a reflection */ + dCROSS(m+8, =, m, m+4); + m[3] = m[4+3] = m[8+3] = 0; +} Modified: trunk/ode/src/util.cpp =================================================================== --- trunk/ode/src/util.cpp 2008-10-29 02:54:23 UTC (rev 1583) +++ trunk/ode/src/util.cpp 2008-10-29 10:33:44 UTC (rev 1584) @@ -411,34 +411,3 @@ - -/* - * This takes what is supposed to be a rotation matrix, - * and make sure it is correct. - * Note: this operates on rows, not columns, because for rotations - * both ways give equivalent results. - */ -void -dOrthogonalizeR(dMatrix3 m) -{ - dReal n0 = dLENGTHSQUARED(m); - if (n0 != 1) - dSafeNormalize3(m); - - // project row[0] on row[1], should be zero - dReal proj = dDOT(m, m+4); - if (proj != 0) { - // Gram-Schmidt step on row[1] - m[4] -= proj * m[0]; - m[5] -= proj * m[1]; - m[6] -= proj * m[2]; - } - dReal n1 = dLENGTHSQUARED(m+4); - if (n1 != 1) - dSafeNormalize3(m+4); - - /* just overwrite row[2], this makes sure the matrix is not - a reflection */ - dCROSS(m+8, =, m, m+4); - m[3] = m[4+3] = m[8+3] = 0; -} Modified: trunk/ode/src/util.h =================================================================== --- trunk/ode/src/util.h 2008-10-29 02:54:23 UTC (rev 1583) +++ trunk/ode/src/util.h 2008-10-29 10:33:44 UTC (rev 1584) @@ -68,8 +68,4 @@ -/* Makes sure the matrix is a proper rotation */ -void dOrthogonalizeR(dMatrix3 m); - - #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ole...@us...> - 2008-10-29 11:29:05
|
Revision: 1587 http://opende.svn.sourceforge.net/opende/?rev=1587&view=rev Author: oleh_derevenko Date: 2008-10-29 11:28:56 +0000 (Wed, 29 Oct 2008) Log Message: ----------- Reverted: Commit #1582 reverted Fixed: Compilation of GIMPACT fixed in MSVC Modified Paths: -------------- trunk/GIMPACT/include/GIMPACT/gim_math.h trunk/build/ode.lua Modified: trunk/GIMPACT/include/GIMPACT/gim_math.h =================================================================== --- trunk/GIMPACT/include/GIMPACT/gim_math.h 2008-10-29 11:25:30 UTC (rev 1586) +++ trunk/GIMPACT/include/GIMPACT/gim_math.h 2008-10-29 11:28:56 UTC (rev 1587) @@ -37,6 +37,11 @@ #include <float.h> #if HAVE_SYS_TYPES_H #include <sys/types.h> +#elif defined(_MSC_VER) +typedef __int32 int32_t; +typedef unsigned __int32 uint32_t; +#elif defined(__GNUC__) +#include <inttypes.h> #else #error "GIMPACT: Must define int32_t and uint32_t" #endif @@ -52,7 +57,7 @@ /*! Types */ #define GREAL float #define GINT32 int32_t -#define GUINT32 u_int32_t +#define GUINT32 uint32_t #define GPTR void* Modified: trunk/build/ode.lua =================================================================== --- trunk/build/ode.lua 2008-10-29 11:25:30 UTC (rev 1586) +++ trunk/build/ode.lua 2008-10-29 11:28:56 UTC (rev 1587) @@ -221,11 +221,8 @@ if (options["no-trimesh"]) then table.insert(package.excludes, trimesh_files) else - if(options["with-gimpact"]) then - table.insert(package.files, gimpact_files) - else - table.insert(package.files, opcode_files) - end + table.insert(package.files, gimpact_files) + table.insert(package.files, opcode_files) end if (options["enable-ou"]) then This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2008-10-29 15:24:29
|
Revision: 1588 http://opende.svn.sourceforge.net/opende/?rev=1588&view=rev Author: danielosmari Date: 2008-10-29 15:24:23 +0000 (Wed, 29 Oct 2008) Log Message: ----------- trimesh vs sphere properly handling zero-depth contacts Modified Paths: -------------- trunk/ode/src/collision_trimesh_sphere.cpp trunk/tests/Makefile.am Added Paths: ----------- trunk/tests/collision.cpp Modified: trunk/ode/src/collision_trimesh_sphere.cpp =================================================================== --- trunk/ode/src/collision_trimesh_sphere.cpp 2008-10-29 11:28:56 UTC (rev 1587) +++ trunk/ode/src/collision_trimesh_sphere.cpp 2008-10-29 15:24:23 UTC (rev 1588) @@ -366,8 +366,8 @@ continue; // Sphere doesn't hit triangle } - if (Depth <= REAL(0.0)){ - continue; // Zero or negative depth does not produce a contact + if (Depth < REAL(0.0)){ + continue; // Negative depth does not produce a contact } dVector3 ContactPos; @@ -386,10 +386,10 @@ dir[2] = Position[2]-ContactPos[2]; dReal dirProj = dDOT(dir, Plane) / dSqrt(dDOT(dir, dir)); - // Since Depht already had a requirement to be positive, + // Since Depth already had a requirement to be non-negative, // negative direction projections should not be allowed as well, // as otherwise the multiplication will result in negative contact depth. - if (dirProj <= REAL(0.0)){ + if (dirProj < REAL(0.0)){ continue; // Zero contact depth could be ignored } @@ -416,37 +416,33 @@ OutTriCount++; } #ifdef MERGECONTACTS // Merge all contacts into 1 - if (OutTriCount != 0){ + if (OutTriCount > 0){ dContactGeom* Contact = SAFECONTACT(Flags, Contacts, 0, Stride); - - if (OutTriCount != 1 && !(Flags & CONTACTS_UNIMPORTANT)){ - Contact->normal[0] *= Contact->depth; - Contact->normal[1] *= Contact->depth; - Contact->normal[2] *= Contact->depth; - Contact->normal[3] *= Contact->depth; - for (int i = 1; i < OutTriCount; i++){ + if (OutTriCount > 1 && !(Flags & CONTACTS_UNIMPORTANT)){ + dVector3 normal = { 0,0,0 }; + dVector3 pos = { 0,0,0 }; + for (int i = 0; i < OutTriCount; i++){ dContactGeom* TempContact = SAFECONTACT(Flags, Contacts, i, Stride); - Contact->pos[0] += TempContact->pos[0]; - Contact->pos[1] += TempContact->pos[1]; - Contact->pos[2] += TempContact->pos[2]; - Contact->pos[3] += TempContact->pos[3]; + pos[0] += TempContact->pos[0]; + pos[1] += TempContact->pos[1]; + pos[2] += TempContact->pos[2]; - Contact->normal[0] += TempContact->normal[0] * TempContact->depth; - Contact->normal[1] += TempContact->normal[1] * TempContact->depth; - Contact->normal[2] += TempContact->normal[2] * TempContact->depth; - Contact->normal[3] += TempContact->normal[3] * TempContact->depth; + normal[0] += TempContact->normal[0] * TempContact->depth; + normal[1] += TempContact->normal[1] * TempContact->depth; + normal[2] += TempContact->normal[2] * TempContact->depth; } - Contact->pos[0] /= OutTriCount; - Contact->pos[1] /= OutTriCount; - Contact->pos[2] /= OutTriCount; - Contact->pos[3] /= OutTriCount; + Contact->pos[0] = pos[0] / OutTriCount; + Contact->pos[1] = pos[1] / OutTriCount; + Contact->pos[2] = pos[2] / OutTriCount; // Remember to divide in square space. - Contact->depth = dSqrt(dDOT(Contact->normal, Contact->normal) / OutTriCount); + Contact->depth = dSqrt(dDOT(normal, normal) / OutTriCount); + if (Contact->depth > dEpsilon) // otherwise the normal is too small + dVector3Copy(Contact->normal, normal); dNormalize3(Contact->normal); } Modified: trunk/tests/Makefile.am =================================================================== --- trunk/tests/Makefile.am 2008-10-29 11:28:56 UTC (rev 1587) +++ trunk/tests/Makefile.am 2008-10-29 15:24:23 UTC (rev 1588) @@ -11,7 +11,7 @@ TESTS = tests -tests_SOURCES = main.cpp joint.cpp odemath.cpp \ +tests_SOURCES = main.cpp joint.cpp odemath.cpp collision.cpp \ joints/ball.cpp \ joints/fixed.cpp \ joints/hinge.cpp \ Added: trunk/tests/collision.cpp =================================================================== --- trunk/tests/collision.cpp (rev 0) +++ trunk/tests/collision.cpp 2008-10-29 15:24:23 UTC (rev 1588) @@ -0,0 +1,64 @@ +#include <UnitTest++.h> +#include <ode/ode.h> + +TEST(test_collision_trimesh_sphere) +{ + dInitODE(); + + { + const int VertexCount = 4; + const int IndexCount = 2*3; + // this is a square on the XY plane + float vertices[VertexCount * 3] = { + 0,0,0, + 1,0,0, + 1,1,0, + 0,1,0 + }; + dTriIndex indices[IndexCount] = { + 0,1,2, + 0,2,3 + }; + + dTriMeshDataID data = dGeomTriMeshDataCreate(); + dGeomTriMeshDataBuildSingle(data, + vertices, + 3 * sizeof(float), + VertexCount, + indices, + IndexCount, + 3 * sizeof(dTriIndex)); + dGeomID trimesh = dCreateTriMesh(0, data, 0, 0, 0); + const dReal radius = 4; + dGeomID sphere = dCreateSphere(0, radius); + dGeomSetPosition(sphere, 0,0,radius); + dContactGeom cg[4]; + int nc; + + // check extreme case + nc = dCollide(trimesh, sphere, 4, &cg[0], sizeof cg[0]); + CHECK_EQUAL(1, nc); + CHECK_EQUAL(0, cg[0].depth); + + // now translate both geoms + dGeomSetPosition(trimesh, 10,30,40); + dGeomSetPosition(sphere, 10,30,40+radius); + // check extreme case, again + nc = dCollide(trimesh, sphere, 4, &cg[0], sizeof cg[0]); + CHECK_EQUAL(1, nc); + CHECK_EQUAL(0, cg[0].depth); + + // and now, let's rotate the trimesh, 90 degrees on X + dMatrix3 rot = { 1, 0, 0, 0, + 0, 0, -1, 0, + 0, 1, 0, 0 }; + dGeomSetPosition(trimesh, 10,30,40); + dGeomSetRotation(trimesh, rot); + + dGeomSetPosition(sphere, 10,30-radius,40); + // check extreme case, again + nc = dCollide(trimesh, sphere, 4, &cg[0], sizeof cg[0]); + CHECK_EQUAL(1, nc); + CHECK_EQUAL(0, cg[0].depth); + } +} Property changes on: trunk/tests/collision.cpp ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ole...@us...> - 2008-10-29 20:28:35
|
Revision: 1591 http://opende.svn.sourceforge.net/opende/?rev=1591&view=rev Author: oleh_derevenko Date: 2008-10-29 20:28:31 +0000 (Wed, 29 Oct 2008) Log Message: ----------- Added: --all-collis-libs premake option added to allow inclusion of all collision library sources into the project Modified Paths: -------------- trunk/CHANGELOG.txt trunk/build/ode.lua trunk/build/premake.lua Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2008-10-29 20:22:27 UTC (rev 1590) +++ trunk/CHANGELOG.txt 2008-10-29 20:28:31 UTC (rev 1591) @@ -8,6 +8,13 @@ * keep the format consistent (79 char width, M/D/Y date format). ------------------------------------------------------------------------------ +10/29/08 Oleh_Derevenko + + * Premake scripts changed to only include chosen collision library + sources in project on Windows. --all-collis-libs premake option + added to allow inclusion of all collision library sources into the + project + 10/15/08 Remi Ricard (papaDoc) * Applying patch #2158425 64-bit GIMPACT provided by Mark William. This patch enable GIMPACT to works on 64-bit machine. Modified: trunk/build/ode.lua =================================================================== --- trunk/build/ode.lua 2008-10-29 20:22:27 UTC (rev 1590) +++ trunk/build/ode.lua 2008-10-29 20:28:31 UTC (rev 1591) @@ -221,14 +221,12 @@ if (options["no-trimesh"]) then table.insert(package.excludes, trimesh_files) else - if(options["all-trimesh"]) then - table.insert(package.files, gimpact_files) - table.insert(package.files, opcode_files) - elseif(options["with-gimpact"]) then - table.insert(package.files, gimpact_files) - else - table.insert(package.files, opcode_files) + if (options["all-collis-libs"] or options["with-gimpact"]) then + table.insert(package.files, gimpact_files) end + if (options["all-collis-libs"] or not options["with-gimpact"]) then + table.insert(package.files, opcode_files) + end end if (options["enable-ou"]) then Modified: trunk/build/premake.lua =================================================================== --- trunk/build/premake.lua 2008-10-29 20:22:27 UTC (rev 1590) +++ trunk/build/premake.lua 2008-10-29 20:28:31 UTC (rev 1591) @@ -26,6 +26,7 @@ addoption("with-demos", "Builds the demo applications and DrawStuff library") addoption("with-tests", "Builds the unit test application") addoption("with-gimpact", "Use GIMPACT for trimesh collisions (experimental)") + addoption("all-collis-libs", "Include sources of all collision libraries into the project") addoption("enable-static-only", "Only create static library (.lib) project configurations") addoption("enable-shared-only", "Only create dynamic library (.dll) project configurations") addoption("no-dif", "Exclude DIF (Dynamics Interchange Format) exports") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2008-11-18 16:40:25
|
Revision: 1594 http://opende.svn.sourceforge.net/opende/?rev=1594&view=rev Author: papaDoc Date: 2008-11-18 16:40:20 +0000 (Tue, 18 Nov 2008) Log Message: ----------- - Remove unused variable - Remove confusing text in slider unittest - Fix bug: When a slider joint had only one body attached to position 2, dJointAttach(jId, 0, bId). The body was not push in the right direction to move back between the limits. The fix is to invert the ax1 in getInfo2. - Add unit test to check for this problem. - Add unit test to check one body dJointGetSliderPosition with only one body at position 2 Modified Paths: -------------- trunk/CHANGELOG.txt trunk/ode/src/joints/slider.cpp trunk/tests/joints/slider.cpp Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2008-10-30 00:56:51 UTC (rev 1593) +++ trunk/CHANGELOG.txt 2008-11-18 16:40:20 UTC (rev 1594) @@ -8,6 +8,11 @@ * keep the format consistent (79 char width, M/D/Y date format). ------------------------------------------------------------------------------ +11/19/08 Remi Ricard (papaDoc) + * Fix bug: When a slider joint had only one body attached to position 2, + dJointAttach(jId, 0, bId). The body was not push in the right direction to + move back between the limits. + 10/29/08 Oleh_Derevenko * Premake scripts changed to only include chosen collision library Modified: trunk/ode/src/joints/slider.cpp =================================================================== --- trunk/ode/src/joints/slider.cpp 2008-10-30 00:56:51 UTC (rev 1593) +++ trunk/ode/src/joints/slider.cpp 2008-11-18 16:40:20 UTC (rev 1594) @@ -207,6 +207,9 @@ for ( i = 0; i < 3; i++ ) ofs[i] = offset[i] - pos1[i]; info->c[3] = k * dDOT ( p, ofs ); info->c[4] = k * dDOT ( q, ofs ); + + if ( flags & dJOINT_REVERSE ) + for ( i = 0; i < 3; ++i ) ax1[i] = -ax1[i]; } // if the slider is powered, or has joint limits, add in the extra row @@ -217,7 +220,6 @@ void dJointSetSliderAxis ( dJointID j, dReal x, dReal y, dReal z ) { dxJointSlider* joint = ( dxJointSlider* ) j; - int i; dUASSERT ( joint, "bad joint argument" ); checktype ( joint, Slider ); setAxes ( joint, x, y, z, joint->axis1, 0 ); @@ -231,7 +233,6 @@ void dJointSetSliderAxisDelta ( dJointID j, dReal x, dReal y, dReal z, dReal dx, dReal dy, dReal dz ) { dxJointSlider* joint = ( dxJointSlider* ) j; - int i; dUASSERT ( joint, "bad joint argument" ); checktype ( joint, Slider ); setAxes ( joint, x, y, z, joint->axis1, 0 ); Modified: trunk/tests/joints/slider.cpp =================================================================== --- trunk/tests/joints/slider.cpp 2008-10-30 00:56:51 UTC (rev 1593) +++ trunk/tests/joints/slider.cpp 2008-11-18 16:40:20 UTC (rev 1594) @@ -457,10 +457,6 @@ // X-------> X---------> Axis --> // B1 => B1 // - // Start with a Offset of offset unit - // - // X-------> X---------> Axis --> - // B1 => B1 TEST_FIXTURE (Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X, test_dJointSetSliderAxisOffset_B1_OffsetUnit) { @@ -476,10 +472,6 @@ // X-------> X---------> Axis --> // B1 => B1 // - // Start with a Offset of -offset unit - // - // X-------> X---------> Axis --> - // B1 => B1 TEST_FIXTURE (Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X, test_dJointSetSliderAxisOffset_B1_Minus_OffsetUnit) { @@ -490,6 +482,7 @@ CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4); } + // Only body 1 // The body are positionned at (0, 0, 0), with no rotation // The joint is a Slider Joint @@ -537,10 +530,6 @@ // X-------> X---------> <--- Axis // B1 => B1 // - // Start with a Offset of offset unit - // - // X-------> X---------> <--- Axis - // B1 => B1 TEST_FIXTURE (Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X, test_dJointSetSliderAxisOffset_B1_OffsetUnit) { @@ -556,10 +545,6 @@ // X-------> X---------> <--- Axis // B1 => B1 // - // Start with a Offset of -offset unit - // - // X-------> X---------> <--- Axis - // B1 => B1 TEST_FIXTURE (Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X, test_dJointSetSliderAxisOffset_B1_Minus_OffsetUnit) { @@ -571,13 +556,6 @@ } - - - - - - - // Only body 2 // The body are positionned at (0, 0, 0), with no rotation // The joint is a Slider Joint @@ -625,10 +603,6 @@ // X-------> X---------> Axis --> // B2 => B2 // - // Start with a Offset of offset unit - // - // X-------> X---------> Axis --> - // B2 => B2 TEST_FIXTURE (Fixture_dxJointSlider_B2_At_Zero_Axis_Along_X, test_dJointSetSliderAxisOffset_B2_OffsetUnit) { @@ -644,10 +618,6 @@ // X-------> X---------> Axis --> // B2 => B2 // - // Start with a Offset of -offset unit - // - // X-------> X---------> Axis --> - // B2 => B2 TEST_FIXTURE (Fixture_dxJointSlider_B2_At_Zero_Axis_Along_X, test_dJointSetSliderAxisOffset_B2_Minus_OffsetUnit) { @@ -705,10 +675,6 @@ // X-------> X---------> <--- Axis // B2 => B2 // - // Start with a Offset of offset unit - // - // X-------> X---------> <--- Axis - // B2 => B2 TEST_FIXTURE (Fixture_dxJointSlider_B2_At_Zero_Axis_Inverse_of_X, test_dJointSetSliderAxisOffset_B2_OffsetUnit) { @@ -724,10 +690,6 @@ // X-------> X---------> <--- Axis // B2 => B2 // - // Start with a Offset of -offset unit - // - // X-------> X---------> <--- Axis - // B2 => B2 TEST_FIXTURE (Fixture_dxJointSlider_B2_At_Zero_Axis_Inverse_of_X, test_dJointSetSliderAxisOffset_B2_Minus_OffsetUnit) { @@ -1139,4 +1101,226 @@ } + + // Compare Only body 1 to 2 bodies with one fixed. + // + // The body are positionned at (0, 0, 0), with no rotation + // The joint is a Slider Joint + // Axis is along the X axis + // Anchor at (0, 0, 0) + struct Fixture_dxJointSlider_Compare_Body_At_Zero_Axis_Along_X + { + Fixture_dxJointSlider_Compare_Body_At_Zero_Axis_Along_X() + { + wId = dWorldCreate(); + + bId1_12 = dBodyCreate (wId); + dBodySetPosition (bId1_12, 0, 0, 0); + + bId2_12 = dBodyCreate (wId); + dBodySetPosition (bId2_12, 0, 0, 0); + // The force will be added in the function since it is not + // always on the same body + + jId_12 = dJointCreateSlider (wId, 0); + dJointAttach(jId_12, bId1_12, bId2_12); + + fixed = dJointCreateFixed (wId, 0); + + + + bId = dBodyCreate (wId); + dBodySetPosition (bId, 0, 0, 0); + + dBodyAddForce (bId, 4, 0, 0); + + jId = dJointCreateSlider (wId, 0); + } + + ~Fixture_dxJointSlider_Compare_Body_At_Zero_Axis_Along_X() + { + dWorldDestroy (wId); + } + + dWorldID wId; + + dBodyID bId1_12; + dBodyID bId2_12; + + dJointID jId_12; // Joint with 2 bodies + + dJointID fixed; + + + + dBodyID bId; + dJointID jId; // Joint with one body + }; + + // This test compare the result of a slider with 2 bodies where body body 2 is + // fixed to the world to a slider with only one body at position 1. + // + // Test the limits [-1, 0.25] when only one body at is attached to the joint + // using dJointAttache(jId, bId, 0); + // + TEST_FIXTURE(Fixture_dxJointSlider_Compare_Body_At_Zero_Axis_Along_X, + test_Limit_minus1_025_One_Body_on_left) + { + dBodyAddForce (bId1_12, 4, 0, 0); + + dJointAttach(jId_12, bId1_12, bId2_12); + dJointSetSliderParam(jId_12, dParamLoStop, -1); + dJointSetSliderParam(jId_12, dParamHiStop, 0.25); + + dJointAttach(fixed, 0, bId2_12); + dJointSetFixed(fixed); + + dJointAttach(jId, bId, 0); + dJointSetSliderParam(jId, dParamLoStop, -1); + dJointSetSliderParam(jId, dParamHiStop, 0.25); + + + for (int i=0; i<50; ++i) + dWorldStep(wId, 1.0); + + const dReal *pos1_12 = dBodyGetPosition(bId1_12); + + const dReal *pos = dBodyGetPosition(bId); + + + CHECK_CLOSE (pos[0], pos1_12[0], 1e-4); + CHECK_CLOSE (pos[1], pos1_12[1], 1e-4); + CHECK_CLOSE (pos[2], pos1_12[2], 1e-4); + } + + + + // This test compare the result of a slider with 2 bodies where body body 1 is + // fixed to the world to a slider with only one body at position 2. + // + // Test the limits [-1, 0.25] when only one body at is attached to the joint + // using dJointAttache(jId, 0, bId); + // + TEST_FIXTURE(Fixture_dxJointSlider_Compare_Body_At_Zero_Axis_Along_X, + test_Limit_minus1_025_One_Body_on_right) + { + dBodyAddForce (bId2_12, 4, 0, 0); + + dJointAttach(jId_12, bId1_12, bId2_12); + dJointSetSliderParam(jId_12, dParamLoStop, -1); + dJointSetSliderParam(jId_12, dParamHiStop, 0.25); + + dJointAttach(fixed, bId1_12, 0); + dJointSetFixed(fixed); + + + dJointAttach(jId, 0, bId); + dJointSetSliderParam(jId, dParamLoStop, -1); + dJointSetSliderParam(jId, dParamHiStop, 0.25); + + for (int i=0; i<50; ++i) + { + dWorldStep(wId, 1.0); + } + + const dReal *pos2_12 = dBodyGetPosition(bId2_12); + + const dReal *pos = dBodyGetPosition(bId); + + + CHECK_CLOSE (pos[0], pos2_12[0], 1e-4); + CHECK_CLOSE (pos[1], pos2_12[1], 1e-4); + CHECK_CLOSE (pos[2], pos2_12[2], 1e-4); + } + + + + // This test compare the result of a slider with 2 bodies where body body 2 is + // fixed to the world to a slider with only one body at position 1. + // + // Test the limits [0, 0] when only one body at is attached to the joint + // using dJointAttache(jId, bId, 0); + // + // The body should not move since their is no room between the two limits + // + TEST_FIXTURE(Fixture_dxJointSlider_Compare_Body_At_Zero_Axis_Along_X, + test_Limit_0_0_One_Body_on_left) + { + dBodyAddForce (bId1_12, 4, 0, 0); + + dJointAttach(jId_12, bId1_12, bId2_12); + dJointSetSliderParam(jId_12, dParamLoStop, 0); + dJointSetSliderParam(jId_12, dParamHiStop, 0); + + dJointAttach(fixed, 0, bId2_12); + dJointSetFixed(fixed); + + + dJointAttach(jId, bId, 0); + dJointSetSliderParam(jId, dParamLoStop, 0); + dJointSetSliderParam(jId, dParamHiStop, 0); + + for (int i=0; i<500; ++i) + dWorldStep(wId, 1.0); + + const dReal *pos1_12 = dBodyGetPosition(bId1_12); + + const dReal *pos = dBodyGetPosition(bId); + + + CHECK_CLOSE (pos[0], pos1_12[0], 1e-4); + CHECK_CLOSE (pos[1], pos1_12[1], 1e-4); + CHECK_CLOSE (pos[2], pos1_12[2], 1e-4); + + CHECK_CLOSE (pos[0], 0, 1e-4); + CHECK_CLOSE (pos[1], 0, 1e-4); + CHECK_CLOSE (pos[2], 0, 1e-4); + } + + + // This test compare the result of a slider with 2 bodies where body body 1 is + // fixed to the world to a slider with only one body at position 2. + // + // Test the limits [0, 0] when only one body at is attached to the joint + // using dJointAttache(jId, 0, bId); + // + // The body should not move since their is no room between the two limits + // + TEST_FIXTURE(Fixture_dxJointSlider_Compare_Body_At_Zero_Axis_Along_X, + test_Limit_0_0_One_Body_on_right) + { + dBodyAddForce (bId2_12, 4, 0, 0); + + dJointAttach(jId_12, bId1_12, bId2_12); + dJointSetSliderParam(jId_12, dParamLoStop, 0); + dJointSetSliderParam(jId_12, dParamHiStop, 0); + + dJointAttach(fixed, bId1_12, 0); + dJointSetFixed(fixed); + + + dJointAttach(jId, 0, bId); + dJointSetSliderParam(jId, dParamLoStop, 0); + dJointSetSliderParam(jId, dParamHiStop, 0); + + for (int i=0; i<500; ++i) + dWorldStep(wId, 1.0); + + const dReal *pos2_12 = dBodyGetPosition(bId2_12); + + const dReal *pos = dBodyGetPosition(bId); + + + CHECK_CLOSE (pos[0], pos2_12[0], 1e-4); + CHECK_CLOSE (pos[1], pos2_12[1], 1e-4); + CHECK_CLOSE (pos[2], pos2_12[2], 1e-4); + + CHECK_CLOSE (pos[0], 0, 1e-4); + CHECK_CLOSE (pos[1], 0, 1e-4); + CHECK_CLOSE (pos[2], 0, 1e-4); + } + + + + } // End of SUITE TestdxJointSlider This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2008-11-18 19:16:31
|
Revision: 1595 http://opende.svn.sourceforge.net/opende/?rev=1595&view=rev Author: papaDoc Date: 2008-11-18 19:16:26 +0000 (Tue, 18 Nov 2008) Log Message: ----------- - Fix bug: When a piston joint had only one body attached to position 2, dJointAttach(jId, 0, bId). The body was not push in the right direction to move back between the limits. - Add more functionality to demo_piston.cpp - Run astyle on modified files. - Add svn:eol-style to demo_pistojn.cpp Modified Paths: -------------- trunk/CHANGELOG.txt trunk/ode/demo/demo_piston.cpp trunk/ode/src/joints/piston.cpp trunk/tests/joints/piston.cpp Property Changed: ---------------- trunk/ode/demo/demo_piston.cpp Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2008-11-18 16:40:20 UTC (rev 1594) +++ trunk/CHANGELOG.txt 2008-11-18 19:16:26 UTC (rev 1595) @@ -8,7 +8,15 @@ * keep the format consistent (79 char width, M/D/Y date format). ------------------------------------------------------------------------------ + 11/19/08 Remi Ricard (papaDoc) + * Fix bug: When a piston joint had only one body attached to position 2, + dJointAttach(jId, 0, bId). The body was not push in the right direction to + move back between the limits. + * Add more functionality to demo_piston.cpp + * Run astyle on modified files. + +11/19/08 Remi Ricard (papaDoc) * Fix bug: When a slider joint had only one body attached to position 2, dJointAttach(jId, 0, bId). The body was not push in the right direction to move back between the limits. @@ -77,7 +85,7 @@ * Add unittest for the piston joint * Fix problem with dJointGetPistonPosition and dJointGetPistonPositionRate when the joint is attached to only - a body 2. The sign was inversed. + a body 2. The sign was inverted. 07/09/08 Remi Ricard (papaDoc) * Optimize function Multiply1_12q1 in quickstep Modified: trunk/ode/demo/demo_piston.cpp =================================================================== --- trunk/ode/demo/demo_piston.cpp 2008-11-18 16:40:20 UTC (rev 1594) +++ trunk/ode/demo/demo_piston.cpp 2008-11-18 19:16:26 UTC (rev 1595) @@ -1,734 +1,813 @@ -/************************************************************************* - * * - * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. * - * All rights reserved. Email: ru...@q1... Web: www.q12.org * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of EITHER: * - * (1) The GNU Lesser General Public License as published by the Free * - * Software Foundation; either version 2.1 of the License, or (at * - * your option) any later version. The text of the GNU Lesser * - * General Public License is included with this library in the * - * file LICENSE.TXT. * - * (2) The BSD-style license that is included with this library in * - * the file LICENSE-BSD.TXT. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * - * LICENSE.TXT and LICENSE-BSD.TXT for more details. * - * * - * Created by: Remi Ricard * - * (rem...@si... or pa...@vi...) * - * Creation date: 2007/05/04 * - *************************************************************************/ - -/* - This program demonstrates how the Piston joint works. - - A Piston joint enables the sliding of a body with respect to another body - and the 2 bodies are free to rotate about the sliding axis. - - - The yellow body is fixed to the world. - - The yellow body and the blue body are attached by a Piston joint with - the axis along the x direction. - - The purple object is a geometry obstacle. - - The red line is the representation of the prismatic axis - - The orange line is the representation of the rotoide axis - - The light blue ball is the anchor position - - N.B. Many command options are available type -h to print them. -*/ - -#include <ode/ode.h> -#include <drawstuff/drawstuff.h> -#include <iostream> -#include <math.h> -#include "texturepath.h" - -#ifdef _MSC_VER -#pragma warning(disable:4244 4305) // for VC++, no precision loss complaints -#endif -// select correct drawing functions -#ifdef dDOUBLE -#define dsDrawBox dsDrawBoxD -#define dsDrawCylinder dsDrawCylinderD -#define dsDrawCapsule dsDrawCapsuleD -#define dsDrawSphere dsDrawSphereD -#endif +/************************************************************************* + * * + * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. * + * All rights reserved. Email: ru...@q1... Web: www.q12.org * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of EITHER: * + * (1) The GNU Lesser General Public License as published by the Free * + * Software Foundation; either version 2.1 of the License, or (at * + * your option) any later version. The text of the GNU Lesser * + * General Public License is included with this library in the * + * file LICENSE.TXT. * + * (2) The BSD-style license that is included with this library in * + * the file LICENSE-BSD.TXT. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * + * LICENSE.TXT and LICENSE-BSD.TXT for more details. * + * * + * Created by: Remi Ricard * + * (rem...@si... or pa...@vi...) * + * Creation date: 2007/05/04 * + *************************************************************************/ -//using namespace ode; - -const dReal VEL_INC = 0.01; // Velocity increment - -// physics parameters -const dReal PI = 3.14159265358979323846264338327950288419716939937510; -const dReal BODY1_LENGTH = 1.5; // Size along the X axis - -const dReal RADIUS = 0.2; -const dReal AXIS_RADIUS = 0.01; - - -#define X 0 -#define Y 1 -#define Z 2 - -enum INDEX -{ - BODY1 = 0, - BODY2, - RECT, - BOX, - OBS, - GROUND, - NUM_PARTS, - ALL = NUM_PARTS -}; - -const int catBits[NUM_PARTS+1] = - { - 0x0001, ///< Ext Cylinder category - 0x0002, ///< Int Cylinder category - 0x0004, ///< Int_Rect Cylinder category - 0x0008, ///< Box category - 0x0010, ///< Obstacle category - 0x0020, ///< Ground category - ~0L ///< All categories - }; - -#define Mass1 10 -#define Mass2 8 - - -//camera view -static float xyz[3] = {2.0f,-3.5f,2.0000f}; -static float hpr[3] = {90.000f,-25.5000f,0.0000f}; - - -//world,space,body & geom -static dWorld world; -static dSpaceID space; -static dJointGroupID contactgroup; -static dBody body[NUM_PARTS]; -static dGeomID geom[NUM_PARTS]; - -// Default Positions and anchor of the 2 bodies -dVector3 pos1; -dVector3 pos2; -dVector3 anchor; - -static dJoint *joint; - - -const dReal BODY2_SIDES[3] = {0.4, 0.4, 0.4}; -const dReal OBS_SIDES[3] = {1,1,1}; -const dReal RECT_SIDES[3] = {0.3, 0.1, 0.2}; - - -int type = dJointTypePiston; - -//#pragma message("tc to be changed to 0") - -int tc = 0; // The test case choice; - - -//collision detection -static void nearCallback (void *data, dGeomID o1, dGeomID o2) -{ - int i,n; - - dBodyID b1 = dGeomGetBody (o1); - dBodyID b2 = dGeomGetBody (o2); - if (b1 && b2 && dAreConnectedExcluding (b1,b2,dJointTypeContact) ) return; - const int N = 10; - dContact contact[N]; - n = dCollide (o1,o2,N,&contact[0].geom,sizeof (dContact) ); - if (n > 0) { - for (i=0; i<n; i++) { - contact[i].surface.mode = (dContactSlip1 | dContactSlip2 | - dContactSoftERP | dContactSoftCFM | - dContactApprox1); - contact[i].surface.mu = 0.1; - contact[i].surface.slip1 = 0.02; - contact[i].surface.slip2 = 0.02; - contact[i].surface.soft_erp = 0.1; - contact[i].surface.soft_cfm = 0.0001; - dJointID c = dJointCreateContact (world,contactgroup,&contact[i]); - dJointAttach (c,dGeomGetBody (contact[i].geom.g1),dGeomGetBody (contact[i].geom.g2) ); - } - } -} - -static void printKeyBoardShortCut() -{ - printf ("Press 'h' for this help.\n"); - printf ("Press 'q' to add force on BLUE body along positive x direction.\n"); - printf ("Press 'w' to add force on BLUE body along negative x direction.\n"); - - printf ("Press 'a' to add force on BLUE body along positive y direction.\n"); - printf ("Press 's' to add force on BLUE body along negative y direction.\n"); - - printf ("Press 'z' to add force on BLUE body along positive z direction.\n"); - printf ("Press 'x' to add force on BLUE body along negative z direction.\n"); - - printf ("Press 'e' to add torque on BLUE body around positive x direction \n"); - printf ("Press 'r' to add torque on BLUE body around negative x direction \n"); - - printf ("Press 'd' to add torque on BLUE body around positive y direction \n"); - printf ("Press 'f' to add torque on BLUE body around negative y direction \n"); - - printf ("Press 'c' to add torque on BLUE body around positive z direction \n"); - printf ("Press 'v' to add torque on BLUE body around negative z direction \n"); - - printf ("Press 't' to add force on prismatic joint in the positive axis direction\n"); - printf ("Press 'y' to add force on prismatic joint in the negative axis direction\n"); - - printf ("Press 'k' to add limits on the rotoide joint (-45 to 45deg) \n"); - printf ("Press 'l' to remove limits on the rotoide joint \n"); - - - printf ("Press '.' to increase joint velocity along the prismatic direction.\n"); - printf ("Press ',' to decrease joint velocity along the prismatic direction.\n"); - - printf ("Press 'p' to print the Position of the joint.\n"); - - printf ("Press '+' Go to the next test case.\n"); - printf ("Press '-' Go to the previous test case.\n"); -} - - -// start simulation - set viewpoint -static void start() -{ - dAllocateODEDataForThread(dAllocateMaskAll); - - dsSetViewpoint (xyz,hpr); - printf ("This program demonstrates how the Piston joint works.\n"); - printf ("A Piston joint enables the sliding of a body with respect to another body\n"); - printf ("and the 2 bodies are free to rotate about the sliding axis.\n\n"); - printf ("The yellow body is fixed to the world\n"); - printf ("The yellow body and the blue body are attached by a Piston joint with\n"); - printf ("the axis along the x direction.\n"); - printf ("The purple object is a geometry obstacle.\n"); - - printKeyBoardShortCut(); -} - - -void setPositionBodies (int val) -{ - const dVector3 POS1 = {0,0,1.5,0}; - const dVector3 POS2 = {0,0,1.5,0}; - const dVector3 ANCHOR = {0,0,1.5,0}; - - for (int i=0; i<3; ++i) { - pos1[i] = POS1[i]; - pos2[i] = POS2[i]; - anchor[i] = ANCHOR[i]; - } - - if (body[BODY1]) { - body[BODY1].setLinearVel(0,0,0); - body[BODY1].setAngularVel(0,0,0); - } - - if (body[BODY2]) { - body[BODY2].setLinearVel(0,0,0); - body[BODY2].setAngularVel(0,0,0); - } - - switch (val) { - case 3: - pos1[Z] += -0.5; - anchor[Z] -= 0.25; - break; - case 2: - pos1[Z] -= 0.5; - anchor[Z] -= 0.5; - break; - case 1: - pos1[Z] += -0.5; - break; - default: // This is also case 0 - // Nothing to be done - break; - } - - const dMatrix3 R = { - 1,0,0,0, - 0,1,0,0, - 0,0,1,0 - }; - - if (body[BODY1]) { - body[BODY1].setPosition(pos1[X], pos1[Y], pos1[Z]); - body[BODY1].setRotation(R); - } - - if (body[BODY2]) { - body[BODY2].setPosition(pos2[X], pos2[Y], pos2[Z]); - body[BODY2].setRotation(R); - } - - - - if (joint) { - joint->attach (body[BODY1], body[BODY2]); - if (joint->getType() == dJointTypePiston) - dJointSetPistonAnchor(joint->id(), anchor[X], anchor[Y], anchor[Z]); - } - -} - - -// function to update camera position at each step. -void update() -{ -// static FILE *file = fopen("x:/sim/src/libode/tstsrcSF/export.dat", "w"); - -// static int cnt = 0; -// char str[24]; -// sprintf(str, "%06d",cnt++); - -// dWorldExportDIF(world, file, str); -} - - -// called when a key pressed -static void command (int cmd) -{ - switch (cmd) { -case 'h' : case 'H' : case '?' : - printKeyBoardShortCut(); - break; - - // Force - case 'q' : case 'Q' : - dBodyAddForce (body[BODY1],4,0,0); - break; - case 'w' : case 'W' : - dBodyAddForce (body[BODY1],-4,0,0); - break; - - case 'a' : case 'A' : - dBodyAddForce (body[BODY1],0,40,0); - break; - case 's' : case 'S' : - dBodyAddForce (body[BODY1],0,-40,0); - break; - - case 'z' : case 'Z' : - dBodyAddForce (body[BODY1],0,0,4); - break; - case 'x' : case 'X' : - dBodyAddForce (body[BODY1],0,0,-4); - break; - - // Torque - case 'e': case 'E': - dBodyAddTorque (body[BODY1],0.1,0,0); - break; - case 'r': case 'R': - dBodyAddTorque (body[BODY1],-0.1,0,0); - break; - - case 'd': case 'D': - dBodyAddTorque (body[BODY1],0, 0.1,0); - break; - case 'f': case 'F': - dBodyAddTorque (body[BODY1],0,-0.1,0); - break; - - case 'c': case 'C': - dBodyAddTorque (body[BODY1],0.1,0,0); - break; - case 'v': case 'V': - dBodyAddTorque (body[BODY1],-0.1,0,0); - break; - - case 't': case 'T': - if (joint->getType() == dJointTypePiston) - dJointAddPistonForce (joint->id(),1); - else - dJointAddSliderForce (joint->id(),1); - break; - case 'y': case 'Y': - if (joint->getType() == dJointTypePiston) - dJointAddPistonForce (joint->id(),-1); - else - dJointAddSliderForce (joint->id(),-1); - break; - - - case 'k': case 'K': - if (joint->getType() == dJointTypePiston) { - dJointSetPistonParam (joint->id(),dParamLoStop2, -45.0*3.14159267/180.0); - dJointSetPistonParam (joint->id(),dParamHiStop2, 45.0*3.14159267/180.0); - } - break; - case 'l': case 'L': - if (joint->getType() == dJointTypePiston) { - dJointSetPistonParam (joint->id(),dParamLoStop2, -dInfinity); - dJointSetPistonParam (joint->id(),dParamHiStop2, dInfinity); - } - break; - - // Velocity of joint - case ',': case '<' : { - dReal vel = joint->getParam (dParamVel) - VEL_INC; - joint->setParam (dParamVel, vel); - std::cout<<"Velocity = "<<vel<<" FMax = 2"<<'\n'; - } - break; - - case '.': case '>' : { - dReal vel = joint->getParam (dParamVel) + VEL_INC; - joint->setParam (dParamVel, vel); - std::cout<<"Velocity = "<<vel<<" FMax = 2"<<'\n'; - } - break; - -case 'p' :case 'P' : { - switch (joint->getType() ) { - case dJointTypeSlider : { - dSliderJoint *sj = reinterpret_cast<dSliderJoint *> (joint); - std::cout<<"Position ="<<sj->getPosition() <<"\n"; - } - break; - case dJointTypePiston : { - dPistonJoint *rj = reinterpret_cast<dPistonJoint *> (joint); - std::cout<<"Position ="<<rj->getPosition() <<"\n"; - } +/* + This program demonstrates how the Piston joint works. + + A Piston joint enables the sliding of a body with respect to another body + and the 2 bodies are free to rotate about the sliding axis. + + - The yellow body is fixed to the world. + - The yellow body and the blue body are attached by a Piston joint with + the axis along the x direction. + - The purple object is a geometry obstacle. + - The red line is the representation of the prismatic axis + - The orange line is the representation of the rotoide axis + - The light blue ball is the anchor position + + N.B. Many command options are available type -h to print them. +*/ + +#include <ode/ode.h> +#include <drawstuff/drawstuff.h> +#include <iostream> +#include <math.h> +#include "texturepath.h" + +#ifdef _MSC_VER +#pragma warning(disable:4244 4305) // for VC++, no precision loss complaints +#endif +// select correct drawing functions +#ifdef dDOUBLE +#define dsDrawBox dsDrawBoxD +#define dsDrawCylinder dsDrawCylinderD +#define dsDrawCapsule dsDrawCapsuleD +#define dsDrawSphere dsDrawSphereD +#endif + +//using namespace ode; + +const dReal VEL_INC = 0.01; // Velocity increment + +// physics parameters +const dReal PI = 3.14159265358979323846264338327950288419716939937510; +const dReal BODY1_LENGTH = 1.5; // Size along the X axis + +const dReal RADIUS = 0.2; +const dReal AXIS_RADIUS = 0.01; + + +#define X 0 +#define Y 1 +#define Z 2 + +enum INDEX +{ + BODY1 = 0, + BODY2, + RECT, + BOX, + OBS, + GROUND, + NUM_PARTS, + ALL = NUM_PARTS +}; + +const int catBits[NUM_PARTS+1] = +{ + 0x0001, ///< Ext Cylinder category + 0x0002, ///< Int Cylinder category + 0x0004, ///< Int_Rect Cylinder category + 0x0008, ///< Box category + 0x0010, ///< Obstacle category + 0x0020, ///< Ground category + ~0L ///< All categories +}; + +#define Mass1 10 +#define Mass2 8 + + +//camera view +static float xyz[3] = {2.0f,-3.5f,2.0000f}; +static float hpr[3] = {90.000f,-25.5000f,0.0000f}; + + +//world,space,body & geom +static dWorld world; +static dSpaceID space; +static dJointGroupID contactgroup; +static dBody body[NUM_PARTS]; +static dGeomID geom[NUM_PARTS]; + +// Default Positions and anchor of the 2 bodies +dVector3 pos1; +dVector3 pos2; +dVector3 anchor; + +static dJoint *joint; + + +const dReal BODY2_SIDES[3] = {0.4, 0.4, 0.4}; +const dReal OBS_SIDES[3] = {1,1,1}; +const dReal RECT_SIDES[3] = {0.3, 0.1, 0.2}; + + +int type = dJointTypePiston; + +//#pragma message("tc to be changed to 0") + +int tc = 0; // The test case choice; + + +//collision detection +static void nearCallback (void *data, dGeomID o1, dGeomID o2) +{ + int i,n; + + dBodyID b1 = dGeomGetBody (o1); + dBodyID b2 = dGeomGetBody (o2); + if (b1 && b2 && dAreConnectedExcluding (b1,b2,dJointTypeContact) ) return; + const int N = 10; + dContact contact[N]; + n = dCollide (o1,o2,N,&contact[0].geom,sizeof (dContact) ); + if (n > 0) + { + for (i=0; i<n; i++) + { + contact[i].surface.mode = (dContactSlip1 | dContactSlip2 | + dContactSoftERP | dContactSoftCFM | + dContactApprox1); + contact[i].surface.mu = 0.1; + contact[i].surface.slip1 = 0.02; + contact[i].surface.slip2 = 0.02; + contact[i].surface.soft_erp = 0.1; + contact[i].surface.soft_cfm = 0.0001; + dJointID c = dJointCreateContact (world,contactgroup,&contact[i]); + dJointAttach (c,dGeomGetBody (contact[i].geom.g1),dGeomGetBody (contact[i].geom.g2) ); + } + } +} + +static void printKeyBoardShortCut() +{ + printf ("Press 'h' for this help.\n"); + printf ("Press 'q' to add force on BLUE body along positive x direction.\n"); + printf ("Press 'w' to add force on BLUE body along negative x direction.\n"); + + printf ("Press 'a' to add force on BLUE body along positive y direction.\n"); + printf ("Press 's' to add force on BLUE body along negative y direction.\n"); + + printf ("Press 'z' to add force on BLUE body along positive z direction.\n"); + printf ("Press 'x' to add force on BLUE body along negative z direction.\n"); + + printf ("Press 'e' to add torque on BLUE body around positive x direction \n"); + printf ("Press 'r' to add torque on BLUE body around negative x direction \n"); + + printf ("Press 'd' to add torque on BLUE body around positive y direction \n"); + printf ("Press 'f' to add torque on BLUE body around negative y direction \n"); + + printf ("Press 'c' to add torque on BLUE body around positive z direction \n"); + printf ("Press 'v' to add torque on BLUE body around negative z direction \n"); + + printf ("Press 't' to add force on prismatic joint in the positive axis direction\n"); + printf ("Press 'y' to add force on prismatic joint in the negative axis direction\n"); + + printf ("Press 'i' to add limits on the prismatic joint (0 to 0) \n"); + printf ("Press 'o' to add limits on the rotoide joint (0 to 0)\n"); + printf ("Press 'k' to add limits on the rotoide joint (-45 to 45deg) \n"); + printf ("Press 'l' to remove limits on the rotoide joint \n"); + + + printf ("Press '.' to increase joint velocity along the prismatic direction.\n"); + printf ("Press ',' to decrease joint velocity along the prismatic direction.\n"); + + printf ("Press 'p' to print the Position of the joint.\n"); + + printf ("Press '+' Go to the next test case.\n"); + printf ("Press '-' Go to the previous test case.\n"); + + printf ("Press '8' To remove one of the body. The blue body and the world will be\n"); + printf (" attached to the joint (blue body at position 1)\n"); + printf ("Press '9' To remove one of the body. The blue body and the world will be\n"); + printf (" attached to the joint (body body at position 2)\n"); + + +} + + +// start simulation - set viewpoint +static void start() +{ + dAllocateODEDataForThread(dAllocateMaskAll); + + dsSetViewpoint (xyz,hpr); + printf ("This program demonstrates how the Piston joint works.\n"); + printf ("A Piston joint enables the sliding of a body with respect to another body\n"); + printf ("and the 2 bodies are free to rotate about the sliding axis.\n\n"); + printf ("The yellow body is fixed to the world\n"); + printf ("The yellow body and the blue body are attached by a Piston joint with\n"); + printf ("the axis along the x direction.\n"); + printf ("The purple object is a geometry obstacle.\n"); + + printKeyBoardShortCut(); +} + + +void setPositionBodies (int val) +{ + const dVector3 POS1 = {0,0,1.5,0}; + const dVector3 POS2 = {0,0,1.5,0}; + const dVector3 ANCHOR = {0,0,1.5,0}; + + for (int i=0; i<3; ++i) + { + pos1[i] = POS1[i]; + pos2[i] = POS2[i]; + anchor[i] = ANCHOR[i]; + } + + if (body[BODY1]) + { + body[BODY1].setLinearVel(0,0,0); + body[BODY1].setAngularVel(0,0,0); + } + + if (body[BODY2]) + { + body[BODY2].setLinearVel(0,0,0); + body[BODY2].setAngularVel(0,0,0); + } + + switch (val) + { + case 3: + pos1[Z] += -0.5; + anchor[Z] -= 0.25; break; - default: {} // keep the compiler happy - } - } - break; - - case '+' : - (++tc) %= 4; - setPositionBodies (tc); - break; - case '-' : - (--tc) %= 4; - setPositionBodies (tc); - break; - - - } -} - -static void drawBox (dGeomID id, int R, int G, int B) -{ - if (!id) - return; - - const dReal *pos = dGeomGetPosition (id); - const dReal *rot = dGeomGetRotation (id); - dsSetColor (R,G,B); - - dVector3 l; - dGeomBoxGetLengths (id, l); - dsDrawBox (pos, rot, l); -} - - -// simulation loop -static void simLoop (int pause) -{ - const dReal *rot; - dVector3 ax; - dReal l=0; - - switch (joint->getType() ) { - case dJointTypeSlider : - ( (dSliderJoint *) joint)->getAxis (ax); - l = ( (dSliderJoint *) joint)->getPosition(); - break; - case dJointTypePiston : - ( (dPistonJoint *) joint)->getAxis (ax); - l = ( (dPistonJoint *) joint)->getPosition(); - break; - default: {} // keep the compiler happy - } - - - if (!pause) { - double simstep = 0.01; // 1ms simulation steps - double dt = dsElapsedTime(); - - int nrofsteps = (int) ceilf (dt/simstep); - if (!nrofsteps) - nrofsteps = 1; - - for (int i=0; i<nrofsteps && !pause; i++) { - dSpaceCollide (space,0,&nearCallback); - dWorldStep (world, simstep); - - dJointGroupEmpty (contactgroup); - } - - update(); - - - dReal radius, length; - - dsSetTexture (DS_WOOD); - - drawBox (geom[BODY2], 1,1,0); - - drawBox (geom[RECT], 0,0,1); - - if ( geom[BODY1] ) { - const dReal *pos = dGeomGetPosition (geom[BODY1]); - rot = dGeomGetRotation (geom[BODY1]); - dsSetColor (0,0,1); - - dGeomCapsuleGetParams (geom[BODY1], &radius, &length); - dsDrawCapsule (pos, rot, length, radius); - } - - - drawBox (geom[OBS], 1,0,1); - - - // Draw the prismatic axis - if ( geom[BODY1] ) { - const dReal *pos = dGeomGetPosition (geom[BODY1]); - rot = dGeomGetRotation (geom[BODY2]); - dVector3 p; - p[X] = pos[X] - l*ax[X]; - p[Y] = pos[Y] - l*ax[Y]; - p[Z] = pos[Z] - l*ax[Z]; - dsSetColor (1,0,0); - dsDrawCylinder (p, rot, 3.75, 1.05*AXIS_RADIUS); - } - - - if (joint->getType() == dJointTypePiston ) { - dVector3 anchor; - dJointGetPistonAnchor(joint->id(), anchor); - - // Draw the rotoide axis - rot = dGeomGetRotation (geom[BODY2]); - dsSetColor (1,0.5,0); - dsDrawCylinder (anchor, rot, 4, AXIS_RADIUS); - - - dsSetColor (0,1,1); - rot = dGeomGetRotation (geom[BODY1]); - dsDrawSphere (anchor, rot, 1.5*RADIUS); - } - - } -} - - -void Help (char **argv) -{ - printf ("%s ", argv[0]); - printf (" -h | --help : print this help\n"); - printf (" -s | --slider : Set the joint as a slider\n"); - printf (" -p | --piston : Set the joint as a Piston. (Default joint)\n"); - printf (" -1 | --offset1 : Create an offset between the 2 bodies\n"); - printf (" Offset one of the body by z=-0.5 and keep the anchor\n"); - printf (" point in the middle of the fixed body\n"); - printf (" -2 | --offset2 : Create an offset between the 2 bodies\n"); - printf (" Offset one of the body by z=-0.5 and set the anchor\n"); - printf (" point in the middle of the movable body\n"); - printf (" -3 | --offset3 : Create an offset between the 2 bodies\n"); - printf (" Offset one of the body by z=-0.5 and set the anchor\n"); - printf (" point in the middle of the 2 bodies\n"); - printf (" -t | --texture-path path : Path to the texture.\n"); - printf (" Default = %s\n", DRAWSTUFF_TEXTURE_PATH); - printf (" -n | --notFixed : In free space with no gravity mode"); - printf ("-notex : Don't use texture\n"); - printf ("-noshadow : No shadow\n"); - printf ("-noshadows : No shadows\n"); - printf ("-pause : Initial pause\n"); - printf ("--------------------------------------------------\n"); - printf ("Hit any key to continue:"); - getchar(); - - exit (0); -} - -int main (int argc, char **argv) -{ - dInitODE2(0); - bool fixed = true; - - // setup pointers to drawstuff callback functions - dsFunctions fn; - fn.version = DS_VERSION; - fn.start = &start; - fn.step = &simLoop; - fn.command = &command; - fn.stop = 0; - fn.path_to_textures = DRAWSTUFF_TEXTURE_PATH; - - dVector3 offset; - dSetZero (offset, 4); - - // Default test case - - if (argc >= 2 ) { - for (int i=1; i < argc; ++i) { - //static int tata = 0; - - if (0) { - if ( 0 == strcmp ("-h", argv[i]) || 0 == strcmp ("--help", argv[i]) ) - Help (argv); - - if ( 0 == strcmp ("-s", argv[i]) || 0 == strcmp ("--slider", argv[i]) ) - type = dJointTypeSlider; - - if ( 0 == strcmp ("-t", argv[i]) || 0 == strcmp ("--texture-path", argv[i]) ) { - int j = i+1; - if ( j+1 > argc || // Check if we have enough arguments - argv[j] == '\0' || // We should have a path here - argv[j][0] == '-' ) // We should have a path not a command line - Help (argv); - else - fn.path_to_textures = argv[++i]; // Increase i since we use this argument - } - } - - - if ( 0 == strcmp ("-1", argv[i]) || 0 == strcmp ("--offset1", argv[i]) ) - tc = 1; - - if ( 0 == strcmp ("-2", argv[i]) || 0 == strcmp ("--offset2", argv[i]) ) - tc = 2; - - if ( 0 == strcmp ("-3", argv[i]) || 0 == strcmp ("--offset3", argv[i]) ) - tc = 3; - - if (0 == strcmp ("-n", argv[i]) || 0 == strcmp ("--notFixed", argv[i]) ) - fixed = false; - } - } - - world.setERP (0.8); - - space = dSimpleSpaceCreate (0); - contactgroup = dJointGroupCreate (0); - geom[GROUND] = dCreatePlane (space, 0,0,1,0); - dGeomSetCategoryBits (geom[GROUND], catBits[GROUND]); - dGeomSetCollideBits (geom[GROUND], catBits[ALL]); - - dMass m; - dMatrix3 R; - - - // Create the Obstacle - geom[OBS] = dCreateBox (space, OBS_SIDES[0], OBS_SIDES[1], OBS_SIDES[2]); - dGeomSetCategoryBits (geom[OBS], catBits[OBS]); - dGeomSetCollideBits (geom[OBS], catBits[ALL]); - //Rotation of 45deg around y - dRFromAxisAndAngle (R, 1,1,0, -0.25*PI); - dGeomSetRotation (geom[OBS], R); - dGeomSetPosition (geom[OBS], 1.95, -0.2, 0.5); - - - //Rotation of 90deg around y - // Will orient the Z axis along X - dRFromAxisAndAngle (R, 0,1,0, -0.5*PI); - - - // Create Body2 (Wiil be attached to the world) - body[BODY2].create (world); - // Main axis of cylinder is along X=1 - m.setBox (1, BODY2_SIDES[0], BODY2_SIDES[1], BODY2_SIDES[2]); - m.adjust (Mass1); - geom[BODY2] = dCreateBox (space, BODY2_SIDES[0], BODY2_SIDES[1], BODY2_SIDES[2]); - dGeomSetBody (geom[BODY2], body[BODY2]); - dGeomSetOffsetRotation (geom[BODY2], R); - dGeomSetCategoryBits (geom[BODY2], catBits[BODY2]); - dGeomSetCollideBits (geom[BODY2], catBits[ALL] & (~catBits[BODY1]) ); - body[BODY2].setMass(&m); - - - // Create Body 1 (Slider on the prismatic axis) - body[BODY1].create (world); - // Main axis of capsule is along X=1 - m.setCapsule (1, 1, RADIUS, BODY1_LENGTH); - m.adjust(Mass1); - geom[BODY1] = dCreateCapsule (space, RADIUS, BODY1_LENGTH); - dGeomSetBody (geom[BODY1], body[BODY1]); - dGeomSetOffsetRotation (geom[BODY1], R); - dGeomSetCategoryBits (geom[BODY1], catBits[BODY1]); - dGeomSetCollideBits (geom[BODY1], catBits[ALL] & ~catBits[BODY2] & ~catBits[RECT]); - - dMass mRect; - mRect.setBox(1, RECT_SIDES[0], RECT_SIDES[1], RECT_SIDES[2]); - m.add(&mRect); - // TODO: translate m? - geom[RECT] = dCreateBox (space, RECT_SIDES[0], RECT_SIDES[1], RECT_SIDES[2]); - dGeomSetBody (geom[RECT], body[BODY1]); - dGeomSetOffsetPosition (geom[RECT], - (BODY1_LENGTH-RECT_SIDES[0]) /2.0, - 0.0, - -RADIUS -RECT_SIDES[2]/2.0); - dGeomSetCategoryBits (geom[RECT], catBits[RECT]); - dGeomSetCollideBits (geom[RECT], catBits[ALL] & (~catBits[BODY1]) ); - - body[BODY1].setMass(&m); - - - - setPositionBodies (tc); - - - if ( fixed ) { - // Attache external cylinder to the world - dJointID fixed = dJointCreateFixed (world,0); - dJointAttach (fixed , NULL, body[BODY2]); - dJointSetFixed (fixed ); - dWorldSetGravity (world,0,0,-0.8); - } - else { - dWorldSetGravity (world,0,0,0); - } - - - - - // The static is here only to help debugging - switch (type) { - case dJointTypeSlider : { - dSliderJoint *sj = new dSliderJoint (world, 0); - sj->attach (body[BODY1], body[BODY2]); - sj->setAxis (1, 0, 0); - joint = sj; - } - break; - - case dJointTypePiston : // fall through default - default: { - dPistonJoint *pj = new dPistonJoint (world, 0); - pj->attach (body[BODY1], body[BODY2]); - pj->setAxis (1, 0, 0); - - dJointSetPistonAnchor(pj->id(), anchor[X], anchor[Y], anchor[Z]); - - joint = pj; - } - break; - }; - - - // run simulation - dsSimulationLoop (argc,argv,400,300,&fn); - - delete joint; - dJointGroupDestroy (contactgroup); - dSpaceDestroy (space); - dWorldDestroy (world); - dCloseODE(); - return 0; -} - - - - + case 2: + pos1[Z] -= 0.5; + anchor[Z] -= 0.5; + break; + case 1: + pos1[Z] += -0.5; + break; + default: // This is also case 0 + // Nothing to be done + break; + } + + const dMatrix3 R = + { + 1,0,0,0, + 0,1,0,0, + 0,0,1,0 + }; + + if (body[BODY1]) + { + body[BODY1].setPosition(pos1[X], pos1[Y], pos1[Z]); + body[BODY1].setRotation(R); + } + + if (body[BODY2]) + { + body[BODY2].setPosition(pos2[X], pos2[Y], pos2[Z]); + body[BODY2].setRotation(R); + } + + + + if (joint) + { + joint->attach (body[BODY1], body[BODY2]); + if (joint->getType() == dJointTypePiston) + dJointSetPistonAnchor(joint->id(), anchor[X], anchor[Y], anchor[Z]); + } + +} + + +// function to update camera position at each step. +void update() +{ +// static FILE *file = fopen("x:/sim/src/libode/tstsrcSF/export.dat", "w"); + +// static int cnt = 0; +// char str[24]; +// sprintf(str, "%06d",cnt++); + +// dWorldExportDIF(world, file, str); +} + + +// called when a key pressed +static void command (int cmd) +{ + switch (cmd) + { + case 'h' : + case 'H' : + case '?' : + printKeyBoardShortCut(); + break; + + // Force + case 'q' : + case 'Q' : + dBodyAddForce (body[BODY1],4,0,0); + break; + case 'w' : + case 'W' : + dBodyAddForce (body[BODY1],-4,0,0); + break; + + case 'a' : + case 'A' : + dBodyAddForce (body[BODY1],0,40,0); + break; + case 's' : + case 'S' : + dBodyAddForce (body[BODY1],0,-40,0); + break; + + case 'z' : + case 'Z' : + dBodyAddForce (body[BODY1],0,0,4); + break; + case 'x' : + case 'X' : + dBodyAddForce (body[BODY1],0,0,-4); + break; + + // Torque + case 'e': + case 'E': + dBodyAddTorque (body[BODY1],0.1,0,0); + break; + case 'r': + case 'R': + dBodyAddTorque (body[BODY1],-0.1,0,0); + break; + + case 'd': + case 'D': + dBodyAddTorque (body[BODY1],0, 0.1,0); + break; + case 'f': + case 'F': + dBodyAddTorque (body[BODY1],0,-0.1,0); + break; + + case 'c': + case 'C': + dBodyAddTorque (body[BODY1],0.1,0,0); + break; + case 'v': + case 'V': + dBodyAddTorque (body[BODY1],-0.1,0,0); + break; + + case 't': + case 'T': + if (joint->getType() == dJointTypePiston) + dJointAddPistonForce (joint->id(),1); + else + dJointAddSliderForce (joint->id(),1); + break; + case 'y': + case 'Y': + if (joint->getType() == dJointTypePiston) + dJointAddPistonForce (joint->id(),-1); + else + dJointAddSliderForce (joint->id(),-1); + break; + + + case '8' : + dJointAttach(joint->id(), body[0], 0); + break; + case '9' : + dJointAttach(joint->id(), 0, body[0]); + break; + + case 'i': + case 'I' : + joint->setParam (dParamLoStop, 0); + joint->setParam (dParamHiStop, 0); + break; + + case 'o': + case 'O' : + joint->setParam (dParamLoStop2, 0); + joint->setParam (dParamHiStop2, 0); + break; + + case 'k': + case 'K': + joint->setParam (dParamLoStop2, -45.0*3.14159267/180.0); + joint->setParam (dParamHiStop2, 45.0*3.14159267/180.0); + break; + case 'l': + case 'L': + joint->setParam (dParamLoStop2, -dInfinity); + joint->setParam (dParamHiStop2, dInfinity); + break; + + // Velocity of joint + case ',': + case '<' : + { + dReal vel = joint->getParam (dParamVel) - VEL_INC; + joint->setParam (dParamVel, vel); + std::cout<<"Velocity = "<<vel<<" FMax = 2"<<'\n'; + } + break; + + case '.': + case '>' : + { + dReal vel = joint->getParam (dParamVel) + VEL_INC; + joint->setParam (dParamVel, vel); + std::cout<<"Velocity = "<<vel<<" FMax = 2"<<'\n'; + } + break; + + case 'p' : + case 'P' : + { + switch (joint->getType() ) + { + case dJointTypeSlider : + { + dSliderJoint *sj = reinterpret_cast<dSliderJoint *> (joint); + std::cout<<"Position ="<<sj->getPosition() <<"\n"; + } + break; + case dJointTypePiston : + { + dPistonJoint *rj = reinterpret_cast<dPistonJoint *> (joint); + std::cout<<"Position ="<<rj->getPosition() <<"\n"; + } + break; + default: + {} // keep the compiler happy + } + } + break; + + case '+' : + (++tc) %= 4; + setPositionBodies (tc); + break; + case '-' : + (--tc) %= 4; + setPositionBodies (tc); + break; + + + } +} + +static void drawBox (dGeomID id, int R, int G, int B) +{ + if (!id) + return; + + const dReal *pos = dGeomGetPosition (id); + const dReal *rot = dGeomGetRotation (id); + dsSetColor (R,G,B); + + dVector3 l; + dGeomBoxGetLengths (id, l); + dsDrawBox (pos, rot, l); +} + + +// simulation loop +static void simLoop (int pause) +{ + const dReal *rot; + dVector3 ax; + dReal l=0; + + switch (joint->getType() ) + { + case dJointTypeSlider : + ( (dSliderJoint *) joint)->getAxis (ax); + l = ( (dSliderJoint *) joint)->getPosition(); + break; + case dJointTypePiston : + ( (dPistonJoint *) joint)->getAxis (ax); + l = ( (dPistonJoint *) joint)->getPosition(); + break; + default: + {} // keep the compiler happy + } + + + if (!pause) + { + double simstep = 0.01; // 1ms simulation steps + double dt = dsElapsedTime(); + + int nrofsteps = (int) ceilf (dt/simstep); + if (!nrofsteps) + nrofsteps = 1; + + for (int i=0; i<nrofsteps && !pause; i++) + { + dSpaceCollide (space,0,&nearCallback); + dWorldStep (world, simstep); + + dJointGroupEmpty (contactgroup); + } + + update(); + + + dReal radius, length; + + dsSetTexture (DS_WOOD); + + drawBox (geom[BODY2], 1,1,0); + + drawBox (geom[RECT], 0,0,1); + + if ( geom[BODY1] ) + { + const dReal *pos = dGeomGetPosition (geom[BODY1]); + rot = dGeomGetRotation (geom[BODY1]); + dsSetColor (0,0,1); + + dGeomCapsuleGetParams (geom[BODY1], &radius, &length); + dsDrawCapsule (pos, rot, length, radius); + } + + + drawBox (geom[OBS], 1,0,1); + + + // Draw the prismatic axis + if ( geom[BODY1] ) + { + const dReal *pos = dGeomGetPosition (geom[BODY1]); + rot = dGeomGetRotation (geom[BODY2]); + dVector3 p; + p[X] = pos[X] - l*ax[X]; + p[Y] = pos[Y] - l*ax[Y]; + p[Z] = pos[Z] - l*ax[Z]; + dsSetColor (1,0,0); + dsDrawCylinder (p, rot, 3.75, 1.05*AXIS_RADIUS); + } + + + if (joint->getType() == dJointTypePiston ) + { + dVector3 anchor; + dJointGetPistonAnchor(joint->id(), anchor); + + // Draw the rotoide axis + rot = dGeomGetRotation (geom[BODY2]); + dsSetColor (1,0.5,0); + dsDrawCylinder (anchor, rot, 4, AXIS_RADIUS); + + + dsSetColor (0,1,1); + rot = dGeomGetRotation (geom[BODY1]); + dsDrawSphere (anchor, rot, 1.5*RADIUS); + } + + } +} + + +void Help (char **argv) +{ + printf ("%s ", argv[0]); + printf (" -h | --help : print this help\n"); + printf (" -s | --slider : Set the joint as a slider\n"); + printf (" -p | --piston : Set the joint as a Piston. (Default joint)\n"); + printf (" -1 | --offset1 : Create an offset between the 2 bodies\n"); + printf (" Offset one of the body by z=-0.5 and keep the anchor\n"); + printf (" point in the middle of the fixed body\n"); + printf (" -2 | --offset2 : Create an offset between the 2 bodies\n"); + printf (" Offset one of the body by z=-0.5 and set the anchor\n"); + printf (" point in the middle of the movable body\n"); + printf (" -3 | --offset3 : Create an offset between the 2 bodies\n"); + printf (" Offset one of the body by z=-0.5 and set the anchor\n"); + printf (" point in the middle of the 2 bodies\n"); + printf (" -t | --texture-path path : Path to the texture.\n"); + printf (" Default = %s\n", DRAWSTUFF_TEXTURE_PATH); + printf (" -n | --notFixed : In free space with no gravity mode"); + printf ("-notex : Don't use texture\n"); + printf ("-noshadow : No shadow\n"); + printf ("-noshadows : No shadows\n"); + printf ("-pause : Initial pause\n"); + printf ("--------------------------------------------------\n"); + printf ("Hit any key to continue:"); + getchar(); + + exit (0); +} + +int main (int argc, char **argv) +{ + dInitODE2(0); + bool fixed = true; + + // setup pointers to drawstuff callback functions + dsFunctions fn; + fn.version = DS_VERSION; + fn.start = &start; + fn.step = &simLoop; + fn.command = &command; + fn.stop = 0; + fn.path_to_textures = DRAWSTUFF_TEXTURE_PATH; + + dVector3 offset; + dSetZero (offset, 4); + + // Default test case + + if (argc >= 2 ) + { + for (int i=1; i < argc; ++i) + { + //static int tata = 0; + + if (1) + { + if ( 0 == strcmp ("-h", argv[i]) || 0 == strcmp ("--help", argv[i]) ) + Help (argv); + + if ( 0 == strcmp ("-s", argv[i]) || 0 == strcmp ("--slider", argv[i]) ) + type = dJointTypeSlider; + + if ( 0 == strcmp ("-t", argv[i]) || 0 == strcmp ("--texture-path", argv[i]) ) + { + int j = i+1; + if ( j+1 > argc || // Check if we have enough arguments + argv[j] == '\0' || // We should have a path here + argv[j][0] == '-' ) // We should have a path not a command line + Help (argv); + else + fn.path_to_textures = argv[++i]; // Increase i since we use this argument + } + } + + + if ( 0 == strcmp ("-1", argv[i]) || 0 == strcmp ("--offset1", argv[i]) ) + tc = 1; + + if ( 0 == strcmp ("-2", argv[i]) || 0 == strcmp ("--offset2", argv[i]) ) + tc = 2; + + if ( 0 == strcmp ("-3", argv[i]) || 0 == strcmp ("--offset3", argv[i]) ) + tc = 3; + + if (0 == strcmp ("-n", argv[i]) || 0 == strcmp ("--notFixed", argv[i]) ) + fixed = false; + } + } + + world.setERP (0.8); + + space = dSimpleSpaceCreate (0); + contactgroup = dJointGroupCreate (0); + geom[GROUND] = dCreatePlane (space, 0,0,1,0); + dGeomSetCategoryBits (geom[GROUND], catBits[GROUND]); + dGeomSetCollideBits (geom[GROUND], catBits[ALL]); + + dMass m; + dMatrix3 R; + + + // Create the Obstacle + geom[OBS] = dCreateBox (space, OBS_SIDES[0], OBS_SIDES[1], OBS_SIDES[2]); + dGeomSetCategoryBits (geom[OBS], catBits[OBS]); + dGeomSetCollideBits (geom[OBS], catBits[ALL]); + //Rotation of 45deg around y + dRFromAxisAndAngle (R, 1,1,0, -0.25*PI); + dGeomSetRotation (geom[OBS], R); + dGeomSetPosition (geom[OBS], 1.95, -0.2, 0.5); + + + //Rotation of 90deg around y + // Will orient the Z axis along X + dRFromAxisAndAngle (R, 0,1,0, -0.5*PI); + + + // Create Body2 (Wiil be attached to the world) + body[BODY2].create (world); + // Main axis of cylinder is along X=1 + m.setBox (1, BODY2_SIDES[0], BODY2_SIDES[1], BODY2_SIDES[2]); + m.adjust (Mass1); + geom[BODY2] = dCreateBox (space, BODY2_SIDES[0], BODY2_SIDES[1], BODY2_SIDES[2]); + dGeomSetBody (geom[BODY2], body[BODY2]); + dGeomSetOffsetRotation (geom[BODY2], R); + dGeomSetCategoryBits (geom[BODY2], catBits[BODY2]); + dGeomSetCollideBits (geom[BODY2], catBits[ALL] & (~catBits[BODY1]) ); + body[BODY2].setMass(&m); + + + // Create Body 1 (Slider on the prismatic axis) + body[BODY1].create (world); + // Main axis of capsule is along X=1 + m.setCapsule (1, 1, RADIUS, BODY1_LENGTH); + m.adjust(Mass1); + geom[BODY1] = dCreateCapsule (space, RADIUS, BODY1_LENGTH); + dGeomSetBody (geom[BODY1], body[BODY1]); + dGeomSetOffsetRotation (geom[BODY1], R); + dGeomSetCategoryBits (geom[BODY1], catBits[BODY1]); + dGeomSetCollideBits (geom[BODY1], catBits[ALL] & ~catBits[BODY2] & ~catBits[RECT]); + + dMass mRect; + mRect.setBox(1, RECT_SIDES[0], RECT_SIDES[1], RECT_SIDES[2]); + m.add(&mRect); + // TODO: translate m? + geom[RECT] = dCreateBox (space, RECT_SIDES[0], RECT_SIDES[1], RECT_SIDES[2]); + dGeomSetBody (geom[RECT], body[BODY1]); + dGeomSetOffsetPosition (geom[RECT], + (BODY1_LENGTH-RECT_SIDES[0]) /2.0, + 0.0, + -RADIUS -RECT_SIDES[2]/2.0); + dGeomSetCategoryBits (geom[RECT], catBits[RECT]); + dGeomSetCollideBits (geom[RECT], catBits[ALL] & (~catBits[BODY1]) ); + + body[BODY1].setMass(&m); + + + + setPositionBodies (tc); + + + if ( fixed ) + { + // Attache external cylinder to the world + dJointID fixed = dJointCreateFixed (world,0); + dJointAttach (fixed , NULL, body[BODY2]); + dJointSetFixed (fixed ); + dWorldSetGravity (world,0,0,-0.8); + } + else + { + dWorldSetGravity (world,0,0,0); + } + + + + + // The static is here only to help debugging + switch (type) + { + case dJointTypeSlider : + { + dSliderJoint *sj = new dSliderJoint (world, 0); + sj->attach (body[BODY1], body[BODY2]); + sj->setAxis (1, 0, 0); + joint = sj; + } + break; + + case dJointTypePiston : // fall through default + default: + { + dPistonJoint *pj = new dPistonJoint (world, 0); + pj->attach (body[BODY1], body[BODY2]); + pj->setAxis (1, 0, 0); + + dJointSetPistonAnchor(pj->id(), anchor[X], anchor[Y], anchor[Z]); + + joint = pj; + } + break; + }; + + + // run simulation + dsSimulationLoop (argc,argv,400,300,&fn); + + delete joint; + dJointGroupDestroy (contactgroup); + dSpaceDestroy (space); + dWorldDestroy (world); + dCloseODE(); + return 0; +} + + + + Property changes on: trunk/ode/demo/demo_piston.cpp ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ode/src/joints/piston.cpp =================================================================== --- trunk/ode/src/joints/piston.cpp 2008-11-18 16:40:20 UTC (rev 1594) +++ trunk/ode/src/joints/piston.cpp 2008-11-18 19:16:26 UTC (rev 1595) @@ -248,8 +248,18 @@ { // pos2 = 0; // N.B. We can do that to be safe but it is no necessary // R2 = 0; // N.B. We can do that to be safe but it is no necessary - // dist[i] = joint->anchor2[i] - pos1[ui]; - dOPE2 ( dist, = , anchor2, -, pos1 ); + if (flags & dJOINT_REVERSE ) + { + dist[0] = pos1[0] - anchor2[0]; // Invert the value + dist[1] = pos1[1] - anchor2[1]; + dist[2] = pos1[2] - anchor2[2]; + } + else + { + dist[0] = anchor2[0] - pos1[0]; + dist[1] = anchor2[1] - pos1[1]; + dist[2] = anchor2[2] - pos1[2]; + } } // ====================================================================== @@ -320,6 +330,7 @@ info->c[0] = k * dDOT ( p, b ); info->c[1] = k * dDOT ( q, b ); + // ====================================================================== // Work on the linear part (i.e row 2,3) // p2 + R2 anchor2' = p1 + R1 dist' @@ -383,7 +394,22 @@ info->c[3] = k * dDOT ( q, err ); - int row = 4 + limotP.addLimot ( this, info, 4, ax1, 0 ); + int row = 4; + if ( node[1].body ) + { + row += limotP.addLimot ( this, info, 4, ax1, 0 ); + } + else if (flags & dJOINT_REVERSE ) + { + dVector3 rAx1; + rAx1[0] = -ax1[0]; + rAx1[1] = -ax1[1]; + rAx1[2] = -ax1[2]; + row += limotP.addLimot ( this, info, 4, rAx1, 0 ); + } + else + row += limotP.addLimot ( this, info, 4, ax1, 0 ); + limotR.addLimot ( this, info, row, ax1, 1 ); } Modified: trunk/tests/joints/piston.cpp =================================================================== --- trunk/tests/joints/piston.cpp 2008-11-18 16:40:20 UTC (rev 1594) +++ trunk/tests/joints/piston.cpp 2008-11-18 19:16:26 UTC (rev 1595) @@ -80,9 +80,9 @@ static const dReal offset; }; const dVector3 Fixture_dxJointPiston_B1_and_B2_At_Zero_Axis_Along_X::axis = - { - 1, 0, 0 - }; + { + 1, 0, 0 + }; const dReal Fixture_dxJointPiston_B1_and_B2_At_Zero_Axis_Along_X::offset = REAL (3.1); // Move 1st body offset unit in the X direction @@ -254,9 +254,9 @@ static const dReal offset; }; const dVector3 Fixture_dxJointPiston_B1_and_B2_At_Zero_Axis_Inverse_of_X::axis = - { - -1, 0, 0 - }; + { + -1, 0, 0 + }; const dReal Fixture_dxJointPiston_B1_and_B2_At_Zero_Axis_Inverse_of_X::offset = REAL (3.1); // Move 1st body offset unit in the X direction @@ -420,9 +420,9 @@ static const dReal offset; }; const dVector3 Fixture_dxJointPiston_B1_At_Zero_Axis_Along_X::axis = - { - 1, 0, 0 - }; + { + 1, 0, 0 + }; const dReal Fixture_dxJointPiston_B1_At_Zero_Axis_Along_X::offset = REAL (3.1); // Move 1st body offset unit in the X direction @@ -521,9 +521,9 @@ static const dReal offset; }; const dVector3 Fixture_dxJointPiston_B1_At_Zero_Axis_Inverse_of_X::axis = - { - -1, 0, 0 - }; + { + -1, 0, 0 + }; const dReal Fixture_dxJointPiston_B1_At_Zero_Axis_Inverse_of_X::offset = REAL (3.1); // Move 1st body offset unit in the X direction @@ -630,9 +630,9 @@ static const dReal offset; }; const dVector3 Fixture_dxJointPiston_B2_At_Zero_Axis_Along_X::axis = - { - 1, 0, 0 - }; + { + 1, 0, 0 + }; const dReal Fixture_dxJointPiston_B2_At_Zero_Axis_Along_X::offset = REAL (3.1); // Move 2nd body offset unit in the X direction @@ -731,9 +731,9 @@ static const dReal offset; }; const dVector3 Fixture_dxJointPiston_B2_At_Zero_Axis_Inverse_of_X::axis = - { - -1, 0, 0 - }; + { + -1, 0, 0 + }; const dReal Fixture_dxJointPiston_B2_At_Zero_Axis_Inverse_of_X::offset = REAL (3.1); // Move 2nd body offset unit in the X direction @@ -1071,126 +1071,381 @@ - // Create 2 bodies attached by a Piston joint - // Axis is along the X axis (Default value - // Anchor at (0, 0, 0) (Default value) - // - // ^Y - // | - // * Body2 - // | - // | - // Body1 | - // * Z--------> - struct dxJointPiston_Test_Initialization { - dxJointPiston_Test_Initialization() +// Create 2 bodies attached by a Piston joint + // Axis is along the X axis (Default value + // Anchor at (0, 0, 0) (Default value) + // + // ^Y + // | + // * Body2 + // | + // | + // Body1 | + // * Z--------> + struct dxJointPiston_Test_Initialization { - wId = dWorldCreate(); + dxJointPiston_Test_Initialization() + { + wId = dWorldCreate(); - // Remove gravity to have the only force be the force of the joint - dWorldSetGravity(wId, 0,0,0); + // Remove gravity to have the only force be the force of the joint + dWorldSetGravity(wId, 0,0,0); - for (int j=0; j<2; ++j) { - bId[j][0] = dBodyCreate (wId); - dBodySetPosition (bId[j][0], -1, -2, -3); + for (int j=0; j<2; ++j) + { + bId[j][0] = dBodyCreate (wId); + dBodySetPosition (bId[j][0], -1, -2, -3); - bId[j][1] = dBodyCreate (wId); - dBodySetPosition (bId[j][1], 11, 22, 33); + bId[j][1] = dBodyCreate (wId); + dBodySetPosition (bId[j][1], 11, 22, 33); - dMatrix3 R; - dVector3 axis; // Random axis + dMatrix3 R; + dVector3 axis; // Random axis - axis[0] = 0.53; - axis[1] = -0.71; - axis[2] = 0.43; - dNormalize3(axis); - dRFromAxisAndAngle (R, axis[0], axis[1], axis[2], - REAL(0.47123)); // 27deg - dBodySetRotation (bId[j][0], R); + axis[0] = 0.53; + axis[1] = -0.71; + axis[2] = 0.43; + dNormalize3(axis); + dRFromAxisAndAngle (R, axis[0], axis[1], axis[2], + REAL(0.47123)); // 27deg + dBodySetRotation (bId[j][0], R); - axis[0] = 1.2; - axis[1] = 0.87; - axis[2] = -0.33; - dNormalize3(axis); - dRFromAxisAndAngle (R, axis[0], axis[1], axis[2], - REAL(0.47123)); // 27deg - dBodySetRotation (bId[j][1], R); + axis[0] = 1.2; + axis[1] = 0.87; + axis[2] = -0.33; + dNormalize3(axis); + dRFromAxisAndAngle (R, axis[0], axis[1], axis[2], + REAL(0.47123)); // 27deg + dBodySetRotation (bId[j][1], R); - jId[j] = dJointCreatePiston (wId, 0); - dJointAttach (jId[j], bId[j][0], bId[j][1]); - } + jId[j] = dJointCreatePiston (wId, 0); + dJointAttach (jId[j], bId[j][0], bId[j][1]); + } + } + + ~dxJointPiston_Test_Initialization() + { + dWorldDestroy (wId); + } + + dWorldID wId; + + dBodyID bId[2][2]; + + + dJointID jId[2]; + + }; + + + // Test if setting a Piston with its default values + // will behave the same as a default Piston joint + TEST_FIXTURE (dxJointPiston_Test_Initialization, + test_Piston_Initialization) + { + using namespace std; + + dVector3 axis; + dJointGetPistonAxis(jId[1], axis); + dJointSetPistonAxis(jId[1], axis[0], axis[1], axis[2]); + + + dVector3 anchor; + dJointGetPistonAnchor(jId[1], anchor); + dJointSetPistonAnchor(jId[1], anchor[0], anchor[1], anchor[2]); + + + for (int b=0; b<2; ++b) + { + // Compare body b of the first joint with its equivalent on the + // second joint + const dReal *qA = dBodyGetQuaternion(bId[0][b]); + const dReal *qB = dBodyGetQuaternion(bId[1][b]); + CHECK_CLOSE (qA[0], qB[0], 1e-6); + CHECK_CLOSE (qA[1], qB[1], 1e-6); + CHECK_CLOSE (qA[2], qB[2], 1e-6); + CHECK_CLOSE (qA[3], qB[3], 1e-6); + } + + dWorldStep (wId,0.5); + dWorldStep (wId,0.5); + dWorldStep (wId,0.5); + dWorldStep (wId,0.5); + + for (int b=0; b<2; ++b) + { + // Compare body b of the first joint with its equivalent on the + // second joint + const dReal *qA = dBodyGetQuaternion(bId[0][b]); + const dReal *qB = dBodyGetQuaternion(bId[1][b]); + CHECK_CLOSE (qA[0], qB[0], 1e-6); + CHECK_CLOSE (qA[1], qB[1], 1e-6); + CHECK_CLOSE (qA[2], qB[2], 1e-6); + CHECK_CLOSE (qA[3], qB[3], 1e-6); + + + const dReal *posA = dBodyGetPosition(bId[0][b]); + const dReal *posB = dBodyGetPosition(bId[1][b]); + CHECK_CLOSE (posA[0], posB[0], 1e-6); + CHECK_CLOSE (posA[1], posB[1], 1e-6); + CHECK_CLOSE (posA[2], posB[2], 1e-6); + CHECK_CLOSE (posA[3], posB[3], 1e-6); + } + + } - ~dxJointPiston_Test_Initialization() + + + + + // Compare only one body to 2 bodies with one fixed. + // + // The body are positionned at (0, 0, 0), with no rotation + // The joint is a Piston Joint + // Axis is along the X axis + // Anchor at (0, 0, 0) + struct Fixture_dxJointPiston_Compare_Body_At_Zero_Axis_Along_X { - dWorldDestroy (wId); + Fixture_dxJointPiston_Compare_Body_At_Zero_Axis_Along_X() + { + wId = dWorldCreate(); + + bId1_12 = dBodyCreate (wId); + dBodySetPosition (bId1_12, 0, 0, 0); + + bId2_12 = dBodyCreate (wId); + dBodySetPosition (bId2_12, 0, 0, 0); + // The force will be added in the function since it is not + // always on the same body + + jId_12 = dJointCreatePiston (wId, 0); + dJointAttach(jId_12, bId1_12, bId2_12); + + fixed = dJointCreateFixed (wId, 0); + + + + bId = dBodyCreate (wId); + dBodySetPosition (bId, 0, 0, 0); + + dBodyAddForce (bId, 4, 0, 0); + + jId = dJointCreatePiston (wId, 0); + } + + ~Fixture_dxJointPiston_Compare_Body_At_Zero_Axis_Along_X() + { + dWorldDestroy (wId); + } + + dWorldID wId; + + dBodyID bId1_12; + dBodyID bId2_12; + + dJointID jId_12; // Joint with 2 bodies + + dJointID fixed; + + + + dBodyID bId; + dJointID jId; // Joint with one body + }; + + // This test compare the result of a slider with 2 bodies where body body 2 is + // fixed to the world to a slider with only one body at position 1. + // + // Test the limits [-1, 0.25] when only one body at is attached to the joint + // using dJointAttache(jId, bId, 0); + // + TEST_FIXTURE(Fixture_dxJointPiston_Compare_Body_At_Zero_Axis_Along_X, + test_Limit_minus1_025_One_Body_on_left) + { + dBodyAddForce (bId1_12, 4, 0, 0); + + dJointAttach(jId_12, bId1_12, bId2_12); + dJointSetPistonParam(jId_12, dParamLoStop, -1); + dJointSetPistonParam(jId_12, dParamHiStop, 0.25); + + dJointAttach(fixed, 0, bId2_12); + dJointSetFixed(fixed); + + dJointAttach(jId, bId, 0); + dJointSetPistonParam(jId, dParamLoStop, -1); + dJointSetPistonParam(jId, dParamHiStop, 0.25); + + + for (int i=0; i<50; ++i) + dWorldStep(wId, 1.0); + + + const dReal *pos1_12 = dBodyGetPosition(bId1_12); + const dReal *pos = dBodyGetPosition(bId); + + CHECK_CLOSE (pos1_12[0], pos[0], 1e-4); + CHECK_CLOSE (pos1_12[1], pos[1], 1e-4); + CHECK_CLOSE (pos1_12[2], pos[2], 1e-4); + + const dReal *q1_12 = dBodyGetQuaternion(bId1_12); + const dReal *q = dBodyGetQuaternion(bId); + + CHECK_CLOSE (q1_12[0], q[0], 1e-4); + CHE... [truncated message content] |
From: <pa...@us...> - 2008-11-19 18:45:56
|
Revision: 1596 http://opende.svn.sourceforge.net/opende/?rev=1596&view=rev Author: papaDoc Date: 2008-11-19 18:45:46 +0000 (Wed, 19 Nov 2008) Log Message: ----------- - Fix problem with dJointGetPRPosition and dJointGetPRPositionRate when the joint is attached to only a body 2. The sign was inverted. - Add unit test to check the above problem - Increase the tolerance to remove failure in unit test - Remove compilation warning in unit test with the use of REAL() Modified Paths: -------------- trunk/CHANGELOG.txt trunk/ode/src/joints/pr.cpp trunk/tests/joints/piston.cpp trunk/tests/joints/pr.cpp trunk/tests/joints/slider.cpp Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2008-11-18 19:16:26 UTC (rev 1595) +++ trunk/CHANGELOG.txt 2008-11-19 18:45:46 UTC (rev 1596) @@ -10,13 +10,21 @@ ------------------------------------------------------------------------------ 11/19/08 Remi Ricard (papaDoc) + * Fix problem with dJointGetPRPosition and + dJointGetPRPositionRate when the joint is attached to only + a body 2. The sign was inverted. + * Add unit test to check the above problem + * Increase the tolerance to remove failure in unit test + * Remove compilation warning in unit test with the use of REAL() + +11/18/08 Remi Ricard (papaDoc) * Fix bug: When a piston joint had only one body attached to position 2, dJointAttach(jId, 0, bId). The body was not push in the right direction to move back between the limits. * Add more functionality to demo_piston.cpp * Run astyle on modified files. -11/19/08 Remi Ricard (papaDoc) +11/18/08 Remi Ricard (papaDoc) * Fix bug: When a slider joint had only one body attached to position 2, dJointAttach(jId, 0, bId). The body was not push in the right direction to move back between the limits. Modified: trunk/ode/src/joints/pr.cpp =================================================================== --- trunk/ode/src/joints/pr.cpp 2008-11-18 19:16:26 UTC (rev 1595) +++ trunk/ode/src/joints/pr.cpp 2008-11-19 18:45:46 UTC (rev 1596) @@ -95,6 +95,12 @@ q[2] = (( joint->node[0].body->posr.pos[2] + q[2] ) - ( joint->anchor2[2] ) ); + if ( joint->flags & dJOINT_REVERSE ) + { + q[0] = -q[0]; + q[1] = -q[1]; + q[2] = -q[2]; + } } dVector3 axP; @@ -120,7 +126,10 @@ return dDOT( ax1, joint->node[0].body->lvel ) - dDOT( ax1, lv2 ); } else - return dDOT( ax1, joint->node[0].body->lvel ); + { + dReal rate = dDOT( ax1, joint->node[0].body->lvel ); + return ( (joint->flags & dJOINT_REVERSE) ? -rate : rate); + } } Modified: trunk/tests/joints/piston.cpp =================================================================== --- trunk/tests/joints/piston.cpp 2008-11-18 19:16:26 UTC (rev 1595) +++ trunk/tests/joints/piston.cpp 2008-11-19 18:45:46 UTC (rev 1596) @@ -1103,18 +1103,18 @@ dMatrix3 R; dVector3 axis; // Random axis - axis[0] = 0.53; - axis[1] = -0.71; - axis[2] = 0.43; + axis[0] = REAL(0.53); + axis[1] = -REAL(0.71); + axis[2] = REAL(0.43); dNormalize3(axis); dRFromAxisAndAngle (R, axis[0], axis[1], axis[2], REAL(0.47123)); // 27deg dBodySetRotation (bId[j][0], R); - axis[0] = 1.2; - axis[1] = 0.87; - axis[2] = -0.33; + axis[0] = REAL(1.2); + axis[1] = REAL(0.87); + axis[2] = -REAL(0.33); dNormalize3(axis); dRFromAxisAndAngle (R, axis[0], axis[1], axis[2], REAL(0.47123)); // 27deg @@ -1286,9 +1286,9 @@ const dReal *pos1_12 = dBodyGetPosition(bId1_12); const dReal *pos = dBodyGetPosition(bId); - CHECK_CLOSE (pos1_12[0], pos[0], 1e-4); - CHECK_CLOSE (pos1_12[1], pos[1], 1e-4); - CHECK_CLOSE (pos1_12[2], pos[2], 1e-4); + CHECK_CLOSE (pos1_12[0], pos[0], 1e-2); + CHECK_CLOSE (pos1_12[1], pos[1], 1e-2); + CHECK_CLOSE (pos1_12[2], pos[2], 1e-2); const dReal *q1_12 = dBodyGetQuaternion(bId1_12); const dReal *q = dBodyGetQuaternion(bId); @@ -1331,9 +1331,9 @@ const dReal *pos2_12 = dBodyGetPosition(bId2_12); const dReal *pos = dBodyGetPosition(bId); - CHECK_CLOSE (pos2_12[0], pos[0], 1e-4); - CHECK_CLOSE (pos2_12[1], pos[1], 1e-4); - CHECK_CLOSE (pos2_12[2], pos[2], 1e-4); + CHECK_CLOSE (pos2_12[0], pos[0], 1e-2); + CHECK_CLOSE (pos2_12[1], pos[1], 1e-2); + CHECK_CLOSE (pos2_12[2], pos[2], 1e-2); const dReal *q2_12 = dBodyGetQuaternion(bId2_12); Modified: trunk/tests/joints/pr.cpp =================================================================== --- trunk/tests/joints/pr.cpp 2008-11-18 19:16:26 UTC (rev 1595) +++ trunk/tests/joints/pr.cpp 2008-11-19 18:45:46 UTC (rev 1596) @@ -36,8 +36,7 @@ SUITE (TestdxJointPR) { - // The 2 bodies are positionned at (0, 0, 0), and (0, 0, 0) - // The bodis have rotation of 27deg around some axis. + // The 2 bodies are positionned at (0, 0, 0), with no rotation // The joint is a PR Joint // Axis is along the X axis // Anchor at (0, 0, 0) @@ -53,22 +52,717 @@ bId2 = dBodyCreate (wId); dBodySetPosition (bId2, 0, 0, 0); + jId = dJointCreatePR (wId, 0); + joint = (dxJointPR*) jId; + + + dJointAttach (jId, bId1, bId2); + + dJointSetPRAxis1 (jId, axis[0], axis[1], axis[2]); + } + + ~Fixture_dxJointPR_B1_and_B2_At_Zero_Axis_Along_X() + { + dWorldDestroy (wId); + } + + dWorldID wId; + + dBodyID bId1; + dBodyID bId2; + + + dJointID jId; + dxJointPR* joint; + + static const dVector3 axis; + + static const dReal offset; + }; + const dVector3 Fixture_dxJointPR_B1_and_B2_At_Zero_Axis_Along_X::axis = + { + 1, 0, 0 + }; + const dReal Fixture_dxJointPR_B1_and_B2_At_Zero_Axis_Along_X::offset = REAL (3.1); + + + + + + // Move 1st body offset unit in the X direction + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + // + // Start with a Offset of offset unit + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + TEST_FIXTURE (Fixture_dxJointPR_B1_and_B2_At_Zero_Axis_Along_X, + test_dJointSetPRAxisOffset_B1_3Unit) + { + dJointSetPRAnchor (jId, 0, 0, 0); + + CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + + dBodySetPosition (bId1, offset, 0, 0); + + CHECK_CLOSE (offset, dJointGetPRPosition (jId), 1e-4); + +// dJointSetPRAnchorOffset (jId, 0, 0, 0, +// offset*axis[0],offset*axis[1],offset*axis[2]); +// CHECK_CLOSE (offset, dJointGetPRPosition (jId), 1e-4); + +// dBodySetPosition (bId1, 0, 0, 0); +// CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + +// // Only here to test a deprecated warning +// dJointSetPRAxisDelta (jId, 1, 0, 0, 0, 0, 0); + } + + // Move 1st body offset unit in the opposite X direction + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + // + // Start with a Offset of -offset unit + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + TEST_FIXTURE (Fixture_dxJointPR_B1_and_B2_At_Zero_Axis_Along_X, + test_dJointSetPRAxisOffset_B1_Minus_3Unit) + { + dJointSetPRAnchor (jId, 0, 0, 0); + + CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + + dBodySetPosition (bId1, -offset, 0, 0); + + CHECK_CLOSE (-offset, dJointGetPRPosition (jId), 1e-4); + +// dJointSetPRAnchorOffset (jId, 0, 0, 0, +// -offset*axis[0],-offset*axis[1],-offset*axis[2]); +// CHECK_CLOSE (-offset, dJointGetPRPosition (jId), 1e-4); + +// dBodySetPosition (bId1, 0, 0, 0); +// CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + } + + // Move 2nd body offset unit in the X direction + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + // + // Start with a Offset of offset unit + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + TEST_FIXTURE (Fixture_dxJointPR_B1_and_B2_At_Zero_Axis_Along_X, + test_dJointSetPRAxisOffset_B2_3Unit) + { + dJointSetPRAnchor (jId, 0, 0, 0); + + CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + + dBodySetPosition (bId2, offset, 0, 0); + + CHECK_CLOSE (-offset, dJointGetPRPosition (jId), 1e-4); + +// dJointSetPRAnchorOffset (jId, 0, 0, 0, +// -offset*axis[0],-offset*axis[1],-offset*axis[2]); +// CHECK_CLOSE (-offset, dJointGetPRPosition (jId), 1e-4); + +// dBodySetPosition (bId2, 0, 0, 0); +// CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + } + + // Move 2nd body offset unit in the opposite X direction + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + // + // Start with a Offset of -offset unit + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + TEST_FIXTURE (Fixture_dxJointPR_B1_and_B2_At_Zero_Axis_Along_X, + test_dJointSetPRAxisOffset_B2_Minus_3Unit) + { + dJointSetPRAnchor (jId, 0, 0, 0); + + CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + + dBodySetPosition (bId2, -offset, 0, 0); + + CHECK_CLOSE (offset, dJointGetPRPosition (jId), 1e-4); + +// dJointSetPRAnchorOffset (jId, 0, 0, 0, +// offset*axis[0],offset*axis[1],offset*axis[2]); +// CHECK_CLOSE (offset, dJointGetPRPosition (jId), 1e-4); + +// dBodySetPosition (bId2, 0, 0, 0); +// CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + } + + + + + + + // Only body 1 + // The body are positionned at (0, 0, 0), with no rotation + // The joint is a PR Joint + // Axis is along the X axis + // Anchor at (0, 0, 0) + struct Fixture_dxJointPR_B1_At_Zero_Axis_Along_X + { + Fixture_dxJointPR_B1_At_Zero_Axis_Along_X() + { + wId = dWorldCreate(); + + bId1 = dBodyCreate (wId); + dBodySetPosition (bId1, 0, 0, 0); + + jId = dJointCreatePR (wId, 0); + joint = (dxJointPR*) jId; + + + dJointAttach (jId, bId1, NULL); + + dJointSetPRAxis1 (jId, axis[0], axis[1], axis[2]); + } + + ~Fixture_dxJointPR_B1_At_Zero_Axis_Along_X() + { + dWorldDestroy (wId); + } + + dWorldID wId; + + dBodyID bId1; + + dJointID jId; + dxJointPR* joint; + + static const dVector3 axis; + + static const dReal offset; + }; + const dVector3 Fixture_dxJointPR_B1_At_Zero_Axis_Along_X::axis = + { + 1, 0, 0 + }; + const dReal Fixture_dxJointPR_B1_At_Zero_Axis_Along_X::offset = REAL (3.1); + + // Move 1st body offset unit in the X direction + // + // X-------> X---------> Axis --> + // B1 => B1 + // + // Start with a Offset of offset unit + // + // X-------> X---------> Axis --> + // B1 => B1 + TEST_FIXTURE (Fixture_dxJointPR_B1_At_Zero_Axis_Along_X, + test_dJointSetPRAxisOffset_B1_OffsetUnit) + { + dJointSetPRAnchor (jId, 0, 0, 0); + + CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + + dBodySetPosition (bId1, offset, 0, 0); + + CHECK_CLOSE (offset, dJointGetPRPosition (jId), 1e-4); + +// dJointSetPRAnchorOffset (jId, 0, 0, 0, +// offset*axis[0],offset*axis[1],offset*axis[2]); +// CHECK_CLOSE (offset, dJointGetPRPosition (jId), 1e-4); + +// dBodySetPosition (bId1, 0, 0, 0); +// CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + } + + // Move 1st body offset unit in the opposite X direction + // + // X-------> X---------> Axis --> + // B1 => B1 + // + // Start with a Offset of -offset unit + // + // X-------> X---------> Axis --> + // B1 => B1 + TEST_FIXTURE (Fixture_dxJointPR_B1_At_Zero_Axis_Along_X, + test_dJointSetPRAxisOffset_B1_Minus_OffsetUnit) + { + dJointSetPRAnchor (jId, 0, 0, 0); + + CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + + dBodySetPosition (bId1, -offset, 0, 0); + + CHECK_CLOSE (-offset, dJointGetPRPosition (jId), 1e-4); + +// dJointSetPRAnchorOffset (jId, 0, 0, 0, +// -offset*axis[0],-offset*axis[1],-offset*axis[2]); +// CHECK_CLOSE (-offset, dJointGetPRPosition (jId), 1e-4); + +// dBodySetPosition (bId1, 0, 0, 0); +// CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + } + + // Only body 1 + // The body are positionned at (0, 0, 0), with no rotation + // The joint is a PR Joint + // Axis is in the oppsite X axis + // Anchor at (0, 0, 0) + struct Fixture_dxJointPR_B1_At_Zero_Axis_Inverse_of_X + { + Fixture_dxJointPR_B1_At_Zero_Axis_Inverse_of_X() + { + wId = dWorldCreate(); + + bId1 = dBodyCreate (wId); + dBodySetPosition (bId1, 0, 0, 0); + + jId = dJointCreatePR (wId, 0); + joint = (dxJointPR*) jId; + + + dJointAttach (jId, bId1, NULL); + + dJointSetPRAxis1 (jId, axis[0], axis[1], axis[2]); + } + + ~Fixture_dxJointPR_B1_At_Zero_Axis_Inverse_of_X() + { + dWorldDestroy (wId); + } + + dWorldID wId; + + dBodyID bId1; + + dJointID jId; + dxJointPR* joint; + + static const dVector3 axis; + + static const dReal offset; + }; + const dVector3 Fixture_dxJointPR_B1_At_Zero_Axis_Inverse_of_X::axis = + { + -1, 0, 0 + }; + const dReal Fixture_dxJointPR_B1_At_Zero_Axis_Inverse_of_X::offset = REAL (3.1); + + // Move 1st body offset unit in the X direction + // + // X-------> X---------> <--- Axis + // B1 => B1 + // + // Start with a Offset of offset unit + // + // X-------> X---------> <--- Axis + // B1 => B1 + TEST_FIXTURE (Fixture_dxJointPR_B1_At_Zero_Axis_Inverse_of_X, + test_dJointSetPRAxisOffset_B1_OffsetUnit) + { + dJointSetPRAnchor (jId, 0, 0, 0); + + CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + + dBodySetPosition (bId1, offset, 0, 0); + + CHECK_CLOSE (-offset, dJointGetPRPosition (jId), 1e-4); + +// dJointSetPRAnchorOffset (jId, 0, 0, 0, +// -offset*axis[0],-offset*axis[1],-offset*axis[2]); +// CHECK_CLOSE (-offset, dJointGetPRPosition (jId), 1e-4); + +// dBodySetPosition (bId1, 0, 0, 0); +// CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + } + + // Move 1st body offset unit in the opposite X direction + // + // X-------> X---------> <--- Axis + // B1 => B1 + // + // Start with a Offset of -offset unit + // + // X-------> X---------> <--- Axis + // B1 => B1 + TEST_FIXTURE (Fixture_dxJointPR_B1_At_Zero_Axis_Inverse_of_X, + test_dJointSetPRAxisOffset_B1_Minus_OffsetUnit) + { + dJointSetPRAnchor (jId, 0, 0, 0); + + CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + + dBodySetPosition (bId1, -offset, 0, 0); + + CHECK_CLOSE (offset, dJointGetPRPosition (jId), 1e-4); + +// dJointSetPRAnchorOffset (jId, 0, 0, 0, +// offset*axis[0],offset*axis[1],offset*axis[2]); +// CHECK_CLOSE (offset, dJointGetPRPosition (jId), 1e-4); + +// dBodySetPosition (bId1, 0, 0, 0); +// CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + } + + + + + // Compare only one body to 2 bodies with one fixed. + // + // The body are positionned at (0, 0, 0), with no rotation + // The joint is a PR Joint + // Axis is along the X axis + // Anchor at (0, 0, 0) + struct Fixture_dxJointPR_Compare_Body_At_Zero_Axis_Along_X + { + Fixture_dxJointPR_Compare_Body_At_Zero_Axis_Along_X() + { + wId = dWorldCreate(); + + bId1_12 = dBodyCreate (wId); + dBodySetPosition (bId1_12, 0, 0, 0); + + bId2_12 = dBodyCreate (wId); + dBodySetPosition (bId2_12, 0, 0, 0); + // The force will be added in the function since it is not + // always on the same body + + jId_12 = dJointCreatePR (wId, 0); + dJointAttach(jId_12, bId1_12, bId2_12); + + fixed = dJointCreateFixed (wId, 0); + + + + jId = dJointCreatePR (wId, 0); + + bId = dBodyCreate (wId); + dBodySetPosition (bId, 0, 0, 0); + + // Linear velocity along the prismatic axis; + dVector3 axis; + dJointGetPRAxis1(jId_12, axis); + dJointSetPRAxis1(jId, axis[0], axis[1], axis[2]); + dBodySetLinearVel (bId, 4*axis[0], 4*axis[1], 4*axis[2]); + } + + ~Fixture_dxJointPR_Compare_Body_At_Zero_Axis_Along_X() + { + dWorldDestroy (wId); + } + + dWorldID wId; + + dBodyID bId1_12; + dBodyID bId2_12; + + dJointID jId_12; // Joint with 2 bodies + + dJointID fixed; + + + + dBodyID bId; + dJointID jId; // Joint with one body + }; + + + TEST_FIXTURE (Fixture_dxJointPR_Compare_Body_At_Zero_Axis_Along_X, + test_dJointSetPRPositionRate_Only_B1) + { + // Linear velocity along the prismatic axis; + dVector3 axis; + dJointGetPRAxis1(jId_12, axis); + dBodySetLinearVel (bId1_12, 4*axis[0], 4*axis[1], 4*axis[2]); + + dJointAttach(jId_12, bId1_12, bId2_12); + + dJointAttach(fixed, 0, bId2_12); + dJointSetFixed(fixed); + + dJointAttach(jId, bId, 0); + + CHECK_CLOSE(dJointGetPRPositionRate(jId_12), dJointGetPRPositionRate(jId), 1e-2); + + CHECK_CLOSE(dJointGetPRAngleRate(jId_12), dJointGetPRAngleRate(jId), 1e-2); + } + + + TEST_FIXTURE (Fixture_dxJointPR_Compare_Body_At_Zero_Axis_Along_X, + test_dJointSetPRPositionRate_Only_B2) + { + // Linear velocity along the prismatic axis; + dVector3 axis; + dJointGetPRAxis1(jId_12, axis); + dBodySetLinearVel (bId2_12, 4*axis[0], 4*axis[1], 4*axis[2]); + + dJointAttach(jId_12, bId1_12, bId2_12); + + dJointAttach(fixed, bId1_12, 0); + dJointSetFixed(fixed); + + dJointAttach(jId, 0, bId); + + CHECK_CLOSE(dJointGetPRPositionRate(jId_12), dJointGetPRPositionRate(jId), 1e-2); + CHECK_CLOSE(dJointGetPRAngleRate(jId_12), dJointGetPRAngleRate(jId), 1e-2); + } + + + + + + // Only body 2 + // The body are positionned at (0, 0, 0), with no rotation + // The joint is a PR Joint + // Axis is along the X axis + // Anchor at (0, 0, 0) + struct Fixture_dxJointPR_B2_At_Zero_Axis_Along_X + { + Fixture_dxJointPR_B2_At_Zero_Axis_Along_X() + { + wId = dWorldCreate(); + + bId2 = dBodyCreate (wId); + dBodySetPosition (bId2, 0, 0, 0); + + jId = dJointCreatePR (wId, 0); + joint = (dxJointPR*) jId; + + + dJointAttach (jId, NULL, bId2); + + dJointSetPRAxis1 (jId, axis[0], axis[1], axis[2]); + } + + ~Fixture_dxJointPR_B2_At_Zero_Axis_Along_X() + { + dWorldDestroy (wId); + } + + dWorldID wId; + + dBodyID bId2; + + dJointID jId; + dxJointPR* joint; + + static const dVector3 axis; + + static const dReal offset; + }; + const dVector3 Fixture_dxJointPR_B2_At_Zero_Axis_Along_X::axis = + { + 1, 0, 0 + }; + const dReal Fixture_dxJointPR_B2_At_Zero_Axis_Along_X::offset = REAL (3.1); + + // Move 2nd body offset unit in the X direction + // + // X-------> X---------> Axis --> + // B2 => B2 + // + // Start with a Offset of offset unit + // + // X-------> X---------> Axis --> + // B2 => B2 + TEST_FIXTURE (Fixture_dxJointPR_B2_At_Zero_Axis_Along_X, + test_dJointSetPRAxisOffset_B2_OffsetUnit) + { + dJointSetPRAnchor (jId, 0, 0, 0); + + CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + + dBodySetPosition (bId2, offset, 0, 0); + + CHECK_CLOSE (-offset, dJointGetPRPosition (jId), 1e-4); + +// dJointSetPRAnchorOffset (jId, 0, 0, 0, +// -offset*axis[0],-offset*axis[1],-offset*axis[2]); +// CHECK_CLOSE (-offset, dJointGetPRPosition (jId), 1e-4); + +// dBodySetPosition (bId2, 0, 0, 0); +// CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + } + + // Move 2nd body offset unit in the opposite X direction + // + // X-------> X---------> Axis --> + // B2 => B2 + // + // Start with a Offset of -offset unit + // + // X-------> X---------> Axis --> + // B2 => B2 + TEST_FIXTURE (Fixture_dxJointPR_B2_At_Zero_Axis_Along_X, + test_dJointSetPRAxisOffset_B2_Minus_OffsetUnit) + { + dJointSetPRAnchor (jId, 0, 0, 0); + + CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + + dBodySetPosition (bId2, -offset, 0, 0); + + CHECK_CLOSE (offset, dJointGetPRPosition (jId), 1e-4); + +// dJointSetPRAnchorOffset (jId, 0, 0, 0, +// offset*axis[0],offset*axis[1],offset*axis[2]); +// CHECK_CLOSE (offset, dJointGetPRPosition (jId), 1e-4); + +// dBodySetPosition (bId2, 0, 0, 0); +// CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + } + + // Only body 2 + // The body are positionned at (0, 0, 0), with no rotation + // The joint is a PR Joint + // Axis is in the opposite X axis + // Anchor at (0, 0, 0) + struct Fixture_dxJointPR_B2_At_Zero_Axis_Inverse_of_X + { + Fixture_dxJointPR_B2_At_Zero_Axis_Inverse_of_X() + { + wId = dWorldCreate(); + + bId2 = dBodyCreate (wId); + dBodySetPosition (bId2, 0, 0, 0); + + jId = dJointCreatePR (wId, 0); + joint = (dxJointPR*) jId; + + + dJointAttach (jId, NULL, bId2); + + dJointSetPRAxis1 (jId, axis[0], axis[1], axis[2]); + } + + ~Fixture_dxJointPR_B2_At_Zero_Axis_Inverse_of_X() + { + dWorldDestroy (wId); + } + + dWorldID wId; + + dBodyID bId2; + + dJointID jId; + dxJointPR* joint; + + static const dVector3 axis; + + static const dReal offset; + }; + const dVector3 Fixture_dxJointPR_B2_At_Zero_Axis_Inverse_of_X::axis = + { + -1, 0, 0 + }; + const dReal Fixture_dxJointPR_B2_At_Zero_Axis_Inverse_of_X::offset = REAL (3.1); + + // Move 2nd body offset unit in the X direction + // + // X-------> X---------> <--- Axis + // B2 => B2 + // + // Start with a Offset of offset unit + // + // X-------> X---------> <--- Axis + // B2 => B2 + TEST_FIXTURE (Fixture_dxJointPR_B2_At_Zero_Axis_Inverse_of_X, + test_dJointSetPRAxisOffset_B2_OffsetUnit) + { + dJointSetPRAnchor (jId, 0, 0, 0); + + CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + + dBodySetPosition (bId2, offset, 0, 0); + + CHECK_CLOSE (offset, dJointGetPRPosition (jId), 1e-4); + +// dJointSetPRAnchorOffset (jId, 0, 0, 0, +// offset*axis[0],offset*axis[1],offset*axis[2]); +// CHECK_CLOSE (offset, dJointGetPRPosition (jId), 1e-4); + +// dBodySetPosition (bId2, 0, 0, 0); +// CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); +// dJointSetPRAxisDelta (jId, 1, 0, 0, 0, 0, 0); + } + + // Move 1st body offset unit in the opposite X direction + // + // X-------> X---------> <--- Axis + // B2 => B2 + // + // Start with a Offset of -offset unit + // + // X-------> X---------> <--- Axis + // B2 => B2 + TEST_FIXTURE (Fixture_dxJointPR_B2_At_Zero_Axis_Inverse_of_X, + test_dJointSetPRAxisOffset_B2_Minus_OffsetUnit) + { + dJointSetPRAnchor (jId, 0, 0, 0); + + CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + + dBodySetPosition (bId2, -offset, 0, 0); + + CHECK_CLOSE (-offset, dJointGetPRPosition (jId), 1e-4); + +// dJointSetPRAnchorOffset (jId, 0, 0, 0, +// -offset*axis[0],-offset*axis[1],-offset*axis[2]); +// CHECK_CLOSE (-offset, dJointGetPRPosition (jId), 1e-4); + +// dBodySetPosition (bId2, 0, 0, 0); +// CHECK_CLOSE (0.0, dJointGetPRPosition (jId), 1e-4); + } + + + // The 2 bodies are positionned at (0, 0, 0), and (0, 0, 0) + // The bodis have rotation of 27deg around some axis. + // The joint is a PR Joint + // Axis is along the X axis + // Anchor at (0, 0, 0) + struct Fixture_dxJointPR_B1_and_B2_Random_Orientation_At_Zero_Axis_Along_X + { + Fixture_dxJointPR_B1_and_B2_Random_Orientation_At_Zero_Axis_Along_X() + { + wId = dWorldCreate(); + + bId1 = dBodyCreate (wId); + dBodySetPosition (bId1, 0, 0, 0); + + bId2 = dBodyCreate (wId); + dBodySetPosition (bId2, 0, 0, 0); + dMatrix3 R; dVector3 axis; // Random axis - axis[0] = 0.53; - axis[1] = -0.71; - axis[2] = 0.43; + axis[0] = REAL(0.53); + axis[1] = -REAL(0.71); + axis[2] = REAL(0.43); dNormalize3(axis); dRFromAxisAndAngle (R, axis[0], axis[1], axis[2], REAL(0.47123)); // 27deg dBodySetRotation (bId1, R); - axis[0] = 1.2; - axis[1] = 0.87; - axis[2] = -0.33; + axis[0] = REAL(1.2); + axis[1] = REAL(0.87); + axis[2] = -REAL(0.33); dNormalize3(axis); dRFromAxisAndAngle (R, axis[0], axis[1], axis[2], REAL(0.47123)); // 27deg @@ -81,7 +775,7 @@ dJointAttach (jId, bId1, bId2); } - ~Fixture_dxJointPR_B1_and_B2_At_Zero_Axis_Along_X() + ~Fixture_dxJointPR_B1_and_B2_Random_Orientation_At_Zero_Axis_Along_X() { dWorldDestroy (wId); } @@ -97,7 +791,7 @@ }; // Test is dJointSetPRAxis and dJointGetPRAxis return same value - TEST_FIXTURE (Fixture_dxJointPR_B1_and_B2_At_Zero_Axis_Along_X, + TEST_FIXTURE (Fixture_dxJointPR_B1_and_B2_Random_Orientation_At_Zero_Axis_Along_X, test_dJointSetGetPRAxis) { dVector3 axisOrig, axis; @@ -123,126 +817,131 @@ - // Create 2 bodies attached by a PR joint - // Axis is along the X axis (Default value - // Anchor at (0, 0, 0) (Default value) - // - // ^Y - // | - // * Body2 - // | - // | - // Body1 | - // * Z--------> - struct dxJointPR_Test_Initialization { - dxJointPR_Test_Initialization() + // Create 2 bodies attached by a PR joint + // Axis is along the X axis (Default value + // Anchor at (0, 0, 0) (Default value) + // + // ^Y + // | + // * Body2 + // | + // | + // Body1 | + // * Z--------> + struct dxJointPR_Test_Initialization { - wId = dWorldCreate(); + dxJointPR_Test_Initialization() + { + wId = dWorldCreate(); - // Remove gravity to have the only force be the force of the joint - dWorldSetGravity(wId, 0,0,0); + // Remove gravity to have the only force be the force of the joint + dWorldSetGravity(wId, 0,0,0); - for (int j=0; j<2; ++j) { - bId[j][0] = dBodyCreate (wId); - dBodySetPosition (bId[j][0], -1, -2, -3); + for (int j=0; j<2; ++j) + { + bId[j][0] = dBodyCreate (wId); + dBodySetPosition (bId[j][0], -1, -2, -3); - bId[j][1] = dBodyCreate (wId); - dBodySetPosition (bId[j][1], 11, 22, 33); + bId[j][1] = dBodyCreate (wId); + dBodySetPosition (bId[j][1], 11, 22, 33); - dMatrix3 R; - dVector3 axis; // Random axis + dMatrix3 R; + dVector3 axis; // Random axis - axis[0] = 0.53; - axis[1] = -0.71; - axis[2] = 0.43; - dNormalize3(axis); - dRFromAxisAndAngle (R, axis[0], axis[1], axis[2], - REAL(0.47123)); // 27deg - dBodySetRotation (bId[j][0], R); + axis[0] = REAL(0.53); + axis[1] = -REAL(0.71); + axis[2] = REAL(0.43); + dNormalize3(axis); + dRFromAxisAndAngle (R, axis[0], axis[1], axis[2], + REAL(0.47123)); // 27deg + dBodySetRotation (bId[j][0], R); - axis[0] = 1.2; - axis[1] = 0.87; - axis[2] = -0.33; - dNormalize3(axis); - dRFromAxisAndAngle (R, axis[0], axis[1], axis[2], - REAL(0.47123)); // 27deg - dBodySetRotation (bId[j][1], R); + axis[0] = REAL(1.2); + axis[1] = REAL(0.87); + axis[2] = -REAL(0.33); + dNormalize3(axis); + dRFromAxisAndAngle (R, axis[0], axis[1], axis[2], + REAL(0.47123)); // 27deg + dBodySetRotation (bId[j][1], R); - jId[j] = dJointCreatePR (wId, 0); - dJointAttach (jId[j], bId[j][0], bId[j][1]); - } - } + jId[j] = dJointCreatePR (wId, 0); + dJointAttach (jId[j], bId[j][0], bId[j][1]); + } + } - ~dxJointPR_Test_Initialization() - { - dWorldDestroy (wId); - } + ~dxJointPR_Test_Initialization() + { + dWorldDestroy (wId); + } - dWorldID wId; + dWorldID wId; - dBodyID bId[2][2]; + dBodyID bId[2][2]; - dJointID jId[2]; + dJointID jId[2]; - }; + }; - // Test if setting a PR with its default values - // will behave the same as a default PR joint - TEST_FIXTURE (dxJointPR_Test_Initialization, - test_PR_Initialization) { - using namespace std; + // Test if setting a PR with its default values + // will behave the same as a default PR joint + TEST_FIXTURE (dxJointPR_Test_Initialization, + test_PR_Initialization) + { + using namespace std; - dVector3 axis; - dJointGetPRAxis1(jId[1], axis); - dJointSetPRAxis1(jId[1], axis[0], axis[1], axis[2]); + dVector3 axis; + dJointGetPRAxis1(jId[1], axis); + dJointSetPRAxis1(jId[1], axis[0], axis[1], axis[2]); - dJointGetPRAxis2(jId[1], axis); - dJointSetPRAxis2(jId[1], axis[0], axis[1], axis[2]); + dJointGetPRAxis2(jId[1], axis); + dJointSetPRAxis2(jId[1], axis[0], axis[1], axis[2]); - dVector3 anchor; - dJointGetPRAnchor(jId[1], anchor); - dJointSetPRAnchor(jId[1], anchor[0], anchor[1], anchor[2]); + dVector3 anchor; + dJointGetPRAnchor(jId[1], anchor); + dJointSetPRAnchor(jId[1], anchor[0], anchor[1], anchor[2]); - for (int b=0; b<2; ++b) { - // Compare body b of the first joint with its equivalent on the - // second joint - const dReal *qA = dBodyGetQuaternion(bId[0][b]); - const dReal *qB = dBodyGetQuaternion(bId[1][b]); - CHECK_CLOSE (qA[0], qB[0], 1e-4); - CHECK_CLOSE (qA[1], qB[1], 1e-4); - CHECK_CLOSE (qA[2], qB[2], 1e-4); - CHECK_CLOSE (qA[3], qB[3], 1e-4); - } + for (int b=0; b<2; ++b) + { + // Compare body b of the first joint with its equivalent on the + // second joint + const dReal *qA = dBodyGetQuaternion(bId[0][b]); + const dReal *qB = dBodyGetQuaternion(bId[1][b]); + CHECK_CLOSE (qA[0], qB[0], 1e-4); + CHECK_CLOSE (qA[1], qB[1], 1e-4); + CHECK_CLOSE (qA[2], qB[2], 1e-4); + CHECK_CLOSE (qA[3], qB[3], 1e-4); + } - dWorldStep (wId,0.5); - dWorldStep (wId,0.5); - dWorldStep (wId,0.5); - dWorldStep (wId,0.5); + dWorldStep (wId,0.5); + dWorldStep (wId,0.5); + dWorldStep (wId,0.5); + dWorldStep (wId,0.5); - for (int b=0; b<2; ++b) { - // Compare body b of the first joint with its equivalent on the - // second joint - const dReal *qA = dBodyGetQuaternion(bId[0][b]); - const dReal *qB = dBodyGetQuaternion(bId[1][b]); - CHECK_CLOSE (qA[0], qB[0], 1e-4); - CHECK_CLOSE (qA[1], qB[1], 1e-4); - CHECK_CLOSE (qA[2], qB[2], 1e-4); - CHECK_CLOSE (qA[3], qB[3], 1e-4); + for (int b=0; b<2; ++b) + { + // Compare body b of the first joint with its equivalent on the + // second joint + const dReal *qA = dBodyGetQuaternion(bId[0][b]); + const dReal *qB = dBodyGetQuaternion(bId[1][b]); + CHECK_CLOSE (qA[0], qB[0], 1e-4); + CHECK_CLOSE (qA[1], qB[1], 1e-4); + CHECK_CLOSE (qA[2], qB[2], 1e-4); + CHECK_CLOSE (qA[3], qB[3], 1e-4); - const dReal *posA = dBodyGetPosition(bId[0][b]); - const dReal *posB = dBodyGetPosition(bId[1][b]); - CHECK_CLOSE (posA[0], posB[0], 1e-4); - CHECK_CLOSE (posA[1], posB[1], 1e-4); - CHECK_CLOSE (posA[2], posB[2], 1e-4); - CHECK_CLOSE (posA[3], posB[3], 1e-4); + const dReal *posA = dBodyGetPosition(bId[0][b]); + const dReal *posB = dBodyGetPosition(bId[1][b]); + CHECK_CLOSE (posA[0], posB[0], 1e-4); + CHECK_CLOSE (posA[1], posB[1], 1e-4); + CHECK_CLOSE (posA[2], posB[2], 1e-4); + CHECK_CLOSE (posA[3], posB[3], 1e-4); + } } - } } // End of SUITE TestdxJointPR Modified: trunk/tests/joints/slider.cpp =================================================================== --- trunk/tests/joints/slider.cpp 2008-11-18 19:16:26 UTC (rev 1595) +++ trunk/tests/joints/slider.cpp 2008-11-19 18:45:46 UTC (rev 1596) @@ -147,833 +147,833 @@ - // The 2 bodies are positionned at (0, 0, 0), with no rotation - // The joint is a Slider Joint - // Axis is along the X axis - // Anchor at (0, 0, 0) - struct Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X - { - Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X() - { - wId = dWorldCreate(); + // The 2 bodies are positionned at (0, 0, 0), with no rotation + // The joint is a Slider Joint + // Axis is along the X axis + // Anchor at (0, 0, 0) + struct Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X + { + Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X() + { + wId = dWorldCreate(); - bId1 = dBodyCreate (wId); - dBodySetPosition (bId1, 0, 0, 0); + bId1 = dBodyCreate (wId); + dBodySetPosition (bId1, 0, 0, 0); - bId2 = dBodyCreate (wId); - dBodySetPosition (bId2, 0, 0, 0); + bId2 = dBodyCreate (wId); + dBodySetPosition (bId2, 0, 0, 0); - jId = dJointCreateSlider (wId, 0); - joint = (dxJointSlider*) jId; + jId = dJointCreateSlider (wId, 0); + joint = (dxJointSlider*) jId; - dJointAttach (jId, bId1, bId2); + dJointAttach (jId, bId1, bId2); - dJointSetSliderAxis(jId, axis[0], axis[1], axis[2]); - } + dJointSetSliderAxis(jId, axis[0], axis[1], axis[2]); + } - ~Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X() - { - dWorldDestroy (wId); - } + ~Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X() + { + dWorldDestroy (wId); + } - dWorldID wId; + dWorldID wId; - dBodyID bId1; - dBodyID bId2; + dBodyID bId1; + dBodyID bId2; - dJointID jId; - dxJointSlider* joint; + dJointID jId; + dxJointSlider* joint; - static const dVector3 axis; + static const dVector3 axis; - static const dReal offset; - }; - const dVector3 Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X::axis = {1, 0, 0}; - const dReal Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X::offset = REAL(3.1); + static const dReal offset; + }; + const dVector3 Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X::axis = {1, 0, 0}; + const dReal Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X::offset = REAL(3.1); - // Move 1st body offset unit in the X direction - // - // X-------> X---------> Axis --> - // B1 => B1 - // B2 B2 - // - // Start with a Offset of offset unit - // - // X-------> X---------> Axis --> - // B1 => B1 - // B2 B2 - TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X, - test_dJointSetSliderAxisOffset_B1_3Unit) + // Move 1st body offset unit in the X direction + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + // + // Start with a Offset of offset unit + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X, + test_dJointSetSliderAxisOffset_B1_3Unit) { - CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); - dBodySetPosition(bId1, offset, 0, 0); + dBodySetPosition(bId1, offset, 0, 0); - CHECK_CLOSE (offset, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (offset, dJointGetSliderPosition(jId), 1e-4); } - // Move 1st body offset unit in the opposite X direction - // - // X-------> X---------> Axis --> - // B1 => B1 - // B2 B2 - // - // Start with a Offset of -offset unit - // - // X-------> X---------> Axis --> - // B1 => B1 - // B2 B2 - TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X, - test_dJointSetSliderAxisOffset_B1_Minus_3Unit) + // Move 1st body offset unit in the opposite X direction + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + // + // Start with a Offset of -offset unit + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X, + test_dJointSetSliderAxisOffset_B1_Minus_3Unit) { - CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); - dBodySetPosition(bId1, -offset, 0, 0); + dBodySetPosition(bId1, -offset, 0, 0); - CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4); } - // Move 2nd body offset unit in the X direction - // - // X-------> X---------> Axis --> - // B1 => B1 - // B2 B2 - // - // Start with a Offset of offset unit - // - // X-------> X---------> Axis --> - // B1 => B1 - // B2 B2 - TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X, - test_dJointSetSliderAxisOffset_B2_3Unit) + // Move 2nd body offset unit in the X direction + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + // + // Start with a Offset of offset unit + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X, + test_dJointSetSliderAxisOffset_B2_3Unit) { - CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); - dBodySetPosition(bId2, offset, 0, 0); + dBodySetPosition(bId2, offset, 0, 0); - CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4); } - // Move 2nd body offset unit in the opposite X direction - // - // X-------> X---------> Axis --> - // B1 => B1 - // B2 B2 - // - // Start with a Offset of -offset unit - // - // X-------> X---------> Axis --> - // B1 => B1 - // B2 B2 - TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X, - test_dJointSetSliderAxisOffset_B2_Minus_3Unit) + // Move 2nd body offset unit in the opposite X direction + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + // + // Start with a Offset of -offset unit + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X, + test_dJointSetSliderAxisOffset_B2_Minus_3Unit) { - CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); - dBodySetPosition(bId2, -offset, 0, 0); + dBodySetPosition(bId2, -offset, 0, 0); - CHECK_CLOSE (offset, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (offset, dJointGetSliderPosition(jId), 1e-4); } - // The 2 bodies are positionned at (0, 0, 0), with no rotation - // The joint is a Slider Joint - // Axis is the opposite of the X axis - // Anchor at (0, 0, 0) - struct Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X - { - Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X() - { - wId = dWorldCreate(); + // The 2 bodies are positionned at (0, 0, 0), with no rotation + // The joint is a Slider Joint + // Axis is the opposite of the X axis + // Anchor at (0, 0, 0) + struct Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X + { + Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X() + { + wId = dWorldCreate(); - bId1 = dBodyCreate (wId); - dBodySetPosition (bId1, 0, 0, 0); + bId1 = dBodyCreate (wId); + dBodySetPosition (bId1, 0, 0, 0); - bId2 = dBodyCreate (wId); - dBodySetPosition (bId2, 0, 0, 0); + bId2 = dBodyCreate (wId); + dBodySetPosition (bId2, 0, 0, 0); - jId = dJointCreateSlider (wId, 0); - joint = (dxJointSlider*) jId; + jId = dJointCreateSlider (wId, 0); + joint = (dxJointSlider*) jId; - dJointAttach (jId, bId1, bId2); + dJointAttach (jId, bId1, bId2); - dJointSetSliderAxis(jId, axis[0], axis[1], axis[2]); - } + dJointSetSliderAxis(jId, axis[0], axis[1], axis[2]); + } - ~Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X() - { - dWorldDestroy (wId); - } + ~Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X() + { + dWorldDestroy (wId); + } - dWorldID wId; + dWorldID wId; - dBodyID bId1; - dBodyID bId2; + dBodyID bId1; + dBodyID bId2; - dJointID jId; - dxJointSlider* joint; + dJointID jId; + dxJointSlider* joint; - static const dVector3 axis; - static const dReal offset; - }; - const dVector3 Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X::axis = {-1, 0, 0}; - const dReal Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X::offset = REAL(3.1); + static const dVector3 axis; + static const dReal offset; + }; + const dVector3 Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X::axis = {-1, 0, 0}; + const dReal Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X::offset = REAL(3.1); - // Move 1st body offset unit in the X direction - // - // X-------> X---------> <-- Axis - // B1 => B1 - // B2 B2 - // - // Start with a Offset of offset unit - // - // X-------> X---------> <-- Axis - // B1 => B1 - // B2 B2 - TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X, - test_dJointSetSliderAxisOffset_B1_3Unit) + // Move 1st body offset unit in the X direction + // + // X-------> X---------> <-- Axis + // B1 => B1 + // B2 B2 + // + // Start with a Offset of offset unit + // + // X-------> X---------> <-- Axis + // B1 => B1 + // B2 B2 + TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X, + test_dJointSetSliderAxisOffset_B1_3Unit) { - CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); - dBodySetPosition(bId1, offset, 0, 0); + dBodySetPosition(bId1, offset, 0, 0); - CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4); } - // Move 1st body offset unit in the opposite X direction - // - // X-------> X---------> <-- Axis - // B1 => B1 - // B2 B2 - // - // Start with a Offset of offset unit - // - // X-------> X---------> <-- Axis - // B1 => B1 - // B2 B2 - TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X, - test_dJointSetSliderAxisOffset_B1_Minus_3Unit) + // Move 1st body offset unit in the opposite X direction + // + // X-------> X---------> <-- Axis + // B1 => B1 + // B2 B2 + // + // Start with a Offset of offset unit + // + // X-------> X---------> <-- Axis + // B1 => B1 + // B2 B2 + TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X, + test_dJointSetSliderAxisOffset_B1_Minus_3Unit) { - CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); - dBodySetPosition(bId1, -offset, 0, 0); + dBodySetPosition(bId1, -offset, 0, 0); - CHECK_CLOSE (offset, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (offset, dJointGetSliderPosition(jId), 1e-4); } - // Move 2nd body offset unit in the X direction - // - // X-------> X---------> <-- Axis - // B1 => B1 - // B2 B2 - // - // Start with a Offset of offset unit - // - // X-------> X---------> <-- Axis - // B1 => B1 - // B2 B2 - TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X, - test_dJointSetSliderAxisOffset_B2_3Unit) + // Move 2nd body offset unit in the X direction + // + // X-------> X---------> <-- Axis + // B1 => B1 + // B2 B2 + // + // Start with a Offset of offset unit + // + // X-------> X---------> <-- Axis + // B1 => B1 + // B2 B2 + TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X, + test_dJointSetSliderAxisOffset_B2_3Unit) { - CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); - dBodySetPosition(bId2, offset, 0, 0); + dBodySetPosition(bId2, offset, 0, 0); - CHECK_CLOSE (offset, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (offset, dJointGetSliderPosition(jId), 1e-4); } - // Move 2nd body offset unit in the opposite X direction - // - // X-------> X---------> <-- Axis - // B1 => B1 - // B2 B2 - // - // Start with a Offset of -offset unit - // - // X-------> X---------> <-- Axis - // B1 => B1 - // B2 B2 - TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X, - test_dJointSetSliderAxisOffset_B2_Minus_3Unit) + // Move 2nd body offset unit in the opposite X direction + // + // X-------> X---------> <-- Axis + // B1 => B1 + // B2 B2 + // + // Start with a Offset of -offset unit + // + // X-------> X---------> <-- Axis + // B1 => B1 + // B2 B2 + TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X, + test_dJointSetSliderAxisOffset_B2_Minus_3Unit) { - CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); - dBodySetPosition(bId2, -offset, 0, 0); + dBodySetPosition(bId2, -offset, 0, 0); - CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4); } - // Only body 1 - // The body are positionned at (0, 0, 0), with no rotation - // The joint is a Slider Joint - // Axis is along the X axis - // Anchor at (0, 0, 0) - struct Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X - { - Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X() - { - wId = dWorldCreate(); + // Only body 1 + // The body are positionned at (0, 0, 0), with no rotation + // The joint is a Slider Joint + // Axis is along the X axis + // Anchor at (0, 0, 0) + struct Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X + { + Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X() + { + wId = dWorldCreate(); - bId1 = dBodyCreate (wId); - dBodySetPosition (bId1, 0, 0, 0); + bId1 = dBodyCreate (wId); + dBodySetPosition (bId1, 0, 0, 0); - jId = dJointCreateSlider (wId, 0); - joint = (dxJointSlider*) jId; + jId = dJointCreateSlider (wId, 0); + joint = (dxJointSlider*) jId; - dJointAttach (jId, bId1, NULL); + dJointAttach (jId, bId1, NULL); - dJointSetSliderAxis(jId, axis[0], axis[1], axis[2]); - } + dJointSetSliderAxis(jId, axis[0], axis[1], axis[2]); + } - ~Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X() - { - dWorldDestroy (wId); - } + ~Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X() + { + dWorldDestroy (wId); + } - dWorldID wId; + dWorldID wId; - dBodyID bId1; + dBodyID bId1; - dJointID jId; - dxJointSlider* joint; + dJointID jId; + dxJointSlider* joint; - static const dVector3 axis; + static const dVector3 axis; - static const dReal offset; - }; - const dVector3 Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X::axis = {1, 0, 0}; - const dReal Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X::offset = REAL(3.1); + static const dReal offset; + }; + const dVector3 Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X::axis = {1, 0, 0}; + const dReal Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X::offset = REAL(3.1); - // Move 1st body offset unit in the X direction - // - // X-------> X---------> Axis --> - // B1 => B1 - // - TEST_FIXTURE (Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X, - test_dJointSetSliderAxisOffset_B1_OffsetUnit) + // Move 1st body offset unit in the X direction + // + // X-------> X---------> Axis --> + // B1 => B1 + // + TEST_FIXTURE (Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X, + test_dJointSetSliderAxisOffset_B1_OffsetUnit) { - CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); - dBodySetPosition(bId1, offset, 0, 0); + dBodySetPosition(bId1, offset, 0, 0); - CHECK_CLOSE (offset, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (offset, dJointGetSliderPosition(jId), 1e-4); } - // Move 1st body offset unit in the opposite X direction - // - // X-------> X---------> Axis --> - // B1 => B1 - // - TEST_FIXTURE (Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X, - test_dJointSetSliderAxisOffset_B1_Minus_OffsetUnit) + // Move 1st body offset unit in the opposite X direction + // + // X-------> X---------> Axis --> + // B1 => B1 + // + TEST_FIXTURE (Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X, + test_dJointSetSliderAxisOffset_B1_Minus_OffsetUnit) { - CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); - dBodySetPosition(bId1, -offset, 0, 0); + dBodySetPosition(bId1, -offset, 0, 0); - CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4); } - // Only body 1 - // The body are positionned at (0, 0, 0), with no rotation - // The joint is a Slider Joint - // Axis is in the oppsite X axis - // Anchor at (0, 0, 0) - struct Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X - { - Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X() - { - wId = dWorldCreate(); + // Only body 1 + // The body are positionned at (0, 0, 0), with no rotation + // The joint is a Slider Joint + // Axis is in the oppsite X axis + // Anchor at (0, 0, 0) + struct Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X + { + Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X() + { + wId = dWorldCreate(); - bId1 = dBodyCreate (wId); - dBodySetPosition (bId1, 0, 0, 0); + bId1 = dBodyCreate (wId); + dBodySetPosition (bId1, 0, 0, 0); - jId = dJointCreateSlider (wId, 0); - joint = (dxJointSlider*) jId; + jId = dJointCreateSlider (wId, 0); + joint = (dxJointSlider*) jId; - dJointAttach (jId, bId1, NULL); + dJointAttach (jId, bId1, NULL); - dJointSetSliderAxis(jId, axis[0], axis[1], axis[2]); - } + dJointSetSliderAxis(jId, axis[0], axis[1], axis[2]); + } - ~Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X() - { - dWorldDestroy (wId); - } + ~Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X() + { + dWorldDestroy (wId); + } - dWorldID wId; + dWorldID wId; - dBodyID bId1; + dBodyID bId1; - dJointID jId; - dxJointSlider* joint; + dJointID jId; + dxJointSlider* joint; - static const dVector3 axis; + static const dVector3 axis; - static const dReal offset; - }; - const dVector3 Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X::axis = {-1, 0, 0}; - const dReal Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X::offset = REAL(3.1); + static const dReal offset; + }; + const dVector3 Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X::axis = {-1, 0, 0}; + const dReal Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X::offset = REAL(3.1); - // Move 1st body offset unit in the X direction - // - // X-------> X---------> <--- Axis - // B1 => B1 - // - TEST_FIXTURE (Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X, - test_dJointSetSliderAxisOffset_B1_OffsetUnit) + // Move 1st body offset unit in the X direction + // + // X-------> X---------> <--- Axis + // B1 => B1 + // + TEST_FIXTURE (Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X, + test_dJointSetSliderAxisOffset_B1_OffsetUnit) { - CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); - dBodySetPosition(bId1, offset, 0, 0); + dBodySetPosition(bId1, offset, 0, 0); - CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4); } - // Move 1st body offset unit in the opposite X direction - // - // X-------> X---------> <--- Axis - // B1 => B1 - // - TEST_FIXTURE (Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X, - test_dJointSetSliderAxisOffset_B1_Minus_OffsetUnit) + // Move 1st body offset unit in the opposite X direction + // + // X-------> X---------> <--- Axis + // B1 => B1 + // + TEST_FIXTURE (Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X, + test_dJointSetSliderAxisOffset_B1_Minus_OffsetUnit) { - CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4); - dBodySetPosition(bId1, -offset, 0, 0); + dBodySetPosition(bId1, -offset, 0, 0); - CHECK_CLOSE (offset, dJointGetSliderPosition(jId), 1e-4); + CHECK_CLOSE (offset, dJointGetSliderPosition(jId), 1e-4); } - // Only body 2 - // The body are positionned at (0, 0, 0), with no rotation - // The joint is a Slider Joint - // Axis is along the X axis - // Anchor at (0, 0, 0) - struct Fixture_dxJointSlider_B2_At_Zero_Axis_Along_X - { - Fixture_dxJointSlider_B2_At_Zero_Axis_Along_X() - { - wId = dWorldCreate(); + // Only body 2 + // The body are positionned at (0, 0, 0), with no rotation + // The joint is a Slider Joint + // Axis is along the X axis + // Anchor at (0, 0, 0) + struct Fixture_dxJointSlider_B2_At_Zero_Axis_Along_X + { + Fixture_dxJointSlider_B2_At_Zero_Axis_Along_X() + { + wId = dWorldCreate(); - bId2 = dBodyCreate (wId); - dBodySetPosition (bId2, 0, 0, 0); + bId2 = dBodyCreate (wId); + dBodySetPosition (bId2, 0, 0, 0); - jId = dJointCreateSlider (wId, 0); - joint = (dxJointSlider*) jId; + jId = dJointCreateSlider (wId, 0); + joint = (dxJointSlider*) jId; - dJointAttach (jId, NULL, bId2); + dJointAttach (jId, NULL, bId2); - dJointSetSliderAxis(jId, axis[0], axis[1], axis[2]); - } + dJointSetSliderAxis(jId, axis[0], axis[1], axis[2]); + } - ~Fixture_dxJointSlider_B2_At_Zero_Axis_Along_X() - { - dWorldDestroy (wId); - } + ~Fixture_dxJointSlider_B2_At_Zero_Axis_Along_X() + { + dWorldDestroy (wId); + } - dWorldID wId; + dWorldID wId; - dBodyID bId2; + dBodyID bId2; - dJointID jId; - dxJoi... [truncated message content] |
From: <pa...@us...> - 2008-11-19 19:47:12
|
Revision: 1597 http://opende.svn.sourceforge.net/opende/?rev=1597&view=rev Author: papaDoc Date: 2008-11-19 19:47:10 +0000 (Wed, 19 Nov 2008) Log Message: ----------- - Fix bug: When a pr joint had only one body attached to position 2, dJointAttach(jId, 0, bId). The body was not push in the right direction to move back between the limits. - Add unit test to check the above problem Modified Paths: -------------- trunk/CHANGELOG.txt trunk/ode/src/joints/pr.cpp trunk/tests/joints/pr.cpp Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2008-11-19 18:45:46 UTC (rev 1596) +++ trunk/CHANGELOG.txt 2008-11-19 19:47:10 UTC (rev 1597) @@ -8,6 +8,11 @@ * keep the format consistent (79 char width, M/D/Y date format). ------------------------------------------------------------------------------ +11/19/08 Remi Ricard (papaDoc) + * Fix bug: When a pr joint had only one body attached to position 2, + dJointAttach(jId, 0, bId). The body was not push in the right direction to + move back between the limits. + * Add unit test to check the above problem 11/19/08 Remi Ricard (papaDoc) * Fix problem with dJointGetPRPosition and Modified: trunk/ode/src/joints/pr.cpp =================================================================== --- trunk/ode/src/joints/pr.cpp 2008-11-19 18:45:46 UTC (rev 1596) +++ trunk/ode/src/joints/pr.cpp 2008-11-19 19:47:10 UTC (rev 1597) @@ -262,9 +262,18 @@ } else { - dist[0] = anchor2[0] - pos1[0]; - dist[1] = anchor2[1] - pos1[1]; - dist[2] = anchor2[2] - pos1[2]; + if (flags & dJOINT_REVERSE ) + { + dist[0] = pos1[0] - anchor2[0]; // Invert the value + dist[1] = pos1[1] - anchor2[1]; + dist[2] = pos1[2] - anchor2[2]; + } + else + { + dist[0] = anchor2[0] - pos1[0]; + dist[1] = anchor2[1] - pos1[1]; + dist[2] = anchor2[2] - pos1[2]; + } } @@ -408,7 +417,20 @@ info->c[2] = k * dDOT( ax1, err ); info->c[3] = k * dDOT( q, err ); - int row = 4 + limotP.addLimot( this, info, 4, axP, 0 ); + int row = 4; + if ( node[1].body || !(flags & dJOINT_REVERSE) ) + { + row += limotP.addLimot ( this, info, 4, axP, 0 ); + } + else + { + dVector3 rAxP; + rAxP[0] = -axP[0]; + rAxP[1] = -axP[1]; + rAxP[2] = -axP[2]; + row += limotP.addLimot ( this, info, 4, rAxP, 0 ); + } + limotR.addLimot ( this, info, row, ax1, 1 ); } Modified: trunk/tests/joints/pr.cpp =================================================================== --- trunk/tests/joints/pr.cpp 2008-11-19 18:45:46 UTC (rev 1596) +++ trunk/tests/joints/pr.cpp 2008-11-19 19:47:10 UTC (rev 1597) @@ -428,9 +428,9 @@ // The joint is a PR Joint // Axis is along the X axis // Anchor at (0, 0, 0) - struct Fixture_dxJointPR_Compare_Body_At_Zero_Axis_Along_X + struct Fixture_dxJointPR_Compare_Body_At_Zero_AxisP_Along_Y { - Fixture_dxJointPR_Compare_Body_At_Zero_Axis_Along_X() + Fixture_dxJointPR_Compare_Body_At_Zero_AxisP_Along_Y() { wId = dWorldCreate(); @@ -461,7 +461,7 @@ dBodySetLinearVel (bId, 4*axis[0], 4*axis[1], 4*axis[2]); } - ~Fixture_dxJointPR_Compare_Body_At_Zero_Axis_Along_X() + ~Fixture_dxJointPR_Compare_Body_At_Zero_AxisP_Along_Y() { dWorldDestroy (wId); } @@ -482,7 +482,7 @@ }; - TEST_FIXTURE (Fixture_dxJointPR_Compare_Body_At_Zero_Axis_Along_X, + TEST_FIXTURE (Fixture_dxJointPR_Compare_Body_At_Zero_AxisP_Along_Y, test_dJointSetPRPositionRate_Only_B1) { // Linear velocity along the prismatic axis; @@ -503,7 +503,7 @@ } - TEST_FIXTURE (Fixture_dxJointPR_Compare_Body_At_Zero_Axis_Along_X, + TEST_FIXTURE (Fixture_dxJointPR_Compare_Body_At_Zero_AxisP_Along_Y, test_dJointSetPRPositionRate_Only_B2) { // Linear velocity along the prismatic axis; @@ -943,5 +943,217 @@ } } + + + + + + // This test compare the result of a slider with 2 bodies where body body 2 is + // fixed to the world to a slider with only one body at position 1. + // + // Test the limits [-1, 0.25] when only one body at is attached to the joint + // using dJointAttache(jId, bId, 0); + // + TEST_FIXTURE(Fixture_dxJointPR_Compare_Body_At_Zero_AxisP_Along_Y, + test_Limit_minus1_025_One_Body_on_left) + { + // Linear velocity along the prismatic axis; + dVector3 axis; + dJointGetPRAxis1(jId_12, axis); + dBodySetLinearVel (bId1_12, 4*axis[0], 4*axis[1], 4*axis[2]); + + dJointAttach(jId_12, bId1_12, bId2_12); + dJointSetPRParam(jId_12, dParamLoStop, -1); + dJointSetPRParam(jId_12, dParamHiStop, 0.25); + + dJointAttach(fixed, 0, bId2_12); + dJointSetFixed(fixed); + + dJointAttach(jId, bId, 0); + dJointSetPRParam(jId, dParamLoStop, -1); + dJointSetPRParam(jId, dParamHiStop, 0.25); + + + for (int i=0; i<50; ++i) + dWorldStep(wId, 1.0); + + + const dReal *pos1_12 = dBodyGetPosition(bId1_12); + const dReal *pos = dBodyGetPosition(bId); + + CHECK_CLOSE (pos1_12[0], pos[0], 1e-2); + CHECK_CLOSE (pos1_12[1], pos[1], 1e-2); + CHECK_CLOSE (pos1_12[2], pos[2], 1e-2); + + const dReal *q1_12 = dBodyGetQuaternion(bId1_12); + const dReal *q = dBodyGetQuaternion(bId); + + CHECK_CLOSE (q1_12[0], q[0], 1e-4); + CHECK_CLOSE (q1_12[1], q[1], 1e-4); + CHECK_CLOSE (q1_12[2], q[2], 1e-4); + CHECK_CLOSE (q1_12[3], q[3], 1e-4); + } + + + + // This test compare the result of a slider with 2 bodies where body body 1 is + // fixed to the world to a slider with only one body at position 2. + // + // Test the limits [-1, 0.25] when only one body at is attached to the joint + // using dJointAttache(jId, 0, bId); + // + TEST_FIXTURE(Fixture_dxJointPR_Compare_Body_At_Zero_AxisP_Along_Y, + test_Limit_minus1_025_One_Body_on_right) + { + // Linear velocity along the prismatic axis; + dVector3 axis; + dJointGetPRAxis1(jId_12, axis); + dBodySetLinearVel (bId2_12, 4*axis[0], 4*axis[1], 4*axis[2]); + + dJointAttach(jId_12, bId1_12, bId2_12); + dJointSetPRParam(jId_12, dParamLoStop, -1); + dJointSetPRParam(jId_12, dParamHiStop, 0.25); + + dJointAttach(fixed, bId1_12, 0); + dJointSetFixed(fixed); + + + dJointAttach(jId, 0, bId); + dJointSetPRParam(jId, dParamLoStop, -1); + dJointSetPRParam(jId, dParamHiStop, 0.25); + + for (int i=0; i<50; ++i) + dWorldStep(wId, 1.0); + + + const dReal *pos2_12 = dBodyGetPosition(bId2_12); + const dReal *pos = dBodyGetPosition(bId); + + CHECK_CLOSE (pos2_12[0], pos[0], 1e-2); + CHECK_CLOSE (pos2_12[1], pos[1], 1e-2); + CHECK_CLOSE (pos2_12[2], pos[2], 1e-2); + + + const dReal *q2_12 = dBodyGetQuaternion(bId2_12); + const dReal *q = dBodyGetQuaternion(bId); + + CHECK_CLOSE (q2_12[0], q[0], 1e-4); + CHECK_CLOSE (q2_12[1], q[1], 1e-4); + CHECK_CLOSE (q2_12[2], q[2], 1e-4); + CHECK_CLOSE (q2_12[3], q[3], 1e-4); + } + + + + // This test compare the result of a slider with 2 bodies where body body 2 is + // fixed to the world to a slider with only one body at position 1. + // + // Test the limits [0, 0] when only one body at is attached to the joint + // using dJointAttache(jId, bId, 0); + // + // The body should not move since their is no room between the two limits + // + TEST_FIXTURE(Fixture_dxJointPR_Compare_Body_At_Zero_AxisP_Along_Y, + test_Limit_0_0_One_Body_on_left) + { + // Linear velocity along the prismatic axis; + dVector3 axis; + dJointGetPRAxis1(jId_12, axis); + dBodySetLinearVel (bId1_12, 4*axis[0], 4*axis[1], 4*axis[2]); + + dJointAttach(jId_12, bId1_12, bId2_12); + dJointSetPRParam(jId_12, dParamLoStop, 0); + dJointSetPRParam(jId_12, dParamHiStop, 0); + + dJointAttach(fixed, 0, bId2_12); + dJointSetFixed(fixed); + + + dJointAttach(jId, bId, 0); + dJointSetPRParam(jId, dParamLoStop, 0); + dJointSetPRParam(jId, dParamHiStop, 0); + + for (int i=0; i<50; ++i) + dWorldStep(wId, 1.0); + + + + const dReal *pos1_12 = dBodyGetPosition(bId1_12); + const dReal *pos = dBodyGetPosition(bId); + + CHECK_CLOSE (pos1_12[0], pos[0], 1e-4); + CHECK_CLOSE (pos1_12[1], pos[1], 1e-4); + CHECK_CLOSE (pos1_12[2], pos[2], 1e-4); + + CHECK_CLOSE (0, pos[0], 1e-4); + CHECK_CLOSE (0, pos[1], 1e-4); + CHECK_CLOSE (0, pos[2], 1e-4); + + + const dReal *q1_12 = dBodyGetQuaternion(bId1_12); + const dReal *q = dBodyGetQuaternion(bId); + + CHECK_CLOSE (q1_12[0], q[0], 1e-4); + CHECK_CLOSE (q1_12[1], q[1], 1e-4); + CHECK_CLOSE (q1_12[2], q[2], 1e-4); + CHECK_CLOSE (q1_12[3], q[3], 1e-4); + } + + + // This test compare the result of a slider with 2 bodies where body body 1 is + // fixed to the world to a slider with only one body at position 2. + // + // Test the limits [0, 0] when only one body at is attached to the joint + // using dJointAttache(jId, 0, bId); + // + // The body should not move since their is no room between the two limits + // + TEST_FIXTURE(Fixture_dxJointPR_Compare_Body_At_Zero_AxisP_Along_Y, + test_Limit_0_0_One_Body_on_right) + { + // Linear velocity along the prismatic axis; + dVector3 axis; + dJointGetPRAxis1(jId_12, axis); + dBodySetLinearVel (bId2_12, 4*axis[0], 4*axis[1], 4*axis[2]); + + dJointAttach(jId_12, bId1_12, bId2_12); + dJointSetPRParam(jId_12, dParamLoStop, 0); + dJointSetPRParam(jId_12, dParamHiStop, 0); + + dJointAttach(fixed, bId1_12, 0); + dJointSetFixed(fixed); + + + dJointAttach(jId, 0, bId); + dJointSetPRParam(jId, dParamLoStop, 0); + dJointSetPRParam(jId, dParamHiStop, 0); + + for (int i=0; i<50; ++i) + { + dWorldStep(wId, 1.0); + } + + + const dReal *pos2_12 = dBodyGetPosition(bId2_12); + const dReal *pos = dBodyGetPosition(bId); + + CHECK_CLOSE (pos2_12[0], pos[0], 1e-4); + CHECK_CLOSE (pos2_12[1], pos[1], 1e-4); + CHECK_CLOSE (pos2_12[2], pos[2], 1e-4); + + CHECK_CLOSE (0, pos[0], 1e-4); + CHECK_CLOSE (0, pos[1], 1e-4); + CHECK_CLOSE (0, pos[2], 1e-4); + + + const dReal *q2_12 = dBodyGetQuaternion(bId2_12); + const dReal *q = dBodyGetQuaternion(bId); + + CHECK_CLOSE (q2_12[0], q[0], 1e-4); + CHECK_CLOSE (q2_12[1], q[1], 1e-4); + CHECK_CLOSE (q2_12[2], q[2], 1e-4); + CHECK_CLOSE (q2_12[3], q[3], 1e-4); + } + } // End of SUITE TestdxJointPR This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pa...@us...> - 2008-11-20 16:23:17
|
Revision: 1598 http://opende.svn.sourceforge.net/opende/?rev=1598&view=rev Author: papaDoc Date: 2008-11-20 16:23:11 +0000 (Thu, 20 Nov 2008) Log Message: ----------- - Fix problem with dJointGetPUPosition and dJointGetPUPositionRate when the joint is attached to only a body 2. The sign was inverted. - Fix bug: When a pu joint had only one body attached to position 2, dJointAttach(jId, 0, bId). The body was not push in the right direction to move back between the limits. - Add unit test to check the above problem - Add the function void dJointSetPUAnchorOffset - Make the function void dJointSetPUAnchorDelta deprecated Modified Paths: -------------- trunk/CHANGELOG.txt trunk/include/ode/objects.h trunk/ode/src/joints/pu.cpp trunk/tests/joints/pu.cpp Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2008-11-19 19:47:10 UTC (rev 1597) +++ trunk/CHANGELOG.txt 2008-11-20 16:23:11 UTC (rev 1598) @@ -8,6 +8,17 @@ * keep the format consistent (79 char width, M/D/Y date format). ------------------------------------------------------------------------------ +11/20/08 Remi Ricard (papaDoc) + * Fix problem with dJointGetPUPosition and + dJointGetPUPositionRate when the joint is attached to only + a body 2. The sign was inverted. + * Fix bug: When a pu joint had only one body attached to position 2, + dJointAttach(jId, 0, bId). The body was not push in the right direction to + move back between the limits. + * Add unit test to check the above problem + * Add the function void dJointSetPUAnchorOffset + * Make the function void dJointSetPUAnchorDelta deprecated + 11/19/08 Remi Ricard (papaDoc) * Fix bug: When a pr joint had only one body attached to position 2, dJointAttach(jId, 0, bId). The body was not push in the right direction to Modified: trunk/include/ode/objects.h =================================================================== --- trunk/include/ode/objects.h 2008-11-19 19:47:10 UTC (rev 1597) +++ trunk/include/ode/objects.h 2008-11-20 16:23:11 UTC (rev 1598) @@ -1776,7 +1776,39 @@ * @brief set anchor * @ingroup joints */ - ODE_API void dJointSetPUAnchorDelta (dJointID, dReal x, dReal y, dReal z, + ODE_API_DEPRECATED ODE_API void dJointSetPUAnchorDelta (dJointID, dReal x, dReal y, dReal z, + dReal dx, dReal dy, dReal dz); + + /** + * @brief Set the PU anchor as if the 2 bodies were already at [dx, dy, dz] appart. + * @ingroup joints + * + * This function initialize the anchor and the relative position of each body + * as if the position between body1 and body2 was already the projection of [dx, dy, dz] + * along the Piston axis. (i.e as if the body1 was at its current position - [dx,dy,dy] when the + * axis is set). + * Ex: + * <PRE> + * dReal offset = 3; + * dVector3 axis; + * dJointGetPUAxis(jId, axis); + * dJointSetPUAnchor(jId, 0, 0, 0); + * // If you request the position you will have: dJointGetPUPosition(jId) == 0 + * dJointSetPUAnchorOffset(jId, 0, 0, 0, axis[X]*offset, axis[Y]*offset, axis[Z]*offset); + * // If you request the position you will have: dJointGetPUPosition(jId) == offset + * </PRE> + * @param j The PU joint for which the anchor point will be set + * @param x The X position of the anchor point in world frame + * @param y The Y position of the anchor point in world frame + * @param z The Z position of the anchor point in world frame + * @param dx A delta to be substracted to the X position as if the anchor was set + * when body1 was at current_position[X] - dx + * @param dx A delta to be substracted to the Y position as if the anchor was set + * when body1 was at current_position[Y] - dy + * @param dx A delta to be substracted to the Z position as if the anchor was set + * when body1 was at current_position[Z] - dz + */ + ODE_API void dJointSetPUAnchorOffset (dJointID, dReal x, dReal y, dReal z, dReal dx, dReal dy, dReal dz); /** Modified: trunk/ode/src/joints/pu.cpp =================================================================== --- trunk/ode/src/joints/pu.cpp 2008-11-19 19:47:10 UTC (rev 1597) +++ trunk/ode/src/joints/pu.cpp 2008-11-20 16:23:11 UTC (rev 1598) @@ -109,6 +109,12 @@ q[2] = (( joint->node[0].body->posr.pos[2] + q[2] ) - ( joint->anchor2[2] ) ); + if ( joint->flags & dJOINT_REVERSE ) + { + q[0] = -q[0]; + q[1] = -q[1]; + q[2] = -q[2]; + } } dVector3 axP; @@ -165,6 +171,12 @@ // lvel1 += joint->node[0].body->lvel; dOPE( lvel1, += , joint->node[0].body->lvel ); + // Since we want rate of change along the prismatic axis + // get axisP1 in global coordinates and get the component + // along this axis only + dVector3 axP1; + dMULTIPLY0_331( axP1, joint->node[0].body->posr.R, joint->axisP1 ); + if ( joint->node[1].body ) { // Find the contribution of the angular rotation to the linear speed @@ -175,15 +187,14 @@ // lvel1 -= lvel2 + joint->node[1].body->lvel; dOPE2( lvel1, -= , lvel2, + , joint->node[1].body->lvel ); + + return dDOT( axP1, lvel1 ); } - - - // Since we want rate of change along the prismatic axis - // get axisP1 in global coordinates and get the component - // along this axis only - dVector3 axP1; - dMULTIPLY0_331( axP1, joint->node[0].body->posr.R, joint->axisP1 ); - return dDOT( axP1, lvel1 ); + else + { + dReal rate = dDOT( axP1, lvel1 ); + return ( (joint->flags & dJOINT_REVERSE) ? -rate : rate); + } } return 0.0; @@ -274,8 +285,19 @@ } else { - // dist[i] = joint->anchor2[i] - pos1[i]; - dOPE2( dist, = , anchor2, -, pos1 ); + if (flags & dJOINT_REVERSE ) + { + // Invert the sign of dist + dist[0] = pos1[0] - anchor2[0]; + dist[1] = pos1[1] - anchor2[1]; + dist[2] = pos1[2] - anchor2[2]; + } + else + { + dist[0] = anchor2[0] - pos1[0]; + dist[1] = anchor2[1] - pos1[1]; + dist[2] = anchor2[2] - pos1[2]; + } } dVector3 q; // Temporary axis vector @@ -401,8 +423,16 @@ info->c[2] = k * dDOT( q, err ); int row = 3 + limot1.addLimot( this, info, 3, ax1, 1 ); - row += limot2.addLimot( this, info, row, ax2, 1 ); - limotP.addLimot( this, info, row, axP, 0 ); + + if ( node[1].body || !(flags & dJOINT_REVERSE) ) + limotP.addLimot( this, info, row, axP, 0 ); + else + { + axP[0] = -axP[0]; + axP[1] = -axP[1]; + axP[2] = -axP[2]; + limotP.addLimot ( this, info, row, axP, 0 ); + } } void dJointSetPUAnchor( dJointID j, dReal x, dReal y, dReal z ) @@ -466,8 +496,74 @@ joint->computeInitialRelativeRotations(); } +/** + * \brief This function initialize the anchor and the relative position of each body + * such that dJointGetPUPosition will return the dot product of axis and [dx,dy,dy]. + * + * The body 1 is moved to [-dx, -dy, -dx] then the anchor is set. This will be the + * position 0 for the prismatic part of the joint. Then the body 1 is moved to its + * original position. + * + * Ex: + * <PRE> + * dReal offset = 1; + * dVector3 dir; + * dJointGetPUAxis3(jId, dir); + * dJointSetPUAnchor(jId, 0, 0, 0); + * // If you request the position you will have: dJointGetPUPosition(jId) == 0 + * dJointSetPUAnchorDelta(jId, 0, 0, 0, dir[X]*offset, dir[Y]*offset, dir[Z]*offset); + * // If you request the position you will have: dJointGetPUPosition(jId) == offset + * </PRE> + * @param j The PU joint for which the anchor point will be set + * @param x The X position of the anchor point in world frame + * @param y The Y position of the anchor point in world frame + * @param z The Z position of the anchor point in world frame + * @param dx A delta to be added to the X position as if the anchor was set + * when body1 was at current_position[X] + dx + * @param dx A delta to be added to the Y position as if the anchor was set + * when body1 was at current_position[Y] + dy + * @param dx A delta to be added to the Z position as if the anchor was set + * when body1 was at current_position[Z] + dz + * @note Should have the same meaning as dJointSetSliderAxisDelta + */ +void dJointSetPUAnchorOffset( dJointID j, dReal x, dReal y, dReal z, + dReal dx, dReal dy, dReal dz ) +{ + dxJointPU* joint = ( dxJointPU* ) j; + dUASSERT( joint, "bad joint argument" ); + checktype( joint, PU ); + if (joint->flags & dJOINT_REVERSE) + { + dx = -dx; + dy = -dy; + dz = -dz; + } + + if ( joint->node[0].body ) + { + joint->node[0].body->posr.pos[0] -= dx; + joint->node[0].body->posr.pos[1] -= dy; + joint->node[0].body->posr.pos[2] -= dz; + } + + setAnchors( joint, x, y, z, joint->anchor1, joint->anchor2 ); + + if ( joint->node[0].body ) + { + joint->node[0].body->posr.pos[0] += dx; + joint->node[0].body->posr.pos[1] += dy; + joint->node[0].body->posr.pos[2] += dz; + } + + joint->computeInitialRelativeRotations(); +} + + + + + void dJointSetPUAxis1( dJointID j, dReal x, dReal y, dReal z ) { dxJointPU* joint = ( dxJointPU* ) j; Modified: trunk/tests/joints/pu.cpp =================================================================== --- trunk/tests/joints/pu.cpp 2008-11-19 19:47:10 UTC (rev 1597) +++ trunk/tests/joints/pu.cpp 2008-11-20 16:23:11 UTC (rev 1598) @@ -114,119 +114,806 @@ CHECK_CLOSE (axis[2], axisOrig[2] , 1e-4); } - // Create 2 bodies attached by a PU joint - // Axis is along the X axis (Default value - // Anchor at (0, 0, 0) (Default value) - // - // ^Y - // | - // * Body2 - // | - // | - // Body1 | - // * Z--------> - struct dxJointPU_Test_Initialization { - dxJointPU_Test_Initialization() + + + + + + + + + + + + + + // The joint is a PU Joint + // Default joint value + // The two bodies at at (0, 0, 0) + struct Fixture_dxJointPU_B1_and_B2_At_Zero { - wId = dWorldCreate(); + Fixture_dxJointPU_B1_and_B2_At_Zero() + { + wId = dWorldCreate(); - // Remove gravity to have the only force be the force of the joint - dWorldSetGravity(wId, 0,0,0); + bId1 = dBodyCreate (wId); + dBodySetPosition (bId1, 0, 0, 0); - for (int j=0; j<2; ++j) { - bId[j][0] = dBodyCreate (wId); - dBodySetPosition (bId[j][0], -1, 0, 0); + bId2 = dBodyCreate (wId); + dBodySetPosition (bId2, 0, 0, 0); - bId[j][1] = dBodyCreate (wId); - dBodySetPosition (bId[j][1], 1, 0, 0); + jId = dJointCreatePU (wId, 0); + joint = (dxJointPU*) jId; - dMatrix3 R; - dRFromAxisAndAngle (R, 1, 0, 0, REAL(1.57)); - dBodySetRotation (bId[j][1], R); + dJointAttach (jId, bId1, bId2); + } - jId[j] = dJointCreatePU (wId, 0); - dJointAttach (jId[j], bId[j][0], bId[j][1]); - dJointSetPUParam(jId[j], dParamLoStop, 1); - dJointSetPUParam(jId[j], dParamHiStop, 2); - dJointSetPUParam(jId[j], dParamFMax, 200); - } + ~Fixture_dxJointPU_B1_and_B2_At_Zero() + { + dWorldDestroy (wId); + } + + dWorldID wId; + + dBodyID bId1; + dBodyID bId2; + + + dJointID jId; + dxJointPU* joint; + + static const dReal offset; + }; + const dReal Fixture_dxJointPU_B1_and_B2_At_Zero::offset = REAL (3.1); + + + + + + // Move 1st body offset unit in the X direction + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + // + // Start with a Offset of offset unit + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + TEST_FIXTURE (Fixture_dxJointPU_B1_and_B2_At_Zero, + test_dJointSetPUAxisOffset_B1_3Unit) + { + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); + + dBodySetPosition (bId1, offset, 0, 0); + + CHECK_CLOSE (offset, dJointGetPUPosition (jId), 1e-4); + + dVector3 axis; + dJointGetPUAxisP (jId, axis); + + dJointSetPUAnchorOffset (jId, 0, 0, 0, + offset*axis[0],offset*axis[1],offset*axis[2]); + CHECK_CLOSE (offset, dJointGetPUPosition (jId), 1e-4); + + dBodySetPosition (bId1, 0, 0, 0); + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); } - ~dxJointPU_Test_Initialization() + // Move 1st body offset unit in the opposite X direction + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + // + // Start with a Offset of -offset unit + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + TEST_FIXTURE (Fixture_dxJointPU_B1_and_B2_At_Zero, + test_dJointSetPUAxisOffset_B1_Minus_3Unit) { - dWorldDestroy (wId); + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); + + dBodySetPosition (bId1, -offset, 0, 0); + + CHECK_CLOSE (-offset, dJointGetPUPosition (jId), 1e-4); + + dVector3 axis; + dJointGetPUAxisP (jId, axis); + dJointSetPUAnchorOffset (jId, 0, 0, 0, + -offset*axis[0],-offset*axis[1],-offset*axis[2]); + CHECK_CLOSE (-offset, dJointGetPUPosition (jId), 1e-4); + + dBodySetPosition (bId1, 0, 0, 0); + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); } - dWorldID wId; + // Move 2nd body offset unit in the X direction + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + // + // Start with a Offset of offset unit + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + TEST_FIXTURE (Fixture_dxJointPU_B1_and_B2_At_Zero, + test_dJointSetPUAxisOffset_B2_3Unit) + { + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); - dBodyID bId[2][2]; + dBodySetPosition (bId2, offset, 0, 0); + CHECK_CLOSE (-offset, dJointGetPUPosition (jId), 1e-4); - dJointID jId[2]; + dVector3 axis; + dJointGetPUAxisP (jId, axis); + dJointSetPUAnchorOffset (jId, 0, 0, 0, + -offset*axis[0],-offset*axis[1],-offset*axis[2]); + CHECK_CLOSE (-offset, dJointGetPUPosition (jId), 1e-4); - }; + dBodySetPosition (bId2, 0, 0, 0); + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); + } + // Move 2nd body offset unit in the opposite X direction + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + // + // Start with a Offset of -offset unit + // + // X-------> X---------> Axis --> + // B1 => B1 + // B2 B2 + TEST_FIXTURE (Fixture_dxJointPU_B1_and_B2_At_Zero, + test_dJointSetPUAxisOffset_B2_Minus_3Unit) + { + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); - // Test if setting a PU with its default values - // will behave the same as a default PU joint - TEST_FIXTURE (dxJointPU_Test_Initialization, - test_PU_Initialization) { - using namespace std; + dBodySetPosition (bId2, -offset, 0, 0); - dVector3 axis; - dJointGetPUAxis1(jId[1], axis); - dJointSetPUAxis1(jId[1], axis[0], axis[1], axis[2]); + CHECK_CLOSE (offset, dJointGetPUPosition (jId), 1e-4); - dJointGetPUAxis2(jId[1], axis); - dJointSetPUAxis2(jId[1], axis[0], axis[1], axis[2]); + dVector3 axis; + dJointGetPUAxisP (jId, axis); + dJointSetPUAnchorOffset (jId, 0, 0, 0, + offset*axis[0],offset*axis[1],offset*axis[2]); + CHECK_CLOSE (offset, dJointGetPUPosition (jId), 1e-4); - dJointGetPUAxis3(jId[1], axis); - dJointSetPUAxis3(jId[1], axis[0], axis[1], axis[2]); + dBodySetPosition (bId2, 0, 0, 0); + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); + } - dVector3 anchor; - dJointGetPUAnchor(jId[1], anchor); - dJointSetPUAnchor(jId[1], anchor[0], anchor[1], anchor[2]); + // Attach only one body at position 1 to the joint dJointAttach (jId, bId, 0) + // Move 1st body offset unit in the X direction + // + // X-------> X---------> Axis --> + // B1 => B1 + // + // Start with a Offset of offset unit + // + // X-------> X---------> Axis --> + // B1 => B1 + TEST_FIXTURE (Fixture_dxJointPU_B1_and_B2_At_Zero, + test_dJointSetPUAxisOffset_B1_OffsetUnit) + { + dJointAttach (jId, bId1, 0); + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); - for (int b=0; b<2; ++b) { - // Compare body b of the first joint with its equivalent on the - // second joint - const dReal *qA = dBodyGetQuaternion(bId[0][b]); - const dReal *qB = dBodyGetQuaternion(bId[1][b]); - CHECK_CLOSE (qA[0], qB[0], 1e-6); - CHECK_CLOSE (qA[1], qB[1], 1e-6); - CHECK_CLOSE (qA[2], qB[2], 1e-6); - CHECK_CLOSE (qA[3], qB[3], 1e-6); + dBodySetPosition (bId1, offset, 0, 0); + + CHECK_CLOSE (offset, dJointGetPUPosition (jId), 1e-4); + + dVector3 axis; + dJointGetPUAxisP (jId, axis); + dJointSetPUAnchorOffset (jId, 0, 0, 0, + offset*axis[0],offset*axis[1],offset*axis[2]); + CHECK_CLOSE (offset, dJointGetPUPosition (jId), 1e-4); + + dBodySetPosition (bId1, 0, 0, 0); + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); } - dWorldStep (wId,0.5); - dWorldStep (wId,0.5); - dWorldStep (wId,0.5); - dWorldStep (wId,0.5); + // Attache only one body at position 1 to the joint dJointAttach (jId, bId, 0) + // Move 1st body offset unit in the opposite X direction + // + // X-------> X---------> Axis --> + // B1 => B1 + // + // Start with a Offset of -offset unit + // + // X-------> X---------> Axis --> + // B1 => B1 + TEST_FIXTURE (Fixture_dxJointPU_B1_and_B2_At_Zero, + test_dJointSetPUAxisOffset_B1_Minus_OffsetUnit) + { + dJointAttach (jId, bId1, 0); - for (int b=0; b<2; ++b) { - // Compare body b of the first joint with its equivalent on the - // second joint - const dReal *qA = dBodyGetQuaternion(bId[0][b]); - const dReal *qB = dBodyGetQuaternion(bId[1][b]); - CHECK_CLOSE (qA[0], qB[0], 1e-6); - CHECK_CLOSE (qA[1], qB[1], 1e-6); - CHECK_CLOSE (qA[2], qB[2], 1e-6); - CHECK_CLOSE (qA[3], qB[3], 1e-6); + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); + dBodySetPosition (bId1, -offset, 0, 0); - const dReal *posA = dBodyGetPosition(bId[0][b]); - const dReal *posB = dBodyGetPosition(bId[1][b]); - CHECK_CLOSE (posA[0], posB[0], 1e-6); - CHECK_CLOSE (posA[1], posB[1], 1e-6); - CHECK_CLOSE (posA[2], posB[2], 1e-6); - CHECK_CLOSE (posA[3], posB[3], 1e-6); + CHECK_CLOSE (-offset, dJointGetPUPosition (jId), 1e-4); + + dVector3 axis; + dJointGetPUAxisP (jId, axis); + dJointSetPUAnchorOffset (jId, 0, 0, 0, + -offset*axis[0],-offset*axis[1],-offset*axis[2]); + CHECK_CLOSE (-offset, dJointGetPUPosition (jId), 1e-4); + + dBodySetPosition (bId1, 0, 0, 0); + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); } - } + + // Attache only one body at position 2 to the joint dJointAttach (jId, 0, bId) + // Move 1st body offset unit in the X direction + // + // X-------> X---------> Axis --> + // B2 => B2 + // + // Start with a Offset of offset unit + // + // X-------> X---------> Axis --> + // B2 => B2 + TEST_FIXTURE (Fixture_dxJointPU_B1_and_B2_At_Zero, + test_dJointSetPUAxisOffset_B2_OffsetUnit) + { + dJointAttach (jId, 0, bId2); + + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); + + dBodySetPosition (bId2, offset, 0, 0); + + CHECK_CLOSE (-offset, dJointGetPUPosition (jId), 1e-4); + + dVector3 axis; + dJointGetPUAxisP (jId, axis); + dJointSetPUAnchorOffset (jId, 0, 0, 0, + -offset*axis[0], -offset*axis[1], -offset*axis[2]); + CHECK_CLOSE (-offset, dJointGetPUPosition (jId), 1e-4); + + dBodySetPosition (bId2, 0, 0, 0); + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); + } + + // Attache only one body at position 2 to the joint dJointAttach (jId, 0, bId) + // Move 1st body offset unit in the opposite X direction + // + // X-------> X---------> Axis --> + // B2 => B2 + // + // Start with a Offset of -offset unit + // + // X-------> X---------> Axis --> + // B2 => B2 + TEST_FIXTURE (Fixture_dxJointPU_B1_and_B2_At_Zero, + test_dJointSetPUAxisOffset_B2_Minus_OffsetUnit) + { + dJointAttach (jId, 0, bId2); + + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); + + dBodySetPosition (bId2, -offset, 0, 0); + + CHECK_CLOSE (offset, dJointGetPUPosition (jId), 1e-4); + + dVector3 axis; + dJointGetPUAxisP (jId, axis); + dJointSetPUAnchorOffset (jId, 0, 0, 0, + offset*axis[0], offset*axis[1], offset*axis[2]); + CHECK_CLOSE (offset, dJointGetPUPosition (jId), 1e-4); + + dBodySetPosition (bId2, 0, 0, 0); + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); + } + + + + + // Only one body + // The body are positionned at (0, 0, 0), with no rotation + // The joint is a PU Joint + // Axis is in the oppsite X axis + // Anchor at (0, 0, 0) + // N.B. By default the body is attached at position 1 on the joint + // dJointAttach (jId, bId, 0); + struct Fixture_dxJointPU_One_Body_At_Zero_Axis_Inverse_of_X + { + Fixture_dxJointPU_One_Body_At_Zero_Axis_Inverse_of_X() + { + wId = dWorldCreate(); + + bId = dBodyCreate (wId); + dBodySetPosition (bId, 0, 0, 0); + + jId = dJointCreatePU (wId, 0); + joint = (dxJointPU*) jId; + + + dJointAttach (jId, bId, NULL); + + dJointSetPUAxisP (jId, axis[0], axis[1], axis[2]); + } + + ~Fixture_dxJointPU_One_Body_At_Zero_Axis_Inverse_of_X() + { + dWorldDestroy (wId); + } + + dWorldID wId; + + dBodyID bId; + + dJointID jId; + dxJointPU* joint; + + static const dVector3 axis; + + static const dReal offset; + }; + const dVector3 Fixture_dxJointPU_One_Body_At_Zero_Axis_Inverse_of_X::axis = + { + -1, 0, 0 + }; + const dReal Fixture_dxJointPU_One_Body_At_Zero_Axis_Inverse_of_X::offset = REAL (3.1); + + + // Move 1st body offset unit in the X direction + // + // X-------> X---------> <--- Axis + // B1 => B1 + // + // Start with a Offset of offset unit + // + // X-------> X---------> <--- Axis + // B1 => B1 + TEST_FIXTURE (Fixture_dxJointPU_One_Body_At_Zero_Axis_Inverse_of_X, + test_dJointSetPUAxisOffset_B1_At_Position_1_OffsetUnit) + { + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); + + dBodySetPosition (bId, offset, 0, 0); + + CHECK_CLOSE (-offset, dJointGetPUPosition (jId), 1e-4); + + dJointSetPUAnchorOffset (jId, 0, 0, 0, + -offset*axis[0],-offset*axis[1],-offset*axis[2]); + CHECK_CLOSE (-offset, dJointGetPUPosition (jId), 1e-4); + + dBodySetPosition (bId, 0, 0, 0); + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); + } + + // Move 1st body offset unit in the opposite X direction + // + // X-------> X---------> <--- Axis + // B1 => B1 + // + // Start with a Offset of -offset unit + // + // X-------> X---------> <--- Axis + // B1 => B1 + TEST_FIXTURE (Fixture_dxJointPU_One_Body_At_Zero_Axis_Inverse_of_X, + test_dJointSetPUAxisOffset_B1_Minus_OffsetUnit) + { + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); + + dBodySetPosition (bId, -offset, 0, 0); + + CHECK_CLOSE (offset, dJointGetPUPosition (jId), 1e-4); + + dJointSetPUAnchorOffset (jId, 0, 0, 0, + offset*axis[0],offset*axis[1],offset*axis[2]); + CHECK_CLOSE (offset, dJointGetPUPosition (jId), 1e-4); + + dBodySetPosition (bId, 0, 0, 0); + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); + } + + + // Move 1st body offset unit in the X direction + // + // X-------> X---------> <--- Axis + // B2 => B2 + // + // Start with a Offset of offset unit + // + // X-------> X---------> <--- Axis + // B2 => B2 + TEST_FIXTURE (Fixture_dxJointPU_One_Body_At_Zero_Axis_Inverse_of_X, + test_dJointSetPUAxisOffset_B2_OffsetUnit) + { + // By default it is attached to position 1 + // Now attach the body at positiojn 2 + dJointAttach(jId, 0, bId); + + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); + + dBodySetPosition (bId, offset, 0, 0); + + CHECK_CLOSE (offset, dJointGetPUPosition (jId), 1e-4); + + dJointSetPUAnchorOffset (jId, 0, 0, 0, + offset*axis[0], offset*axis[1], offset*axis[2]); + CHECK_CLOSE (offset, dJointGetPUPosition (jId), 1e-4); + + dBodySetPosition (bId, 0, 0, 0); + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); + } + + // Move 1st body offset unit in the opposite X direction + // + // X-------> X---------> <--- Axis + // B2 => B2 + // + // Start with a Offset of -offset unit + // + // X-------> X---------> <--- Axis + // B2 => B2 + TEST_FIXTURE (Fixture_dxJointPU_One_Body_At_Zero_Axis_Inverse_of_X, + test_dJointSetPUAxisOffset_B2_Minus_OffsetUnit) + { + // By default it is attached to position 1 + // Now attach the body at positiojn 2 + dJointAttach(jId, 0, bId); + + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); + + dBodySetPosition (bId, -offset, 0, 0); + + CHECK_CLOSE (-offset, dJointGetPUPosition (jId), 1e-4); + + dJointSetPUAnchorOffset (jId, 0, 0, 0, + -offset*axis[0], -offset*axis[1], -offset*axis[2]); + CHECK_CLOSE (-offset, dJointGetPUPosition (jId), 1e-4); + + dBodySetPosition (bId, 0, 0, 0); + CHECK_CLOSE (0.0, dJointGetPUPosition (jId), 1e-4); + } + + + + + + + + + + // Compare only one body to 2 bodies with one fixed. + // + // The body are positionned at (0, 0, 0), with no rotation + // The joint is a PU Joint with default values + struct Fixture_dxJointPU_Compare_One_Body_To_Two_Bodies_At_Zero + { + Fixture_dxJointPU_Compare_One_Body_To_Two_Bodies_At_Zero() + { + wId = dWorldCreate(); + + bId1_12 = dBodyCreate (wId); + dBodySetPosition (bId1_12, 0, 0, 0); + + bId2_12 = dBodyCreate (wId); + dBodySetPosition (bId2_12, 0, 0, 0); + // The force will be added in the function since it is not + // always on the same body + + jId_12 = dJointCreatePU (wId, 0); + dJointAttach(jId_12, bId1_12, bId2_12); + + fixed = dJointCreateFixed (wId, 0); + + + + jId = dJointCreatePU (wId, 0); + + bId = dBodyCreate (wId); + dBodySetPosition (bId, 0, 0, 0); + + // Linear velocity along the prismatic axis; + dVector3 axis; + dJointGetPUAxisP(jId_12, axis); + dJointSetPUAxisP(jId, axis[0], axis[1], axis[2]); + dBodySetLinearVel (bId, magnitude*axis[0], magnitude*axis[1], magnitude*axis[2]); + } + + ~Fixture_dxJointPU_Compare_One_Body_To_Two_Bodies_At_Zero() + { + dWorldDestroy (wId); + } + + dWorldID wId; + + dBodyID bId1_12; + dBodyID bId2_12; + + dJointID jId_12; // Joint with 2 bodies + + dJointID fixed; + + + + dBodyID bId; + dJointID jId; // Joint with one body + + static const dReal magnitude; + }; + const dReal Fixture_dxJointPU_Compare_One_Body_To_Two_Bodies_At_Zero::magnitude = REAL (4.27); + + + TEST_FIXTURE (Fixture_dxJointPU_Compare_One_Body_To_Two_Bodies_At_Zero, + test_dJointSetPUPositionRate_Only_B1) + { + // Linear velocity along the prismatic axis; + dVector3 axis; + dJointGetPUAxisP(jId_12, axis); + dBodySetLinearVel (bId1_12, magnitude*axis[0], magnitude*axis[1], magnitude*axis[2]); + + dJointAttach(jId_12, bId1_12, bId2_12); + + dJointAttach(fixed, 0, bId2_12); + dJointSetFixed(fixed); + + dJointAttach(jId, bId, 0); + + CHECK_CLOSE(dJointGetPUPositionRate(jId_12), dJointGetPUPositionRate(jId), 1e-2); + } + + + TEST_FIXTURE (Fixture_dxJointPU_Compare_One_Body_To_Two_Bodies_At_Zero, + test_dJointSetPUPositionRate_Only_B2) + { + // Linear velocity along the prismatic axis; + dVector3 axis; + dJointGetPUAxisP(jId_12, axis); + dBodySetLinearVel (bId2_12, magnitude*axis[0], magnitude*axis[1], magnitude*axis[2]); + + dJointAttach(jId_12, bId1_12, bId2_12); + + dJointAttach(fixed, bId1_12, 0); + dJointSetFixed(fixed); + + dJointAttach(jId, 0, bId); + + CHECK_CLOSE(dJointGetPUPositionRate(jId_12), dJointGetPUPositionRate(jId), 1e-2); + } + + + + + + + + + // This test compare the result of a pu joint with 2 bodies where body body 2 is + // fixed to the world to a pu joint with only one body at position 1. + // + // Test the limits [-1, 0.25] when only one body at is attached to the joint + // using dJointAttache(jId, bId, 0); + // + TEST_FIXTURE(Fixture_dxJointPU_Compare_One_Body_To_Two_Bodies_At_Zero, + test_Limit_minus1_025_One_Body_on_left) + { + dVector3 axis; + dJointGetPUAxisP(jId_12, axis); + dJointSetPUAxisP(jId, axis[0], axis[1], axis[2]); + dBodySetLinearVel (bId1_12, magnitude*axis[0], magnitude*axis[1], magnitude*axis[2]); + + dJointAttach(jId_12, bId1_12, bId2_12); + dJointSetPUParam(jId_12, dParamLoStop3, -1); + dJointSetPUParam(jId_12, dParamHiStop3, 0.25); + + dJointAttach(fixed, 0, bId2_12); + dJointSetFixed(fixed); + + dJointAttach(jId, bId, 0); + dJointSetPUParam(jId, dParamLoStop3, -1); + dJointSetPUParam(jId, dParamHiStop3, 0.25); + + + for (int i=0; i<50; ++i) + dWorldStep(wId, 1.0); + + + const dReal *pos1_12 = dBodyGetPosition(bId1_12); + const dReal *pos = dBodyGetPosition(bId); + + CHECK_CLOSE (pos1_12[0], pos[0], 1e-2); + CHECK_CLOSE (pos1_12[1], pos[1], 1e-2); + CHECK_CLOSE (pos1_12[2], pos[2], 1e-2); + + const dReal *q1_12 = dBodyGetQuaternion(bId1_12); + const dReal *q = dBodyGetQuaternion(bId); + + CHECK_CLOSE (q1_12[0], q[0], 1e-4); + CHECK_CLOSE (q1_12[1], q[1], 1e-4); + CHECK_CLOSE (q1_12[2], q[2], 1e-4); + CHECK_CLOSE (q1_12[3], q[3], 1e-4); + + // Should be different than zero + CHECK( dJointGetPUPosition(jId_12) ); + CHECK( dJointGetPUPosition(jId) ); + + CHECK( dJointGetPUPositionRate(jId_12) ); + CHECK( dJointGetPUPositionRate(jId) ); + } + + + + // This test compare the result of a pu joint with 2 bodies where body body 1 is + // fixed to the world to a pu joint with only one body at position 2. + // + // Test the limits [-1, 0.25] when only one body at is attached to the joint + // using dJointAttache(jId, 0, bId); + // + TEST_FIXTURE(Fixture_dxJointPU_Compare_One_Body_To_Two_Bodies_At_Zero, + test_Limit_minus1_025_One_Body_on_right) + { + dVector3 axis; + dJointGetPUAxisP(jId_12, axis); + dJointSetPUAxisP(jId, axis[0], axis[1], axis[2]); + dBodySetLinearVel (bId2_12, magnitude*axis[0], magnitude*axis[1], magnitude*axis[2]); + + dJointAttach(jId_12, bId1_12, bId2_12); + dJointSetPUParam(jId_12, dParamLoStop3, -1); + dJointSetPUParam(jId_12, dParamHiStop3, 0.25); + + dJointAttach(fixed, bId1_12, 0); + dJointSetFixed(fixed); + + + dJointAttach(jId, 0, bId); + dJointSetPUParam(jId, dParamLoStop3, -1); + dJointSetPUParam(jId, dParamHiStop3, 0.25); + + for (int i=0; i<50; ++i) + dWorldStep(wId, 1.0); + + + const dReal *pos2_12 = dBodyGetPosition(bId2_12); + const dReal *pos = dBodyGetPosition(bId); + + CHECK_CLOSE (pos2_12[0], pos[0], 1e-2); + CHECK_CLOSE (pos2_12[1], pos[1], 1e-2); + CHECK_CLOSE (pos2_12[2], pos[2], 1e-2); + + + const dReal *q2_12 = dBodyGetQuaternion(bId2_12); + const dReal *q = dBodyGetQuaternion(bId); + + CHECK_CLOSE (q2_12[0], q[0], 1e-4); + CHECK_CLOSE (q2_12[1], q[1], 1e-4); + CHECK_CLOSE (q2_12[2], q[2], 1e-4); + CHECK_CLOSE (q2_12[3], q[3], 1e-4); + + // Should be different than zero + CHECK( dJointGetPUPosition(jId_12) ); + CHECK( dJointGetPUPosition(jId) ); + + CHECK( dJointGetPUPositionRate(jId_12) ); + CHECK( dJointGetPUPositionRate(jId) ); + } + + + + // This test compare the result of a pu joint with 2 bodies where body 2 is + // fixed to the world to a pu joint with only one body at position 1. + // + // Test the limits [0, 0] when only one body at is attached to the joint + // using dJointAttache(jId, bId, 0); + // + // The body should not move since their is no room between the two limits + // + TEST_FIXTURE(Fixture_dxJointPU_Compare_One_Body_To_Two_Bodies_At_Zero, + test_Limit_0_0_One_Body_on_left) + { + dVector3 axis; + dJointGetPUAxisP(jId_12, axis); + dJointSetPUAxisP(jId, axis[0], axis[1], axis[2]); + dBodySetLinearVel (bId1_12, magnitude*axis[0], magnitude*axis[1], magnitude*axis[2]); + + dJointAttach(jId_12, bId1_12, bId2_12); + dJointSetPUParam(jId_12, dParamLoStop3, 0); + dJointSetPUParam(jId_12, dParamHiStop3, 0); + + dJointAttach(fixed, 0, bId2_12); + dJointSetFixed(fixed); + + + dJointAttach(jId, bId, 0); + dJointSetPUParam(jId, dParamLoStop3, 0); + dJointSetPUParam(jId, dParamHiStop3, 0); + + for (int i=0; i<500; ++i) + dWorldStep(wId, 1.0); + + + const dReal *pos1_12 = dBodyGetPosition(bId1_12); + const dReal *pos = dBodyGetPosition(bId); + + CHECK_CLOSE (pos1_12[0], pos[0], 1e-4); + CHECK_CLOSE (pos1_12[1], pos[1], 1e-4); + CHECK_CLOSE (pos1_12[2], pos[2], 1e-4); + + CHECK_CLOSE (0, pos[0], 1e-4); + CHECK_CLOSE (0, pos[1], 1e-4); + CHECK_CLOSE (0, pos[2], 1e-4); + + + const dReal *q1_12 = dBodyGetQuaternion(bId1_12); + const dReal *q = dBodyGetQuaternion(bId); + + CHECK_CLOSE (q1_12[0], q[0], 1e-4); + CHECK_CLOSE (q1_12[1], q[1], 1e-4); + CHECK_CLOSE (q1_12[2], q[2], 1e-4); + CHECK_CLOSE (q1_12[3], q[3], 1e-4); + } + + + // This test compare the result of a pu joint with 2 bodies where body body 1 is + // fixed to the world to a pu joint with only one body at position 2. + // + // Test the limits [0, 0] when only one body at is attached to the joint + // using dJointAttache(jId, 0, bId); + // + // The body should not move since their is no room between the two limits + // + TEST_FIXTURE(Fixture_dxJointPU_Compare_One_Body_To_Two_Bodies_At_Zero, + test_Limit_0_0_One_Body_on_right) + { + dVector3 axis; + dJointGetPUAxisP(jId_12, axis); + dJointSetPUAxisP(jId, axis[0], axis[1], axis[2]); + dBodySetLinearVel (bId2_12, magnitude*axis[0], magnitude*axis[1], magnitude*axis[2]); + + dJointAttach(jId_12, bId1_12, bId2_12); + dJointSetPUParam(jId_12, dParamLoStop3, 0); + dJointSetPUParam(jId_12, dParamHiStop3, 0); + + dJointAttach(fixed, bId1_12, 0); + dJointSetFixed(fixed); + + + dJointAttach(jId, 0, bId); + dJointSetPUParam(jId, dParamLoStop3, 0); + dJointSetPUParam(jId, dParamHiStop3, 0); + + for (int i=0; i<500; ++i) + dWorldStep(wId, 1.0); + + const dReal *pos2_12 = dBodyGetPosition(bId2_12); + const dReal *pos = dBodyGetPosition(bId); + + CHECK_CLOSE (pos2_12[0], pos[0], 1e-4); + CHECK_CLOSE (pos2_12[1], pos[1], 1e-4); + CHECK_CLOSE (pos2_12[2], pos[2], 1e-4); + + CHECK_CLOSE (0, pos[0], 1e-4); + CHECK_CLOSE (0, pos[1], 1e-4); + CHECK_CLOSE (0, pos[2], 1e-4); + + + const dReal *q2_12 = dBodyGetQuaternion(bId2_12); + const dReal *q = dBodyGetQuaternion(bId); + + CHECK_CLOSE (q2_12[0], q[0], 1e-4); + CHECK_CLOSE (q2_12[1], q[1], 1e-4); + CHECK_CLOSE (q2_12[2], q[2], 1e-4); + CHECK_CLOSE (q2_12[3], q[3], 1e-4); + } + + } // End of SUITE TestdxJointPU This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ole...@us...> - 2008-12-06 13:43:13
|
Revision: 1601 http://opende.svn.sourceforge.net/opende/?rev=1601&view=rev Author: oleh_derevenko Date: 2008-12-06 13:43:10 +0000 (Sat, 06 Dec 2008) Log Message: ----------- Changed: Order of geometries returned in contact structures for OPCODE trimesh-plane collisions chnaged to be more natural and consistent with GIMPACT (now trimesh is returned in g1 and plane in g2) Modified Paths: -------------- trunk/CHANGELOG.txt trunk/ode/src/collision_trimesh_plane.cpp Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2008-12-06 13:39:16 UTC (rev 1600) +++ trunk/CHANGELOG.txt 2008-12-06 13:43:10 UTC (rev 1601) @@ -12,6 +12,8 @@ * Applied a patch by Martijn Buijs to make GIMPACT trimesh-ray collisions to be consistent with those in OPCODE. + * Swapped geometries returned in contacts for OPCODE Trimesh-Plane collisions + as they were returned in unnatural order being different from that in GIMPACT 11/20/08 Remi Ricard (papaDoc) * Fix problem with dJointGetPUPosition and Modified: trunk/ode/src/collision_trimesh_plane.cpp =================================================================== --- trunk/ode/src/collision_trimesh_plane.cpp 2008-12-06 13:39:16 UTC (rev 1600) +++ trunk/ode/src/collision_trimesh_plane.cpp 2008-12-06 13:43:10 UTC (rev 1601) @@ -122,13 +122,13 @@ contact->pos[ 1 ] = vertex[ 1 ]; contact->pos[ 2 ] = vertex[ 2 ]; - contact->normal[ 0 ] = plane->p[ 0 ]; - contact->normal[ 1 ] = plane->p[ 1 ]; - contact->normal[ 2 ] = plane->p[ 2 ]; + contact->normal[ 0 ] = -plane->p[ 0 ]; + contact->normal[ 1 ] = -plane->p[ 1 ]; + contact->normal[ 2 ] = -plane->p[ 2 ]; contact->depth = alpha; - contact->g1 = plane; - contact->g2 = trimesh; + contact->g1 = trimesh; + contact->g2 = plane; ++contact_count; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ole...@us...> - 2008-12-06 15:51:05
|
Revision: 1603 http://opende.svn.sourceforge.net/opende/?rev=1603&view=rev Author: oleh_derevenko Date: 2008-12-06 15:50:57 +0000 (Sat, 06 Dec 2008) Log Message: ----------- Fixed: A patch by Martijn Buijs (with my corrections) applied to make side1, side2 fields of contact structure be always initialized. Added: dGeomTriMeshSetTriMergeCallback/dGeomTriMeshGetTriMergeCallback API added to let user generate a fake triangle index on contact merging (see CHANGELOG.txt for details) Modified Paths: -------------- trunk/CHANGELOG.txt trunk/include/ode/collision_trimesh.h trunk/ode/src/box.cpp trunk/ode/src/capsule.cpp trunk/ode/src/collision_cylinder_box.cpp trunk/ode/src/collision_cylinder_plane.cpp trunk/ode/src/collision_cylinder_sphere.cpp trunk/ode/src/collision_cylinder_trimesh.cpp trunk/ode/src/collision_trimesh_box.cpp trunk/ode/src/collision_trimesh_ccylinder.cpp trunk/ode/src/collision_trimesh_disabled.cpp trunk/ode/src/collision_trimesh_gimpact.cpp trunk/ode/src/collision_trimesh_internal.h trunk/ode/src/collision_trimesh_opcode.cpp trunk/ode/src/collision_trimesh_plane.cpp trunk/ode/src/collision_trimesh_ray.cpp trunk/ode/src/collision_trimesh_sphere.cpp trunk/ode/src/collision_trimesh_trimesh.cpp trunk/ode/src/collision_trimesh_trimesh_new.cpp trunk/ode/src/convex.cpp trunk/ode/src/heightfield.cpp trunk/ode/src/ray.cpp trunk/ode/src/sphere.cpp Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/CHANGELOG.txt 2008-12-06 15:50:57 UTC (rev 1603) @@ -14,6 +14,19 @@ be consistent with those in OPCODE. * Swapped geometries returned in contacts for OPCODE Trimesh-Plane collisions as they were returned in unnatural order being different from that in GIMPACT + * Applied a patch by Martijn Buijs to make side1, side2 fields of contact + structure be always initialized, either with -1 for non-trmesh geometries + or with triangle index for trimeshes. These fields were only assigned for + trimesh-trimesh collisions before. + * dGeomTriMeshSetTriMergeCallback/dGeomTriMeshGetTriMergeCallback API added + to set/get user defined callback procedure for trimeshes that would be + invoked when contacts are merged to let user code accumulate attributes of + original contact triangles and generate a fake index by which it would + later be able to determine those attributes. If the callback is not + assigned (the default) -1 is generated as triangle index for merged + contacts (there was an index of first of merged triangles before!!!). + The callback is currently used within OPCODE trimesh-sphere and OPCODE + new trimesh-trimesh collisions. 11/20/08 Remi Ricard (papaDoc) * Fix problem with dJointGetPUPosition and Modified: trunk/include/ode/collision_trimesh.h =================================================================== --- trunk/include/ode/collision_trimesh.h 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/include/ode/collision_trimesh.h 2008-12-06 15:50:57 UTC (rev 1603) @@ -136,6 +136,17 @@ ODE_API dTriRayCallback* dGeomTriMeshGetRayCallback(dGeomID g); /* + * Triangle merging callback. + * Allows the user to generate a fake triangle index for a new contact generated + * from merging of two other contacts. That index could later be used by the + * user to determine attributes of original triangles used as sources for a + * merged contact. + */ +typedef int dTriTriMergeCallback(dGeomID TriMesh, int FirstTriangleIndex, int SecondTriangleIndex); +ODE_API void dGeomTriMeshSetTriMergeCallback(dGeomID g, dTriTriMergeCallback* Callback); +ODE_API dTriTriMergeCallback* dGeomTriMeshGetTriMergeCallback(dGeomID g); + +/* * Trimesh class * Construction. Callbacks are optional. */ Modified: trunk/ode/src/box.cpp =================================================================== --- trunk/ode/src/box.cpp 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/box.cpp 2008-12-06 15:50:57 UTC (rev 1603) @@ -728,11 +728,14 @@ int num = dBoxBox (o1->final_posr->pos,o1->final_posr->R,b1->side, o2->final_posr->pos,o2->final_posr->R,b2->side, normal,&depth,&code,flags,contact,skip); for (int i=0; i<num; i++) { - CONTACT(contact,i*skip)->normal[0] = -normal[0]; - CONTACT(contact,i*skip)->normal[1] = -normal[1]; - CONTACT(contact,i*skip)->normal[2] = -normal[2]; - CONTACT(contact,i*skip)->g1 = o1; - CONTACT(contact,i*skip)->g2 = o2; + dContactGeom *currContact = CONTACT(contact,i*skip); + currContact->normal[0] = -normal[0]; + currContact->normal[1] = -normal[1]; + currContact->normal[2] = -normal[2]; + currContact->g1 = o1; + currContact->g2 = o2; + currContact->side1 = -1; + currContact->side2 = -1; } return num; } @@ -751,6 +754,9 @@ contact->g1 = o1; contact->g2 = o2; + contact->side1 = -1; + contact->side2 = -1; + int ret = 0; //@@@ problem: using 4-vector (plane->p) as 3-vector (normal). @@ -856,8 +862,11 @@ done: for (int i=0; i<ret; i++) { - CONTACT(contact,i*skip)->g1 = o1; - CONTACT(contact,i*skip)->g2 = o2; + dContactGeom *currContact = CONTACT(contact,i*skip); + currContact->g1 = o1; + currContact->g2 = o2; + currContact->side1 = -1; + currContact->side2 = -1; } return ret; } Modified: trunk/ode/src/capsule.cpp =================================================================== --- trunk/ode/src/capsule.cpp 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/capsule.cpp 2008-12-06 15:50:57 UTC (rev 1603) @@ -139,6 +139,8 @@ contact->g1 = o1; contact->g2 = o2; + contact->side1 = -1; + contact->side2 = -1; // find the point on the cylinder axis that is closest to the sphere dReal alpha = @@ -171,6 +173,8 @@ contact->g1 = o1; contact->g2 = o2; + contact->side1 = -1; + contact->side2 = -1; // get p1,p2 = cylinder axis endpoints, get radius dVector3 p1,p2; @@ -213,6 +217,8 @@ contact->g1 = o1; contact->g2 = o2; + contact->side1 = -1; + contact->side2 = -1; // copy out some variables, for convenience dReal lz1 = cyl1->lz * REAL(0.5); @@ -275,6 +281,8 @@ if (n2) { c2->g1 = o1; c2->g2 = o2; + c2->side1 = -1; + c2->side2 = -1; return 2; } } @@ -363,8 +371,11 @@ } for (int i=0; i < ncontacts; i++) { - CONTACT(contact,i*skip)->g1 = o1; - CONTACT(contact,i*skip)->g2 = o2; + dContactGeom *currContact = CONTACT(contact,i*skip); + currContact->g1 = o1; + currContact->g2 = o2; + currContact->side1 = -1; + currContact->side2 = -1; } return ncontacts; } Modified: trunk/ode/src/collision_cylinder_box.cpp =================================================================== --- trunk/ode/src/collision_cylinder_box.cpp 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/collision_cylinder_box.cpp 2008-12-06 15:50:57 UTC (rev 1603) @@ -693,6 +693,8 @@ dVector3Copy(m_vEp0,Contact0->pos); Contact0->g1 = m_gCylinder; Contact0->g2 = m_gBox; + Contact0->side1 = -1; + Contact0->side2 = -1; dVector3Inv(Contact0->normal); m_nContacts++; @@ -704,6 +706,8 @@ dVector3Copy(m_vEp1,Contact1->pos); Contact1->g1 = m_gCylinder; Contact1->g2 = m_gBox; + Contact1->side1 = -1; + Contact1->side2 = -1; dVector3Inv(Contact1->normal); m_nContacts++; } @@ -929,6 +933,8 @@ dVector3Copy(vPoint,Contact0->pos); Contact0->g1 = m_gCylinder; Contact0->g2 = m_gBox; + Contact0->side1 = -1; + Contact0->side2 = -1; dVector3Inv(Contact0->normal); m_nContacts++; @@ -961,6 +967,8 @@ dVector3Copy(vPoint,Contact0->pos); Contact0->g1 = m_gCylinder; Contact0->g2 = m_gBox; + Contact0->side1 = -1; + Contact0->side2 = -1; dVector3Inv(Contact0->normal); m_nContacts++; Modified: trunk/ode/src/collision_cylinder_plane.cpp =================================================================== --- trunk/ode/src/collision_cylinder_plane.cpp 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/collision_cylinder_plane.cpp 2008-12-06 15:50:57 UTC (rev 1603) @@ -157,6 +157,8 @@ dVector3Copy(PlaneNormal, contact->normal); contact->g1 = Cylinder; contact->g2 = Plane; + contact->side1 = -1; + contact->side2 = -1; GeomCount++; if( GeomCount >= (flags & NUMC_MASK)) return GeomCount; // enough contactgeoms @@ -171,6 +173,8 @@ dVector3Copy(PlaneNormal, contact->normal); contact->g1 = Cylinder; contact->g2 = Plane; + contact->side1 = -1; + contact->side2 = -1; GeomCount++; if( GeomCount >= (flags & NUMC_MASK)) return GeomCount; // enough contactgeoms @@ -185,6 +189,8 @@ dVector3Copy(PlaneNormal, contact->normal); contact->g1 = Cylinder; contact->g2 = Plane; + contact->side1 = -1; + contact->side2 = -1; GeomCount++; if( GeomCount >= (flags & NUMC_MASK)) return GeomCount; // enough contactgeoms @@ -199,6 +205,8 @@ dVector3Copy(PlaneNormal, contact->normal); contact->g1 = Cylinder; contact->g2 = Plane; + contact->side1 = -1; + contact->side2 = -1; GeomCount++; if( GeomCount >= (flags & NUMC_MASK)) return GeomCount; // enough contactgeoms @@ -226,6 +234,8 @@ dVector3Copy(PlaneNormal, contact->normal); contact->g1 = Cylinder; contact->g2 = Plane; + contact->side1 = -1; + contact->side2 = -1; GeomCount++; if( GeomCount >= (flags & NUMC_MASK)) return GeomCount; // enough contactgeoms @@ -244,6 +254,8 @@ dVector3Copy(PlaneNormal, contact->normal); contact->g1 = Cylinder; contact->g2 = Plane; + contact->side1 = -1; + contact->side2 = -1; GeomCount++; if( GeomCount >= (flags & NUMC_MASK)) return GeomCount; // enough contactgeoms Modified: trunk/ode/src/collision_cylinder_sphere.cpp =================================================================== --- trunk/ode/src/collision_cylinder_sphere.cpp 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/collision_cylinder_sphere.cpp 2008-12-06 15:50:57 UTC (rev 1603) @@ -139,6 +139,8 @@ contact->normal[2] = (contact->pos[2] - SpherePos[2]) / (radius2 - contact->depth); contact->g1 = Cylinder; contact->g2 = Sphere; + contact->side1 = -1; + contact->side2 = -1; GeomCount++; return GeomCount; } @@ -159,6 +161,8 @@ contact->normal[2] = (contact->pos[2] - SpherePos[2]) / (radius2 - contact->depth); contact->g1 = Cylinder; contact->g2 = Sphere; + contact->side1 = -1; + contact->side2 = -1; GeomCount++; return GeomCount; } @@ -188,6 +192,8 @@ contact->normal[2] = C[2]; contact->g1 = Cylinder; contact->g2 = Sphere; + contact->side1 = -1; + contact->side2 = -1; GeomCount++; return GeomCount; } @@ -211,6 +217,8 @@ contact->normal[2] = C[2] / t; contact->g1 = Cylinder; contact->g2 = Sphere; + contact->side1 = -1; + contact->side2 = -1; GeomCount++; return GeomCount; } @@ -236,6 +244,8 @@ contact->normal[2] = vDir1[2]; contact->g1 = Cylinder; contact->g2 = Sphere; + contact->side1 = -1; + contact->side2 = -1; GeomCount++; return GeomCount; } @@ -256,6 +266,8 @@ contact->normal[2] = -vDir1[2]; contact->g1 = Cylinder; contact->g2 = Sphere; + contact->side1 = -1; + contact->side2 = -1; GeomCount++; return GeomCount; } Modified: trunk/ode/src/collision_cylinder_trimesh.cpp =================================================================== --- trunk/ode/src/collision_cylinder_trimesh.cpp 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/collision_cylinder_trimesh.cpp 2008-12-06 15:50:57 UTC (rev 1603) @@ -213,6 +213,7 @@ dVector3Copy(m_gLocalContacts[iContact].vPos,Contact->pos); Contact->g1 = Cylinder; Contact->g2 = Trimesh; + Contact->side1 = -1; Contact->side2 = m_gLocalContacts[iContact].triIndex; dVector3Inv(Contact->normal); Modified: trunk/ode/src/collision_trimesh_box.cpp =================================================================== --- trunk/ode/src/collision_trimesh_box.cpp 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/collision_trimesh_box.cpp 2008-12-06 15:50:57 UTC (rev 1603) @@ -41,7 +41,7 @@ static void GenerateContact(int in_Flags, dContactGeom* in_Contacts, int in_Stride, - dxGeom* in_g1, dxGeom* in_g2, + dxGeom* in_g1, dxGeom* in_g2, int TriIndex, const dVector3 in_ContactPos, const dVector3 in_Normal, dReal in_Depth, int& OutTriCount); @@ -139,8 +139,8 @@ bool _cldTestEdge(dReal fp0, dReal fp1, dReal fR, dReal fD, dVector3 vNormal, int iAxis); bool _cldTestSeparatingAxes(const dVector3 &v0, const dVector3 &v1, const dVector3 &v2); - void _cldClipping(const dVector3 &v0, const dVector3 &v1, const dVector3 &v2); - void _cldTestOneTriangle(const dVector3 &v0, const dVector3 &v1, const dVector3 &v2); + void _cldClipping(const dVector3 &v0, const dVector3 &v1, const dVector3 &v2, int TriIndex); + void _cldTestOneTriangle(const dVector3 &v0, const dVector3 &v1, const dVector3 &v2, int TriIndex); // box data dMatrix3 m_mHullBoxRot; @@ -702,7 +702,7 @@ // clip and generate contacts -void sTrimeshBoxColliderData::_cldClipping(const dVector3 &v0, const dVector3 &v1, const dVector3 &v2) { +void sTrimeshBoxColliderData::_cldClipping(const dVector3 &v0, const dVector3 &v1, const dVector3 &v2, int TriIndex) { dIASSERT( !(m_iFlags & CONTACTS_UNIMPORTANT) || m_ctContacts < (m_iFlags & NUMC_MASK) ); // Do not call the function if there is no room to store results // if we have edge/edge intersection @@ -773,9 +773,11 @@ SET(Contact->pos,vPntTmp); Contact->g1 = Geom1; Contact->g2 = Geom2; + Contact->side1 = TriIndex; + Contact->side2 = -1; m_ctContacts++; #endif - GenerateContact(m_iFlags, m_ContactGeoms, m_iStride, m_Geom1, m_Geom2, + GenerateContact(m_iFlags, m_ContactGeoms, m_iStride, m_Geom1, m_Geom2, TriIndex, vPntTmp, m_vBestNormal, m_fBestDepth, m_ctContacts); @@ -939,9 +941,11 @@ SET(Contact->pos,vPntTmp); Contact->g1 = Geom1; Contact->g2 = Geom2; + Contact->side1 = TriIndex; + Contact->side2 = -1; m_ctContacts++; #endif - GenerateContact(m_iFlags, m_ContactGeoms, m_iStride, m_Geom1, m_Geom2, + GenerateContact(m_iFlags, m_ContactGeoms, m_iStride, m_Geom1, m_Geom2, TriIndex, vPntTmp, m_vBestNormal, -fTempDepth, m_ctContacts); if ((m_ctContacts | CONTACTS_UNIMPORTANT) == (m_iFlags & (NUMC_MASK | CONTACTS_UNIMPORTANT))) { @@ -1061,9 +1065,11 @@ SET(Contact->pos,vPntTmp); Contact->g1 = Geom1; Contact->g2 = Geom2; + Contact->side1 = TriIndex; + Contact->side2 = -1; m_ctContacts++; #endif - GenerateContact(m_iFlags, m_ContactGeoms, m_iStride, m_Geom1, m_Geom2, + GenerateContact(m_iFlags, m_ContactGeoms, m_iStride, m_Geom1, m_Geom2, TriIndex, vPntTmp, m_vBestNormal, -fTempDepth, m_ctContacts); if ((m_ctContacts | CONTACTS_UNIMPORTANT) == (m_iFlags & (NUMC_MASK | CONTACTS_UNIMPORTANT))) { @@ -1080,7 +1086,7 @@ // test one mesh triangle on intersection with given box -void sTrimeshBoxColliderData::_cldTestOneTriangle(const dVector3 &v0, const dVector3 &v1, const dVector3 &v2)//, void *pvUser) +void sTrimeshBoxColliderData::_cldTestOneTriangle(const dVector3 &v0, const dVector3 &v1, const dVector3 &v2, int TriIndex)//, void *pvUser) { // do intersection test and find best separating axis if(!_cldTestSeparatingAxes(v0, v1, v2)) { @@ -1096,7 +1102,7 @@ return; } - _cldClipping(v0, v1, v2); + _cldClipping(v0, v1, v2, TriIndex); } @@ -1141,11 +1147,14 @@ dVector3 dv[3], bool &bOutFinishSearching) { // test this triangle - _cldTestOneTriangle(dv[0],dv[1],dv[2]); + _cldTestOneTriangle(dv[0],dv[1],dv[2],Triint); // fill-in tri index for generated contacts - for (; ctContacts0 < m_ctContacts; ctContacts0++) - SAFECONTACT(m_iFlags, m_ContactGeoms, ctContacts0, m_iStride)->side1 = Triint; + for (; ctContacts0 < m_ctContacts; ctContacts0++) { + dContactGeom* pContact = SAFECONTACT(m_iFlags, m_ContactGeoms, ctContacts0, m_iStride); + pContact->side1 = Triint; + pContact->side2 = -1; + } /* NOTE by Oleh_Derevenko: @@ -1374,7 +1383,7 @@ // static void GenerateContact(int in_Flags, dContactGeom* in_Contacts, int in_Stride, - dxGeom* in_g1, dxGeom* in_g2, + dxGeom* in_g1, dxGeom* in_g2, int TriIndex, const dVector3 in_ContactPos, const dVector3 in_Normal, dReal in_Depth, int& OutTriCount) { @@ -1454,6 +1463,9 @@ Contact->g1 = in_g1; Contact->g2 = in_g2; + + Contact->side1 = TriIndex; + Contact->side2 = -1; OutTriCount++; } Modified: trunk/ode/src/collision_trimesh_ccylinder.cpp =================================================================== --- trunk/ode/src/collision_trimesh_ccylinder.cpp 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/collision_trimesh_ccylinder.cpp 2008-12-06 15:50:57 UTC (rev 1603) @@ -325,7 +325,8 @@ SET(Contact->pos,m_gLocalContacts[iContact].vPos); Contact->g1 = TriMesh; Contact->g2 = Capsule; - Contact->side2 = m_gLocalContacts[iContact].triIndex; + Contact->side1 = m_gLocalContacts[iContact].triIndex; + Contact->side2 = -1; nFinalContact++; } @@ -1220,7 +1221,9 @@ pcontact->depth = ptrimeshcontacts->m_depth; pcontact->g1 = TriMesh; pcontact->g2 = gCylinder; - + pcontact->side1 = ptrimeshcontacts->m_feature1; + pcontact->side2 = -1; + ptrimeshcontacts++; } Modified: trunk/ode/src/collision_trimesh_disabled.cpp =================================================================== --- trunk/ode/src/collision_trimesh_disabled.cpp 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/collision_trimesh_disabled.cpp 2008-12-06 15:50:57 UTC (rev 1603) @@ -29,7 +29,7 @@ #include "collision_util.h" #include "collision_trimesh_internal.h" -dxTriMesh::dxTriMesh(dSpaceID Space, dTriMeshDataID Data) : dxGeom(Space, 1){ type = dTriMeshClass; } +dxTriMesh::dxTriMesh(dSpaceID Space, dTriMeshDataID Data) : dxGeom(Space, 1) { type = dTriMeshClass; } dxTriMesh::~dxTriMesh(){} int dxTriMesh::AABBTest(dxGeom* g, dReal aabb[6]) { return 0; } @@ -111,6 +111,8 @@ void dGeomTriMeshSetRayCallback(dGeomID g, dTriRayCallback* Callback) { } dTriRayCallback* dGeomTriMeshGetRayCallback(dGeomID g) { return 0; } +void dGeomTriMeshSetTriMergeCallback(dGeomID g, dTriTriMergeCallback* Callback) { } +dTriTriMergeCallback* dGeomTriMeshGetTriMergeCallback(dGeomID g) { return 0; } void dGeomTriMeshEnableTC(dGeomID g, int geomClass, int enable) {} int dGeomTriMeshIsTCEnabled(dGeomID g, int geomClass) { return 0; } Modified: trunk/ode/src/collision_trimesh_gimpact.cpp =================================================================== --- trunk/ode/src/collision_trimesh_gimpact.cpp 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/collision_trimesh_gimpact.cpp 2008-12-06 15:50:57 UTC (rev 1603) @@ -156,6 +156,11 @@ dxTriMesh::dxTriMesh(dSpaceID Space, dTriMeshDataID Data) : dxGeom(Space, 1){ type = dTriMeshClass; + Callback = NULL; + ArrayCallback = NULL; + RayCallback = NULL; + TriMergeCallback = NULL; // Not initialized in dCreateTriMesh + gim_init_buffer_managers(m_buffer_managers); dGeomTriMeshSetData(this,Data); @@ -258,6 +263,18 @@ return ((dxTriMesh*)g)->RayCallback; } +void dGeomTriMeshSetTriMergeCallback(dGeomID g, dTriTriMergeCallback* Callback) +{ + dUASSERT(g && g->type == dTriMeshClass, "argument not a trimesh"); + ((dxTriMesh*)g)->TriMergeCallback = Callback; +} + +dTriTriMergeCallback* dGeomTriMeshGetTriMergeCallback(dGeomID g) +{ + dUASSERT(g && g->type == dTriMeshClass, "argument not a trimesh"); + return ((dxTriMesh*)g)->TriMergeCallback; +} + void dGeomTriMeshSetData(dGeomID g, dTriMeshDataID Data) { dUASSERT(g && g->type == dTriMeshClass, "argument not a trimesh"); @@ -470,6 +487,8 @@ pcontact->depth = ptrimeshcontacts->m_depth; pcontact->g1 = g1; pcontact->g2 = g2; + pcontact->side1 = ptrimeshcontacts->m_feature1; + pcontact->side2 = ptrimeshcontacts->m_feature2; ptrimeshcontacts++; } Modified: trunk/ode/src/collision_trimesh_internal.h =================================================================== --- trunk/ode/src/collision_trimesh_internal.h 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/collision_trimesh_internal.h 2008-12-06 15:50:57 UTC (rev 1603) @@ -271,6 +271,7 @@ dTriCallback* Callback; dTriArrayCallback* ArrayCallback; dTriRayCallback* RayCallback; + dTriTriMergeCallback* TriMergeCallback; // Data types dxTriMeshData* Data; Modified: trunk/ode/src/collision_trimesh_opcode.cpp =================================================================== --- trunk/ode/src/collision_trimesh_opcode.cpp 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/collision_trimesh_opcode.cpp 2008-12-06 15:50:57 UTC (rev 1603) @@ -530,6 +530,11 @@ { type = dTriMeshClass; + Callback = NULL; + ArrayCallback = NULL; + RayCallback = NULL; + TriMergeCallback = NULL; // Not initialized in dCreateTriMesh + this->Data = Data; /* TC has speed/space 'issues' that don't make it a clear @@ -681,6 +686,18 @@ return ((dxTriMesh*)g)->RayCallback; } +void dGeomTriMeshSetTriMergeCallback(dGeomID g, dTriTriMergeCallback* Callback) +{ + dUASSERT(g && g->type == dTriMeshClass, "argument not a trimesh"); + ((dxTriMesh*)g)->TriMergeCallback = Callback; +} + +dTriTriMergeCallback* dGeomTriMeshGetTriMergeCallback(dGeomID g) +{ + dUASSERT(g && g->type == dTriMeshClass, "argument not a trimesh"); + return ((dxTriMesh*)g)->TriMergeCallback; +} + void dGeomTriMeshSetData(dGeomID g, dTriMeshDataID Data) { dUASSERT(g && g->type == dTriMeshClass, "argument not a trimesh"); Modified: trunk/ode/src/collision_trimesh_plane.cpp =================================================================== --- trunk/ode/src/collision_trimesh_plane.cpp 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/collision_trimesh_plane.cpp 2008-12-06 15:50:57 UTC (rev 1603) @@ -129,6 +129,8 @@ contact->depth = alpha; contact->g1 = trimesh; contact->g2 = plane; + contact->side1 = t; + contact->side2 = -1; ++contact_count; @@ -199,8 +201,10 @@ pcontact->normal[3] = 0; pcontact->depth = (*planecontact_results)[3]; - pcontact->g1 = o1; - pcontact->g2 = o2; + pcontact->g1 = o1; // trimesh geom + pcontact->g2 = o2; // plane geom + pcontact->side1 = -1; // note: don't have the triangle index, but OPCODE *does* do this properly + pcontact->side2 = -1; planecontact_results++; } Modified: trunk/ode/src/collision_trimesh_ray.cpp =================================================================== --- trunk/ode/src/collision_trimesh_ray.cpp 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/collision_trimesh_ray.cpp 2008-12-06 15:50:57 UTC (rev 1603) @@ -131,6 +131,8 @@ Contact->depth = T; Contact->g1 = TriMesh; Contact->g2 = RayGeom; + Contact->side1 = TriIndex; + Contact->side2 = -1; OutTriCount++; @@ -189,7 +191,8 @@ Contact->depth = contact_data.tparam; Contact->g1 = TriMesh; Contact->g2 = RayGeom; - + Contact->side1 = contact_data.m_face_id; + Contact->side2 = -1; return 1; } Modified: trunk/ode/src/collision_trimesh_sphere.cpp =================================================================== --- trunk/ode/src/collision_trimesh_sphere.cpp 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/collision_trimesh_sphere.cpp 2008-12-06 15:50:57 UTC (rev 1603) @@ -33,6 +33,7 @@ #if dTRIMESH_OPCODE #define MERGECONTACTS +//#define MERGECONTACTNORMALS // Ripped from Opcode 1.1. static bool GetContactData(const dVector3& Center, dReal Radius, const dVector3 Origin, const dVector3 Edge0, const dVector3 Edge1, dReal& Dist, dReal& u, dReal& v){ @@ -408,21 +409,39 @@ Contact->depth = Depth * dirProj; //Contact->depth = Radius - side; // (mg) penetration depth is distance along normal not shortest distance - Contact->side1 = TriIndex; + +#if !defined MERGECONTACTS // Merge all contacts into 1 + Contact->g1 = TriMesh; + Contact->g2 = SphereGeom; - //Contact->g1 = TriMesh; - //Contact->g2 = SphereGeom; - + Contact->side2 = -1; +#endif // Otherwise assigned later + + Contact->side1 = TriIndex; + OutTriCount++; } -#ifdef MERGECONTACTS // Merge all contacts into 1 +#if defined MERGECONTACTS // Merge all contacts into 1 if (OutTriCount > 0){ dContactGeom* Contact = SAFECONTACT(Flags, Contacts, 0, Stride); + Contact->g1 = TriMesh; + Contact->g2 = SphereGeom; + Contact->side2 = -1; if (OutTriCount > 1 && !(Flags & CONTACTS_UNIMPORTANT)){ - dVector3 normal = { 0,0,0 }; - dVector3 pos = { 0,0,0 }; - for (int i = 0; i < OutTriCount; i++){ + dVector3 pos; + pos[0] = Contact->pos[0]; + pos[1] = Contact->pos[1]; + pos[2] = Contact->pos[2]; + + dVector3 normal; + normal[0] = Contact->normal[0] * Contact->depth; + normal[1] = Contact->normal[1] * Contact->depth; + normal[2] = Contact->normal[2] * Contact->depth; + + int TriIndex = Contact->side1; + + for (int i = 1; i < OutTriCount; i++){ dContactGeom* TempContact = SAFECONTACT(Flags, Contacts, i, Stride); pos[0] += TempContact->pos[0]; @@ -432,9 +451,13 @@ normal[0] += TempContact->normal[0] * TempContact->depth; normal[1] += TempContact->normal[1] * TempContact->depth; normal[2] += TempContact->normal[2] * TempContact->depth; + + TriIndex = (TriMesh->TriMergeCallback) ? TriMesh->TriMergeCallback(TriMesh, TriIndex, TempContact->side1) : -1; } - Contact->pos[0] = pos[0] / OutTriCount; + Contact->side1 = TriIndex; + + Contact->pos[0] = pos[0] / OutTriCount; Contact->pos[1] = pos[1] / OutTriCount; Contact->pos[2] = pos[2] / OutTriCount; @@ -447,25 +470,20 @@ } // otherwise original Contact's normal would be used and it should be already normalized } - Contact->g1 = TriMesh; - Contact->g2 = SphereGeom; - - // TODO: - // Side1 now contains index of triangle that gave first hit - // Probably we should find index of triangle with deepest penetration - return 1; } else return 0; #elif defined MERGECONTACTNORMALS // Merge all normals, and distribute between all contacts if (OutTriCount != 0){ - if (OutTriCount != 1 && !(Flags & CONTACTS_UNIMPORTANT)){ - dVector3& Normal = SAFECONTACT(Flags, Contacts, 0, Stride)->normal; - Normal[0] *= SAFECONTACT(Flags, Contacts, 0, Stride)->depth; - Normal[1] *= SAFECONTACT(Flags, Contacts, 0, Stride)->depth; - Normal[2] *= SAFECONTACT(Flags, Contacts, 0, Stride)->depth; - Normal[3] *= SAFECONTACT(Flags, Contacts, 0, Stride)->depth; + if (OutTriCount != 1 && !(Flags & CONTACTS_UNIMPORTANT)){ + dVector3 Normal; + dContactGeom* FirstContact = SAFECONTACT(Flags, Contacts, 0, Stride); + Normal[0] = FirstContact->normal[0] * FirstContact->depth; + Normal[1] = FirstContact->normal[1] * FirstContact->depth; + Normal[2] = FirstContact->normal[2] * FirstContact->depth; + Normal[3] = FirstContact->normal[3] * FirstContact->depth; + for (int i = 1; i < OutTriCount; i++){ dContactGeom* Contact = SAFECONTACT(Flags, Contacts, i, Stride); @@ -474,44 +492,25 @@ Normal[2] += Contact->normal[2] * Contact->depth; Normal[3] += Contact->normal[3] * Contact->depth; } - dNormalize3(Normal); - for (int i = 1; i < OutTriCount; i++){ + dNormalize3(Normal); + + for (int i = 0; i < OutTriCount; i++){ dContactGeom* Contact = SAFECONTACT(Flags, Contacts, i, Stride); Contact->normal[0] = Normal[0]; Contact->normal[1] = Normal[1]; Contact->normal[2] = Normal[2]; Contact->normal[3] = Normal[3]; - - Contact->g1 = TriMesh; - Contact->g2 = SphereGeom; } } - else{ - SAFECONTACT(Flags, Contacts, 0, Stride)->g1 = TriMesh; - SAFECONTACT(Flags, Contacts, 0, Stride)->g2 = SphereGeom; - } return OutTriCount; } else return 0; -#else //MERGECONTACTNORMALS // Just gather penetration depths and return - for (int i = 0; i < OutTriCount; i++){ - dContactGeom* Contact = SAFECONTACT(Flags, Contacts, i, Stride); +#else // none of MERGECONTACTS and MERGECONTACTNORMALS // Just return - //Contact->depth = dSqrt(dDOT(Contact->normal, Contact->normal)); - - /*Contact->normal[0] /= Contact->depth; - Contact->normal[1] /= Contact->depth; - Contact->normal[2] /= Contact->depth; - Contact->normal[3] /= Contact->depth;*/ - - Contact->g1 = TriMesh; - Contact->g2 = SphereGeom; - } - - return OutTriCount; + return OutTriCount; #endif // MERGECONTACTS } else return 0; @@ -574,6 +573,8 @@ pcontact->depth = ptrimeshcontacts->m_depth; pcontact->g1 = g1; pcontact->g2 = SphereGeom; + pcontact->side1 = ptrimeshcontacts->m_feature1; + pcontact->side2 = -1; ptrimeshcontacts++; } Modified: trunk/ode/src/collision_trimesh_trimesh.cpp =================================================================== --- trunk/ode/src/collision_trimesh_trimesh.cpp 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/collision_trimesh_trimesh.cpp 2008-12-06 15:50:57 UTC (rev 1603) @@ -68,6 +68,7 @@ // static void GetTriangleGeometryCallback(udword, VertexPointers&, udword); -- not used static void GenerateContact(int, dContactGeom*, int, dxTriMesh*, dxTriMesh*, + int TriIndex1, int TriIndex2, const dVector3, const dVector3, dReal, int&); static int TriTriIntersectWithIsectLine(dReal V0[3],dReal V1[3],dReal V2[3], dReal U0[3],dReal U1[3],dReal U2[3],int *coplanar, @@ -308,8 +309,8 @@ if (depth < 0) depth *= -1.0; - GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, - ContactPt, n, depth, OutTriCount); + GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, id1, id2, + ContactPt, n, depth, OutTriCount); } } else { @@ -428,7 +429,7 @@ for (int j=0; j<3; j++) { if (SimpleUnclippedTest(CoplanarPt, pen_v[j], pen_elt[j], n, col_v, depth)) { - GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, + GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, id1, id2, pen_v[j], n, depth, OutTriCount); badPen = false; @@ -444,7 +445,7 @@ for (int j=0; j<3; j++) if (SimpleUnclippedTest(CoplanarPt, pen_v[j], pen_elt[j], n, col_v, depth)) { - GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, + GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, id1, id2, pen_v[j], n, depth, OutTriCount); badPen = false; @@ -558,7 +559,7 @@ if (depth <= contact_elt_length) { // Add a contact - GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, + GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, id1, id2, firstClippedTri.Points[j], n, depth, OutTriCount); badPen = false; @@ -660,7 +661,7 @@ if (depth <= contact_elt_length) { // Add a contact - GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, + GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, id1, id2, secondClippedTri.Points[j], n, depth, OutTriCount); badPen = false; @@ -695,7 +696,7 @@ if (depth > REAL(1e-12)) { dNormalize3(n); - GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, + GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, id1, id2, CoplanarPt, n, depth, OutTriCount); badPen = false; } @@ -742,7 +743,7 @@ } if ((depth > 0.0) && (depth <= contact_elt_length)) { - GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, + GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, id1, id2, ContactPt, n, depth, OutTriCount); badPen = false; } @@ -784,7 +785,7 @@ } if ((depth > 0.0) && (depth <= contact_elt_length)) { - GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, + GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, id1, id2, ContactPt, esn, depth, OutTriCount); badPen = false; } @@ -822,7 +823,7 @@ if (depth <= contact_elt_length) { // Add a contact - GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, + GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, id1, id2, firstClippedTri.Points[j], esn, depth, OutTriCount); badPen = false; @@ -850,7 +851,7 @@ if (depth <= contact_elt_length) { // Add a contact - GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, + GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, id1, id2, secondClippedTri.Points[j], esn, depth, OutTriCount); badPen = false; @@ -882,7 +883,7 @@ if ( (dp > 0.0) && (dp <= SMALL_ELT)) { // Add a contact - GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, + GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, id1, id2, pen_v[j], n, dp, OutTriCount); badPen = false; @@ -904,7 +905,7 @@ dp = TINY_PENETRATION; if ( (dp > 0.0) && (dp <= SMALL_ELT)) { - GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, + GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, id1, id2, pen_v[j], n, dp, OutTriCount); badPen = false; @@ -945,7 +946,7 @@ if (depth > 0.0) { // Add a tiny contact at the coplanar point - GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, + GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, id1, id2, CoplanarPt, ContactNormal, depth, OutTriCount); badPen = false; } @@ -961,7 +962,7 @@ SET(ContactNormal, n2); } - GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, + GenerateContact(Flags, Contacts, Stride, TriMesh1, TriMesh2, id1, id2, CoplanarPt, ContactNormal, TINY_PENETRATION, OutTriCount); badPen = false; } @@ -1977,6 +1978,7 @@ static void GenerateContact(int in_Flags, dContactGeom* in_Contacts, int in_Stride, dxTriMesh* in_TriMesh1, dxTriMesh* in_TriMesh2, + int TriIndex1, int TriIndex2, const dVector3 in_ContactPos, const dVector3 in_Normal, dReal in_Depth, int& OutTriCount) { @@ -2060,7 +2062,10 @@ Contact->g1 = in_TriMesh1; Contact->g2 = in_TriMesh2; - + + Contact->side1 = TriIndex1; + Contact->side2 = TriIndex2; + OutTriCount++; } while (false); Modified: trunk/ode/src/collision_trimesh_trimesh_new.cpp =================================================================== --- trunk/ode/src/collision_trimesh_trimesh_new.cpp 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/collision_trimesh_trimesh_new.cpp 2008-12-06 15:50:57 UTC (rev 1603) @@ -84,6 +84,7 @@ static bool TriTriContacts(const dVector3 tr1[3], const dVector3 tr2[3], + int TriIndex1, int TriIndex2, dxGeom* g1, dxGeom* g2, int Flags, CONTACT_KEY_HASH_TABLE &hashcontactset, dContactGeom* Contacts, int Stride, @@ -386,7 +387,7 @@ } -dContactGeom * PushNewContact( dxGeom* g1, dxGeom* g2, +dContactGeom * PushNewContact( dxGeom* g1, dxGeom* g2, int TriIndex1, int TriIndex2, const dVector3 point, dVector3 normal, dReal depth, @@ -413,12 +414,19 @@ pcontact->g1 = g1; pcontact->g2 = g2; + pcontact->side1 = TriIndex1; + pcontact->side2 = TriIndex2; } else if (depthDifference >= -CONTACT_DIFF_EPSILON) ///average { if(pcontact->g1 == g2) { MULT(normal,normal, REAL(-1.0)); + int tempInt = TriIndex1; TriIndex1 = TriIndex2; TriIndex2 = tempInt; + // This should be discarded by optimizer as g1 and g2 are + // not used any more but it's preferable to keep this line for + // the sake of consistency in variable values. + dxGeom *tempGeom = g1; g1 = g2; g2 = tempGeom; } const dReal oldLen = pcontact->normal[3]; @@ -429,6 +437,9 @@ { MULT(pcontact->normal, pcontact->normal, REAL(1.0) / len); pcontact->normal[3] = len; + + pcontact->side1 = ((dxTriMesh *)pcontact->g1)->TriMergeCallback ? ((dxTriMesh *)pcontact->g1)->TriMergeCallback((dxTriMesh *)pcontact->g1, pcontact->side1, TriIndex1) : -1; + pcontact->side2 = ((dxTriMesh *)pcontact->g2)->TriMergeCallback ? ((dxTriMesh *)pcontact->g2)->TriMergeCallback((dxTriMesh *)pcontact->g2, pcontact->side2, TriIndex2) : -1; } else { @@ -446,6 +457,8 @@ pcontact->depth = depth; pcontact->g1 = g1; pcontact->g2 = g2; + pcontact->side1 = TriIndex1; + pcontact->side2 = TriIndex2; } return pcontact; @@ -540,7 +553,7 @@ v2[j][3] = 1.0; } - TriTriContacts(v1,v2, + TriTriContacts(v1,v2, id1,id2, g1, g2, Flags, hashcontactset, Contacts,Stride,OutTriCount); @@ -1238,6 +1251,7 @@ ///SUPPORT UP TO 8 CONTACTS bool TriTriContacts(const dVector3 tr1[3], const dVector3 tr2[3], + int TriIndex1, int TriIndex2, dxGeom* g1, dxGeom* g2, int Flags, CONTACT_KEY_HASH_TABLE &hashcontactset, dContactGeom* Contacts, int Stride, @@ -1270,7 +1284,7 @@ ccount = 0; while (ccount<contactpoints.Count) { - PushNewContact( g1, g2, + PushNewContact( g1, g2, TriIndex1, TriIndex2, contactpoints.Points[ccount], normal, depth, Flags, hashcontactset, Contacts,Stride,contactcount); Modified: trunk/ode/src/convex.cpp =================================================================== --- trunk/ode/src/convex.cpp 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/convex.cpp 2008-12-06 15:50:57 UTC (rev 1603) @@ -633,6 +633,8 @@ target->depth = -distance2; target->g1 = Convex; target->g2 = Plane; + target->side1 = -1; // TODO: set plane index? + target->side2 = -1; contacts++; } } @@ -709,6 +711,8 @@ contact->depth = Sphere->radius-dist; contact->g1 = Sphere; contact->g2 = Convex; + contact->side1 = -1; + contact->side2 = -1; // TODO: set plane index? return 1; } else @@ -740,6 +744,8 @@ contact->depth = Sphere->radius-dist; contact->g1 = Sphere; contact->g2 = Convex; + contact->side1 = -1; + contact->side2 = -1; // TODO: set plane index? return 1; } } @@ -769,6 +775,8 @@ contact->depth = closestdist+Sphere->radius; contact->g1 = Sphere; contact->g2 = Convex; + contact->side1 = -1; + contact->side2 = -1; // TODO: set plane index? return 1; } return 0; @@ -1453,6 +1461,8 @@ contact->depth=depth; contact->g1 = ray; contact->g2 = convex; + contact->side1 = -1; + contact->side2 = -1; // TODO: set plane index? return 1; } } @@ -1475,6 +1485,8 @@ contact->g1 = ray; contact->g2 = convex; + contact->side1 = -1; + contact->side2 = -1; // TODO: set plane index? dReal alpha, beta, nsign; int flag; Modified: trunk/ode/src/heightfield.cpp =================================================================== --- trunk/ode/src/heightfield.cpp 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/heightfield.cpp 2008-12-06 15:50:57 UTC (rev 1603) @@ -997,6 +997,9 @@ pContact->depth = minY - maxO2Height; + pContact->side1 = -1; + pContact->side2 = -1; + return 1; } } @@ -1450,8 +1453,9 @@ const size_t planeTriListSize = itPlane->trianglelistCurrentSize; for (i = 0; i < numPlaneContacts; i++) { + dContactGeom *planeCurrContact = PlaneContact + i; // Check if contact point found in plane is inside Triangle. - const dVector3 &pCPos = PlaneContact[i].pos; + const dVector3 &pCPos = planeCurrContact->pos; for (size_t b = 0; planeTriListSize > b; b++) { if (m_p_data->IsOnHeightfield2 (itPlane->trianglelist[b]->vertices[0], @@ -1461,7 +1465,9 @@ pContact = CONTACT(contact, numTerrainContacts*skip); dVector3Copy(pCPos, pContact->pos); dOPESIGN(pContact->normal, =, -, itPlane->planeDef); - pContact->depth = PlaneContact[i].depth; + pContact->depth = planeCurrContact->depth; + pContact->side1 = planeCurrContact->side1; + pContact->side2 = planeCurrContact->side2; numTerrainContacts++; if ( numTerrainContacts == numMaxContactsPossible ) return numTerrainContacts; @@ -1563,6 +1569,8 @@ dOPESIGN(pContact->normal, =, -, itTriangle->planeDef); pContact->depth = depth; + pContact->side1 = -1; + pContact->side2 = -1; numTerrainContacts++; if ( numTerrainContacts == numMaxContactsPossible ) @@ -1754,70 +1762,73 @@ - numTerrainContacts += terrain->dCollideHeightfieldZone( + int numTerrainOrigContacts = numTerrainContacts; + numTerrainContacts += terrain->dCollideHeightfieldZone( nMinX,nMaxX,nMinZ,nMaxZ,o2,numMaxTerrainContacts - numTerrainContacts, flags,CONTACT(contact,numTerrainContacts*skip),skip ); - dIASSERT( numTerrainContacts <= numMaxTerrainContacts ); + dIASSERT( numTerrainContacts <= numMaxTerrainContacts ); - dContactGeom *pContact; - for ( i = 0; i < numTerrainContacts; ++i ) - { - pContact = CONTACT(contact,i*skip); - pContact->g1 = o1; - pContact->g2 = o2; - } + dContactGeom *pContact; + for ( i = numTerrainOrigContacts; i != numTerrainContacts; ++i ) + { + pContact = CONTACT(contact,i*skip); + pContact->g1 = o1; + pContact->g2 = o2; + // pContact->side1 = -1; -- Oleh_Derevenko: sides must not be erased here as they are set by respective colliders during ray/plane tests + // pContact->side2 = -1; + } - //------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ dCollideHeightfieldExit: - if (reComputeAABB) + if (reComputeAABB) + { + // Restore o2 position, rotation and AABB + dVector3Copy( posbak, o2->final_posr->pos ); + dMatrix3Copy( Rbak, o2->final_posr->R ); + memcpy( o2->aabb, aabbbak, sizeof(dReal)*6 ); + o2->gflags = gflagsbak; + + // + // Transform Contacts to World Space + // + if ( terrain->gflags & GEOM_PLACEABLE ) { - // Restore o2 position, rotation and AABB - dVector3Copy( posbak, o2->final_posr->pos ); - dMatrix3Copy( Rbak, o2->final_posr->R ); - memcpy( o2->aabb, aabbbak, sizeof(dReal)*6 ); - o2->gflags = gflagsbak; - - // - // Transform Contacts to World Space - // - if ( terrain->gflags & GEOM_PLACEABLE ) + for ( i = 0; i < numTerrainContacts; ++i ) { - for ( i = 0; i < numTerrainContacts; ++i ) - { - pContact = CONTACT(contact,i*skip); - dOPE( pos0, =, pContact->pos ); + pContact = CONTACT(contact,i*skip); + dOPE( pos0, =, pContact->pos ); #ifndef DHEIGHTFIELD_CORNER_ORIGIN - pos0[ 0 ] -= terrain->m_p_data->m_fHalfWidth; - pos0[ 2 ] -= terrain->m_p_data->m_fHalfDepth; + pos0[ 0 ] -= terrain->m_p_data->m_fHalfWidth; + pos0[ 2 ] -= terrain->m_p_data->m_fHalfDepth; #endif // !DHEIGHTFIELD_CORNER_ORIGIN - dMULTIPLY0_331( pContact->pos, terrain->final_posr->R, pos0 ); + dMULTIPLY0_331( pContact->pos, terrain->final_posr->R, pos0 ); - dOP( pContact->pos, +, pContact->pos, terrain->final_posr->pos ); - dOPE( pos0, =, pContact->normal ); + dOP( pContact->pos, +, pContact->pos, terrain->final_posr->pos ); + dOPE( pos0, =, pContact->normal ); - dMULTIPLY0_331( pContact->normal, terrain->final_posr->R, pos0 ); - } + dMULTIPLY0_331( pContact->normal, terrain->final_posr->R, pos0 ); } + } #ifndef DHEIGHTFIELD_CORNER_ORIGIN - else + else + { + for ( i = 0; i < numTerrainContacts; ++i ) { - for ( i = 0; i < numTerrainContacts; ++i ) - { - pContact = CONTACT(contact,i*skip); - pContact->pos[ 0 ] -= terrain->m_p_data->m_fHalfWidth; - pContact->pos[ 2 ] -= terrain->m_p_data->m_fHalfDepth; - } + pContact = CONTACT(contact,i*skip); + pContact->pos[ 0 ] -= terrain->m_p_data->m_fHalfWidth; + pContact->pos[ 2 ] -= terrain->m_p_data->m_fHalfDepth; } + } #endif // !DHEIGHTFIELD_CORNER_ORIGIN - } - // Return contact count. - return numTerrainContacts; + } + // Return contact count. + return numTerrainContacts; } Modified: trunk/ode/src/ray.cpp =================================================================== --- trunk/ode/src/ray.cpp 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/ray.cpp 2008-12-06 15:50:57 UTC (rev 1603) @@ -243,6 +243,8 @@ dxSphere *sphere = (dxSphere*) o2; contact->g1 = ray; contact->g2 = sphere; + contact->side1 = -1; + contact->side2 = -1; return ray_sphere_helper (ray,sphere->final_posr->pos,sphere->radius,contact,0); } @@ -260,6 +262,8 @@ contact->g1 = ray; contact->g2 = box; + contact->side1 = -1; + contact->side2 = -1; int i; @@ -357,6 +361,9 @@ contact->g1 = ray; contact->g2 = ccyl; + contact->side1 = -1; + contact->side2 = -1; + dReal lz2 = ccyl->lz * REAL(0.5); // compute some useful info @@ -483,6 +490,8 @@ contact->depth = alpha; contact->g1 = ray; contact->g2 = plane; + contact->side1 = -1; + contact->side2 = -1; return 1; } @@ -500,6 +509,8 @@ // Fill in contact information. contact->g1 = ray; contact->g2 = cyl; + contact->side1 = -1; + contact->side2 = -1; const dReal half_length = cyl->lz * REAL( 0.5 ); Modified: trunk/ode/src/sphere.cpp =================================================================== --- trunk/ode/src/sphere.cpp 2008-12-06 15:20:50 UTC (rev 1602) +++ trunk/ode/src/sphere.cpp 2008-12-06 15:50:57 UTC (rev 1603) @@ -119,6 +119,8 @@ contact->g1 = o1; contact->g2 = o2; + contact->side1 = -1; + contact->side2 = -1; return dCollideSpheres (o1->final_posr->pos,sphere1->radius, o2->final_posr->pos,sphere2->radius,contact); @@ -148,6 +150,8 @@ contact->g1 = o1; contact->g2 = o2; + contact->side1 = -1; + contact->side2 = -1; p[0] = o1->final_posr->pos[0] - o2->final_posr->pos[0]; p[1] = o1->final_posr->pos[1] - o2->final_posr->pos[1]; @@ -227,6 +231,9 @@ contact->g1 = o1; contact->g2 = o2; + contact->side1 = -1; + contact->side2 = -1; + dReal k = dDOT (o1->final_posr->pos,plane->p); dReal depth = plane->p[3] - k + sphere->radius; if (depth >= 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dan...@us...> - 2008-12-09 01:24:00
|
Revision: 1607 http://opende.svn.sourceforge.net/opende/?rev=1607&view=rev Author: danielosmari Date: 2008-12-09 01:23:55 +0000 (Tue, 09 Dec 2008) Log Message: ----------- Applied patch 2381592, Kinematic Bodies Modified Paths: -------------- trunk/CHANGELOG.txt trunk/build/demos.lua trunk/include/ode/objects.h trunk/include/ode/odecpp.h trunk/ode/demo/Makefile.am trunk/ode/src/joints/joint.cpp trunk/ode/src/joints/joint.h trunk/ode/src/ode.cpp trunk/ode/src/util.cpp Added Paths: ----------- trunk/ode/demo/demo_kinematic.cpp Modified: trunk/CHANGELOG.txt =================================================================== --- trunk/CHANGELOG.txt 2008-12-07 18:23:08 UTC (rev 1606) +++ trunk/CHANGELOG.txt 2008-12-09 01:23:55 UTC (rev 1607) @@ -8,6 +8,9 @@ * keep the format consistent (79 char width, M/D/Y date format). ------------------------------------------------------------------------------ +12/09/08 Daniel K. O. + * Applied patch #2381592, which adds support for Kinematic Bodies. + 12/06/08 Oleh Derevenko * Applied a patch by Martijn Buijs to make GIMPACT trimesh-ray collisions to Modified: trunk/build/demos.lua =================================================================== --- trunk/build/demos.lua 2008-12-07 18:23:08 UTC (rev 1606) +++ trunk/build/demos.lua 2008-12-09 01:23:55 UTC (rev 1607) @@ -19,6 +19,7 @@ "jointPR", "jointPU", "joints", + "kinematic", "motion", "motor", "ode", Modified: trunk/include/ode/objects.h =================================================================== --- trunk/include/ode/objects.h 2008-12-07 18:23:08 UTC (rev 1606) +++ trunk/include/ode/objects.h 2008-12-09 01:23:55 UTC (rev 1607) @@ -1065,7 +1065,38 @@ */ ODE_API dJointID dBodyGetJoint (dBodyID, int index); + + + /** + * @brief Set rigid body to dynamic state (default). + * @param dBodyID identification of body. + * @ingroup bodies + */ +ODE_API void dBodySetDynamic (dBodyID); + +/** + * @brief Set rigid body to kinematic state. + * When in kinematic state the body isn't simulated as a dynamic + * body (it's "unstoppable", doesn't respond to forces), + * but can still affect dynamic bodies (e.g. in joints). + * Kinematic bodies can be controlled by position and velocity. + * @note A kinematic body has infinite mass. If you set its mass + * to something else, it loses the kinematic state and behaves + * as a normal dynamic body. + * @param dBodyID identification of body. + * @ingroup bodies + */ +ODE_API void dBodySetKinematic (dBodyID); + +/** + * @brief Check wether a body is in kinematic state. + * @ingroup bodies + * @return 1 if a body is kinematic or 0 if it is dynamic. + */ +ODE_API int dBodyIsKinematic (dBodyID); + +/** * @brief Manually enable a body. * @param dBodyID identification of body. * @ingroup bodies Modified: trunk/include/ode/odecpp.h =================================================================== --- trunk/include/ode/odecpp.h 2008-12-07 18:23:08 UTC (rev 1606) +++ trunk/include/ode/odecpp.h 2008-12-09 01:23:55 UTC (rev 1607) @@ -269,6 +269,13 @@ void setTorque (const dVector3 t) { setTorque (t[0], t[1], t[2]); } + void setDynamic() + { dBodySetDynamic (_id); } + void setKinematic() + { dBodySetKinematic (_id); } + bool isKinematic() const + { return dBodyIsKinematic (_id) != 0; } + void enable() { dBodyEnable (_id); } void disable() Modified: trunk/ode/demo/Makefile.am =================================================================== --- trunk/ode/demo/Makefile.am 2008-12-07 18:23:08 UTC (rev 1606) +++ trunk/ode/demo/Makefile.am 2008-12-09 01:23:55 UTC (rev 1607) @@ -29,6 +29,7 @@ demo_jointPR \ demo_joints \ demo_jointPU \ + demo_kinematic \ demo_motion \ demo_motor \ demo_ode \ @@ -58,6 +59,7 @@ demo_jointPR_SOURCES = demo_jointPR.cpp demo_joints_SOURCES = demo_joints.cpp demo_jointPU_SOURCES = demo_jointPU.cpp +demo_kinematic_SOURCES = demo_kinematic.cpp demo_motion_SOURCES = demo_motion.cpp demo_motor_SOURCES = demo_motor.cpp demo_ode_SOURCES = demo_ode.cpp Added: trunk/ode/demo/demo_kinematic.cpp =================================================================== --- trunk/ode/demo/demo_kinematic.cpp (rev 0) +++ trunk/ode/demo/demo_kinematic.cpp 2008-12-09 01:23:55 UTC (rev 1607) @@ -0,0 +1,217 @@ +#include <iostream> +#include <set> +#include <algorithm> +#include <functional> +#include <ode/ode.h> +#include <drawstuff/drawstuff.h> +#include "texturepath.h" + +#ifdef dDOUBLE +#define dsDrawBox dsDrawBoxD +#define dsDrawCylinder dsDrawCylinderD +#endif + + +using namespace std; + +dWorld *world; +dSpace *space; +dPlane *ground; +dBody *kbody; +dBox *kbox; +dJointGroup joints; +dCylinder *kpole; +dBody *matraca; +dBox *matraca_geom; +dHingeJoint *hinge; + +struct Box { + dBody body; + dBox geom; + Box() : + body(*world), + geom(*space, 0.2, 0.2, 0.2) + { + dMass mass; + mass.setBox(1, 0.2, 0.2, 0.2); + body.setMass(mass); + geom.setData(this); + geom.setBody(body); + } + void draw() const + { + dVector3 lengths; + geom.getLengths(lengths); + dsSetTexture(DS_WOOD); + dsSetColor(0,1,0); + dsDrawBox(geom.getPosition(), geom.getRotation(), lengths); + } +}; + +set<Box*> boxes; +set<Box*> to_remove; + +void dropBox() +{ + Box *box = new Box(); + + dReal px = (rand() / float(RAND_MAX)) * 2 - 1; + dReal py = (rand() / float(RAND_MAX)) * 2 - 1; + dReal pz = 3; + box->body.setPosition(px, py, pz); + + boxes.insert(box); +} + +void queueRemoval(dGeomID g) +{ + Box *b = (Box*)dGeomGetData(g); + to_remove.insert(b); +} + +void removeQueued() +{ + while (!to_remove.empty()) { + Box *b = *to_remove.begin(); + to_remove.erase(b); + boxes.erase(b); + delete b; + } +} + + +void nearCallback(void *data, dGeomID g1, dGeomID g2) +{ + if (g1 == ground->id()) { + queueRemoval(g2); + return; + } + if (g2 == ground->id()) { + queueRemoval(g1); + return; + } + + dBodyID b1 = dGeomGetBody(g1); + dBodyID b2 = dGeomGetBody(g2); + + if (b1 and b2 and dAreConnectedExcluding(b1, b2, dJointTypeContact)) + return; + + const int MAX_CONTACTS = 10; + dContact contact[MAX_CONTACTS]; + int n = dCollide(g1, g2, MAX_CONTACTS, &contact[0].geom, sizeof(dContact)); + for (int i=0; i<n; ++i) { + contact[i].surface.mode = 0; + contact[i].surface.mu = 1; + dJointID j = dJointCreateContact (*world, joints.id(), contact+i); + dJointAttach(j, b1, b2); + } +} + + +void +simLoop(int pause) +{ + if (!pause) { + const dReal timestep = 0.005; + + // this does a hard-coded circular motion animation + static float t=0; + t += timestep/4; + if (t > 2*M_PI) + t = 0; + dReal px = cos(t); + dReal py = sin(t); + dReal vx = -sin(t)/4; + dReal vy = cos(t)/4; + kbody->setPosition(px, py, .5); + kbody->setLinearVel(vx, vy, 0); + // end of hard-coded animation + + space->collide(0, nearCallback); + removeQueued(); + + world->quickStep(timestep); + joints.clear(); + } + + dVector3 lengths; + + // the moving platform + kbox->getLengths(lengths); + dsSetTexture(DS_WOOD); + dsSetColor(.3, .3, 1); + dsDrawBox(kbox->getPosition(), kbox->getRotation(), lengths); + dReal length, radius; + kpole->getParams(&radius, &length); + dsSetTexture(DS_CHECKERED); + dsSetColor(1, 1, 0); + dsDrawCylinder(kpole->getPosition(), kpole->getRotation(), length, radius); + + // the matraca + matraca_geom->getLengths(lengths); + dsSetColor(1,0,0); + dsSetTexture(DS_WOOD); + dsDrawBox(matraca_geom->getPosition(), matraca_geom->getRotation(), lengths); + + // and the boxes + for_each(boxes.begin(), boxes.end(), mem_fun(&Box::draw)); +} + +void command(int c) +{ + switch (c) { + case ' ': + dropBox(); + break; + } +} + +int main(int argc, char **argv) +{ + dInitODE(); + + // setup pointers to drawstuff callback functions + dsFunctions fn; + fn.version = DS_VERSION; + fn.start = 0; + fn.step = &simLoop; + fn.command = &command; + fn.stop = 0; + fn.path_to_textures = DRAWSTUFF_TEXTURE_PATH; + + cout << endl << "*** Press SPACE to drop boxes **" << endl; + + space = new dSimpleSpace(); + ground = new dPlane(*space, 0, 0, 1, 0); + + world = new dWorld; + world->setGravity(0, 0, -.5); + + kbody = new dBody(*world); + kbody->setKinematic(); + const dReal kx = 1, ky = 0, kz = .5; + kbody->setPosition(kx, ky, kz); + kbox = new dBox(*space, 3, 3, .5); + kbox->setBody(*kbody); + kpole = new dCylinder(*space, .125, 1.5); + kpole->setBody(*kbody); + dGeomSetOffsetPosition(kpole->id(), 0, 0, 0.8); + + matraca = new dBody(*world); + matraca->setPosition(kx+0, ky+1, kz+1); + matraca_geom = new dBox(*space, 0.5, 2, 0.75); + matraca_geom->setBody(*matraca); + dMass mass; + mass.setBox(1, 0.5, 2, 0.75); + matraca->setMass(mass); + + hinge = new dHingeJoint(*world); + hinge->attach(*kbody, *matraca); + hinge->setAnchor(kx, ky, kz+1); + hinge->setAxis(0, 0, 1); + + dsSimulationLoop (argc, argv, 640, 480, &fn); + + dCloseODE(); +} Property changes on: trunk/ode/demo/demo_kinematic.cpp ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ode/src/joints/joint.cpp =================================================================== --- trunk/ode/src/joints/joint.cpp 2008-12-07 18:23:08 UTC (rev 1606) +++ trunk/ode/src/joints/joint.cpp 2008-12-09 01:23:55 UTC (rev 1607) @@ -62,8 +62,12 @@ { } +bool dxJoint::isEnabled() const +{ + return ( node[0].body->invMass > 0 || + (node[1].body && node[1].body->invMass > 0) ); +} - //**************************************************************************** // externs Modified: trunk/ode/src/joints/joint.h =================================================================== --- trunk/ode/src/joints/joint.h 2008-12-07 18:23:08 UTC (rev 1606) +++ trunk/ode/src/joints/joint.h 2008-12-09 01:23:55 UTC (rev 1607) @@ -126,6 +126,10 @@ /// Set values which are relative with respect to bodies. /// Each dxJoint should redefined it if need be. virtual void setRelativeValues() {}; + + //Test for connecting two kinematic bodies. In that case, we should consider + // the joint as disabled and not use it in simulation step. + bool isEnabled() const; }; Modified: trunk/ode/src/ode.cpp =================================================================== --- trunk/ode/src/ode.cpp 2008-12-07 18:23:08 UTC (rev 1606) +++ trunk/ode/src/ode.cpp 2008-12-09 01:23:55 UTC (rev 1607) @@ -829,7 +829,26 @@ return 0; } +void dBodySetDynamic (dBodyID b) +{ + dAASSERT (b); + + dBodySetMass(b,&b->mass); +} +void dBodySetKinematic (dBodyID b) +{ + dAASSERT (b); + dSetZero (b->invI,4*3); + b->invMass = 0; +} + +int dBodyIsKinematic (dBodyID b) +{ + dAASSERT (b); + return b->invMass == 0; +} + void dBodyEnable (dBodyID b) { dAASSERT (b); Modified: trunk/ode/src/util.cpp =================================================================== --- trunk/ode/src/util.cpp 2008-12-07 18:23:08 UTC (rev 1606) +++ trunk/ode/src/util.cpp 2008-12-09 01:23:55 UTC (rev 1607) @@ -273,7 +273,7 @@ // notify the user if (b->moved_callback) - b->moved_callback(b); + b->moved_callback(b); // damping @@ -358,7 +358,7 @@ // traverse and tag all body's joints, add untagged connected bodies // to stack for (dxJointNode *n=b->firstjoint; n; n=n->next) { - if (!n->joint->tag) { + if (!n->joint->tag && n->joint->isEnabled()) { n->joint->tag = 1; joint[jcount++] = n->joint; if (n->body && !n->body->tag) { @@ -398,8 +398,10 @@ } } for (j=world->firstjoint; j; j=(dxJoint*)j->next) { - if ((j->node[0].body && (j->node[0].body->flags & dxBodyDisabled)==0) || - (j->node[1].body && (j->node[1].body->flags & dxBodyDisabled)==0)) { + if ( (( j->node[0].body && (j->node[0].body->flags & dxBodyDisabled)==0 ) || + (j->node[1].body && (j->node[1].body->flags & dxBodyDisabled)==0) ) + && + j->isEnabled() ) { if (!j->tag) dDebug (0,"attached enabled joint not tagged"); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |