raSystem  1.0 bata
raHoehenfeld.cpp
Go to the documentation of this file.
1 #include "..\include\raMain.h"
2 
3 namespace System
4 {
6  raMaterial* mat, float tileSize): raEntity(dx, mat)
7  {
8  m_width = width;
9  m_depth = depth;
10 
11  m_tileSize = tileSize;
12 
13  m_nVertices = m_width * m_depth;
14  m_nIndices = 6 * (m_width - 1) * (m_depth - 1);
15  }
17  {
18  }
19 
21  {
23 
24  int n = 0;
25  for(int z = 0; z < m_depth; z++)
26  {
27  for(int x = 0; x < m_width; x++)
28  {
29  m_pVertices[n].position.x = (float)x / (m_width - 1);
31  h(((float)x / (m_width - 1)),
32  ((float)z / (m_depth - 1)));
33  m_pVertices[n].position.z = (float)z / (m_depth - 1);
34 
35  m_pVertices[n].normal = normal(
36  ((float)x / (m_width - 1)),
37  ((float)z / (m_depth - 1)));
38 
39  m_pVertices[n].texcoord.x = x / m_tileSize;
40  m_pVertices[n].texcoord.y = z / m_tileSize;
41 
42  n+=1;
43  }
44  }
45  }
47  {
49 
50  int n = 0;
51  for(int z = 0; z < m_depth - 1; z++)
52  {
53  for(int x = 0; x < m_width - 1; x++)
54  {
55  m_pIndices[n + 0] = (UINT16) (z * m_width + x);
56  m_pIndices[n + 1] = (UINT16) ((z + 1) * m_width + x);
57  m_pIndices[n + 2] = (UINT16) (z * m_width + (x + 1));
58  m_pIndices[n + 3] = (UINT16) ((z + 1) * m_width + x);
59  m_pIndices[n + 4] = (UINT16) ((z + 1) * m_width + (x + 1));
60  m_pIndices[n + 5] = (UINT16) (z * m_width + (x + 1));
61 
62  n+=6;
63  }
64  }
65  m_pSubsets[0].IndexStart = 0;
67  }
68  //----------------
69  raHeightMap::raHeightMap(raSmartPointer<raDirectX> dx, int width, int depth, raMaterial *mat, float tileSize,
70  int PixelFormat,
71  LPCSTR heightTexture, LPCSTR bumpMapTexture) :
72  raHoehenfeld(dx, width, depth, mat, tileSize)
73  {
74  m_PixelFormat = PixelFormat;
75  //Daten einlesen
76  HANDLE hFile;
77  LARGE_INTEGER FileSize;
78  DWORD nByte;
79  DWORD nBytesRead;
80 
81  hFile = CreateFile(heightTexture, FILE_READ_DATA, FILE_SHARE_READ, NULL,
82  OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
83 
84  GetFileSizeEx(hFile, &FileSize);
85  nByte = FileSize.LowPart;
86  m_pHeightMap = new BYTE[nByte];
87 
88  ReadFile(hFile, m_pHeightMap, nByte, &nBytesRead, NULL);
89  CloseHandle(hFile);
90  assert(nBytesRead > 0);
91 
92  // Normal
93  hFile = CreateFile(bumpMapTexture, FILE_READ_DATA, FILE_SHARE_READ, NULL,
94  OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
95 
96  GetFileSizeEx(hFile, &FileSize);
97  nByte = FileSize.LowPart;
98  m_pBumpData = new BYTE[nByte];
99 
100  ReadFile(hFile, m_pBumpData, nByte, &nBytesRead, NULL);
101  CloseHandle(hFile);
102  }
104  {
105  SAFE_DELETE(m_pHeightMap);
106  SAFE_DELETE(m_pBumpData);
107  }
108  float raHeightMap::h(float x, float z)
109  {
110  int w = m_PixelFormat;
111  x *= w;
112  z *= w;
113  if(x >= w)
114  x = (float)w-1;
115  if(z >= w)
116  z = (float)w-1;
117 
118  return m_pHeightMap[3 * ((UINT)x * w + (UINT)z)] / 255.0f;
119  }
120  raVector3 raHeightMap::normal(float x, float z)
121  {
122  int w = m_PixelFormat;
123 
124  z *= w;
125  z *= w;
126 
127  float r = m_pBumpData[3 * ((UINT)x * w + (UINT)z) + 0];
128  float g = m_pBumpData[3 * ((UINT)x * w + (UINT)z) + 1];
129  float b = m_pBumpData[3 * ((UINT)x * w + (UINT)z) + 2];
130 
131  raVector3 n(r, g, b);
132  n = raVector3Normalize(n);
133  return n;
134  }
135 };
raFloat y
Definition: raVector3.h:13
raFloat x
Definition: raVector3.h:12
~raHoehenfeld(void)
raFloat x
Definition: raVector2.h:10
unsigned short UINT16
Definition: d3dx11dbg.h:35
VERTEXPOSITIONNORMALTEXTURED * m_pVertices
Definition: raEntity.h:39
UINT64 IndexCount
Definition: raSDKmesh.h:142
raVector3 raVector3Normalize(const raVector3 &v)
Definition: raVector3.h:60
raFloat z
Definition: raVector3.h:14
SDKMESH_SUBSET * m_pSubsets
Definition: raVisual.h:121
virtual void SetupVertices()
UINT64 IndexStart
Definition: raSDKmesh.h:141
raHeightMap(raSmartPointer< raDirectX > dx, int width, int depth, raMaterial *mat, float tileSize=1.0f, int PixelFormat=1024, LPCSTR heightTexture="raGrafik\eightmap.raw", LPCSTR bumpMapTexture="raGrafik\eightNormals.raw")
raFloat y
Definition: raVector2.h:11
virtual void SetupIndices()
#define SAFE_DELETE(p)
Definition: d3dxGlobal.h:26
raHoehenfeld(raSmartPointer< raDirectX > dx, int width, int depth, raMaterial *mat, float tileSize=1.0f)
Definition: raHoehenfeld.cpp:5