Changeset fe5e3ca in opengl-game


Ignore:
Timestamp:
Jan 11, 2019, 4:10:11 PM (6 years ago)
Author:
dportnoy15 <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
646f3f2, c5fb958
Parents:
8fbd34f
Message:

Apply the model, view, and projection matrices to explosions

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • explosion.vert

    r8fbd34f rfe5e3ca  
    11#version 410 core
    22
    3 // TODO: Pass the explosion center in as a uniform
     3#define MAX_NUM_OBJECTS 1024
     4
     5uniform mat4 view, proj;
     6uniform mat4 model_mat;
     7
     8/*
     9layout (std140) uniform models {
     10  mat4 model_mats[MAX_NUM_OBJECTS];
     11};
     12*/
    413
    514uniform float explosion_start_time;
     
    817layout (location = 0) in vec3 v_i; // initial velocity
    918layout (location = 1) in float start_time;
     19//layout(location = 2) in uint ubo_index;
    1020
    1121out float opacity;
     
    3343   p += normalize(v_i) * mod(t, duration) / duration * 0.3; // allow time to loop around so particle emitter keeps going
    3444
    35    gl_Position = vec4(p, 1.0);
     45   //gl_Position = proj * view * model_mats[0] * vec4(p, 1.0);
     46   gl_Position = proj * view * model_mat * vec4(p, 1.0);
    3647   gl_PointSize = 15.0; // size in pixels
    3748}
  • new-game.cpp

    r8fbd34f rfe5e3ca  
    157157                  GLuint* model_mat_idx_vbo);
    158158
    159 GLuint initializeParticleEffectBuffers();
     159GLuint initializeParticleEffectBuffers(vec3 origin, mat4 proj, mat4 view, GLuint explosion_sp);
    160160
    161161void populateBuffers(vector<SceneObject*>& objects,
     
    565565   glVertexAttribIPointer(2, 1, GL_UNSIGNED_INT, 0, 0);
    566566
    567    GLuint explosion_vao = initializeParticleEffectBuffers();
    568 
    569567   float cam_speed = 1.0f;
    570568   float cam_yaw_speed = 60.0f*ONE_DEG_IN_RAD;
     
    598596   };
    599597   proj_mat = make_mat4(proj_arr);
     598
     599   GLuint explosion_vao = initializeParticleEffectBuffers(vec3(0.0f, -1.2f, 0.65f), proj_mat, view_mat, explosion_sp);
    600600
    601601   GLuint ub_binding_point = 0;
     
    19121912}
    19131913
    1914 GLuint initializeParticleEffectBuffers() {
     1914GLuint initializeParticleEffectBuffers(vec3 origin, mat4 proj, mat4 view, GLuint explosion_sp) {
     1915   //unsigned int num_explosions = 1;
     1916
    19151917   float vv[EXPLOSION_PARTICLE_COUNT * 3]; // initial velocities vec3
    19161918   float vt[EXPLOSION_PARTICLE_COUNT]; // initial times
     
    19271929      vv[i*3 + 2] = 0.0f;
    19281930   }
     1931
     1932   mat4 model_mat = translate(mat4(1.0f), origin);
     1933
     1934   glUseProgram(explosion_sp);
     1935
     1936   GLuint proj_mat_loc = glGetUniformLocation(explosion_sp, "proj");
     1937   GLuint view_mat_loc = glGetUniformLocation(explosion_sp, "view");
     1938
     1939   glUniformMatrix4fv(proj_mat_loc, 1, GL_FALSE, value_ptr(proj));
     1940   glUniformMatrix4fv(view_mat_loc, 1, GL_FALSE, value_ptr(view));
     1941
     1942   GLuint model_mat_loc = glGetUniformLocation(explosion_sp, "model_mat");
     1943
     1944   glUniformMatrix4fv(model_mat_loc, 1, GL_FALSE, value_ptr(model_mat));
     1945
     1946   /*
     1947   GLuint model_ubo = 0;
     1948   glGenBuffers(1, &model_ubo);
     1949
     1950   glBindBuffer(GL_UNIFORM_BUFFER, model_ubo);
     1951   glBufferData(GL_UNIFORM_BUFFER, num_explosions * sizeof(mat4), NULL, GL_DYNAMIC_DRAW);
     1952
     1953   //glBindBuffer(GL_UNIFORM_BUFFER, ubo);
     1954   glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(mat4), value_ptr(model_mat));
     1955   */
    19291956
    19301957   GLuint velocity_vbo;
Note: See TracChangeset for help on using the changeset viewer.