raSystem  1.0 bata
raSkyDome.cpp
Go to the documentation of this file.
1 #include "..\include\raMain.h"
2 namespace System
3 {
5  float radius, bool bProcedural, bool bLighted, raMaterial* pMaterial) : raEntity(dx, pMaterial? pMaterial
6  : (bProcedural ? (raMaterial*)new raProceduralMaterial(dx, 64, "Fbm", 4):
7  ((raMaterial*)new raTexturedMaterial(dx, "raEffects\\NoNormals.fx",
8  bLighted?"RenderWithTextureAmbient":"RenderWithTexture",
9  "raGrafik\\Skydome1.jpg"))))
10  {
11  m_r = radius;
12  m_width = (float)width;
13  m_height = (float)height;
14 
15  m_nVertices = (DWORD)(m_width * m_height);
16  m_nIndices = 6 * ((DWORD)m_width - 1) * ((DWORD)m_height - 1);
17 
18  m_DrawOder = 0;
19  m_bDepthDisable = true;
20  if(bProcedural) ((raProceduralMaterial*)m_pMaterials[0])->SetBias(0.6f);
21  }
22 
24  {
26 
27  int n = 0;
28  for (int y = 0; y < m_height; y++)
29  {
30  float theta;
31  //Polkappe öffnen
32  if(y == 0)
33  theta = 0.5f * PI * (0.5f / ((float)m_height - 1));
34  else
35  theta = 0.5f * PI * (y / ((float)m_height - 1));
36  float rsintheta = m_r * sin(theta);
37  float rcostheta = m_r * cos(theta);
38  for (int x = 0; x < m_width; x++)
39  {
40  float phi = 2 * PI * x / ((float)m_width - 1);
41 
42  m_pVertices[n].position.x = rsintheta * cos(phi);
43  m_pVertices[n].position.y = rcostheta;
44  m_pVertices[n].position.z = rsintheta * sin(phi);
45 
46  m_pVertices[n].texcoord.x = x / ((float)m_width - 1);
47  m_pVertices[n].texcoord.y = y / ((float)m_height - 1);
48 
49  n++;
50  }
51  }
52  }
53 
55  {
57 
58  int n = 0;
59  for(int y = 0; y < m_height - 1; y++)
60  {
61  for(int x = 0; x < m_width - 1; x++)
62  {
63  m_pIndices[n + 0] = (UINT16) (y * m_width + x);
64  m_pIndices[n + 1] = (UINT16) ((y + 1) * m_width + x);
65  m_pIndices[n + 2] = (UINT16) (y * m_width + (x + 1));
66  m_pIndices[n + 3] = (UINT16) ((y + 1) * m_width + x);
67  m_pIndices[n + 4] = (UINT16) ((y + 1) * m_width + (x + 1));
68  m_pIndices[n + 5] = (UINT16) (y * m_width + (x + 1));
69 
70  n+=6;
71  }
72  }
73 
74  m_pSubsets[0].IndexStart = 0;
76  }
77 
78  void raSkyDome::SetupEffectVariables(const raMatrix& pView, const raMatrix& pProj,
79  const raLight *Light)
80  {
81  //Die Größe der Skybox muss auf die Farplane abgestimmt sein
82  //Klappt nur, wenn Mesh den Radius 1 hat - die Hälfte für eckige Skybox
83  float zf = pProj.m43/ (1 - pProj.m33) ;
84  //float scale = 0.4f * zf;
85  float scale = 0.04f * zf;
86  raMatrix mScale;
87  mScale = raMatrixScaling(raVector3(scale, scale, scale));
88 
89  raMatrix mInvView;
90  D3DXMatrixInverse((D3DXMATRIX*)&mInvView, NULL, (D3DXMATRIX*)&pView);
91  raMatrix worldTmp(mScale * m_World);
92  worldTmp.m41 = mInvView.m41;
93  worldTmp.m42 = mInvView.m42 - scale * 0.2f;
94  worldTmp.m43 = mInvView.m43;
95 
96  raMatrix mWorldView, mWorldViewProjection;
97  mWorldView = worldTmp * pView;
98  mWorldViewProjection = mWorldView * pProj;
99 
100  for(DWORD matNo = 0; matNo < m_numMaterials; matNo++)
101  {
102  m_pMaterials[matNo]->SetupPerFrame(Light);
103  m_pMaterials[matNo]->SetupPerObject(worldTmp, mWorldView,
104  mWorldViewProjection);
105  }
106  }
107 };
raFloat y
Definition: raVector3.h:13
Definition: raLight.h:5
raFloat x
Definition: raVector3.h:12
virtual void SetupVertices()
Definition: raSkyDome.cpp:23
virtual void SetupPerFrame(const raLight *Light, const raMatrix *pView=NULL, const raMatrix *pProj=NULL)
Definition: raMaterial.cpp:135
UINT m_DrawOder
Definition: raVisual.h:95
raFloat x
Definition: raVector2.h:10
unsigned short UINT16
Definition: d3dx11dbg.h:35
VERTEXPOSITIONTEXTURED * m_pVertices
Definition: raEntity.h:39
UINT64 IndexCount
Definition: raSDKmesh.h:142
float m33
Definition: raMatrix.h:12
RAPI raMatrix raMatrixScaling(const raVector3 &v)
Definition: raMatrix.cpp:100
raFloat z
Definition: raVector3.h:14
SDKMESH_SUBSET * m_pSubsets
Definition: raVisual.h:121
UINT64 IndexStart
Definition: raSDKmesh.h:141
float m41
Definition: raMatrix.h:12
raSkyDome(raSmartPointer< raDirectX > dx, int width, int height, float radius=1.0f, bool bProcedural=false, bool bLighted=false, raMaterial *pMaterial=NULL)
Definition: raSkyDome.cpp:4
raFloat y
Definition: raVector2.h:11
raMaterial ** m_pMaterials
Definition: raVisual.h:97
bool m_bDepthDisable
Definition: raVisual.h:114
#define PI
Definition: raMain.h:129
virtual void SetupPerObject(const raMatrix &mWorld, const raMatrix &mWorldView, const raMatrix &mWorldViewProjection)
Definition: raMaterial.cpp:121
raMatrix m_World
Definition: raRender.h:34
virtual void SetupIndices()
Definition: raSkyDome.cpp:54
virtual void SetupEffectVariables(const raMatrix &pView, const raMatrix &pProj, const raLight *Light)
Definition: raSkyDome.cpp:78
float m43
Definition: raMatrix.h:12
DWORD m_numMaterials
Definition: raVisual.h:96
float m42
Definition: raMatrix.h:12