LeapUtilGL.h
Go to the documentation of this file.
00001 /******************************************************************************\
00002 * Copyright (C) Leap Motion, Inc. 2011-2013.                                   *
00003 * Leap Motion proprietary and  confidential.  Not for distribution.            *
00004 * Use subject to the terms of the Leap Motion SDK Agreement available at       *
00005 * https://developer.leapmotion.com/sdk_agreement, or another agreement between *
00006 * Leap Motion and you, your company or other organization.                     *
00007 \******************************************************************************/
00008 
00009 #ifndef __LeapUtilGL_h__
00010 #define __LeapUtilGL_h__
00011 
00012 #if !defined(__GL_H__)
00013   #if defined(WIN32)
00014     #include <windows.h>
00015     #include <GL/gl.h>
00016   #elif defined(__MACH__)
00017     #include <OpenGL/gl.h>
00018   #else
00019     #include <GL/gl.h>
00020   #endif
00021 #endif // !__GL_H__
00022 
00023 #include "LeapUtil.h"
00024 
00025 namespace LeapUtilGL {
00026 
00031 
00032 enum eAxis { kAxis_X, kAxis_Y, kAxis_Z };
00033 
00034 enum ePlane { kPlane_XY, kPlane_YZ, kPlane_ZX };
00035 
00036 enum eStyle { kStyle_Outline, kStyle_Solid };
00037 
00039 void drawGrid( ePlane plane, unsigned int horizSubDivs, unsigned int vertSubDivs );
00040 
00041 void drawSphere( eStyle style );
00042 
00044 void drawQuad( eStyle style, ePlane plane );
00045 
00046 void drawBox( eStyle style );
00047 
00048 void drawCylinder( eStyle style, eAxis axis );
00049 
00051 void drawDisk( eStyle style, ePlane plane );
00052 
00054 void drawArrow( eAxis axis );
00055 
00056 void drawAxes();
00057 
00061 struct GLVector4fv
00062 {
00063   GLVector4fv() : x(0), y(0), z(0), w(0) {}
00064   GLVector4fv( float _x, float _y, float _z, float _w=1.0f ) : x(_x), y(_y), z(_z), w(_w) {}
00065   GLVector4fv( const Leap::Vector& vRHS, float _w=1.0f ) : x(vRHS.x), y(vRHS.y), z(vRHS.z), w(_w) {}
00066   static const GLVector4fv& One() { static const GLVector4fv s_one(1.0f, 1.0f, 1.0f, 1.0f); return s_one; }
00067   operator const GLfloat*() const { return &x; }
00068 
00069   GLfloat x, y, z, w;
00070 };
00071 
00073 void drawSphere(eStyle style, const Leap::Vector& vCenter, float fRadius);
00074 
00075 void drawCylinder(eStyle style, const Leap::Vector& vBottom, const Leap::Vector& vTop, float fRadius);
00076 
00078 void drawSkeletonHand(const Leap::Hand& hand, const GLVector4fv& vBoneColor = GLVector4fv::One(), const GLVector4fv& vJointColor = GLVector4fv::One());
00079 
00081 class GLMatrixScope
00082 {
00083 public:
00084   GLMatrixScope() { glPushMatrix(); }
00085   ~GLMatrixScope() { glPopMatrix(); }
00086 
00087 private:
00088   // some compilers don't like zero sized objects.
00089   int m_dummy;
00090 };
00091 
00093 class GLAttribScope
00094 {
00095 public:
00096   GLAttribScope( GLbitfield flags )
00097   {
00098     glPushAttrib( flags );
00099   }
00100 
00101   ~GLAttribScope()
00102   {
00103     glPopAttrib();
00104   }
00105 
00106 private:
00107   // some compilers don't like zero sized objects.
00108   int m_dummy;
00109 };
00110 
00111 class CameraGL : public LeapUtil::Camera
00112 {
00113 public:
00114   CameraGL() {}
00115 
00116   static void ResetGLProjection()
00117   {
00118     glMatrixMode( GL_PROJECTION );
00119     glLoadIdentity();
00120   }
00121 
00122   static void ResetGLView()
00123   {
00124     glMatrixMode( GL_MODELVIEW );
00125     glLoadIdentity();
00126   }
00127 
00128   void SetupGLProjection() const;
00129 
00130   void SetupGLView() const;
00131 };
00132 
00133 }
00134 
00135 #endif // __LeapUtilGL_h__


leap_motion
Author(s): Florian Lier , Mirza Shah , Isaac IY Saito
autogenerated on Sat Jun 8 2019 18:47:25