forked from apurvsinghdark/GraphicProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModel.h
90 lines (71 loc) · 1.59 KB
/
Model.h
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
#pragma once
#include"Mesh.h"
#include"Texture.h"
#include"Shader.h"
#include"Material.h"
class Model
{
private:
Material* material;
Texture* overerideTextureDiffuse;
Texture* overerideTextureSpecular;
std::vector<Mesh*> meshes;
glm::vec3 position;
void UpdateUniforms();
public:
Model(glm::vec3 position, Material* material, Texture* textureDiffuse, Texture* textureSpecular, std::vector<Mesh*>meshes);
~Model();
void Rotate(const glm::vec3 rotation);
void Render(Shader* shader);
};
void Model::UpdateUniforms()
{
}
Model::Model(glm::vec3 position, Material* material, Texture* textureDiffuse, Texture* textureSpecular, std::vector<Mesh*>meshes)
{
this->position = position;
this->material = material;
this->overerideTextureDiffuse = textureDiffuse;
this->overerideTextureSpecular = textureSpecular;
for (auto*& i : meshes)
{
this->meshes.push_back(new Mesh(*i));
}
for (auto& i : this->meshes)
{
i->Move(this->position);
i->SetOrigin(this->position);
}
}
Model::~Model()
{
for (auto*& i : this->meshes)
{
delete i;
}
}
void Model::Rotate(const glm::vec3 rotation)
{
for (auto& i : this->meshes)
i->Rotate(rotation);
}
void Model::Render(Shader* shader)
{
//Update Uniforms
this->UpdateUniforms();
this->material->SendToShader(*shader);
shader->Use();//re-Init for becoz of SetMat
//bind N activate texture
this->overerideTextureDiffuse->bind(0);
this->overerideTextureSpecular->bind(1);
//DRAW
for (auto& i : this->meshes)
{
i->Render(shader);
}
//Unbinding
glBindVertexArray(0);
glUseProgram(0);
glActiveTexture(0);
glBindTexture(GL_TEXTURE_2D, 0);
}