[ODE] composite objects
mpeniak
mpeniak at gmail.com
Sun Oct 28 04:21:04 MST 2007
Hi Guys
I hope someone is willing to help me because I cannot learn how to
redistribute mass so that the object I have created has equal mass alonog
its body. I know how to create composite object by attaching two or more
geoms to the same body and changing geoms offsets.
I was trying to follow howto on composite objects but it did not work, I
tried it several times and it always complained about bad parameter. I also
did it when I tried to run the oringinal howto code.
Any help much appreciated:confused:
Martin
Here's me code where I have connected two geoms to the same body:
#include <ode/ode.h>
#include <drawstuff/drawstuff.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
#endif
#define RADIUS 0.02
#define BUGIE_LENGTH 0.5
static dWorldID world;
static dSpaceID space;
static dJointGroupID contactgroup;
static dGeomID ground;
static dBodyID bugie_body;
static dGeomID bugie_geom1;
static dGeomID bugie_geom2;
// start simulation - set viewpoint
static void start()
{
static float xyz[3] = {1.0382f,-1.0811f,1.4700f};
static float hpr[3] = {135.0000f,-19.5000f,0.0000f};
dsSetViewpoint (xyz,hpr);
}
static void nearCallback (void *data, dGeomID o1, dGeomID o2)
{
int i,n;
// only collide things with the ground
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 = dInfinity;
contact[i].surface.slip1 = 0.1;
contact[i].surface.slip2 = 0.1;
contact[i].surface.soft_erp = 0.5;
contact[i].surface.soft_cfm = 0.3;
dJointID c = dJointCreateContact (world,contactgroup,&contact[i]);
dJointAttach (c,
dGeomGetBody(contact[i].geom.g1),
dGeomGetBody(contact[i].geom.g2));
}
}
}
// simulation loop
static void simLoop (int pause)
{
if (!pause) {
dsSetColor (0,10,7);
dsSetTexture (DS_WOOD);
dsDrawCylinder(dGeomGetPosition(bugie_geom1),dGeomGetRotation(bugie_geom1),BUGIE_LENGTH,
RADIUS);
dsDrawCylinder
(dGeomGetPosition(bugie_geom2),dGeomGetRotation(bugie_geom2),BUGIE_LENGTH,
RADIUS);
dSpaceCollide (space,0,&nearCallback);
dWorldStep (world,0.05);
// remove all contact joints
dJointGroupEmpty (contactgroup);
}
}
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.stop = 0;
fn.path_to_textures = "../../drawstuff/textures";
if(argc==2)
{
fn.path_to_textures = argv[1];
}
// create world
dInitODE();
world = dWorldCreate();
space = dHashSpaceCreate (0);
dWorldSetGravity (world,0,0,-0.5);
ground = dCreatePlane (space,0,0,1,0);
contactgroup = dJointGroupCreate (0);
// bugie body
bugie_body = dBodyCreate (world);
dBodySetPosition(bugie_body,0,0,0.8);
bugie_geom1 = dCreateCylinder (space,RADIUS,BUGIE_LENGTH);
dGeomSetBody (bugie_geom1,bugie_body);
dGeomSetOffsetPosition(bugie_geom1,0,0,0);
bugie_geom2 = dCreateCylinder (space,RADIUS,BUGIE_LENGTH);
dGeomSetBody (bugie_geom2,bugie_body);
dGeomSetOffsetPosition(bugie_geom1,0,0,0.4);
dMatrix3 rotation;
dRFromAxisAndAngle(rotation,0,2,0,0.6);
dGeomSetOffsetRotation(bugie_geom1,rotation);
dRFromAxisAndAngle(rotation,0,2,0,-0.6);
dGeomSetOffsetRotation(bugie_geom2,rotation);
dRFromAxisAndAngle(rotation,0,1,0,1.7);
dBodySetRotation(bugie_body,rotation);
// run simulation
dsSimulationLoop (argc,argv,352,288,&fn);
dWorldDestroy (world);
dCloseODE();
return 0;
}
--
View this message in context: http://www.nabble.com/composite-objects-tf4706600.html#a13452401
Sent from the ODE mailing list archive at Nabble.com.
More information about the ODE
mailing list