13 this->number = number;
14 position.resize(number);
15 velocity.resize(number);
16 lifetime.resize(number);
17 indices.resize(number);
18 for(
unsigned int i = 0; i < number; i++) {
21 pos_buf = mesh.attach_vertex_buffer(position, GL_STREAM_DRAW);
22 vel_buf = mesh.attach_vertex_buffer(velocity, GL_STREAM_DRAW);
23 life_buf = mesh.attach_vertex_buffer(lifetime, GL_STREAM_DRAW);
24 mesh.attach_index_buffer(indices);
25 mesh.set_vertex_attribute(
"position_in", pos_buf, 3, GL_FLOAT, 0, 0);
26 mesh.set_vertex_attribute(
"velocity_in", vel_buf, 3, GL_FLOAT, 0, 0);
27 mesh.set_vertex_attribute(
"lifetime_in", life_buf, 2, GL_FLOAT, 0, 0);
54 float time = (float)timer.get_time_s();
55 for(
unsigned int i = 0; i < number; i++) {
56 if(this->lifetime[i][0] + this->lifetime[i][1] < time) {
57 this->position[i] = position;
58 this->velocity[i] = velocity;
59 this->lifetime[i] = glm::vec2(time, lifetime);
70 float time = (float)timer.get_time_s();
71 for(
unsigned int i = 0; i < number; i++) {
72 if(this->lifetime[i][0] + this->lifetime[i][1] < time) {
73 this->position[i] = position;
74 this->velocity[i] = velocity;
75 this->lifetime[i] = glm::vec2(time, lifetime);
76 mesh.replace_partial_data(pos_buf, i *
sizeof(glm::vec3), &this->position[i], 1);
77 mesh.replace_partial_data(vel_buf, i *
sizeof(glm::vec3), &this->velocity[i], 1);
78 mesh.replace_partial_data(life_buf, i *
sizeof(glm::vec2), &this->lifetime[i], 1);
79 mesh.set_vertex_attribute(
"position_in", pos_buf, 3, GL_FLOAT, 0, 0);
80 mesh.set_vertex_attribute(
"velocity_in", vel_buf, 3, GL_FLOAT, 0, 0);
81 mesh.set_vertex_attribute(
"lifetime_in", life_buf, 2, GL_FLOAT, 0, 0);
89 mesh.replace_buffer_data(pos_buf, position);
90 mesh.replace_buffer_data(vel_buf, velocity);
91 mesh.replace_buffer_data(life_buf, lifetime);
92 mesh.set_vertex_attribute(
"position_in", pos_buf, 3, GL_FLOAT, 0, 0);
93 mesh.set_vertex_attribute(
"velocity_in", vel_buf, 3, GL_FLOAT, 0, 0);
94 mesh.set_vertex_attribute(
"lifetime_in", life_buf, 2, GL_FLOAT, 0, 0);
bool add_particle_immediately(glm::vec3 position, glm::vec3 velocity, float lifetime)
Adds a new particle to the system if the particle buffer has an empty space and immediately updates t...
void setup_camera(sgltk::Camera *camera)
Sets up the view and projection matrices that will be used to render the particles.
void setup_shader(sgltk::Shader *shader)
Specifies the shader to use to render the particles.
void attach_texture(const std::string &name, const sgltk::Texture &texture)
Attaches a texture to the particles.
bool add_particle(glm::vec3 position, glm::vec3 velocity, float lifetime)
Adds a new particle to the system if the particle buffer has an empty space.
void update_all()
Updates the particle buffers.
void resize(unsigned int number)
Sets the number of the particles in the system.