forked from Kitcham/ToyRayTracer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasePartList.cpp
58 lines (50 loc) · 1.78 KB
/
BasePartList.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
#include "BasePartList.h"
#include <algorithm>
void BasePartList::Draw(Shader shader, Camera camera, glm::mat4 projection)
{
shader.use();
for (int i = 0; i < PartList.size(); i++) {
PartList[i]->CreatVAO();
//shader.setInt("texture1", PartList[i]->getTexture());
shader.setMat4("projection", projection);
shader.setMat4("view", camera.GetViewMatrix());
shader.setMat4("model", modelList[i]);
if (PartList[i]->Matrial == 4 && Light.flag==0) {
float x0(1e8 + 7), x1(-1e8 + 7), z0(1e8 + 7), z1(-1e8 + 7);
for (int j = 0; j < PartList[i]->positions.size(); j++) {
glm::vec4 v1 = modelList[i] * glm::vec4(PartList[i]->positions[j], 1.0) ;
x0 = std::min(x0, v1.x);
x1 = std::max(x1, v1.x);
z0 = std::min(z0, v1.z);
z1 = std::max(z1, v1.z);
}
Light.x0 = x0;
Light.x1 = x1;
Light.z0 = z0;
Light.z1 = z1;
Light.y = PartList[i]->positions[0].y;
Light.flag = 1;
}
PartList[i]->Draw();
}
}
void BasePartList::LoadLight(Shader shader)
{
shader.setFloat("Light.x0", Light.x0);
shader.setFloat("Light.x1", Light.x1);
shader.setFloat("Light.z0", Light.z0);
shader.setFloat("Light.z1", Light.z1);
shader.setFloat("Light.y", Light.y);
}
void BasePartList::Add(std::shared_ptr<BasePart> basePart, glm::mat4 model)
{
PartList.push_back(basePart);
modelList.push_back(model);
}
void BasePartList::Add(std::vector<std::shared_ptr<BasePart>> basePart, glm::mat4 model)
{
for (auto i : basePart) {
PartList.push_back(i);
modelList.push_back(model);
}
}