11 #if !defined(__GLU_H__) 15 #elif defined(__MACH__) 16 #include <OpenGL/glu.h> 37 gluDeleteQuadric( s_pQuadric );
42 operator GLUquadric* ()
46 s_pQuadric = gluNewQuadric();
59 void drawGrid(
ePlane plane,
unsigned int horizSubdivs,
unsigned int vertSubdivs )
61 const float fHalfGridSize = 0.5f;
62 const float fHGridStep = (fHalfGridSize + fHalfGridSize)/static_cast<float>(
Max(horizSubdivs, 1u));
63 const float fVGridStep = (fHalfGridSize + fHalfGridSize)/static_cast<float>(
Max(vertSubdivs, 1u));
64 const float fHEndStep = fHalfGridSize + fHGridStep;
65 const float fVEndStep = fHalfGridSize + fVGridStep;
69 glDisable(GL_LIGHTING);
76 for (
float x = -fHalfGridSize;
x < fHEndStep;
x += fHGridStep )
78 glVertex3f(
x, -fHalfGridSize, 0 );
79 glVertex3f(
x, fHalfGridSize, 0 );
82 for (
float y = -fHalfGridSize;
y < fVEndStep;
y += fVGridStep )
84 glVertex3f( -fHalfGridSize,
y, 0 );
85 glVertex3f( fHalfGridSize,
y, 0 );
90 for (
float y = -fHalfGridSize;
y < fHEndStep;
y += fHGridStep )
92 glVertex3f( 0,
y, -fHalfGridSize );
93 glVertex3f( 0,
y, fHalfGridSize );
96 for (
float z = -fHalfGridSize;
z < fVEndStep;
z += fVGridStep )
98 glVertex3f( 0, -fHalfGridSize,
z );
99 glVertex3f( 0, fHalfGridSize,
z );
104 for (
float z = -fHalfGridSize;
z < fHEndStep;
z += fHGridStep )
106 glVertex3f( -fHalfGridSize, 0,
z );
107 glVertex3f( fHalfGridSize, 0,
z );
110 for (
float x = -fHalfGridSize;
x < fVEndStep;
x += fVGridStep )
112 glVertex3f(
x, 0, -fHalfGridSize );
113 glVertex3f(
x, 0, fHalfGridSize );
126 gluQuadricDrawStyle(s_quadric, GLU_SILHOUETTE);
127 glPushAttrib( GL_LIGHTING_BIT );
128 glDisable(GL_LIGHTING);
132 gluQuadricDrawStyle(s_quadric, GLU_FILL);
136 gluSphere( s_quadric, 1.0, 32, 32 );
154 glPushAttrib( GL_LIGHTING_BIT );
155 glDisable(GL_LIGHTING);
168 glRotatef( 90.0
f, 0, 1, 0 );
172 glRotatef( -90.0
f, 1, 0, 0 );
176 const float kfHalfSize = 0.5f;
179 glNormal3f( 0, 0, 1 );
180 glTexCoord2f( 0, 0 );
181 glVertex3f( -kfHalfSize, -kfHalfSize, 0 );
182 glTexCoord2f( 1, 0 );
183 glVertex3f( kfHalfSize, -kfHalfSize, 0 );
184 glTexCoord2f( 1, 1 );
185 glVertex3f( kfHalfSize, kfHalfSize, 0 );
189 glTexCoord2f( 1, 1 );
190 glVertex3f( kfHalfSize, kfHalfSize, 0 );
191 glTexCoord2f( 0, 1 );
192 glVertex3f( -kfHalfSize, kfHalfSize, 0 );
193 glTexCoord2f( 0, 0 );
194 glVertex3f( -kfHalfSize, -kfHalfSize, 0 );
198 glNormal3f( 0, 0, -1 );
199 glTexCoord2f( 0, 0 );
200 glVertex3f( kfHalfSize, -kfHalfSize, 0 );
201 glTexCoord2f( 1, 0 );
202 glVertex3f( -kfHalfSize, -kfHalfSize, 0 );
203 glTexCoord2f( 1, 1 );
204 glVertex3f( -kfHalfSize, kfHalfSize, 0 );
208 glTexCoord2f( 1, 1 );
209 glVertex3f( -kfHalfSize, kfHalfSize, 0 );
210 glTexCoord2f( 0, 1 );
211 glVertex3f( kfHalfSize, kfHalfSize, 0 );
212 glTexCoord2f( 0, 0 );
213 glVertex3f( kfHalfSize, -kfHalfSize, 0 );
239 static const float s_afCorners[8][3] = {
241 {-0.5f, -0.5f, 0.5f},
242 { 0.5f, -0.5f, 0.5f},
247 { 0.5f, -0.5f, -0.5f},
248 {-0.5f, -0.5f, -0.5f},
249 {-0.5f, 0.5f, -0.5f},
250 { 0.5f, 0.5f, -0.5f},
257 glPushAttrib( GL_LIGHTING_BIT );
258 glDisable(GL_LIGHTING);
265 glBegin( style ==
kStyle_Solid ? GL_TRIANGLES : GL_LINE_LOOP );
268 glNormal3f( 0, 0, 1 );
269 glVertex3fv( s_afCorners[0] );
270 glVertex3fv( s_afCorners[1] );
271 glVertex3fv( s_afCorners[2] );
274 glBegin( style ==
kStyle_Solid ? GL_TRIANGLES : GL_LINE_LOOP );
276 glVertex3fv( s_afCorners[2] );
277 glVertex3fv( s_afCorners[3] );
278 glVertex3fv( s_afCorners[0] );
281 glBegin( style ==
kStyle_Solid ? GL_TRIANGLES : GL_LINE_LOOP );
284 glNormal3f( 0, 0, -1 );
285 glVertex3fv( s_afCorners[4] );
286 glVertex3fv( s_afCorners[5] );
287 glVertex3fv( s_afCorners[6] );
290 glBegin( style ==
kStyle_Solid ? GL_TRIANGLES : GL_LINE_LOOP );
292 glVertex3fv( s_afCorners[6] );
293 glVertex3fv( s_afCorners[7] );
294 glVertex3fv( s_afCorners[4] );
298 glBegin( style ==
kStyle_Solid ? GL_TRIANGLES : GL_LINE_LOOP );
301 glNormal3f( 1, 0, 0 );
302 glVertex3fv( s_afCorners[1] );
303 glVertex3fv( s_afCorners[4] );
304 glVertex3fv( s_afCorners[7] );
307 glBegin( style ==
kStyle_Solid ? GL_TRIANGLES : GL_LINE_LOOP );
309 glVertex3fv( s_afCorners[7] );
310 glVertex3fv( s_afCorners[2] );
311 glVertex3fv( s_afCorners[1] );
314 glBegin( style ==
kStyle_Solid ? GL_TRIANGLES : GL_LINE_LOOP );
317 glNormal3f( -1, 0, 0 );
318 glVertex3fv( s_afCorners[5] );
319 glVertex3fv( s_afCorners[0] );
320 glVertex3fv( s_afCorners[3] );
323 glBegin( style ==
kStyle_Solid ? GL_TRIANGLES : GL_LINE_LOOP );
325 glVertex3fv( s_afCorners[3] );
326 glVertex3fv( s_afCorners[6] );
327 glVertex3fv( s_afCorners[5] );
331 glBegin( style ==
kStyle_Solid ? GL_TRIANGLES : GL_LINE_LOOP );
334 glNormal3f( 0, -1, 0 );
335 glVertex3fv( s_afCorners[0] );
336 glVertex3fv( s_afCorners[5] );
337 glVertex3fv( s_afCorners[4] );
340 glBegin( style ==
kStyle_Solid ? GL_TRIANGLES : GL_LINE_LOOP );
342 glVertex3fv( s_afCorners[4] );
343 glVertex3fv( s_afCorners[1] );
344 glVertex3fv( s_afCorners[0] );
347 glBegin( style ==
kStyle_Solid ? GL_TRIANGLES : GL_LINE_LOOP );
350 glNormal3f( 0, 1, 0 );
351 glVertex3fv( s_afCorners[3] );
352 glVertex3fv( s_afCorners[2] );
353 glVertex3fv( s_afCorners[7] );
356 glBegin( style ==
kStyle_Solid ? GL_TRIANGLES : GL_LINE_LOOP );
358 glVertex3fv( s_afCorners[7] );
359 glVertex3fv( s_afCorners[6] );
360 glVertex3fv( s_afCorners[3] );
382 gluQuadricDrawStyle(s_quadric, GLU_SILHOUETTE);
383 glPushAttrib( GL_LIGHTING_BIT );
384 glDisable(GL_LIGHTING);
388 gluQuadricDrawStyle(s_quadric, GLU_FILL);
395 glRotatef( 90.0
f, 0, 1, 0 );
398 glRotatef( 90.0
f, 1, 0, 0 );
409 glTranslatef( 0, 0, 0.5
f );
412 glTranslatef( 0, 0, -1.0
f );
416 glTranslatef( 0, 0, -0.5
f );
418 gluCylinder( s_quadric, 0.5
f, 0.5
f, 1.0
f, 32, 32 );
438 gluQuadricDrawStyle(s_quadric, GLU_SILHOUETTE);
439 glPushAttrib( GL_LIGHTING_BIT );
440 glDisable(GL_LIGHTING);
444 gluQuadricDrawStyle(s_quadric, GLU_FILL);
453 glRotatef( 90.0
f, 0, 1, 0 );
456 glRotatef( -90.0
f, 1, 0, 0 );
460 gluDisk(s_quadric, 0, 0.5
f, 32, 1);
461 glRotatef( 180.0
f, 0, 1, 0 );
462 gluDisk(s_quadric, 0, 0.5
f, 32, 1);
482 glVertex3f( 0, 0, 0 );
483 glVertex3f( 1, 0, 0 );
485 glVertex3f( 1, 0, 0 );
486 glVertex3f( 0.8
f, 0.2
f, 0 );
488 glVertex3f( 1, 0, 0 );
489 glVertex3f( 0.8
f, -0.2
f, 0 );
493 glVertex3f( 0, 0, 0 );
494 glVertex3f( 0, 1, 0 );
496 glVertex3f( 0, 1, 0 );
497 glVertex3f( 0, 0.8
f, 0.2
f );
499 glVertex3f( 0, 1, 0 );
500 glVertex3f( 0, 0.8
f, -0.2
f );
504 glVertex3f( 0, 0, 0 );
505 glVertex3f( 0, 0, 1 );
507 glVertex3f( 0, 0, 1 );
508 glVertex3f( 0.2
f, 0, 0.8
f );
510 glVertex3f( 0, 0, 1 );
511 glVertex3f( -0.2
f, 0, 0.8
f );
521 GLAttribScope attribScope(GL_CURRENT_BIT | GL_LIGHTING_BIT | GL_DEPTH_BUFFER_BIT);
523 glDisable(GL_LIGHTING);
524 glDisable(GL_DEPTH_TEST);
541 glTranslatef(vCenter.
x, vCenter.
y, vCenter.
z);
542 glScalef(fRadius, fRadius, fRadius);
551 Vector vCenter = (vBottom + vTop) * 0.5
f;
558 glTranslatef(vCenter.
x, vCenter.
y, vCenter.
z);
559 glRotatef(fRotAngle *
RAD_TO_DEG, vRotAxis.
x, vRotAxis.
y, vRotAxis.
z);
560 glScalef(fRadius, fRadius, fHeight);
567 static const float kfJointRadiusScale = 0.75f;
568 static const float kfBoneRadiusScale = 0.5f;
569 static const float kfPalmRadiusScale = 1.15f;
579 const Vector vWrist = vPalm - fThumbDist*(vPalmDir*0.90f + (hand.
isLeft() ? -1.0f : 1.0f)*vPalmSide*0.38
f);
583 float fRadius = 0.0f;
585 Vector vLastBoxBase = vWrist;
587 for (
int i = 0, ei = fingers.
count(); i < ei; i++) {
588 const Finger& finger = fingers[i];
589 fRadius = finger.
width() * 0.5f;
593 const Bone& bone = finger.
bone(static_cast<Bone::Type>(j));
600 glColor4fv(vBoneColor);
602 glColor4fv(vJointColor);
608 glColor4fv(vBoneColor);
610 glColor4fv(vJointColor);
612 vLastBoxBase = vCurBoxBase;
617 vCurBoxBase = vWrist;
618 glColor4fv(vBoneColor);
620 glColor4fv(vJointColor);
624 glColor4fv(vJointColor);
633 gluPerspective( GetVerticalFOVDegrees(), GetAspectRatio(), GetNearClip(), GetFarClip() );
639 glMultMatrixf( GetView().toArray4x4() );
void drawCylinder(eStyle style, eAxis axis)
void drawSkeletonHand(const Leap::Hand &hand, const GLVector4fv &vBoneColor, const GLVector4fv &vJointColor)
utility for drawing a skeleton API hand as seen in diagnostic visualizer
LEAP_EXPORT Vector palmNormal() const
Vector cross(const Vector &other) const
LEAP_EXPORT Vector prevJoint() const
void drawGrid(ePlane plane, unsigned int horizSubdivs, unsigned int vertSubdivs)
grid is drawn with unlit colored lines.
void drawSphere(eStyle style)
LEAP_EXPORT Vector nextJoint() const
static GLUquadric * s_pQuadric
TFSIMD_FORCE_INLINE const tfScalar & y() const
void drawBox(eStyle style)
static const Vector & zAxis()
TFSIMD_FORCE_INLINE Vector3 normalized() const
utility class for caching and restoring GL attributes via the glPushAttrib/glPopAttrib calls...
static const float RAD_TO_DEG
LEAP_EXPORT Vector palmPosition() const
LEAP_EXPORT Bone bone(Bone::Type boneIx) const
void drawDisk(eStyle style, ePlane plane)
disk is double-side
TFSIMD_FORCE_INLINE const tfScalar & x() const
float angleTo(const Vector &other) const
void drawArrow(eAxis axis)
arrow is drawn with unlit colored lines.
TFSIMD_FORCE_INLINE const tfScalar & z() const
LEAP_EXPORT bool isLeft() const
LEAP_EXPORT int count() const
float distanceTo(const Vector &other) const
void drawQuad(eStyle style, ePlane plane)
quad is double-sided.
utility class for keeping the gl matrix stack push/pop operations paired up correctly.
void SetupGLProjection() const