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
|
#include <windows.h>
#include "InitD3D.h"
#include "InitWindow.h"
#include <dxerr9.h>
#include<d3d9.h>
#include<d3dx9.h>
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ |D3DFVF_DIFFUSE)
CInitD3D id3d;
HWND g_hWindow;
int Höhe = 600;
int Breite = 800;
FLOAT RotationX = 0;
FLOAT RotationY = 0;
FLOAT RotationZ = 0;
FLOAT TranslationX = 0;
FLOAT TranslationY = 0;
FLOAT TranslationZ = 0;
//Hier steht wndProc und initwindow
struct CUSTOMVERTEX
{
float x,y,z;
};
CUSTOMVERTEX Vertices[3] =
{
{2.0f,5.0f,1.0f},
{4.0f,2.0f,1.0f},
{6.0f,5.0f,1.0f}
};
HRESULT Render()
{
D3DXMATRIX ViewMatrix;
D3DXMatrixLookAtLH(&ViewMatrix,
&D3DXVECTOR3(0.0f, 0.0f, -10.0f),
&D3DXVECTOR3(0.0f, 0.0f, 0.0f),
&D3DXVECTOR3(0.0f, 1.0f, 0.0f));
D3DXMATRIX WorldMatrix;
D3DXMATRIX RotationMatrix;
D3DXMATRIX TranslationMatrix;
D3DXMatrixRotationX(&RotationMatrix, RotationX);
D3DXMatrixRotationY(&RotationMatrix, RotationY);
D3DXMatrixRotationZ(&RotationMatrix, RotationZ);
D3DXMatrixTranslation(&TranslationMatrix, TranslationX, TranslationY, TranslationZ);
D3DXMatrixMultiply(&WorldMatrix, &RotationMatrix, &TranslationMatrix);
id3d.pd3dDevice->SetTransform(D3DTS_WORLD, &WorldMatrix);
HRESULT hresult;
if(FAILED(hresult = id3d.pd3dDevice->Clear(0,
NULL,
D3DCLEAR_TARGET,
D3DCOLOR_XRGB(0, 0, 63),
1.0f,
0)))
{
MessageBox(NULL,"Fehler beim Leeren des Backbuffers","Fehler",MB_OK);
return 1;
}
id3d.pd3dDevice->BeginScene();
id3d.pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST,1,Vertices,sizeof(CUSTOMVERTEX));
id3d.pd3dDevice->EndScene();
id3d.pd3dDevice->Present(NULL,NULL,NULL,NULL);
return 0;
}
HRESULT InitScene()
{
HRESULT hresult;
hresult = id3d.pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
if(FAILED(hresult))
{
MessageBox(NULL,"Fehler beim Setzen des Vertexformat","Fehler",MB_OK);
return 1;
}
id3d.pd3dDevice->SetRenderState(D3DRS_LIGHTING,FALSE);
id3d.pd3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
id3d.pd3dDevice->SetRenderState(D3DRS_DITHERENABLE,TRUE);
D3DXMATRIX ProjMatrix;
D3DXMatrixPerspectiveFovLH(&ProjMatrix,
D3DX_PI/4,
static_cast<float>(Breite) / static_cast<float>(Höhe),
1.0f,
100.0f );
id3d.pd3dDevice->SetTransform(D3DTS_PROJECTION, &ProjMatrix);
return 0;
}
INT WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
char* lpCmdLine,
int nCmdShow)
{
InitWindow();
id3d.InitD3D(g_hWindow);
InitScene();
MSG message;
ZeroMemory(&message,sizeof(MSG));
while(message.message != WM_QUIT)
{
while(PeekMessage(&message,NULL,0,0,PM_REMOVE))
{
TranslateMessage(&message);
DispatchMessage(&message);
}
Render();
}
return 0;
}
|