TAPs 0.7.7.3
TAPsOpenGLUsefulObjs.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsOpenGLUsefulObjs.hpp
00003 
00004 Useful Objects drawed by OpenGL
00005 
00006 SUKITTI PUNAK   (07/10/2005)
00007 UPDATE          (11/28/2006)
00008 ******************************************************************************/
00009 #ifndef TAPs_OPENGL_USEFUL_OBJS_HPP
00010 #define TAPs_OPENGL_USEFUL_OBJS_HPP
00011 
00012 #include "TAPsOpenGLFns.hpp"
00013 
00014 //===================================================================
00015 // External OpenGL Model(s)
00016 //-------------------------------------------------------------------
00017 #include "TAPsOpenGLLightModel.hpp"     // OpenGL Light  Model
00018 #include "TAPsOpenGLCameraModel.hpp"    // OpenGL Camera Model
00019 //-------------------------------------------------------------------
00020 //===================================================================
00021 
00022 BEGIN_NAMESPACE_TAPs__OpenGL
00023 //=============================================================================
00024 template <typename T>
00025 class OpenGLUsefulObj {
00026 //-----------------------------------------------------------------------------
00027 public:
00028     //---------------------------------------------------------------
00032     //OpenGLUsefulObj ();
00033     OpenGLUsefulObj (
00034         GLenum drawStyle, 
00035         GLint iNumSlices, 
00036         GLint iNumStacks, 
00037         Vector4<T> & vMaterialColor 
00038     );
00039     OpenGLUsefulObj (
00040         GLenum drawStyle = GLU_FILL, 
00041         GLint iNumSlices = 8, 
00042         GLint iNumStacks = 8, 
00043         GLfloat r = 0.5f, 
00044         GLfloat g = 0.5f, 
00045         GLfloat b = 0.5f, 
00046         GLfloat a = 1.0f 
00047     );
00048     //---------------------------------------------------------------
00052     inline void GenDisplayList ( 
00053         GLenum drawStyle, 
00054         GLint iNumSlices, 
00055         GLint iNumStacks, 
00056         Vector4<T> & vMaterialColor 
00057     );
00058     //---------------------------------------------------------------
00062     void GenDisplayList ( 
00063         GLenum drawStyle = GLU_FILL, 
00064         GLint iNumSlices = 15, 
00065         GLint iNumStacks = 15, 
00066         GLfloat r = 0.5f, 
00067         GLfloat g = 0.5f, 
00068         GLfloat b = 0.5f, 
00069         GLfloat a = 1.0f 
00070     );
00071     //=========================================================================
00072     // Sphere
00073     void DrawSphere ();
00074     //-------------------------------------------------------------------------
00078     void DrawSphere ( T scale );             // x, y, z have the same scale
00079     void DrawSphere ( T sx, T sy, T sz );    // individual scale
00080     void DrawSphere ( Vector3<T> & vScale ); // individual scale
00081     //-------------------------------------------------------------------------
00082     //=========================================================================
00083     // Cylinder
00084     //-------------------------------------------------------------------------
00090     void DrawCylinder ();
00094     void DrawCylinder ( Vector3<T> & vDirection );
00098     void DrawCylinder ( Vector3<T> & vDirection, Vector3<T> & vScale );
00099     //-------------------------------------------------------------------------
00100     //=========================================================================
00101     // Cone
00102     //-------------------------------------------------------------------------
00108     void DrawCone ();
00112     void DrawCone ( Vector3<T> & vDirection );
00116     void DrawCone ( Vector3<T> & vDirection, Vector3<T> & vScale );
00117     //-------------------------------------------------------------------------
00118     //=========================================================================
00119     // Cube
00120     //-------------------------------------------------------------------------
00124     void DrawCube ();
00128     void DrawCube ( Vector3<T> & vScale );
00132     //void DrawCube ( Vector3<T> & vDirection );
00136     void DrawCube ( Vector3<T> & vDirection, Vector3<T> & vScale );
00137     //-------------------------------------------------------------------------
00138     //=========================================================================
00142     //-------------------------------------------------------------------------
00153     static void DrawOneHeadArrow ();
00154     /*
00155      * Use DrawOneHeadArrow to draw a head-arrow with the given direction
00156      * with scaled by the length.
00157      */
00158     static void DrawOneHeadArrow ( const Vector3<T> & direction, T length = 1 );
00163     static void DrawOneHeadArrow ( const Vector3<T> & startPos, 
00164                                    const Vector3<T> & endPos );
00165     //-------------------------------------------------------------------------
00166     //=========================================================================
00170     static void DrawWorldCoordinateAxes ();
00171     //-------------------------------------------------------------------------
00172     //=========================================================================
00173     // Get/Set Functions
00174     //-------------------------------------------------------------------------
00175     Vector4<T> & GetColor () const
00176     { return Vector4<T>( 
00177         m_afMaterialColor[0], 
00178         m_afMaterialColor[1], 
00179         m_afMaterialColor[2], 
00180         m_afMaterialColor[3] );
00181     }
00182     void SetColor( Vector4<T> & vColor )
00183     {
00184         m_afMaterialColor[0] = vColor[0];
00185         m_afMaterialColor[1] = vColor[1];
00186         m_afMaterialColor[2] = vColor[2];
00187         m_afMaterialColor[3] = vColor[3];
00188     }
00189     void SetColor( GLfloat r, GLfloat g, GLfloat b, GLfloat a = 1.0f )
00190     {
00191         m_afMaterialColor[0] = r;
00192         m_afMaterialColor[1] = g;
00193         m_afMaterialColor[2] = b;
00194         m_afMaterialColor[3] = a;
00195     }
00196     //-------------------------------------------------------------------------
00197     //=========================================================================
00198     //-------------------------------------------------------------------------
00199 protected:
00200     // Helper functions for drawing sphere, cylinder, and cone.
00201     inline void DrawCallListNo ( int i );
00202     inline void DrawCallListNo ( int i, Vector3<T> & vDirection );
00203     inline void DrawCallListNo ( int i, 
00204         Vector3<T> & vDirection, Vector3<T> & vScale );
00205     //-------------------------------------------------------------------------
00206 //-----------------------------------------------------------------------------
00207 protected:
00208     //-------------------------------------------------------------------------
00209     // Data Members
00210     static GLUquadricObj *  g_pQuadricObj;  // a pointer to a glu quardric object
00211     GLuint      m_uiDisplayList;            // display list of objects
00212     GLsizei     m_iDisplayListSize;         // display list size
00213     GLfloat     m_afMaterialColor[4];       // material color
00214     // m_uiDisplayList + 00 --> Unit Sphere   (radius is one)
00215     // m_uiDisplayList + 01 --> Unit Cylinder (radius and height is one from z=0 to z=1)
00216     // m_uiDisplayList + 02 --> Unit Cone     (base radius and height is one from z=0 to z=1)
00217     // m_uiDisplayList + 03 --> Unit Cube     (a unit cube centered at (0,0,0))
00218     //-------------------------------------------------------------------------
00219 };  // END CLASS OpenGLUsefulObj
00220 
00221 //=============================================================================
00222 END_NAMESPACE_TAPs__OpenGL
00223 //-----------------------------------------------------------------------------
00224 // Include definition if TAPs_USE_EXPORT is not defined
00225 //#if !defined( TAPs_USE_EXPORT )
00226     #include "TAPsOpenGLUsefulObjs.cpp"
00227 //#endif
00228 //-----------------------------------------------------------------------------
00229 #endif
00230 //34567890123456789012345678901234567890123456789012345678901234567890123456789
00231 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines