1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
tbResult RenderProc(float fTime)
{
tbMatrix mProjection;
tbMatrix mProjectionTerrain;
tbMatrix mCamera;
tbMatrix mWorld;
tbVector3 vCameraDir;
D3DLIGHT9 Light;
// int iNumPasses;
// Z-Buffer leeren und die Szene beginnen
tbDirect3D& D3D = tbDirect3D::Instance();
D3D->Clear(0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, tbColor(0.0f, 0.0f, 0.0f), 1.0f, 0);
D3D->BeginScene();
// Projektionsmatrix erstellen und einsetzen.
// Das Sichtfeld hängt leicht von der Geschwindigkeit ab (Bei mir nicht).
mProjection = tbMatrixProjection(TB_DEG_TO_RAD(80.0f), D3D.GetAspect(), 10.0f, 650.0f);
mProjectionTerrain = tbMatrixProjection(TB_DEG_TO_RAD(120.0f), D3D.GetAspect(), 0.0f, 700.0f);
D3D.SetTransform(D3DTS_PROJECTION, mProjection);
// Kameramatrix erstellen und einsetzen
mCamera = tbMatrixCamera(g_Camera.GetPosition(),
g_Camera.GetPosition() + g_Camera.GetZAxis(),
g_Camera.GetYAxis());
D3D.SetTransform(D3DTS_VIEW, mCamera);
emmloader::beginFrame();
tbComputeClipPlanes(mCamera, mProjection, g_aClipPlanes);
// ------------------------------------------------------------------
// ------------------------------------------------------------------
D3D.SetRS(D3DRS_LIGHTING, TRUE);
D3D.SetRS(D3DRS_AMBIENT, tbColor(100.0f, 100.0f, 100.0f));
// Linearer schwarzer Nebel!
D3D.SetRS(D3DRS_FOGENABLE, TRUE);
D3D.SetRS(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);
D3D.SetRS(D3DRS_RANGEFOGENABLE, TRUE);
D3D.SetRS(D3DRS_FOGCOLOR, tbColor(0.71372549f, 0.776470588f, 0.886274509f));
D3D.SetRSF(D3DRS_FOGSTART, 400.0f);
D3D.SetRSF(D3DRS_FOGEND, 700.0f);
//Filter aktivieren
D3D.SetSS(0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);
D3D.SetSS(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
D3D.SetSS(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
if(g_bWireframe == 0)
D3D.SetRS(D3DRS_FILLMODE, D3DFILL_SOLID);
else if(g_bWireframe == 1)
D3D.SetRS(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
else if(g_bWireframe == 2)
D3D.SetRS(D3DRS_FILLMODE, D3DFILL_POINT);
D3D.SetRS(D3DRS_ALPHABLENDENABLE, FALSE);
D3D.SetTSS(1, D3DTSS_COLORARG1, D3DTA_CURRENT);
D3D.SetTSS(1, D3DTSS_COLORARG2, D3DTA_TEXTURE);
D3D.SetTSS(1, D3DTSS_COLOROP, D3DTOP_SELECTARG2);
D3D.SetTSS(2, D3DTSS_COLORARG1, D3DTA_TEXTURE);
D3D.SetTSS(2, D3DTSS_COLORARG2, D3DTA_CURRENT);
D3D.SetTSS(2, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
tbObject* pCamera = &g_Camera;
g_SkyBox.Render(g_Camera.GetPosition());
D3D.SetRS(D3DRS_ZENABLE, D3DZB_TRUE);
QueryPerformanceCounter((LARGE_INTEGER*)&g_LLCurCount);
g_LLLastCount = g_LLCurCount;
if(pTerrain->Render(tbVector2(g_Camera.GetPosition().x, g_Camera.GetPosition().z), mCamera, mProjectionTerrain))
{
TB_WARNING("Programm wird beendet, da ein Fehler beim Rendern des Terrains aufgetreten ist.");
PostQuitMessage(0);
}
if(pVegetation->RenderPlants(g_aClipPlanes))
{
TB_WARNING("Programm wird beendet, da ein Fehler beim Rendern der Vegetation aufgetreten ist.");
PostQuitMessage(0);
}
g_pOldStats->Capture(); //vor dem rendern des emm objekts aufrufen
D3D.SetTransform(D3DTS_WORLD, g_Tree2.GetMatrix());
//Render Animation (an der gleichen Stelle, wie der Baum)
g_pAnimatedModell->getRootObject()->render();
QueryPerformanceCounter((LARGE_INTEGER*)&g_LLCurCount);
g_fTime = (float)(g_LLCurCount - g_LLLastCount)/g_LLFrequency;
//Baum zeichnen
D3D.SetTransform(D3DTS_WORLD, g_Tree1.GetMatrix());
g_pTier->getRootObject()->render();
g_pOldStats->Apply();
if(tbBoxVisible_Inv(g_pTreeModel3->GetBoundingBoxMin(), g_pTreeModel3->GetBoundingBoxMax(), tbMatrixInvert(tbMatrixIdentity()), g_aClipPlanes))
{
D3D.SetTransform(D3DTS_WORLD, g_Tree3.GetMatrix());
if(g_pTreeModel3->Render())
{
TB_ERROR("Fehler beim Render des Mainboards", TB_ERROR);
}
g_pTreeMopdell2->Render();
}
// Weltmatrix zurücksetzen
D3D.SetTransform(D3DTS_WORLD, tbMatrixIdentity());
// Kein Nebel mehr!
D3D.SetRS(D3DRS_FOGENABLE, FALSE);
D3D.SetTSS(0, D3DTSS_TEXCOORDINDEX, 0);
// FPS schreiben
char cFPS[256];
sprintf(&cFPS[0], "FPS: %d",(int)(1.0f/g_fOldTime));
g_pSchrift->Begin();
g_pSchrift->DrawText(tbVector2(0.1f, 0.1f), &cFPS[0], TB_FF_RELATIVE | TB_FF_RELATIVESCALING | TB_FF_ALIGN_HCENTER | TB_FF_ALIGN_VCENTER);
sprintf(&cFPS[0], "Dauer pro Frame: %f", g_fTime);
g_pSchrift->DrawText(tbVector2(0.3f, 0.2f), &cFPS[0], TB_FF_RELATIVE | TB_FF_RELATIVESCALING | TB_FF_ALIGN_HCENTER | TB_FF_ALIGN_VCENTER);
if(g_bCollision) g_pSchrift->DrawText(tbVector2(0.1f, 0.3f), "Collission", TB_FF_RELATIVE | TB_FF_RELATIVESCALING | TB_FF_ALIGN_HCENTER | TB_FF_ALIGN_VCENTER, -1, tbColor(1.0f, 0.0f, 0.0f));
sprintf(&cFPS[0], "%d Vertices", g_LVertexCount);
g_pSchrift->DrawText(tbVector2(0.3f, 0.3f), &cFPS[0], TB_FF_RELATIVE | TB_FF_RELATIVESCALING | TB_FF_ALIGN_HCENTER | TB_FF_ALIGN_VCENTER);
g_LVertexCount = 0;
g_pSchrift->End();
// ------------------------------------------------------------------
// Szene beenden
D3D->EndScene();
return TB_OK;
}
|