-
Notifications
You must be signed in to change notification settings - Fork 0
/
3DModel.cpp
82 lines (69 loc) · 1.46 KB
/
3DModel.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
72
73
74
75
76
77
78
79
80
81
82
#include "Model.h"
Box::Box()
{
}
Model::Model()
{
m_totalVertices = 0;
}
bool Model::pushObject(GameObject* obj)
{
ObjectList.push_back(obj);
totalObjects = static_cast<unsigned int>(ObjectList.size());
return true;
};
void Model::Update()
{
for (UINT i = 0; i < totalObjects; i++)
{
ObjectList[i]->Update();
}
}
void Model::Render(DirectDevice* device, XMMATRIX& viewMat, XMMATRIX& projMat)
{
for (UINT i = 0; i < ObjectList.size(); i++)
{
device->d3dContext_->IASetVertexBuffers(0, 1, &vertexBuffer_, &stride, &offset);
ObjectList[i]->PrepareRender(device, viewMat, projMat);
for (UINT j = 0; j < BoxList.size(); j++)
{
BoxList[j].Render(device, vertexBuffer_);
}
};
};
void Box::Render(DirectDevice* device, ID3D11Buffer* vertexBuffer)
{
for (int i = 0; i < MAX_TEXTURE_MAP; i++)
{
if (material->shaderResourceView_[i] != nullptr)
device->d3dContext_->PSSetShaderResources(i, 1, &material->shaderResourceView_[i]);
}
device->d3dContext_->PSSetConstantBuffers(1, 1, &material->propCB_);
device->d3dContext_->Draw(NumVertex, StartVertex);
}
void Box::Release()
{
delete material;
}
void Model::Release()
{
for (int i = BoxList.size() - 1; i > 0; i--)
{
BoxList[i].Release();
}
BoxList.clear();
if (vertexBuffer_!= nullptr) vertexBuffer_->Release();
vertexBuffer_ = nullptr;
for (int i = ObjectList.size() - 1; i > 0; i--)
{
ObjectList[i]->Release();
}
ObjectList.clear();
}
Model::~Model()
{
this->Release();
}
Box::~Box()
{
}