[ODE] Drawstuff addon
Erwin de Vries
erwin at vo.com
Sun Aug 11 11:07:01 2002
This is a multi-part message in MIME format.
------=_NextPart_000_0033_01C24172.88DC95B0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Could this be added to CVS?
Its for drawing triangles. An upcoming Tricollider test uses it to draw a
bunny. ;-)
------=_NextPart_000_0033_01C24172.88DC95B0
Content-Type: application/octet-stream;
name="DS.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="DS.patch"
Index: drawstuff/src/drawstuff.cpp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/ode/drawstuff/src/drawstuff.cpp,v
retrieving revision 1.21
diff -u -r1.21 drawstuff.cpp
--- drawstuff/src/drawstuff.cpp 2002/07/31 03:11:09 1.21
+++ drawstuff/src/drawstuff.cpp 2002/08/11 18:03:55
@@ -523,6 +523,44 @@
glEnd();
}
=20
+#define dCROSS(a,op,b,c) \
+ (a)[0] op ((b)[1]*(c)[2] - (b)[2]*(c)[1]); \
+ (a)[1] op ((b)[2]*(c)[0] - (b)[0]*(c)[2]); \
+ (a)[2] op ((b)[0]*(c)[1] - (b)[1]*(c)[0]);
+
+inline float dDOT (const float *a, const float *b)
+ { return ((a)[0]*(b)[0] + (a)[1]*(b)[1] + (a)[2]*(b)[2]); }
+
+static void drawTriangle(const float* v0, const float* v1, const float* =
v2)
+{
+ float u[4];
+ u[0] =3D v1[0] - v0[0];
+ u[1] =3D v1[1] - v0[1];
+ u[2] =3D v1[2] - v0[2];
+ u[3] =3D v1[3] - v0[3];
+
+ float v[4];
+ v[0] =3D v2[0] - v0[0];
+ v[1] =3D v2[1] - v0[1];
+ v[2] =3D v2[2] - v0[2];
+ v[3] =3D v2[3] - v0[3];
+
+ float Normal[4];
+ dCROSS(Normal, =3D, u, v);
+ float Mag =3D sqrtf(dDOT(Normal, Normal));
+ Normal[0] /=3D Mag;
+ Normal[1] /=3D Mag;
+ Normal[2] /=3D Mag;
+ Normal[3] /=3D Mag;
+
+ glBegin(GL_TRIANGLES);
+ glNormal3fv(Normal);
+ glVertex3fv(v0);
+ glVertex3fv(v1);
+ glVertex3fv(v2);
+ glEnd();
+}
+
=20
// draw a capped cylinder of length l and radius r, aligned along the x =
axis
=20
@@ -1242,6 +1280,16 @@
drawSphereShadow (pos[0],pos[1],pos[2],radius);
glDepthRange (0,1);
}
+}
+
+extern "C" void dsDrawTriangle(const float pos[3], const float R[12], =
const float* v0, const float* v1, const float* v2)
+{
+ if (current_state !=3D 2) dsError ("drawing function called outside =
simulation loop");
+ setupDrawingMode();
+ glShadeModel (GL_FLAT);
+ setTransform (pos,R);
+ drawTriangle (v0, v1, v2);
+ glPopMatrix();
}
=20
=20
------=_NextPart_000_0033_01C24172.88DC95B0--