raSystem  1.0 bata
raFractal.cpp
Go to the documentation of this file.
1 #include "..\include\raMain.h"
2 
3 namespace System
4 {
5  raFractal::raFractal(raSmartPointer<raDirectX> dx, int Level, bool bRandom, raMaterial* mat)
6  : raEntity(dx, mat ? mat : new raMaterial(dx, "raEffects\\MyEngine.fx", "RenderWithColor"))
7  {
8  m_pSubsets[0].PrimitiveType = D3D11_PRIMITIVE_TOPOLOGY_LINELIST;
9  m_level = Level;
10 
11  m_nVertices = 0;
12 
13  for(int i = 0; i < Level + 2; i++)
14  m_nVertices += (UINT) pow(4.0, i + 1);
15  m_nIndices = 0;
16 
17  m_pVB = NULL;
18  m_max_angle = 45 * PI / 180.0f;
19  m_max_lenght = 0.5f;
20  m_bRandom = bRandom;
21  }
23  {
25 
26  int n = 0;
27  raVector3 v0(0.0f, 0.0f, 0.0f);
28  raVector3 v1(0.0f, 1.0f, 0.0f);
29 
30  makeChildren((VERTEXPOSITIONCOLOR*)m_pVertices, v0, v1, n, m_level);
31  }
32  void raFractal::makeChildren(VERTEXPOSITIONCOLOR* vertices,
33  raVector3 v0, raVector3 d, int& n, int level)
34  {
35  float r = (float) rand() / RAND_MAX;
36  float g = (float) rand() / RAND_MAX;
37  float b = (float) rand() / RAND_MAX;
38 
39  //Anfangs- und Endpunkt hinzufügen
40  vertices[n].position.x = v0.x;
41  vertices[n].position.y = v0.y;
42  vertices[n].position.z = v0.z;
43  vertices[n].color[0] = r;
44  vertices[n].color[1] = 1.0f;
45  vertices[n].color[2] = b;
46 
47  n += 1;
48 
49  vertices[n].position.x = v0.x + d.x;
50  vertices[n].position.y = v0.y + d.y;
51  vertices[n].position.z = v0.z + d.z;
52  vertices[n].color[0] = r;
53  vertices[n].color[1] = 1.0f;
54  vertices[n].color[2] = b;
55  n += 1;
56 
57  // Vier Kinder
58  float angle;
59  if(m_bRandom)
60  angle = m_max_angle * rand() / RAND_MAX;
61  else
62  angle = m_max_angle;
63 
64  if( level >= 0)
65  {
66  raVector4 v;
67  raMatrix m[4];
68 
69  m[0] = raMatrixRotationZ( angle);
70  m[1] = raMatrixRotationZ( -angle);
71  m[2] = raMatrixRotationX( angle);
72  m[3] = raMatrixRotationX( -angle);
73 
74  float l;
75 
76  for(int i = 0; i < 4; i++)
77  {
78  if(m_bRandom)
79  l = 2.0f * m_max_lenght * (float) rand() / RAND_MAX;
80  else
81  l = m_max_lenght;
82 
83  D3DXVec3Transform((D3DXVECTOR4*)&v, (D3DXVECTOR3*)&d, (D3DXMATRIX*)&m[i]);
84  D3DXVECTOR3 v1 = (D3DXVECTOR3)v;
85 
86  makeChildren(vertices, v0 + d, l * v1, n, level - 1);
87  }
88  }
89  }
90 };
raFloat y
Definition: raVector3.h:13
raFloat x
Definition: raVector3.h:12
float m_max_angle
Definition: raFractal.h:10
VERTEXPOSITIONCOLOR * m_pVertices
Definition: raEntity.h:39
raFloat z
Definition: raVector3.h:14
RAPI raMatrix raMatrixRotationX(const float f)
Definition: raMatrix.cpp:12
SDKMESH_SUBSET * m_pSubsets
Definition: raVisual.h:121
float m_max_lenght
Definition: raFractal.h:11
RAPI raMatrix raMatrixRotationZ(const float f)
Definition: raMatrix.cpp:43
virtual void SetupVertices()
Definition: raFractal.cpp:22
raFractal(raSmartPointer< raDirectX > dx, int Level, bool bRandom=true, raMaterial *mat=(NULL))
Definition: raFractal.cpp:5
UINT PrimitiveType
Definition: raSDKmesh.h:140
#define PI
Definition: raMain.h:129