home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 8090 / ModelEdit.7z / gl_modelrender.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-03-08  |  5.0 KB  |  203 lines

  1.  
  2. #ifndef __GL_MODELRENDER_H__
  3. #define __GL_MODELRENDER_H__
  4.  
  5. #include "model.h"
  6. #include "dtxmgr.h"
  7. #include "ltaModel.h"
  8. #include <GL/gl.h>
  9. #include <GL/glu.h>
  10.  
  11. typedef void* GLM_CONTEXT;
  12.  
  13. #define MAX_GLM_LIGHTS        8
  14. #define NUM_ANIM_INFOS        4    // Max number of animations that can be tracked at once.
  15.  
  16.  
  17. // ------------------------------------------------------------------------
  18. // GLMContext
  19. // current GL rendering context. 
  20. // ------------------------------------------------------------------------
  21. class GLMContext
  22. {
  23. public:
  24.     HWND    m_hWnd;
  25.     HDC        m_hDC;
  26.     HGLRC    m_hglrc;
  27.     CMoArray<GLuint> m_Textures;
  28.     GLuint m_nCurTexture;
  29.  
  30.     float m_bgColor[3]; // gl background clear color
  31.  
  32. } ;
  33.  
  34. // ------------------------------------------------------------------------
  35. // DrawStruct
  36. // Model-Scene parameters.
  37. // ------------------------------------------------------------------------
  38. struct DrawStruct
  39. {
  40.     
  41. public:
  42.     
  43.     BOOL        SetupTransformMaker(TransformMaker *pMaker);
  44.  
  45.     // Returns how many (consecutive) AnimTrackers in m_Times are valid.
  46.     DWORD        NumValidTimes();
  47.  
  48.  
  49. public:
  50.  
  51.     Model*        GetModel()    {return m_Times[0]->m_TimeRef.m_pModel;}
  52.  
  53.     // The exact place to draw from.
  54.     AnimTracker    *m_Times[NUM_ANIM_INFOS];
  55.     
  56.     DWORD    m_iLOD;
  57.     float    m_CurrentLODDist ;
  58.  
  59.     // VIEW PARAMS
  60.     float    m_FOV;
  61.     CVector    m_ViewerPos;
  62.     CVector    m_LookAt;
  63.  
  64.     
  65.     // LIGHT PARAMS
  66.     CVector    m_LightPositions[MAX_GLM_LIGHTS];
  67.     // RGB 0-255
  68.     CVector    m_LightColors[MAX_GLM_LIGHTS];
  69.     int        m_nLights;
  70.     
  71.  
  72.     BOOL    m_bDims;
  73.     CVector m_DimsColor;
  74.     CVector m_ModelBoxColor;
  75.     BOOL    m_bAnimBox;
  76.     CVector m_AnimBoxColor;
  77.     
  78.     // --------------------------------------
  79.     // DRAW FLAGS 
  80.     // --------------------------------------
  81.     BOOL    m_bWireframe;
  82.     BOOL    m_bNormals;
  83.     // Draw the model bright (without lighting).
  84.     BOOL    m_bDrawBright;
  85.     BOOL    m_bDrawVertexWeights ;
  86.  
  87.     // Draw the skeleton.
  88.     BOOL    m_bDrawSkeleton;
  89.     BOOL    m_bDrawOBB ;
  90.     // draw the original mesh
  91.     BOOL    m_bDrawOriginalModel;
  92.  
  93.     // draw the model using movement encoding
  94.     bool    m_bMovementEncoding;
  95.  
  96.     // show textures
  97.     BOOL    m_bDrawTextures;
  98.  
  99.     // Show sockets and/or attachments.
  100.     BOOL    m_bDrawSockets;
  101.     BOOL    m_bDrawAttachments;
  102.     BOOL    m_bSolidAttachments;
  103.     
  104.     // calculate the internal radius of the model while rendering
  105.     bool    m_bCalcRadius;
  106.     // filled in with the model radius if m_bCalcRadius is set
  107.     float    m_fModelRadius;
  108.     // if set this will cause it to calculate radius AND draw the animation
  109.     bool    m_bCalcAndDraw;
  110.  
  111.     // Show profile info.
  112.     BOOL    m_bProfile;
  113.  
  114.     BOOL    m_bShowNormalRef;
  115.  
  116.     BYTE    *m_SelectedPieces; // Should be as big as Model::NumPieces().
  117.     BYTE    *m_SelectedNodes; // Should be as big as Model::NumNodes().
  118.     
  119.     
  120. };
  121.  
  122.                            
  123. // Represents a transformed vertex.
  124. class TVert
  125. {
  126. public:
  127.     inline TVert&    operator=(TVert other)
  128.     {
  129.         m_vPos = other.m_vPos;
  130.         m_vNormal = other.m_vNormal;
  131.         m_vColor = other.m_vColor ;
  132.         return *this;
  133.     }
  134.     
  135.     LTVector        m_vPos;
  136.     LTVector        m_vNormal;
  137.     float            m_UV[2];
  138.     LTVector        m_vColor ;
  139. };
  140.  
  141. // ------------------------------------------------------------------------
  142. // Free Floatting functions 
  143. // ------------------------------------------------------------------------
  144.  
  145. // Init and term.
  146. // Note: your window must have WS_CLIPCHILDREN and WS_CLIPSIBLINGS set.
  147. GLM_CONTEXT CreateGLMContext(void *hWnd);
  148. void DeleteGLMContext(GLM_CONTEXT hContext);
  149.  
  150. // The drawing function.
  151. // Draws the model centered at the origin.
  152. // pEyePoint is the position of the viewer.
  153. // pLookAt is where it looks at (it should probably be (0,0,0)).
  154. void DrawModel(GLM_CONTEXT hContext, DrawStruct *pStruct);
  155.  
  156. // ------------------------------------------------------------------------
  157. // DrawMetaModel test the raw lta file
  158. void DrawMetaModel( GLM_CONTEXT, DrawStruct * );
  159.  
  160.  
  161. void DrawCoordSys(DMatrix *pMat, float arrowLength);
  162. void DrawWorldCoordSys();
  163.  
  164. // ------------------------------------------------------------------------
  165. // setup viewing parameters, sets up lookat, lights, wireframe params etc
  166. // for gl
  167. void SetupViewingParameters( GLMContext *pContext, DrawStruct *);
  168.  
  169. // ------------------------------------------------------------------------
  170. // Set the texture to draw with.
  171. BOOL SetGLMTexture(GLM_CONTEXT hContext, TextureData *pTexture, DWORD nTextureNum = 0);
  172. // get rid of animated textures.
  173. void ReleaseAllTextures( GLM_CONTEXT hContext );
  174.  
  175. // set the background color for the gl-window.
  176. void SetGLMBackgroundColor( GLM_CONTEXT , COLORREF );
  177. void SetGLMBackgroundColor( GLM_CONTEXT hContext, float *color );
  178.  
  179. /* The coordinate system this uses...
  180.  
  181.                  +y
  182.                       -z
  183.                  ^     /
  184.                  |    /
  185.                  | /
  186.                  |/
  187.     -x ----------|----------> +x
  188.                 /|
  189.                / |
  190.               +z |
  191. */
  192.  
  193. // updates the draw-buffer vertex and animation .
  194. BOOL AlternateGetVertexPositions(    Model *pModel,
  195.                                      GVPStruct *pStruct, 
  196.                                     BOOL bSetupTransforms,
  197.                                     BOOL bNormals,
  198.                                     BOOL bDrawOriginalModel,
  199.                                     BOOL bMovementEncoding,
  200.                                     void **pNextVert = NULL );
  201.  
  202. #endif  // __GL_MODELRENDER_H__
  203.