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
|
// Render-Funktion
tbResult CFocus::Render(float fNumSecsPassed)
{
HRESULT hResult;
tbMatrix mRotation, mRotationX; // Rotationsmatrix
tbMatrix mTranslation; // Translationsmatrix
tbMatrix mWorld; // Vereinende Weltmatrix
tbMatrix mCamera;
mCamera = tbMatrixCamera(tbVector3(0.0f, 0.0f, 0.0f ),
tbVector3(0.0f, 0.0f, 1.0f ),
tbVector3(0.0f, 1.0f, 0.0f));
// Rotations- und Translationsmatrix des Dreiecks erzeugen
mRotation = tbMatrixRotationY(TB_DEG_TO_RAD(0.0f));
mRotationX = tbMatrixRotationX(TB_DEG_TO_RAD(0.0f));
mTranslation = tbMatrixTranslation(tbVector3(0.0f, 0.0f, Entfernung + 1.0f));
// Beide Matrizen kombinieren und als Weltmatrix einsetzen
mWorld = mRotation * mRotationX*mTranslation * mProjection;
tbDirect3D::GetDevice()->SetTransform(D3DTS_WORLD, (D3DMATRIX*)(&mWorld));
// -------------------------------------------------------------
/// Den Bildpuffer und den Z-Buffer leeren
if(FAILED(hResult = tbDirect3D::GetDevice()->Clear(0,
NULL,
D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
D3DCOLOR_XRGB(0, 0, 63),
1.0f,
0)))
{
// Fehler beim Leeren!
MessageBox(g_hWindow, "Fehler beim Leeren der Puffer!",
"Fehler", MB_OK | MB_ICONEXCLAMATION);
TB_ERROR_DIRECTX("g_pD3DDevice->Clear", hResult, TB_STOP);
}
tbDirect3D::GetDevice()->SetRenderState( D3DRS_LIGHTING,FALSE);
tbDirect3D::GetDevice()->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
// Szene beginnen
tbDirect3D::GetDevice()->BeginScene();
tbDirect3D::GetDevice()->SetStreamSource(0, g_pDreieckVB->GetVB(),0,
sizeof(SVertex));
tbDirect3D::GetDevice()->SetIndices(g_pDreieckB->GetIB());
tbDirect3D::SetTexture(0,g_pTexture);
// Nun das Dreieck zeichnen
if(FAILED(hResult = tbDirect3D::GetDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, // Dreiecksliste
0,0,3,0, 1))) // Vertexgröße
{
// Fehler beim Zeichnen!
MessageBox(g_hWindow, "Fehler beim Zeichnen des Dreiecks!",
"Fehler", MB_OK | MB_ICONEXCLAMATION);
TB_ERROR_DIRECTX("g_pD3DDevice->DrawPrimitiveUP", hResult, TB_STOP);
}
tbDirect3D::GetDevice()->EndScene();
// Update the world state according to user input
D3DXMATRIX matWorld;
D3DXMATRIX matRotY;
D3DXMATRIX matRotX;
D3DXMatrixRotationX( &matRotX, 0 );
D3DXMatrixRotationY( &matRotY, 0 );
D3DXMatrixMultiply( &matWorld, &matRotX, &matRotY );
if(GetAsyncKeyState(VK_UP))
Entfernung += 1.0f;
if(GetAsyncKeyState(VK_DOWN))
Entfernung -= 1.0f;
matWorld._41 = 0.0f;
matWorld._42 = 0.0f;
matWorld._43 = Entfernung + 400.0f;
tbDirect3D::GetDevice()->SetTransform( D3DTS_WORLD, &matWorld );
tbDirect3D::GetDevice()->SetRenderState( D3DRS_LIGHTING, TRUE );
p_scene->getRootObject()->playAnimation("scene", TRUE, emmloader::AM_LOOP);
p_scene->getRootObject()->move(g_fTime);
tbDirect3D::GetDevice()->BeginScene();
D3DXMATRIX m_View;
m_View._11 = mProjection.m11;
m_View._12 = mProjection.m12;
m_View._13 = mProjection.m13;
m_View._14 = mProjection.m14;
m_View._21 = mProjection.m21;
m_View._22 = mProjection.m22;
m_View._23 = mProjection.m23;
m_View._24 = mProjection.m24;
m_View._31 = mProjection.m31;
m_View._32 = mProjection.m32;
m_View._33 = mProjection.m33;
m_View._34 = mProjection.m34;
m_View._41 = mProjection.m41;
m_View._42 = mProjection.m42;
m_View._43 = mProjection.m43;
m_View._44 = mProjection.m44;
emmloader::beginFrame(&m_View);
p_scene->getRootObject()->render();
// Szene beenden
tbDirect3D::GetDevice()->EndScene();
// Der große Moment: den Bildpuffer sichtbar machen
tbDirect3D::GetDevice()->Present(NULL, NULL, NULL, NULL);
return TB_OK;
}
|