-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparticle_system.cpp
More file actions
63 lines (44 loc) · 2.39 KB
/
particle_system.cpp
File metadata and controls
63 lines (44 loc) · 2.39 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
56
57
58
59
60
61
62
63
#define GLM_FORCE_RADIANS
#include <glm/gtc/matrix_transform.hpp>
#include "particle_system.h"
namespace game {
ParticleSystem::ParticleSystem(const glm::vec3& position, GLuint texture,int num_elements, GameObject* parent)
: GameObject(position, texture, num_elements, false, 1) {
parent_ = parent;
}
void ParticleSystem::Update(double delta_time) {
// Call the parent's update method to move the object in standard way, if desired
GameObject::Update(delta_time);
}
void ParticleSystem::Render(Shader& shader, double current_time) {
// Bind the particle texture
glBindTexture(GL_TEXTURE_2D, texture_);
// Set up the shader
shader.Enable();
shader.SetParticleAttributes();
// Setup the scaling matrix for the shader
glm::mat4 scaling_matrix = glm::scale(glm::mat4(1.0f), glm::vec3(scale_, scale_, 1.0));
// Setup the rotation matrix for the shader
glm::mat4 rotation_matrix = glm::rotate(glm::mat4(1.0f), rotation_, glm::vec3(0.0, 0.0, 1.0));
// Set up the translation matrix for the shader
glm::mat4 translation_matrix = glm::translate(glm::mat4(1.0f), position_);
// Set up the parent transformation matrix
glm::mat4 parent_rotation_matrix = glm::rotate(glm::mat4(1.0f), parent_->GetRotation(), glm::vec3(0.0, 0.0, 1.0));
glm::mat4 parent_translation_matrix = glm::translate(glm::mat4(1.0f), parent_->GetPosition());
glm::mat4 parent_transformation_matrix = parent_translation_matrix * parent_rotation_matrix;
// Setup the transformation matrix for the shader
glm::mat4 transformation_matrix = parent_transformation_matrix * translation_matrix * rotation_matrix * scaling_matrix;
// Set the transformation matrix in the shader
shader.SetUniformMat4("transformation_matrix", transformation_matrix);
// Set the time in the shader
shader.SetUniform1f("time", current_time);
// Draw the entity
glDrawElements(GL_TRIANGLES, shader.GetParticleSize(), GL_UNSIGNED_INT, 0);
}
bool ParticleSystem::ValidCollision(GameObject* other_game_object, double deltatime) {
return false;
}
bool ParticleSystem::HandleCollision(GameObject* other_game_object, double deltatime) {
return false;
}
} // namespace game