[ODE] Terrain
Bram Stolk
b.stolk at gmail.com
Tue Nov 6 21:19:46 MST 2007
On Nov 6, 2007 6:39 PM, mpeniak <mpeniak at gmail.com> wrote:
>
> What are the possibilities please?
I use PLIB to read an arbitrary model format.
In my case *.3ds files.
I then use this code (abstract from stormbaan coureur) to convert PLIB's
leaf nodes into ODE geoms:
void StaticWorldObject::AddLeaf(ssgLeaf *leaf, sgVec3 initialpos)
{
// traverse the triangles
int cnt = leaf->getNumTriangles() ;
int nv = leaf->getNumVertices() ;
// int nn = leaf->getNumNormals() ;
float *vertices = new float[3*nv];
int *indices = new int[3*cnt];
int i;
for (i=0; i<nv; i++)
{
float *v = leaf->getVertex( i ) ;
assert(v);
memcpy(vertices+3*i, v, 3*sizeof(float));
}
for (i=0; i<cnt; i++)
{
short idx0, idx1, idx2 ;
leaf->getTriangle( i, &idx0, &idx1, &idx2 ) ;
indices[3*i+0]=idx0;
indices[3*i+1]=idx1;
indices[3*i+2]=idx2;
}
dTriMeshDataID data = dGeomTriMeshDataCreate();
dataids.push_back(data);
dGeomTriMeshDataBuildSingle
(
data,
vertices,
3*sizeof(float),
nv,
indices,
cnt*3,
3*sizeof(int)
);
//fprintf(stderr,"Adding trimesh with %d verts, %d indices\n", nv, cnt*3);
dGeomID trimesh = dCreateTriMesh(space, data, 0,0,0);
geomids.push_back(trimesh);
dGeomSetPosition(trimesh, initialpos[0], initialpos[1], initialpos[2]);
dMatrix3 R;
dRFromAxisAndAngle (R, 0,1,0, 0.0);
dGeomSetRotation (trimesh, R);
dGeomSetData(trimesh, this);
}
If you want to know who to find all leaf nodes in a PLIB scenegraph, consult
the stormbaan coureur source code.
Regards,
Bram
--
Zapp: Captain's log, stardate...er..
Kif: Ohhh. April 13th.
Zapp: April 13th. Point 2.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ode.org/pipermail/ode/attachments/20071106/5bf11937/attachment.htm
More information about the ODE
mailing list