Changeset 7e10667 in opengl-game for new-game.cpp


Ignore:
Timestamp:
May 3, 2019, 7:53:55 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
c55614a
Parents:
dc19a39
git-author:
Dmitry Portnoy <dmitry.portnoy@…> (05/03/19 19:53:42)
git-committer:
Dmitry Portnoy <dmitry.portnoy@…> (05/03/19 19:53:55)
Message:

Finish switching to the new model group rendering algorithm for TYPE_EXPLOSION objects

File:
1 edited

Legend:

Unmodified
Added
Removed
  • new-game.cpp

    rdc19a39 r7e10667  
    3232#include <map>
    3333
     34#include "utils.h"
     35
    3436using namespace std;
    3537using namespace glm;
     
    7577   unsigned int id;
    7678   ObjectType type;
     79   bool deleted;
    7780
    7881   // Currently, model_transform should only have translate, and rotation and scale need to be done in model_base since
     
    9093   vector<GLfloat> texcoords;
    9194   vector<GLfloat> normals;
    92    bool deleted;
    9395   vec3 bounding_center;
    9496   GLfloat bounding_radius;
     
    106108   vector<GLfloat> particleVelocities;
    107109   vector<GLfloat> particleTimes;
     110   GLfloat startTime;
     111   GLfloat duration;
    108112};
    109113
     
    127131
    128132struct BufferInfo {
    129    unsigned int vbo_base;
    130133   unsigned int ubo_base;
    131134   unsigned int ubo_offset;
     
    182185unsigned char* loadImage(string file_name, int* x, int* y);
    183186
    184 void printVector(string label, vec3& v);
    185 void print4DVector(string label, vec4& v);
     187void printVec3(string label, const vec3& v);
     188void printVec4(string label, const vec4& v);
     189void printMat4(string label, const mat4& m);
    186190
    187191void initObject(SceneObject* obj);
     
    228232Asteroid* createAsteroid(vec3 pos);
    229233Laser* createLaser(vec3 start, vec3 end, vec3 color, GLfloat width);
    230 ParticleEffect* createExplosion();
     234ParticleEffect* createExplosion(mat4 model_mat);
    231235
    232236void translateLaser(Laser* laser, const vec3& translation, GLuint ubo);
     
    237241void renderMainMenuGui();
    238242
    239 void renderScene(map<GLuint, BufferInfo>& shaderBufferInfo,
    240                   map<ObjectType, ShaderModelGroup>& modelGroups, GLuint ubo);
    241 
     243void renderScene(map<ObjectType, ShaderModelGroup>& modelGroups, GLuint ubo);
    242244void renderSceneGui(map<string, vector<UIValue>> valueLists);
    243245
     
    287289Laser* rightLaser = NULL;
    288290EffectOverTime* rightLaserEffect = NULL;
    289 
    290 SceneObject* objExplosion;
    291291
    292292map<string, vector<UIValue>> valueLists;
     
    488488
    489489   defineModelGroupAttrib(modelGroups[TYPE_SHIP], "vertex_position", ATTRIB_POINT_VARYING,
    490       3, GL_FLOAT, offsetof(SceneObject, points));
     490      3, GL_FLOAT, offset_of(&SceneObject::points));
    491491   defineModelGroupAttrib(modelGroups[TYPE_SHIP], "vertex_color", ATTRIB_POINT_VARYING,
    492       3, GL_FLOAT, offsetof(SceneObject, colors));
     492      3, GL_FLOAT, offset_of(&SceneObject::colors));
    493493   defineModelGroupAttrib(modelGroups[TYPE_SHIP], "vertex_normal", ATTRIB_POINT_VARYING,
    494       3, GL_FLOAT, offsetof(SceneObject, normals));
     494      3, GL_FLOAT, offset_of(&SceneObject::normals));
    495495   defineModelGroupAttrib(modelGroups[TYPE_SHIP], "ubo_index", ATTRIB_OBJECT_VARYING,
    496       1, GL_UNSIGNED_INT, offsetof(SceneObject, ubo_offset));
     496      1, GL_UNSIGNED_INT, offset_of(&SceneObject::ubo_offset));
    497497
    498498   defineModelGroupUniform(modelGroups[TYPE_SHIP], "view", ATTRIB_UNIFORM,
     
    508508
    509509   defineModelGroupAttrib(modelGroups[TYPE_ASTEROID], "vertex_position", ATTRIB_POINT_VARYING,
    510       3, GL_FLOAT, offsetof(SceneObject, points));
     510      3, GL_FLOAT, offset_of(&SceneObject::points));
    511511   defineModelGroupAttrib(modelGroups[TYPE_ASTEROID], "vertex_color", ATTRIB_POINT_VARYING,
    512       3, GL_FLOAT, offsetof(SceneObject, colors));
     512      3, GL_FLOAT, offset_of(&SceneObject::colors));
    513513   defineModelGroupAttrib(modelGroups[TYPE_ASTEROID], "vertex_normal", ATTRIB_POINT_VARYING,
    514       3, GL_FLOAT, offsetof(SceneObject, normals));
     514      3, GL_FLOAT, offset_of(&SceneObject::normals));
    515515   defineModelGroupAttrib(modelGroups[TYPE_ASTEROID], "ubo_index", ATTRIB_OBJECT_VARYING,
    516       1, GL_UNSIGNED_INT, offsetof(SceneObject, ubo_offset));
     516      1, GL_UNSIGNED_INT, offset_of(&SceneObject::ubo_offset));
    517517
    518518   defineModelGroupUniform(modelGroups[TYPE_ASTEROID], "view", ATTRIB_UNIFORM,
     
    528528
    529529   defineModelGroupAttrib(modelGroups[TYPE_LASER], "vertex_position", ATTRIB_POINT_VARYING,
    530       3, GL_FLOAT, offsetof(SceneObject, points));
     530      3, GL_FLOAT, offset_of(&SceneObject::points));
    531531   defineModelGroupAttrib(modelGroups[TYPE_LASER], "vt", ATTRIB_POINT_VARYING,
    532       2, GL_FLOAT, offsetof(SceneObject, texcoords));
     532      2, GL_FLOAT, offset_of(&SceneObject::texcoords));
    533533   defineModelGroupAttrib(modelGroups[TYPE_LASER], "ubo_index", ATTRIB_OBJECT_VARYING,
    534       1, GL_UNSIGNED_INT, offsetof(SceneObject, ubo_offset));
     534      1, GL_UNSIGNED_INT, offset_of(&SceneObject::ubo_offset));
    535535
    536536   defineModelGroupUniform(modelGroups[TYPE_LASER], "view", ATTRIB_UNIFORM,
     
    547547   shaderBufferInfo[modelGroups[TYPE_EXPLOSION].shaderProgram] = BufferInfo(); // temporary
    548548
    549    // The last parameter (offset) is only used for populating the buffers since the distance
    550    // between each item is needed there. However, the explosion vbos are populated using different
    551    // code anyway and don't use that argument, so I may as well pass in 0 here.
    552549   defineModelGroupAttrib(modelGroups[TYPE_EXPLOSION], "v_i", ATTRIB_POINT_VARYING,
    553       3, GL_FLOAT, 0);
     550      3, GL_FLOAT, offset_of(&ParticleEffect::particleVelocities));
    554551   defineModelGroupAttrib(modelGroups[TYPE_EXPLOSION], "start_time", ATTRIB_POINT_VARYING,
    555       1, GL_FLOAT, 0);
     552      1, GL_FLOAT, offset_of(&ParticleEffect::particleTimes));
    556553   defineModelGroupAttrib(modelGroups[TYPE_EXPLOSION], "ubo_index", ATTRIB_OBJECT_VARYING,
    557       1, GL_UNSIGNED_INT, offsetof(SceneObject, ubo_offset));
    558 
    559    defineModelGroupUniform(modelGroups[TYPE_EXPLOSION], "explosion_start_time", ATTRIB_UNIFORM,
    560       1, UNIFORM_1F, &curTime);
     554      1, GL_UNSIGNED_INT, offset_of(&SceneObject::ubo_offset));
     555
    561556   defineModelGroupUniform(modelGroups[TYPE_EXPLOSION], "cur_time", ATTRIB_UNIFORM,
    562557      1, UNIFORM_1F, &curTime);
     
    577572   vector<SceneObject>::iterator obj_it;
    578573
    579    populateBuffers(objects,
    580       shaderBufferInfo, modelGroups,
    581       ubo);
     574   populateBuffers(objects, shaderBufferInfo, modelGroups, ubo);
    582575
    583576   float cam_speed = 1.0f;
     
    613606   proj_mat = make_mat4(proj_arr);
    614607
    615    initializeParticleEffectBuffers(shaderBufferInfo, modelGroups, ubo);
    616 
    617608   /* TODO: Fix the UBO binding code based on the following forum post (in order to support multiple ubos):
     609      (Also, I bookmarked a great explanation of this under )
    618610
    619611      No, you're misunderstanding how this works. UBO binding works exactly like texture object binding.
     
    689681
    690682   glUseProgram(modelGroups[TYPE_EXPLOSION].shaderProgram);
     683   bindUniformData(modelGroups[TYPE_EXPLOSION].attribs["view"]);
     684   bindUniformData(modelGroups[TYPE_EXPLOSION].attribs["proj"]);
     685
    691686   glUniformBlockBinding(modelGroups[TYPE_EXPLOSION].shaderProgram, explosion_sp_models_ub_index, ub_binding_point);
    692687   glBindBufferRange(GL_UNIFORM_BUFFER, ub_binding_point, ubo, 0, GL_MAX_UNIFORM_BLOCK_SIZE);
     
    843838         // this code moves the asteroids
    844839         for (unsigned int i = 0; i < objects.size(); i++) {
    845             if (objects[i]->type == TYPE_ASTEROID && !objects[i]->deleted) {
    846                transformObject(*objects[i], translate(mat4(1.0f), vec3(0.0f, 0.0f, 0.04f)), ubo);
    847 
    848                vec3 obj_center = vec3(view_mat * vec4(objects[i]->bounding_center, 1.0f));
    849 
    850                if ((obj_center.z - objects[i]->bounding_radius) > -NEAR_CLIP) {
    851                   removeObjectFromScene(*objects[i], ubo);
    852                }
    853                if (((Asteroid*)objects[i])->hp <= 0) {
    854                   // TODO: Optimize this so I don't recalculate the camera rotation every time
    855                   float cam_pitch = -50.0f * 2.0f * 3.14159f / 360.0f;
    856                   mat4 pitch_mat = rotate(mat4(1.0f), cam_pitch, vec3(1.0f, 0.0f, 0.0f));
    857                   mat4 model_mat = translate(mat4(1.0f), objects[i]->bounding_center + vec3(0.0f, 0.0f, 0.0f)) * pitch_mat;
    858 
    859                   removeObjectFromScene(*objects[i], ubo);
    860                   score++;
    861 
    862                   objExplosion->model_mat = model_mat;
    863 
    864                   // initiate an explosion
    865                   glUseProgram(modelGroups[TYPE_EXPLOSION].shaderProgram);
    866 
    867                   bindUniformData(modelGroups[TYPE_EXPLOSION].attribs["explosion_start_time"]);
    868 
    869                   glBindBuffer(GL_UNIFORM_BUFFER, ubo);
    870                   glBufferSubData(GL_UNIFORM_BUFFER, objExplosion->ubo_offset * sizeof(mat4), sizeof(mat4), value_ptr(objExplosion->model_mat));
     840            if (!objects[i]->deleted) {
     841               if (objects[i]->type == TYPE_ASTEROID) {
     842                  transformObject(*objects[i], translate(mat4(1.0f), vec3(0.0f, 0.0f, 0.04f)), ubo);
     843
     844                  vec3 obj_center = vec3(view_mat * vec4(objects[i]->bounding_center, 1.0f));
     845
     846                  if ((obj_center.z - objects[i]->bounding_radius) > -NEAR_CLIP) {
     847                     removeObjectFromScene(*objects[i], ubo);
     848                  }
     849                  if (((Asteroid*)objects[i])->hp <= 0) {
     850                     // TODO: Optimize this so I don't recalculate the camera rotation every time
     851                     float cam_pitch = -50.0f * 2.0f * 3.14159f / 360.0f;
     852                     mat4 pitch_mat = rotate(mat4(1.0f), cam_pitch, vec3(1.0f, 0.0f, 0.0f));
     853                     mat4 model_mat = translate(mat4(1.0f), objects[i]->bounding_center) * pitch_mat;
     854
     855                     removeObjectFromScene(*objects[i], ubo);
     856                     score++;
     857
     858                     addObjectToScene(createExplosion(model_mat), shaderBufferInfo, modelGroups, ubo);
     859                  }
     860               } else if (objects[i]->type == TYPE_EXPLOSION) {
     861                  ParticleEffect* explosion = (ParticleEffect*)objects[i];
     862                  if (glfwGetTime() >= explosion->startTime + explosion->duration) {
     863                     removeObjectFromScene(*objects[i], ubo);
     864                  }
    871865               }
    872866            }
     
    971965            break;
    972966         case STATE_GAME:
    973             renderScene(shaderBufferInfo, modelGroups, ubo);
     967            renderScene(modelGroups, ubo);
    974968            renderSceneGui(valueLists);
    975969            break;
     
    12771271}
    12781272
    1279 void printVector(string label, vec3& v) {
     1273void printVec3(string label, const vec3& v) {
    12801274   cout << label << " -> (" << v.x << "," << v.y << "," << v.z << ")" << endl;
    12811275}
    12821276
    1283 void print4DVector(string label, vec4& v) {
     1277void printVec4(string label, const vec4& v) {
    12841278   cout << label << " -> (" << v.x << "," << v.y << "," << v.z << "," << v.w << ")" << endl;
    12851279}
    12861280
     1281void printMat4(string label, const mat4& m) {
     1282   cout << label << ": " << endl;
     1283   cout << "[ " << m[0][0] << " " << m[1][0] << " " << m[2][0] << " " << m[3][0] <<  " ]" << endl;
     1284   cout << "[ " << m[0][1] << " " << m[1][1] << " " << m[2][1] << " " << m[3][1] <<  " ]" << endl;
     1285   cout << "[ " << m[0][2] << " " << m[1][2] << " " << m[2][2] << " " << m[3][2] <<  " ]" << endl;
     1286   cout << "[ " << m[0][3] << " " << m[1][3] << " " << m[2][3] << " " << m[3][3] <<  " ]" << endl;
     1287}
     1288
     1289// TODO: Pass a reference, not a pointer
    12871290void initObject(SceneObject* obj) {
    1288    // Each objects must have at least 3 points, so the size of
    1289    // the points array must be a positive multiple of 9
    1290    if (obj->points.size() == 0 || (obj->points.size() % 9) != 0) {
    1291       // TODO: Maybe throw some kind of error here instead
    1292       return;
    1293    }
    1294 
    12951291   obj->id = objects.size(); // currently unused
    12961292   obj->num_points = obj->points.size() / 3;
     
    13211317}
    13221318
     1319// TODO: Check if I can pass in a reference to obj instead (do this for all other functions as well)
    13231320void addObjectToScene(SceneObject* obj,
    13241321   map<GLuint, BufferInfo>& shaderBufferInfo,
     
    13311328   // Check if the buffers aren't large enough to fit the new object and, if so, call
    13321329   // populateBuffers() to resize and repopupulate them
    1333    if (modelGroups[obj->type].vboCapacity < (modelGroups[obj->type].numPoints + obj->num_points) ||
    1334       bufferInfo->ubo_capacity < (bufferInfo->ubo_offset + 1)) {
     1330   if ((modelGroups[obj->type].vboCapacity < (modelGroups[obj->type].numPoints + obj->num_points) ||
     1331      bufferInfo->ubo_capacity <= bufferInfo->ubo_offset)) {
    13351332
    13361333      if (leftLaser != NULL && leftLaser->deleted) {
     
    13561353}
    13571354
     1355// TODO: Pass a reference, not a pointer
    13581356void calculateObjectBoundingBox(SceneObject* obj) {
    13591357   GLfloat min_x = obj->points[0];
     
    20252023}
    20262024
    2027 void initializeParticleEffectBuffers(map<GLuint, BufferInfo>& shaderBufferInfo,
    2028                   map<ObjectType, ShaderModelGroup>& modelGroups,
    2029                   GLuint ubo) {
    2030    float vv[EXPLOSION_PARTICLE_COUNT * 3]; // initial velocities vec3
    2031    float vt[EXPLOSION_PARTICLE_COUNT]; // initial times
    2032    float t_accum = 0.0f; // start time
    2033 
    2034    for (int i = 0; i < EXPLOSION_PARTICLE_COUNT; i++) {
    2035       vt[i] = t_accum;
    2036       t_accum += 0.01f;
    2037 
    2038       float randx = ((float)rand() / (float)RAND_MAX) - 0.5f;
    2039       float randy = ((float)rand() / (float)RAND_MAX) - 0.5f;
    2040       vv[i*3] = randx;
    2041       vv[i*3 + 1] = randy;
    2042       vv[i*3 + 2] = 0.0f;
    2043    }
    2044 
    2045    glUseProgram(modelGroups[TYPE_EXPLOSION].shaderProgram);
    2046 
    2047    bindUniformData(modelGroups[TYPE_EXPLOSION].attribs["proj"]);
    2048    bindUniformData(modelGroups[TYPE_EXPLOSION].attribs["view"]);
    2049 
    2050    // the glBufferData calls need to stay here while the corresponding arrays
    2051    // are local to this function. Once they're made part of the explosion object, I might be able
    2052    // to move this code out of here
    2053 
    2054    glBindBuffer(GL_ARRAY_BUFFER, modelGroups[TYPE_EXPLOSION].attribs["v_i"].buffer);
    2055    glBufferData(GL_ARRAY_BUFFER, sizeof(vv), vv, GL_STATIC_DRAW);
    2056 
    2057    glBindBuffer(GL_ARRAY_BUFFER, modelGroups[TYPE_EXPLOSION].attribs["start_time"].buffer);
    2058    glBufferData(GL_ARRAY_BUFFER, sizeof(vt), vt, GL_STATIC_DRAW);
    2059 
    2060    // TODO: createExplosion should take the velocities and times as arguments and copy them to the explosion object
    2061    // That way, this function could maybe be called every time a new explosion is created
    2062    objExplosion = createExplosion();
    2063    addObjectToScene(objExplosion, shaderBufferInfo, modelGroups, ubo);
    2064 }
    2065 
    20662025void populateBuffers(vector<SceneObject*>& objects,
    20672026                  map<GLuint, BufferInfo>& shaderBufferInfo,
     
    21222081      // When populating the buffers, leave as much empty space as space taken up by existing objects
    21232082      // to allow new objects to be added without immediately having to resize the buffers
    2124       shaderBufferInfo[shaderCountIt->first].vbo_base = lastShaderCount * 2;
    21252083      shaderBufferInfo[shaderCountIt->first].ubo_base = lastShaderUboCount * 2;
    21262084
     
    21882146         glBufferData(GL_ARRAY_BUFFER, smg->vboCapacity * GLsizeof(attrib->type) * attrib->size, NULL, GL_DYNAMIC_DRAW);
    21892147      } else if (modelGroupIt->first == TYPE_EXPLOSION) {
     2148         attrib = &smg->attribs["v_i"];
     2149         glBindBuffer(GL_ARRAY_BUFFER, attrib->buffer);
     2150         glBufferData(GL_ARRAY_BUFFER, smg->vboCapacity * GLsizeof(attrib->type) * attrib->size, NULL, GL_DYNAMIC_DRAW);
     2151
     2152         attrib = &smg->attribs["start_time"];
     2153         glBindBuffer(GL_ARRAY_BUFFER, attrib->buffer);
     2154         glBufferData(GL_ARRAY_BUFFER, smg->vboCapacity * GLsizeof(attrib->type) * attrib->size, NULL, GL_DYNAMIC_DRAW);
     2155
    21902156         attrib = &smg->attribs["ubo_index"];
    21912157         glBindBuffer(GL_ARRAY_BUFFER, attrib->buffer);
    21922158         glBufferData(GL_ARRAY_BUFFER, smg->vboCapacity * GLsizeof(attrib->type) * attrib->size, NULL, GL_DYNAMIC_DRAW);
    21932159      }
    2194 
    2195       // TODO: I could move the glBufferData calls for explosions here and call glBufferSubData in copyObjectDataToBuffers
    2196       // To make this work, I would need to store the explosion points and times in the explosion object so I could then copy
    2197       // them to the buffers.
    2198       // Also, confirm that rendering multiple exxplosions would be feasible. They might need different curTimes
    2199       // Also, store the explosion model mat(s) in the global ubo, just like all other objects
    2200       // This should just require setting their ubo_offset correctly
    2201       // (This already seems to be happening. I think I just need to add a ubo index buffer to explosions)
    22022160   }
    22032161
     
    22262184      glBindBuffer(GL_ARRAY_BUFFER, it->second.buffer);
    22272185
    2228       if (obj.type != TYPE_EXPLOSION || it->first == "ubo_index") {
    2229          switch (it->second.attribType) {
    2230             case ATTRIB_POINT_VARYING:
    2231                glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * GLsizeof(it->second.type) * it->second.size,
    2232                   obj.num_points * GLsizeof(it->second.type) * it->second.size, getVectorAttribPtr(obj, it->second.fieldOffset));
    2233                break;
    2234             case ATTRIB_OBJECT_VARYING:
    2235                for (unsigned int i = 0; i < obj.num_points; i++) {
    2236                   glBufferSubData(GL_ARRAY_BUFFER, (obj.vertex_vbo_offset + i) * GLsizeof(it->second.type) * it->second.size,
    2237                      GLsizeof(it->second.type) * it->second.size, getScalarAttribPtr(obj, it->second.fieldOffset));
    2238                }
    2239                break;
    2240             case ATTRIB_UNIFORM:
    2241                break;
    2242          }
    2243       }
    2244    }
    2245 
    2246    if (obj.type != TYPE_EXPLOSION) {
    2247       obj.model_mat = obj.model_transform * obj.model_base;
    2248    }
     2186      switch (it->second.attribType) {
     2187         case ATTRIB_POINT_VARYING:
     2188            glBufferSubData(GL_ARRAY_BUFFER, obj.vertex_vbo_offset * GLsizeof(it->second.type) * it->second.size,
     2189               obj.num_points * GLsizeof(it->second.type) * it->second.size, getVectorAttribPtr(obj, it->second.fieldOffset));
     2190            break;
     2191         case ATTRIB_OBJECT_VARYING:
     2192            for (unsigned int i = 0; i < obj.num_points; i++) {
     2193               glBufferSubData(GL_ARRAY_BUFFER, (obj.vertex_vbo_offset + i) * GLsizeof(it->second.type) * it->second.size,
     2194                  GLsizeof(it->second.type) * it->second.size, getScalarAttribPtr(obj, it->second.fieldOffset));
     2195            }
     2196            break;
     2197         case ATTRIB_UNIFORM:
     2198            break;
     2199      }
     2200   }
     2201
     2202   obj.model_mat = obj.model_transform * obj.model_base;
    22492203
    22502204   glBindBuffer(GL_UNIFORM_BUFFER, ubo);
     
    22562210      ostringstream oss;
    22572211      oss << "hp[" << obj.ubo_offset << "]";
    2258       glUniform1f(glGetUniformLocation(modelGroups[TYPE_ASTEROID].shaderProgram, oss.str().c_str()), ((Asteroid*)&obj)->hp);
     2212      glUniform1f(glGetUniformLocation(modelGroups[TYPE_ASTEROID].shaderProgram, oss.str().c_str()), ((Asteroid&)obj).hp);
     2213   } else if (obj.type == TYPE_EXPLOSION) {
     2214      glUseProgram(modelGroups[TYPE_EXPLOSION].shaderProgram);
     2215
     2216      ostringstream oss;
     2217      oss << "explosion_start_time[" << obj.ubo_offset << "]";
     2218      glUniform1f(glGetUniformLocation(modelGroups[TYPE_EXPLOSION].shaderProgram, oss.str().c_str()), ((ParticleEffect&)obj).startTime);
    22592219   }
    22602220
     
    24252385}
    24262386
    2427 void renderScene(map<GLuint, BufferInfo>& shaderBufferInfo,
    2428                   map<ObjectType, ShaderModelGroup>& modelGroups, GLuint ubo) {
     2387void renderScene(map<ObjectType, ShaderModelGroup>& modelGroups, GLuint ubo) {
    24292388
    24302389   glUseProgram(modelGroups[TYPE_SHIP].shaderProgram);
     
    27222681}
    27232682
    2724 ParticleEffect* createExplosion() {
     2683// TODO: Maybe pass in startTime instead of calling glfwGetTime() here
     2684ParticleEffect* createExplosion(mat4 model_mat) {
    27252685   ParticleEffect* obj = new ParticleEffect();
     2686
    27262687   obj->type = TYPE_EXPLOSION;
    27272688
    2728    obj->points = {};
    2729    obj->colors = {};
    2730 
    27312689   initObject(obj);
     2690
    27322691   obj->num_points = EXPLOSION_PARTICLE_COUNT;
     2692   obj->model_base = model_mat;
     2693   obj->startTime = glfwGetTime();
     2694   obj->duration = 0.5f; // This is also hard-coded in the shader. TODO; Pass this to the shader in an indexable ubo.
     2695
     2696   obj->particleVelocities.clear();
     2697   obj->particleTimes.clear();
     2698   float t_accum = 0.0f; // start time
     2699
     2700   for (int i = 0; i < EXPLOSION_PARTICLE_COUNT; i++) {
     2701      obj->particleTimes.push_back(t_accum);
     2702      t_accum += 0.01f;
     2703
     2704      float randx = ((float)rand() / (float)RAND_MAX) - 0.5f;
     2705      float randy = ((float)rand() / (float)RAND_MAX) - 0.5f;
     2706      obj->particleVelocities.push_back(randx);
     2707      obj->particleVelocities.push_back(randy);
     2708      obj->particleVelocities.push_back(0.0f);
     2709   }
    27332710
    27342711   return obj;
Note: See TracChangeset for help on using the changeset viewer.