forked from CAU-LetsCode/OOP-Proj4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlatform.cpp
71 lines (55 loc) · 1.58 KB
/
Platform.cpp
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
#include "Platform.h"
Platform::Platform(void) {
D3DXMatrixIdentity(&m_mLocal);
ZeroMemory(&m_mtrl, sizeof(m_mtrl));
x, z = 0;
width = PLATFORMWIDTH;
height = PLATFORMHEIGHT;
depth = PLATFORMDEPTH;
m_pBoundMesh = nullptr;
}
Platform::~Platform(void) {
}
bool Platform::create(IDirect3DDevice9* pDevice, D3DXCOLOR color) {
if (NULL == pDevice)
return false;
m_mtrl.Ambient = color;
m_mtrl.Diffuse = color;
m_mtrl.Specular = color;
m_mtrl.Emissive = d3d::BLACK;
m_mtrl.Power = 5.0f;
if (FAILED(D3DXCreateBox(pDevice, PLATFORMWIDTH, PLATFORMHEIGHT, PLATFORMDEPTH, &m_pBoundMesh, NULL)))
return false;
return true;
}
void Platform::destroy(void) {
if (m_pBoundMesh) {
m_pBoundMesh->Release();
m_pBoundMesh = NULL;
}
}
void Platform::draw(IDirect3DDevice9* pDevice, const D3DXMATRIX& mWorld) {
if (!pDevice) return;
pDevice->SetTransform(D3DTS_WORLD, &mWorld);
pDevice->MultiplyTransform(D3DTS_WORLD, &m_mLocal);
pDevice->SetMaterial(&m_mtrl);
m_pBoundMesh->DrawSubset(0);
}
void Platform::setPosition(float x, float y, float z) {
D3DXMATRIX m;
this->x = x;
this->y = y;
this->z = z;
D3DXMatrixTranslation(&m, x, y, z);
setLocalTransform(m);
}
float Platform::getHeight(void) const {
//todo
return PLATFORMHEIGHT;
}
void Platform::setLocalTransform(const D3DXMATRIX& mLocal) { m_mLocal = mLocal; }
//void adjustPosition(CSphere& ball); //todo
D3DXVECTOR3 Platform::getPosition() const {
D3DXVECTOR3 org(this->x, this->y, this->z);
return org;
}