sphere trimesh collision

5 views
Skip to first unread message

phoenix

unread,
Jun 26, 2009, 5:39:11 PM6/26/09
to ode-users
hi
i hv been able to collide simple objects. i need to make a terrain
now. i have rendered the terrain in opengl without problems. but
trimesh does not collide. its like its not even there. I am
initializing the mesh using the commands

triMesh = dGeomTriMeshDataCreate();

dGeomTriMeshDataBuildDouble(triMesh,vertices2,3*sizeof
(GLfloat),WIDTH*HEIGHT,indices2,((WIDTH-1)*(HEIGHT-1)*6),sizeof
(GLint));

terrain=dCreateTriMesh(space,triMesh,null,null,null);

dGeomSetData(terrain,triMesh);

//dMassSetTrimesh(&m,0.5,terrain);

and the declaration for verts and indexes is

GLfloat *vertices2;
GLint *indices2;

i have created a sequential array for both of them. Also i am pretty
sure i have compiled using trimesh collision support.
1 more thing if i use the commented line dMassSetTrimesh then it gives
a check that mass must be >0 .
These were the only commands i used concerning the trimesh. where am i
going wrong? since the vertex and index arrays r working fine and
getting rendered they must be fine right?. help plz :(

Daniel K. O.

unread,
Jun 26, 2009, 7:23:41 PM6/26/09
to ode-...@googlegroups.com
phoenix escreveu:
> dGeomTriMeshDataBuildDouble(triMesh,vertices2,3*sizeof
> (GLfloat),WIDTH*HEIGHT,indices2,((WIDTH-1)*(HEIGHT-1)*6),sizeof
> (GLint));

GLfloat? It should be double; you are using
"dGeomTriMeshDataBuildDouble" after all.


> dGeomSetData(terrain,triMesh);

Why are you doing that?


> GLfloat *vertices2;
> GLint *indices2;

Should be

double *vertices2;
int *indices;

Even if your GLint is a typedef for int, you never know when it might
just throw compiler errors (I know of at least one platform where GLuint
is not just a typedef for unsigned int).


> 1 more thing if i use the commented line dMassSetTrimesh then it gives
> a check that mass must be >0 .

The fact that you are trying to create a mass for a terrain suggests you
are not too sure of what you are doing. I would recommend first trying
to play along the demos. For example, demo_basket.


> These were the only commands i used concerning the trimesh. where am i
> going wrong? since the vertex and index arrays r working fine and
> getting rendered they must be fine right?.

You do realize ODE is not a rendering library, right? The fact that
something is being drawn by another library doesn't mean ODE is actually
simulating it.

--
Daniel K. O.
"The only way to succeed is to build success yourself"

phoenix

unread,
Jun 27, 2009, 7:32:55 AM6/27/09
to ode-users
ok i saw the demos, i wrote this function

#define VertexCount 4
#define IndexCount 6

void LoadMeshODE()
{
static float Vertices[VertexCount][3];
static dTriIndex Indices[IndexCount];


Vertices[0][0] = -25.0f;
Vertices[0][1] = 0.0f;
Vertices[0][2] = 25.0f;

Vertices[1][0] = 25.0f;
Vertices[1][1] = 0.0f;
Vertices[1][2] = 25.0f;

Vertices[2][0] = 25.0f;
Vertices[2][1] = 0.0f;
Vertices[2][2] = -25.0f;

Vertices[3][0] = -25.0f;
Vertices[3][1] = 0.0f;
Vertices[3][2] = -25.0f;

Indices[0] = 2;
Indices[1] = 1;
Indices[2] = 0;

Indices[3] = 2;
Indices[4] = 0;
Indices[5] = 4;

triMesh = dGeomTriMeshDataCreate();
dGeomTriMeshDataBuildSingle(triMesh, Vertices[0], 3 * sizeof(float),
VertexCount, &Indices[0], IndexCount, 3 * sizeof(dTriIndex));
terrain=dCreateTriMesh(space,triMesh,0,0,0);
}

i removed the line dcreateplane to c if this would work. sphere was
bouncing fine on the plane. but on trimesh it just falls through.

objects[++cnt].body=dBodyCreate(world);
objects[cnt].geom=dCreateSphere(space,0.5);
dMassSetSphere(&m,1,2);
dBodySetMass(objects[cnt].body,&m);
dGeomSetBody(objects[cnt].geom,objects[cnt].body);
dBodySetPosition(objects[cnt].body,0,100,0);

so i tried to add the following

objects[++cnt].body=dBodyCreate(world);
objects[cnt].geom=dCreateBox(space,1,0.5,0.2);
dMassSetBox(&m,1,1,0.5,0.2);
dBodySetMass(objects[cnt].body,&m);
dGeomSetBody(objects[cnt].geom,objects[cnt].body);
dBodySetPosition(objects[cnt].body,0,10,0);

surprisingly the box hits near the plane and falls down the edge. but
the sphere still falls through. what am i doing wrong now?

gravity is : dWorldSetGravity(world,0,-9.81,0);

help

phoenix

unread,
Jun 27, 2009, 7:35:08 AM6/27/09
to ode-users
> surprisingly the box hits near the plane and falls down the edge. but
> the sphere still falls through. what am i doing wrong now?

Sorry I meant the box hits the trimesh and falls*
Reply all
Reply to author
Forward
0 new messages