Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

GXLand.h

Go to the documentation of this file.
00001 #ifndef __GXLAND
00002 #define __GXLAND
00003 
00004 
00005 #include "GXStandardDefines.h"
00006 #include "GXVertex.h"
00007 #include "GXSquareTemplate.h"
00008 #include "GXAutoArray.h"
00009 #include "GXMutex.h"
00010 
00011 #define GXINDEX_TYPE unsigned short
00012 #define GXINDEX_FMT  D3DFMT_INDEX16
00013 
00014 
00015 class CGXLand
00016 {
00017 public:
00018         CGXLand();
00019         virtual ~CGXLand();
00020 
00021         //The function pointer is responsible or y coord and texture coords
00022         bool Init(CGXDeviceContainer* pDevice,
00023                                         UINT uSideSize, 
00024                                         void (*pFn)(GXVertex*, void*),
00025                                         void* pCustomData);
00026 
00027         void OnDeviceLost();
00028         bool OnReset(CGXDeviceContainer* pDevice);
00029 
00030 
00031         inline UINT GetSideSize()
00032         {
00033                 return m_Vertices.GetSideSize();
00034         }
00035 
00036         UINT GetVertNumFromIndex(UINT uIndex);
00037 
00038 
00039         inline GXVertex* GetVertexPtr()
00040         {
00041                 return m_Vertices.GetArrayPointer();
00042         }
00043 
00044         inline unsigned short* GetIndexPtr()
00045         {
00046                 return m_Indices.GetPtr();
00047         }
00048 
00049         bool LockBuffers(IDirect3DVertexBuffer8** ppVBOut,
00050                                                         IDirect3DIndexBuffer8** ppIBOut);
00051 
00052         void UnlockBuffers();
00053 
00054 
00055         inline DWORD GetIndexFormat()
00056         {
00057                 return GXINDEX_FMT;
00058         }
00059 
00060         bool GenerateVertices(D3DXVECTOR3* pCameraPos,
00061                                                                   float fSideSize);
00062 
00063 
00064         inline UINT GetIndexCount()
00065         {
00066                 return (GetSideSize()-1)*(GetSideSize()-1)*6;//6 vertices in a triangle
00067         }
00068 
00069         inline UINT GetVertexCount()
00070         {
00071                 return GetSideSize()*GetSideSize();
00072         }
00073 
00074 protected:
00075         void Cleanup();
00076 
00077         bool CreateBuffers(CGXDeviceContainer* pDevice);
00078 
00079         inline UINT GetIndex(const UINT x, const UINT z)
00080         {
00081                 return (x+(GetSideSize())*z);
00082         }
00083 
00084         bool GenerateIndices();
00085 
00086 
00087 
00088         bool GenerateNormals();
00089 
00090         
00091         CGXSquare<GXVertex>                             m_Vertices;
00092         CGXAutoArray<GXINDEX_TYPE>              m_Indices;
00093 
00094         IDirect3DVertexBuffer8*                 m_pVB;
00095         IDirect3DIndexBuffer8*                  m_pIB;
00096 
00097         void    (*m_pLandFunction)(GXVertex*, void*);
00098         void*                                           m_pCustomData;
00099 
00100         CGXMutex                                        m_Mutex;//for abitrating the vertex buffer.. GenerateVertices, and Drawprimitive need to be thread safe
00101 };
00102 
00103 #endif

Generated on Thu May 23 17:51:00 2002 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001