Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cMesh.h
Go to the documentation of this file.
1 //
5 //
6 
7 #ifndef _INC_cMesh_H
8 #define _INC_cMesh_H
9 #ifndef NO_PRAGMA_ONCE
10 #pragma once
11 #endif
12 #include "../Gray3D.h"
18 
19 interface ID3DXBaseMesh;
20 
21 namespace GrayLib
22 {
23  class cPlanef;
24 };
25 
26 namespace Gray3D
27 {
29  {
35  public:
36  cMeshVertsV(size_t nVertStride = sizeof(cVector3f))
37  : m_nVertStride(nVertStride)
38  , m_nVertices(0)
39  {
40  }
41  size_t get_VertStride() const
42  {
44  return m_nVertStride;
45  }
47  {
48  return m_nVertices;
49  }
50 
52  {
55  ASSERT(IS_INDEX_GOOD(i, m_nVertices));
56  return *((cVector3f*)(m_Vertices.get_DataBytes() + (i * m_nVertStride)));
57  }
58  const cVector3f& get_Vert(ITERATE_t i) const
59  {
62  ASSERT(IS_INDEX_GOOD(i, m_nVertices));
63  return *((const cVector3f*)(m_Vertices.get_DataBytes() + (i * m_nVertStride)));
64  }
65 
67  {
68  return (cVector3f*)m_Vertices.get_DataBytes();
69  }
70 
71  void SetVertQty(ITERATE_t dwQty, size_t nVertStride)
72  {
75  m_nVertices = dwQty;
76  m_nVertStride = nVertStride;
77  m_Vertices.ReAlloc(m_nVertices * m_nVertStride);
78  }
79  void FreeVerts()
80  {
81  m_nVertices = 0;
82  m_Vertices.Free();
83  }
84  void AddVert(const void* pVert)
85  {
87  size_t nSize = m_nVertices * m_nVertStride;
88  m_Vertices.ReAlloc(nSize + m_nVertStride);
89  memcpy(m_Vertices.get_DataBytes() + nSize, pVert, m_nVertStride);
90  m_nVertices++;
91  }
92 
93  protected:
94  size_t m_nVertStride;
97  };
98 
99  template< class _TYPE_VERT >
101  {
105 
106  public:
108  : cMeshVertsV(sizeof(_TYPE_VERT))
109  {
110  }
111  };
112 
113  template< typename _TYPE_INDEX = WORD >
115  {
120  public:
121  typedef _TYPE_INDEX INDEX_t;
123  {
124  return m_aIndexes.GetSize();
125  }
127  {
128  m_aIndexes.SetSize(nQty);
129  }
130 
132  {
133  return m_aIndexes.GetAt(i);
134  }
136  {
137  return m_aIndexes.ElementAt(i);
138  }
140  {
141  return m_aIndexes.GetData();
142  }
143  const INDEX_t* get_IndexPtr() const
144  {
145  return m_aIndexes.GetData();
146  }
147 
149  {
150  return m_aIndexes.AddTail(index);
151  }
152  void FreeIndexes()
153  {
154  m_aIndexes.RemoveAll();
155  }
156 
158  {
162  ITERATE_t nCount = 0;
163  for (ITERATE_t i = 0; i < get_IndexQty(); i++)
164  {
165  INDEX_t idx = m_aIndexes[i];
166  if (idx >= 0)
167  {
168  nCount++;
169  }
170  else
171  {
172  nCount -= 2;
173  }
174  }
175  return nCount;
176  }
177 
178  protected:
180  };
181 
182  template< typename _TYPE_INDEX = WORD >
184  {
189  public:
190  typedef _TYPE_INDEX INDEX_t;
191  cMeshT(size_t nVertStride = 0)
192  : m_Verts(nVertStride)
193  {
194  }
195  void FreeMesh()
196  {
197  m_Index.FreeIndexes();
198  m_Verts.FreeVerts();
199  }
200  public:
203  };
204 
205  struct GRAY3D_LINK cMesh : public cMeshT<WORD>
206  {
210  public:
211  // DECLARE_HEAP_ALIGNED_ALLOC(cMeshVar);
212 #ifdef USE_DXX
213  HRESULT put_MeshX(ID3DXBaseMesh* pMesh);
214 #endif
216  };
217 
218  class GRAY3D_LINK cMeshInt : public cMeshT<int>
219  {
228 
229  typedef DWORD HASHUV_t;
231 
232  public:
233  HRESULT GetHalfspaceMesh(const cPlanef& plane, OUT cMeshInt& meshResult, ITERATE_t numVerts = -1, ITERATE_t numInds = -1) const;
234  };
235 };
236 #endif // _INC_cMesh_H
#define GRAY3D_LINK
Definition: Gray3D.h:15
#define IS_INDEX_GOOD(i, q)
cast the (likely) int to unsigned to check for negatives.
Definition: Index.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define ASSERT(exp)
Definition: cDebugAssert.h:87
Definition: cMesh.h:115
cArrayVal< INDEX_t > m_aIndexes
DWORD or WORD = indexes into the m_Vertices. usually triangle triplets.
Definition: cMesh.h:179
INDEX_t get_Index(ITERATE_t i) const
Definition: cMesh.h:131
_TYPE_INDEX INDEX_t
_TYPE_INDEX = WORD or INT32
Definition: cMesh.h:121
ITERATE_t get_TriangleQty() const
Definition: cMesh.h:157
INDEX_t & ref_Index(ITERATE_t i)
Definition: cMesh.h:135
const INDEX_t * get_IndexPtr() const
Definition: cMesh.h:143
void FreeIndexes()
Definition: cMesh.h:152
void put_IndexQty(ITERATE_t nQty)
Definition: cMesh.h:126
ITERATE_t get_IndexQty() const
Definition: cMesh.h:122
INDEX_t * get_IndexPtr()
Definition: cMesh.h:139
ITERATE_t AddIndex(INDEX_t index)
Definition: cMesh.h:148
Definition: cMesh.h:219
Definition: cMesh.h:184
cMeshVertsV m_Verts
flexible vertex format array. ASSUME first element is always cVector3f
Definition: cMesh.h:202
cMeshT(size_t nVertStride=0)
Definition: cMesh.h:191
void FreeMesh()
Definition: cMesh.h:195
_TYPE_INDEX INDEX_t
_TYPE_INDEX = WORD or INT32
Definition: cMesh.h:190
cMeshIndexT< _TYPE_INDEX > m_Index
Index into m_Verts buffer.
Definition: cMesh.h:201
Definition: cMesh.h:101
cMeshVertsT()
Definition: cMesh.h:107
Definition: cMesh.h:29
cHeapBlock m_Vertices
cVector3f based flexible vertex format.
Definition: cMesh.h:96
cVector3f * get_VertPtr()
Definition: cMesh.h:66
size_t m_nVertStride
Size of each vertex blob. ASSUME (m_nVertStride >= sizeof(cVector3f))
Definition: cMesh.h:94
ITERATE_t get_VertQty() const
Definition: cMesh.h:46
const cVector3f & get_Vert(ITERATE_t i) const
Definition: cMesh.h:58
cVector3f & ref_Vert(ITERATE_t i)
Definition: cMesh.h:51
void SetVertQty(ITERATE_t dwQty, size_t nVertStride)
Definition: cMesh.h:71
cMeshVertsV(size_t nVertStride=sizeof(cVector3f))
Definition: cMesh.h:36
void AddVert(const void *pVert)
Definition: cMesh.h:84
size_t get_VertStride() const
Definition: cMesh.h:41
ITERATE_t m_nVertices
Quantity of (m_nVertStride sized) vertex elements allocated. COUNT_t.
Definition: cMesh.h:95
void FreeVerts()
Definition: cMesh.h:79
Definition: cPlane.h:18
Definition: cVector.h:94
Definition: cHeap.h:156
Definition: cPair.h:249
Definition: Gray3D.cpp:12
Definition: cMesh.h:22
int ITERATE_t
like size_t but signed
Definition: Index.h:28
uint16 index
Definition: sample3.cpp:29
Definition: cMesh.h:206
UNITTEST_FRIEND(cMesh)