[ODE] re: ODE-Newbie: dGeomTriMeshDataBuildSimple
Foxy
imfox.mulder at laposte.net
Sun Sep 7 07:59:02 2003
This is a multi-part message in MIME format.
------=_NextPart_000_000B_01C37561.8F6F9D40
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hello/Salut,
I already asked for this question in the last mounth :
William Mallouk said :
"I will try to explain how to do it, but first I will tell you that
there are two very good examples on how to do this on the \ode\test dir =
of
the ODE distribution. The files are test_trimesh.cpp and
test_moving_trimesh.cpp. You may want to take a look at them later.
Basically, there are two steps you have to follow before calling
dGeomTriMeshDataBuildSimple.
First, you have to define what are the vertices of your mesh by creating =
an
array of dVector (each vector represents one vertex).
In the example below, I am defining four vertices.
dVector3* Vertices =3D new dVector3[4];
Vertices[0][0] =3D 10;
Vertices[0][1] =3D 10;
Vertices[0][2] =3D 10;
Vertices[1][0] =3D -10;
Vertices[1][1] =3D -10;
Vertices[1][2] =3D -10;
Vertices[2][0] =3D 10;
Vertices[2][1] =3D -10;
Vertices[2][2] =3D 10;
Vertices[3][0] =3D 0;
Vertices[3][1] =3D 0;
Vertices[3][2] =3D 0;
Second, you have to define what vertices form the triangles (faces) of =
your
mesh by creating an array of int that will contain the indices of the
vertices that you have defined above.
The sample below has two triangles. One of them if made of vertices 0, =
1,
and 3, and the other one is made of vertices 0, 2, and 3. Note that this
data is placed sequentially in one array, so you will one array with 6
positions in order to represent that.
int* Indices =3D new int[6];
// First triangle
Indices[0] =3D 0;
Indices[1] =3D 1;
Indices[2] =3D 3;
// Second triangle
Indices[0] =3D 0;
Indices[1] =3D 2;
Indices[2] =3D 3;
After that, you just have to call dGeomTriMeshDataCreate() to generate =
an ID
for yor trimesh data, and then call dGeomTriMeshDataBuildSimple, and =
finally
call dCreateTriMesh in order to get your timesh's dGeomID.
dTriMeshDataID Data =3D dGeomTriMeshDataCreate();
dGeomTriMeshDataBuildSimple(Data, Vertices, 4, Indices, 6);
dGeomID mGeomID =3D dCreateTriMesh(spaceID, Data, 0, 0, 0);
Hope that helps..!""
Foxy
------=_NextPart_000_000B_01C37561.8F6F9D40
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1226" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial>Hello/Salut,</FONT></DIV>
<DIV><FONT face=3DArial>I already asked for this question in the last =
mounth=20
:</FONT></DIV>
<DIV><FONT face=3DArial></FONT> </DIV>
<DIV><FONT face=3DArial></FONT> </DIV>
<DIV><FONT face=3DArial>William Mallouk said :</FONT><FONT =
face=3DArial><BR><FONT=20
size=3D2>"</FONT>I will try to explain how to do it, but first I will =
tell you=20
that<BR>there are two very good examples on how to do this on the =
\ode\test dir=20
of<BR>the ODE distribution. The files are test_trimesh.cpp=20
and<BR>test_moving_trimesh.cpp. You may want to take a look at them=20
later.<BR><BR>Basically, there are two steps you have to follow before=20
calling<BR>dGeomTriMeshDataBuildSimple.<BR><BR>First, you have to define =
what=20
are the vertices of your mesh by creating an<BR>array of dVector (each =
vector=20
represents one vertex).<BR><BR>In the example below, I am defining four=20
vertices.<BR><BR> dVector3* Vertices =3D new=20
dVector3[4];<BR> Vertices[0][0] =3D =
10;<BR> =20
Vertices[0][1] =3D 10;<BR> Vertices[0][2] =3D=20
10;<BR> Vertices[1][0] =3D -10;<BR> =20
Vertices[1][1] =3D -10;<BR> Vertices[1][2] =3D=20
-10;<BR> Vertices[2][0] =3D 10;<BR> =20
Vertices[2][1] =3D -10;<BR> Vertices[2][2] =3D=20
10;<BR> Vertices[3][0] =3D 0;<BR> =20
Vertices[3][1] =3D 0;<BR> Vertices[3][2] =3D =
0;<BR><BR>Second, you=20
have to define what vertices form the triangles (faces) of your<BR>mesh =
by=20
creating an array of int that will contain the indices of =
the<BR>vertices that=20
you have defined above.<BR><BR>The sample below has two triangles. One =
of them=20
if made of vertices 0, 1,<BR>and 3, and the other one is made of =
vertices 0, 2,=20
and 3. Note that this<BR>data is placed sequentially in one array, so =
you will=20
one array with 6<BR>positions in order to represent=20
that.<BR><BR> int* Indices =3D new =
int[6];<BR> =20
// First triangle<BR> Indices[0] =3D =
0;<BR> =20
Indices[1] =3D 1;<BR> Indices[2] =3D =
3;<BR> //=20
Second triangle<BR> Indices[0] =3D =
0;<BR> =20
Indices[1] =3D 2;<BR> Indices[2] =3D 3;<BR><BR>After =
that, you=20
just have to call dGeomTriMeshDataCreate() to generate an ID<BR>for yor =
trimesh=20
data, and then call dGeomTriMeshDataBuildSimple, and finally<BR>call=20
dCreateTriMesh in order to get your timesh's =
dGeomID.<BR><BR> =20
dTriMeshDataID Data =3D dGeomTriMeshDataCreate();<BR> =20
dGeomTriMeshDataBuildSimple(Data, Vertices, 4, Indices, =
6);<BR> =20
dGeomID mGeomID =3D dCreateTriMesh(spaceID, Data, 0, 0, 0);<BR><BR>Hope =
that=20
helps..!""<BR></FONT></DIV>
<DIV><FONT face=3DArial><FONT size=3D2></FONT></FONT> </DIV>
<DIV><FONT face=3DArial><FONT size=3D2>Foxy</FONT></DIV>
<DIV><BR><BR></DIV></FONT></BODY></HTML>
------=_NextPart_000_000B_01C37561.8F6F9D40--