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
|
objekt::objekt()
{
mesh = NULL;
materialien = NULL;
anz_mat = 0;
texturen = NULL;
}
objekt::~objekt()
{
unsigned int i;
if( materialien)
delete[] materialien;
if( texturen)
{
for( i = 0; i < anz_mat; i++ )
{
if( texturen[i])
texturen[i]->Release();
}
delete[] texturen;
}
if( mesh)
mesh->Release();
}
void objekt::Init(LPDIRECT3DDEVICE9 m_device)
{
device = m_device;
}
void objekt::load( char *xfile)
{
LPD3DXBUFFER buf;
D3DXMATERIAL* mat;
DWORD i;
D3DXLoadMeshFromXA( xfile,D3DXMESH_SYSTEMMEM, device, NULL, &buf, NULL, &anz_mat, &mesh);
mat = (D3DXMATERIAL*)buf->GetBufferPointer();
materialien = new D3DMATERIAL9[anz_mat];
texturen = new LPDIRECT3DTEXTURE9[anz_mat];
for( i=0; i<anz_mat; i++)
{
materialien[i] = mat[i].MatD3D;
materialien[i].Ambient.r = 1.0f;
materialien[i].Ambient.g = 1.0f;
materialien[i].Ambient.b = 1.0f;
if( D3DXCreateTextureFromFileA( device, mat[i].pTextureFilename, &texturen[i]) < 0)
texturen[i] = NULL;
}
buf->Release();
}
void objekt::SetPosition(D3DXVECTOR3 vPos)
{
m_vPosition = vPos;
}
void objekt::SetRotation(float RotX,float RotY, float RotZ)
{
m_RotX = RotX;
m_RotY = RotY;
m_RotZ = RotZ;
}
void objekt::draw()
{
D3DXMATRIX TransMatrix;
D3DXMATRIX RotMatrix;
D3DXMATRIX RotMatrixX, RotMatrixY, RotMatrixZ;
D3DXMATRIX WorldMatrix;
// Rotationsmatrizen anlegen
D3DXMatrixRotationX(&RotMatrixX,m_RotX);
D3DXMatrixRotationY(&RotMatrixY,m_RotY);
D3DXMatrixRotationZ(&RotMatrixZ,m_RotZ);
D3DXMatrixIdentity(&RotMatrix);
// und miteinander multiplizieren
D3DXMatrixMultiply(&RotMatrix,&RotMatrix,&RotMatrixX);
D3DXMatrixMultiply(&RotMatrix,&RotMatrix,&RotMatrixY);
D3DXMatrixMultiply(&RotMatrix,&RotMatrix,&RotMatrixZ);
// Transformations und Rotationsmatrix zur Weltmatrix zusammenfassen
D3DXMatrixMultiply(&WorldMatrix,&RotMatrix,&TransMatrix);
D3DXMatrixTranslation(&TransMatrix,m_vPosition.x,m_vPosition.y,m_vPosition.z);
D3DXMatrixMultiply(&WorldMatrix,&RotMatrix,&TransMatrix);
device->SetTransform(D3DTS_WORLD,&WorldMatrix);
unsigned int i;
for( i=0; i < anz_mat; i++ )
{
device->SetMaterial( &materialien[i]);
device->SetTexture( 0, texturen[i]);
mesh->DrawSubset( i);
}
}
|