Skip to content

Commit a31527a

Browse files
committed
Created a GameObject hierarchy system and a 3D coord axes model.
1 parent 249ac6d commit a31527a

File tree

6 files changed

+154
-50
lines changed

6 files changed

+154
-50
lines changed

NeonEngine/imgui.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Size=1441,1038
5656
Collapsed=0
5757

5858
[Docking][Data]
59-
DockSpace ID=0x3BC79352 Window=0x4647B76E Pos=467,527 Size=1920,1054 Split=X Selected=0x13926F0B
59+
DockSpace ID=0x3BC79352 Window=0x4647B76E Pos=505,565 Size=1920,1054 Split=X Selected=0x13926F0B
6060
DockNode ID=0x00000003 Parent=0x3BC79352 SizeRef=1426,527 Split=Y Selected=0x13926F0B
6161
DockNode ID=0x00000005 Parent=0x00000003 SizeRef=1387,702 CentralNode=1 Selected=0x13926F0B
6262
DockNode ID=0x00000006 Parent=0x00000003 SizeRef=1387,350 Selected=0xBF096F38

NeonEngine/src/cylinder.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,26 @@ void Cylinder::printSelf() const
183183

184184
// Test intersection with a ray
185185
bool Cylinder::intersected_ray(const glm::vec3& orig, const glm::vec3& dir, float& t) {
186+
float min_t = std::numeric_limits<float>::max();
187+
float t_aux;
186188
for (int i = 0; i < indices.size(); i += 3) {
187189
glm::vec3 v0(vertices[indices[i] * 3], vertices[indices[i] * 3 + 1], vertices[indices[i] * 3 + 2]);
188190
glm::vec3 v1(vertices[indices[i+1] * 3], vertices[indices[i+1] * 3 + 1], vertices[indices[i+1] * 3 + 2]);
189191
glm::vec3 v2(vertices[indices[i+2] * 3], vertices[indices[i+2] * 3 + 1], vertices[indices[i+2] * 3 + 2]);
190-
191-
if (ray_triangle_intersection(orig, dir, v0, v1, v2, t)) {
192-
return true;
192+
if (ray_triangle_intersection(orig, dir, v0, v1, v2, t_aux)) {
193+
if (t_aux < min_t) {
194+
min_t = t_aux;
195+
}
193196
}
194197
}
195-
return false;
198+
if (min_t != std::numeric_limits<float>::max()) {
199+
t = min_t;
200+
return true;
201+
}
202+
else {
203+
t = -1.0f;
204+
return false;
205+
}
196206
}
197207

198208
///////////////////////////////////////////////////////////////////////////////

NeonEngine/src/game_object.h

Lines changed: 84 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#pragma once
22

3+
#include "shader.h"
4+
#include "rendering.h"
5+
#include "model.h"
6+
37
#include <glm/glm.hpp>
48
#include <glm/gtc/matrix_transform.hpp>
59
#include <glm/gtc/type_ptr.hpp>
@@ -9,34 +13,95 @@ class GameObject {
913
int idx_loaded_models = -1;
1014
glm::vec3 position;
1115
glm::vec3 scale;
12-
glm::vec3 axis_rotation;
13-
float angle_rotation_degrees;
16+
glm::vec3 rotation;
1417
glm::mat4 model;
1518
glm::mat4 model_inv;
19+
glm::mat3 model_normals;
1620
glm::vec3 color;
1721
bool is_selected;
22+
std::vector<GameObject*> children_game_objects;
1823

19-
GameObject(int idx_loaded_models = 0, const glm::vec3& pos = glm::vec3(0.0f, 0.0f, 0.0f), const glm::vec3& scale = glm::vec3(1.0f, 1.0f, 1.0f),
20-
const glm::vec3& axis_rot = glm::vec3(1.0f, 0.0f, 0.0f), float angle = 0.0f,
21-
const glm::vec3& color = glm::vec3(0.0f, 0.0f, 0.0f), bool is_selected = false) {
24+
GameObject(int idx_loaded_models = 0, const glm::vec3& position = glm::vec3(0.0f, 0.0f, 0.0f), const glm::vec3& scale = glm::vec3(1.0f, 1.0f, 1.0f),
25+
const glm::vec3& rotation = glm::vec3(0.0f, 0.0f, 0.0f), const glm::vec3& color = glm::vec3(0.0f, 0.0f, 0.0f), bool is_selected = false) {
2226
this->idx_loaded_models = idx_loaded_models;
23-
this->position = pos;
27+
this->position = position;
2428
this->scale = scale;
25-
this->axis_rotation = axis_rot;
26-
this->angle_rotation_degrees = angle;
29+
this->rotation = rotation;
2730
this->color = color;
2831
this->is_selected = is_selected;
2932

30-
set_model_and_model_inv();
33+
set_model_matrices_standard();
34+
}
35+
36+
~GameObject() {
37+
for (int i = 0; i < children_game_objects.size(); i++) {
38+
delete children_game_objects[i];
39+
}
3140
}
3241

33-
void set_model_and_model_inv() {
42+
void set_model_matrices_standard() {
3443
model = glm::mat4(1.0f);
3544
model = glm::translate(model, position);
36-
model = glm::rotate(model, glm::radians(angle_rotation_degrees), axis_rotation);
45+
model = glm::rotate(model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
46+
model = glm::rotate(model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
47+
model = glm::rotate(model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
3748
model = glm::scale(model, scale);
3849

3950
model_inv = glm::inverse(model);
51+
52+
model_normals = glm::mat3(glm::transpose(model_inv));
53+
}
54+
55+
void set_model_matrices_type1(GameObject* parent) {
56+
model = glm::mat4(1.0f);
57+
model = glm::translate(model, parent->position);
58+
model = glm::rotate(model, glm::radians(parent->rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
59+
model = glm::rotate(model, glm::radians(parent->rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
60+
model = glm::rotate(model, glm::radians(parent->rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
61+
62+
model = glm::translate(model, position * parent->scale);
63+
model = glm::rotate(model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
64+
model = glm::rotate(model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
65+
model = glm::rotate(model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
66+
model = glm::scale(model, scale * parent->scale);
67+
68+
model_inv = glm::inverse(model);
69+
70+
model_normals = glm::mat3(glm::transpose(model_inv));
71+
}
72+
73+
void draw(Shader* shader, Rendering* rendering) {
74+
shader->setVec3("model_color", color);
75+
shader->setMat4("model", model);
76+
shader->setMat3("model_normals", model_normals);
77+
shader->setMat4("model_view_projection", rendering->projection * rendering->view * model);
78+
if (idx_loaded_models != -1) {
79+
rendering->loaded_models[idx_loaded_models]->draw(*shader, is_selected, rendering);
80+
}
81+
for (int i = 0; i < children_game_objects.size(); i++) {
82+
children_game_objects[i]->draw(shader, rendering);
83+
}
84+
}
85+
86+
bool intersected_ray(Rendering* rendering, const glm::vec3& ray_dir, const glm::vec3& camera_position, float& t) {
87+
glm::vec3 ray_dir_model = model_inv * glm::vec4(ray_dir, 0.0f);
88+
glm::vec3 ray_origin_model = model_inv * glm::vec4(camera_position, 1.0f);
89+
if (idx_loaded_models != -1 && rendering->loaded_models[idx_loaded_models]->intersected_ray(ray_origin_model, ray_dir_model, t)) {
90+
return true;
91+
}
92+
for (int i = 0; i < children_game_objects.size(); i++) {
93+
if (children_game_objects[i]->intersected_ray(rendering, ray_dir, camera_position, t)) {
94+
return true;
95+
}
96+
}
97+
return false;
98+
}
99+
100+
void set_select_state(bool is_game_obj_selected) {
101+
is_selected = is_game_obj_selected;
102+
for (int i = 0; i < children_game_objects.size(); i++) {
103+
children_game_objects[i]->set_select_state(is_game_obj_selected);
104+
}
40105
}
41106
};
42107

@@ -48,9 +113,9 @@ class Light : public GameObject {
48113

49114
Light() {}
50115

51-
Light(int idx_loaded_models, const glm::vec3& pos, const glm::vec3& scale, const glm::vec3& axis_rot, float angle, const glm::vec3& color, bool is_selected,
116+
Light(int idx_loaded_models, const glm::vec3& position, const glm::vec3& scale, const glm::vec3& rotation, const glm::vec3& color, bool is_selected,
52117
const glm::vec3& ambient, const glm::vec3& diffuse, const glm::vec3& specular)
53-
: GameObject(idx_loaded_models, pos, scale, axis_rot, angle, color, is_selected) {
118+
: GameObject(idx_loaded_models, position, scale, rotation, color, is_selected) {
54119
this->ambient = ambient;
55120
this->diffuse = diffuse;
56121
this->specular = specular;
@@ -63,9 +128,9 @@ class PointLight : public Light {
63128
float linear;
64129
float quadratic;
65130

66-
PointLight(int idx_loaded_models, const glm::vec3& pos, const glm::vec3& scale, const glm::vec3& axis_rot, float angle, const glm::vec3& color, bool is_selected,
131+
PointLight(int idx_loaded_models, const glm::vec3& position, const glm::vec3& scale, const glm::vec3& rotation, const glm::vec3& color, bool is_selected,
67132
const glm::vec3& ambient, const glm::vec3& diffuse, const glm::vec3& specular, float constant, float linear, float quadratic)
68-
: Light(idx_loaded_models, pos, scale, axis_rot, angle, color, is_selected, ambient, diffuse, specular) {
133+
: Light(idx_loaded_models, position, scale, rotation, color, is_selected, ambient, diffuse, specular) {
69134
this->constant = constant;
70135
this->linear = linear;
71136
this->quadratic = quadratic;
@@ -76,9 +141,9 @@ class DirectionalLight : public Light {
76141
public:
77142
glm::vec3 direction;
78143

79-
DirectionalLight(int idx_loaded_models, const glm::vec3& pos, const glm::vec3& scale, const glm::vec3& axis_rot, float angle, const glm::vec3& color, bool is_selected,
144+
DirectionalLight(int idx_loaded_models, const glm::vec3& position, const glm::vec3& scale, const glm::vec3& rotation, const glm::vec3& color, bool is_selected,
80145
const glm::vec3& ambient, const glm::vec3& diffuse, const glm::vec3& specular, const glm::vec3& direction)
81-
: Light(idx_loaded_models, pos, scale, axis_rot, angle, color, is_selected, ambient, diffuse, specular) {
146+
: Light(idx_loaded_models, position, scale, rotation, color, is_selected, ambient, diffuse, specular) {
82147
this->direction = direction;
83148
}
84149
};
@@ -94,10 +159,10 @@ class SpotLight : public Light {
94159
float linear;
95160
float quadratic;
96161

97-
SpotLight(int idx_loaded_models, const glm::vec3& pos, const glm::vec3& scale, const glm::vec3& axis_rot, float angle, const glm::vec3& color, bool is_selected,
162+
SpotLight(int idx_loaded_models, const glm::vec3& position, const glm::vec3& scale, const glm::vec3& rotation, const glm::vec3& color, bool is_selected,
98163
const glm::vec3& ambient, const glm::vec3& diffuse, const glm::vec3& specular, const glm::vec3& direction, float inner_cut_off, float outer_cut_off,
99164
float constant, float linear, float quadratic)
100-
: Light(idx_loaded_models, pos, scale, axis_rot, angle, color, is_selected, ambient, diffuse, specular) {
165+
: Light(idx_loaded_models, position, scale, rotation, color, is_selected, ambient, diffuse, specular) {
101166
this->direction = direction;
102167

103168
this->inner_cut_off = inner_cut_off;

NeonEngine/src/input.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ void Input::process_viewport_input() {
5252
int game_object_key = rendering->check_mouse_over_models();
5353
std::cout << "ENDED CHECKING" << std::endl;
5454
if (rendering->key_selected_object != -1) {
55-
rendering->game_objects[rendering->key_selected_object]->is_selected = false;
55+
rendering->game_objects[rendering->key_selected_object]->set_select_state(false);
5656
}
5757
if (game_object_key != -1) {
5858
std::cout << "FOUND INTERSECTION" << std::endl;
59-
rendering->game_objects[game_object_key]->is_selected = true;
59+
rendering->game_objects[game_object_key]->set_select_state(true);
6060
rendering->key_selected_object = game_object_key;
6161
std::cout << "INTERSECTION DETECTED: " << game_object_key << std::endl;
6262
}

NeonEngine/src/mesh.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,26 @@ class Mesh {
135135
}
136136

137137
bool intersected_ray(const glm::vec3& orig, const glm::vec3& dir, float& t) {
138+
float min_t = std::numeric_limits<float>::max();
139+
float t_aux;
138140
for (int i = 0; i < indices.size(); i += 3) {
139141
glm::vec3 v0 = vertices[i].Position;
140142
glm::vec3 v1 = vertices[i+1].Position;
141143
glm::vec3 v2 = vertices[i+2].Position;
142-
if (ray_triangle_intersection(orig, dir, v0, v1, v2, t)) {
143-
return true;
144+
if (ray_triangle_intersection(orig, dir, v0, v1, v2, t_aux)) {
145+
if (t_aux < min_t) {
146+
min_t = t_aux;
147+
}
144148
}
145149
}
146-
return false;
150+
if (min_t != std::numeric_limits<float>::max()) {
151+
t = min_t;
152+
return true;
153+
}
154+
else {
155+
t = -1.0f;
156+
return false;
157+
}
147158
}
148159

149160
private:

NeonEngine/src/rendering.cpp

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,7 @@ int Rendering::check_mouse_over_models() {
7474
float min_t = std::numeric_limits<float>::max();
7575
for (auto it = game_objects.begin(); it != game_objects.end(); it++) {
7676
GameObject* game_object = it->second;
77-
glm::vec3 ray_dir_model = game_object->model_inv * glm::vec4(ray_dir, 0.0f);
78-
glm::vec3 ray_origin_model = game_object->model_inv * glm::vec4(camera_viewport->Position, 1.0f);
79-
80-
/*
81-
if (game_object.idx_loaded_models != 0) {
82-
continue;
83-
}*/
84-
85-
if (loaded_models[game_object->idx_loaded_models]->intersected_ray(ray_origin_model, ray_dir_model, t)) {
77+
if (game_object->intersected_ray(this, ray_dir, camera_viewport->Position, t)) {
8678
if (t < min_t) {
8779
min_t = t;
8880
key_intersected_object = it->first;
@@ -104,39 +96,69 @@ void Rendering::initialize_game_objects() {
10496
int backpack1_key = key_generator->generate_key();
10597
game_objects[backpack1_key] = backpack1;
10698

107-
GameObject* backpack2 = new GameObject(0, glm::vec3(6.0f, 4.0f, -15.0f), glm::vec3(0.5f, 0.5f, 0.5f), glm::vec3(1.0f, 0.0f, 0.0f), 60.0f);
99+
GameObject* backpack2 = new GameObject(0, glm::vec3(6.0f, 4.0f, -15.0f), glm::vec3(0.5f, 0.5f, 0.5f), glm::vec3(60.0f, 0.0f, 0.0f));
108100
int backpack2_key = key_generator->generate_key();
109101
game_objects[backpack2_key] = backpack2;
110102

111-
GameObject* cylinder1 = new GameObject(1, glm::vec3(3.0f, 7.0f, -6.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(0.8f, 1.0f, 0.3f), 60.0f, glm::vec3(1.0f, 1.0f, 0.0f));
103+
GameObject* cylinder1 = new GameObject(1, glm::vec3(3.0f, 7.0f, -6.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(45.0f, 60.0f, 20.0f), glm::vec3(1.0f, 1.0f, 0.0f));
112104
int cylinder1_key = key_generator->generate_key();
113105
game_objects[cylinder1_key] = cylinder1;
114106

115-
GameObject* cone1 = new GameObject(2, glm::vec3(-3.0f, 7.0f, -6.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(1.0f, 0.0f, 0.0f), 0.0f, glm::vec3(0.0f, 1.0f, 0.0f));
107+
GameObject* cone1 = new GameObject(2, glm::vec3(-3.0f, 7.0f, -6.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
116108
int cone1_key = key_generator->generate_key();
117109
game_objects[cone1_key] = cone1;
118110

119-
GameObject* cylinder2 = new GameObject(1, glm::vec3(-3.0f, -7.0f, -6.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(1.0f, 0.0f, 0.0f), 0.0f, glm::vec3(0.0f, 0.0f, 1.0f));
111+
GameObject* cylinder2 = new GameObject(1, glm::vec3(-3.0f, -7.0f, -6.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
120112
int cylinder2_key = key_generator->generate_key();
121113
game_objects[cylinder2_key] = cylinder2;
122114

115+
116+
117+
GameObject* coord_axes_3D = new GameObject(-1, glm::vec3(0.0f, -3.0f, -3.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
118+
int coord_axes_3D_key = key_generator->generate_key();
119+
game_objects[coord_axes_3D_key] = coord_axes_3D;
120+
121+
GameObject* x_arrow_body = new GameObject(1, glm::vec3(0.0f, 0.0f, 1.5f), glm::vec3(0.1f, 0.1f, 3.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 0.0f, 0.0f));
122+
x_arrow_body->set_model_matrices_type1(coord_axes_3D);
123+
coord_axes_3D->children_game_objects.push_back(x_arrow_body);
123124

125+
GameObject* y_arrow_body = new GameObject(1, glm::vec3(0.0f, 1.5f, 0.0f), glm::vec3(0.1f, 0.1f, 3.0f), glm::vec3(90.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
126+
y_arrow_body->set_model_matrices_type1(coord_axes_3D);
127+
coord_axes_3D->children_game_objects.push_back(y_arrow_body);
128+
129+
GameObject* z_arrow_body = new GameObject(1, glm::vec3(1.5f, 0.0f, 0.0f), glm::vec3(0.1f, 0.1f, 3.0f), glm::vec3(0.0f, 90.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
130+
z_arrow_body->set_model_matrices_type1(coord_axes_3D);
131+
coord_axes_3D->children_game_objects.push_back(z_arrow_body);
132+
133+
GameObject* x_arrow_head = new GameObject(2, glm::vec3(0.0f, 0.0f, 3.0f), glm::vec3(0.3f, 0.3f, 0.6f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 0.0f, 0.0f));
134+
x_arrow_head->set_model_matrices_type1(coord_axes_3D);
135+
coord_axes_3D->children_game_objects.push_back(x_arrow_head);
136+
137+
GameObject* y_arrow_head = new GameObject(2, glm::vec3(0.0f, 3.0f, 0.0f), glm::vec3(0.3f, 0.3f, 0.6f), glm::vec3(-90.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
138+
y_arrow_head->set_model_matrices_type1(coord_axes_3D);
139+
coord_axes_3D->children_game_objects.push_back(y_arrow_head);
140+
141+
GameObject* z_arrow_head = new GameObject(2, glm::vec3(3.0f, 0.0f, 0.0f), glm::vec3(0.3f, 0.3f, 0.6f), glm::vec3(0.0f, 90.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
142+
z_arrow_head->set_model_matrices_type1(coord_axes_3D);
143+
coord_axes_3D->children_game_objects.push_back(z_arrow_head);
144+
145+
124146

125-
GameObject* point_light1 = new PointLight(1, glm::vec3(1.0f, 1.0f, -3.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(1.0f, 0.0f, 0.0f), 0.0f, glm::vec3(1.0f, 1.0f, 1.0f), false,
147+
GameObject* point_light1 = new PointLight(1, glm::vec3(1.0f, 1.0f, -3.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), false,
126148
glm::vec3(0.05f, 0.05f, 0.05f), glm::vec3(0.8f, 0.8f, 0.8f), glm::vec3(1.0f, 1.0f, 1.0f), 1.0f, 0.045f, 0.0075f);
127149
int point_light1_key = key_generator->generate_key();
128150
game_objects[point_light1_key] = point_light1;
129151
point_lights[point_light1_key] = (PointLight*)point_light1;
130152

131153

132-
GameObject* directional_light1 = new DirectionalLight(1, glm::vec3(-5.0f, 5.0f, -3.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(1.0f, 0.0f, 0.0f), 0.0f, glm::vec3(1.0f, 1.0f, 1.0f), false,
154+
GameObject* directional_light1 = new DirectionalLight(1, glm::vec3(-5.0f, 5.0f, -3.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), false,
133155
glm::vec3(0.05f, 0.05f, 0.05f), glm::vec3(0.4f, 0.4f, 0.4f), glm::vec3(0.8f, 0.8f, 0.8f), glm::vec3(3.0f, -4.0f, -3.0f));
134156
int directional_light1_key = key_generator->generate_key();
135157
game_objects[directional_light1_key] = directional_light1;
136158
directional_lights[directional_light1_key] = (DirectionalLight*)directional_light1;
137159

138160

139-
GameObject* spot_light1 = new SpotLight(1, glm::vec3(-5.0f, -5.0f, -3.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(1.0f, 0.0f, 0.0f), 0.0f, glm::vec3(1.0f, 1.0f, 1.0f), false,
161+
GameObject* spot_light1 = new SpotLight(1, glm::vec3(-5.0f, -5.0f, -3.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), false,
140162
glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(5.0f, 5.0f, -3.0f),
141163
glm::cos(glm::radians(12.5f)), glm::cos(glm::radians(15.0f)), 1.0f, 0.09f, 0.032f);
142164
int spot_light1_key = key_generator->generate_key();
@@ -208,11 +230,7 @@ void Rendering::render_viewport() {
208230
// render all the game objects
209231
for (auto it = game_objects.begin(); it != game_objects.end(); it++) {
210232
GameObject* game_object = it->second;
211-
ourShader->setVec3("model_color", game_object->color);
212-
ourShader->setMat4("model", game_object->model);
213-
ourShader->setMat3("model_normals", glm::mat3(glm::transpose(glm::inverse(game_object->model))));
214-
ourShader->setMat4("model_view_projection", projection * view * game_object->model);
215-
loaded_models[game_object->idx_loaded_models]->draw(*ourShader, game_object->is_selected, this);
233+
game_object->draw(ourShader, this);
216234
}
217235

218236
glBindFramebuffer(GL_FRAMEBUFFER, 0);

0 commit comments

Comments
 (0)