xFile_Render.h

00001 #ifndef _XFILE_RENDER_H
00002 #define _XFILE_RENDER_H
00003 
00004 #include <stdio.h>
00005 #include "pipeline.h"
00006 #include "ps2matrix4x4.h"
00007 #include "xFile_Loader.h"
00008 
00009 #include "texture.h"
00010 
00011 using namespace std;
00012 
00013 struct Subset;
00014 struct SubsetMesh;
00015 struct mappedTexture;
00016 
00017 
00028 class xFile_Render
00029 {
00030 
00031         public:
00032                 
00033                 xFile_Render();                                                                                         // Default no-args constructor.
00034                 virtual ~xFile_Render();                                                                        // Default destructor.
00035 
00036                 void render(DWORD time = 0);                                                            // Draws the XFile to the screen at its current transformation.
00037                 bool load(LPCSTR fileName,bool verboseOutput = true);           // Loads the specified XFile.
00038                 void setGlobalPose(const Matrix4x4&  newPose);                          // Sets the current world  pose of the entire XFile.
00039 
00040                 void setAnimation(LPCSTR animationSetName = NULL);                      // Sets the current AnimationSet of the XFile (used to switch between animations).
00041                 
00042                 xFile_Loader m_XFile;                                                                           
00043 
00044         protected:
00045 
00046                 bool initialise();                                                                                      // Initialises object instance memory.
00047                 bool cleanUp();                                                                                         // Cleans up all memory used by this Object instance.
00048                 bool reset();                                                                                           // Resets all memory used by Object instance (cleanUp then Initialise).
00049 
00050                 AnimationSet* getAnimationSet(LPCSTR animationSetName);         // Searches for an AnimationSet with the name specified and returns a reference to the first animationSet found if any, otherwise returns NULL.
00051                 
00052                 void updateAnimation(DWORD time = 0, bool Loop = true);         // Recursively updates the frame hierarchy of the XFile. 
00053                 void update(Frame* parent);                                                                     // Recursively updates the frame hierarchy of the XFile (call before rendering if a change has been made).
00054 
00055                 bool createSubsets();                                                                           // Creates SubsetMeshes from the meshes in the XFile (splits the meshes into subsets / arranges triangles by material).
00056                 bool cleanSubsets();                                                                            // Cleans up all memory associated with the subsets.
00057                 bool loadTextures();                                                                            // Loads the textures specified by filename in the XFile into PS2 Specific Textures in memory.
00058                 bool cleanTextures();                                                                           // Cleans up all memory associated with Textures.
00059         
00060                 int getTextureIndex(Material* material);                                        // Searches through the textures Array and returns the index of any texture which matches the FIRST specified in the material instance passed into the parameter.
00061 
00062                 int AddSubsetToDMA(Subset* pSubset,bool bTransparent);          // Unpacks and adds a subset of a mesh to static memory, returning its address.
00063                 
00064                 void drawMesh(int subsetMeshIndex);                                                     // Draws all subsets of the mesh specified by its SubsetMeshes index.
00065 
00066                 void SetWorldMatrix(const Matrix4x4 & matWorld);                        // Allows the world matrix to be set.
00067                 void SetWVPMatrix(const Matrix4x4 & matWVP);                            // Allows the WorldViewProjection matrix to be set.
00068 
00069 
00070                 UINT numTextures;                                                                                       
00071                 mappedTexture** textures;                                                                       
00072 
00073                 UINT numSubsetMeshes;                                                                           
00074                 SubsetMesh** subsetMeshes;                                                                      
00075 
00076                 AnimationSet* setAnimationSet;                                                          // Stores a pointer to the currently set Animation.
00077                 
00078                 // The world and WorldViewProjection Matrices
00079                 Matrix4x4 m_World, m_WVP;                                                                       // Stores the World & WorldViewProjection matrix.
00080                 bool m_bWorldLoaded;                                                                            // Stores true if the world matrix has been loaded this frame, otherwise stores false.
00081 
00082                 bool changed;                                                                                           
00083                 bool verbose;                                                                                           
00084                 bool isAnimated;                                                                                        
00085                 bool loaded;                                                                                            
00086 
00087                 Matrix4x4 matDiff;                                                                                      
00088                 int previousKey;                                                                                        
00089 
00090                 
00091 
00092 };
00093 
00094 
00105 struct Subset
00106 {
00107 public:
00108         Subset()
00109         {
00110                 pMesh = NULL;
00111                 pMaterial = NULL;
00112                 DMAAddress = 0;
00113                 TextureIndex = -1;      // no Texture index =  -1.
00114         }
00115         ~Subset()
00116         {
00117                 pMesh = NULL;           // not responsible for deleting the mesh.
00118                 pMaterial = NULL;       // not responsible for deleting the material.
00119                 TextureIndex = -1;      // no Texture index =  -1.
00120                 DMAAddress = 0;
00121                 // Clear all face indices.
00122                 for(unsigned int i = 0; i < faces.size(); i ++)
00123                 {
00124                         faces[i] = 0;
00125                 }
00126                 faces.empty();
00127         }
00128 
00129         SubsetMesh* pMesh;              
00130         Material* pMaterial;    
00131         int TextureIndex;               
00132         int DMAAddress;                 
00133         vector<DWORD> faces;    
00134 };
00135 
00143 struct SubsetMesh
00144 {
00148         SubsetMesh()
00149         {
00150                 pMesh = NULL;
00151         }
00152 
00156         ~SubsetMesh()
00157         {
00158                 pMesh = NULL;                                                                                   // not responsible for deleting the mesh.
00159 
00160                 for(unsigned int i = 0; i < subsets.size(); i ++)               // Make sure all subsets are deleted.
00161                 {
00162                         if(subsets[i]) delete subsets[i];
00163                         subsets[i] = NULL;
00164                 }
00165                 subsets.empty();
00166         }
00167 
00168         Mesh* pMesh;                                                                    
00169         vector<Subset*> subsets;                                                
00170 };
00171 
00179 struct mappedTexture
00180 {
00184         mappedTexture()                                 
00185         {
00186                 texture = NULL;
00187                 FileName = "";
00188         }
00189 
00193         ~mappedTexture()
00194         {
00195                 if(texture) 
00196                 {
00197                         // Delete Texture
00198                         delete texture;                  
00199                         texture = NULL;                 
00200                 }
00201         }
00202 
00203         string FileName;                                
00204         CTexture* texture;                              
00205 };
00206 
00207 #endif

Generated on Sun May 18 21:45:10 2008 for PS2X by  doxygen 1.5.4