-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_object.cpp
More file actions
55 lines (38 loc) · 1.58 KB
/
game_object.cpp
File metadata and controls
55 lines (38 loc) · 1.58 KB
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
#include <glm/gtc/matrix_transform.hpp>
#include "game_object.h"
#include "collision.h"
namespace game {
GameObject::GameObject(const glm::vec3 &position, GLuint texture, GLint num_elements, bool collidable, float radius)
{
// Initialize all attributes
position_ = position;
scale_ = 1.0;
velocity_ = glm::vec3(0.0f, 0.0f, 0.0f); // Starts out stationary
num_elements_ = num_elements;
texture_ = texture;
collidable_ = collidable;
radius_ = radius;
rotation_ = 0.0f;
//name_ = name;
dead_ = false;
}
void GameObject::Update(double delta_time) {
// Update object position with Euler integration
position_ += velocity_ * ((float) delta_time);
}
void GameObject::Render(Shader &shader, double current_time) {
// Bind the entity's texture
glBindTexture(GL_TEXTURE_2D, texture_);
// Setup the scaling matrix for the shader
glm::mat4 scaling_matrix = glm::scale(glm::mat4(1.0f), glm::vec3(scale_, scale_, 1.0));
// Set up the translation matrix for the shader
glm::mat4 translation_matrix = glm::translate(glm::mat4(1.0f), position_);
glm::mat4 rotation_matrix = glm::rotate(glm::mat4(1.0f), rotation_, glm::vec3(0.0f, 0.0f, 1.0f));
// Setup the transformation matrix for the shader
glm::mat4 transformation_matrix = translation_matrix * rotation_matrix * scaling_matrix;
// Set the transformation matrix in the shader
shader.SetUniformMat4("transformation_matrix", transformation_matrix);
// Draw the entity
glDrawElements(GL_TRIANGLES, num_elements_, GL_UNSIGNED_INT, 0);
}
} // namespace game