Changeset 2ba5617 in opengl-game for vulkan-game.hpp


Ignore:
Timestamp:
Mar 26, 2020, 3:41:42 AM (4 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
bf4744d
Parents:
2ff4d3e
Message:

Center each object before, rather than after, it is copied to the GPU so that the centered vertices are copied, update an object's center when its model matrix is modified in updateObject(), mark an asteroid object as deleted when it moves offscreen, and randomize the initial z-coordinate for a new asteroid

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.hpp

    r2ff4d3e r2ba5617  
    6161   mat4 model_base;
    6262   mat4 model_transform;
    63    vec3 center;
    64    float radius;
     63   vec3 center; // currently only matters for asteroids
     64   float radius; // currently only matters for asteroids
    6565};
    6666
     
    159159      // Or maybe create a higher level wrapper around GraphicsPipeline_Vulkan to hold things like
    160160      // the objects vector, the ubo, and the ssbo
     161
     162      // TODO: Rename *_VP_mats to *_uniforms and possibly use different types for each one
     163      // if there is a need to add other uniform variables to one or more of the shaders
    161164
    162165      GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject> modelPipeline;
     
    263266// and to change the model matrix later by setting model_transform and then calling updateObject()
    264267// Figure out a better way to allow the model matrix to be set during objecting creation
     268
     269// TODO: Maybe return a reference to the object from this method if I decide that updating it
     270// immediately after creation is a good idea (such as setting model_base)
     271// Currently, model_base is set like this in a few places and the radius is set for asteroids
     272// to account for scaling
    265273template<class VertexType, class SSBOType>
    266274void VulkanGame::addObject(vector<SceneObject<VertexType, SSBOType>>& objects,
     
    268276      const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType ssbo,
    269277      bool pipelinesCreated) {
     278   // TODO: Use the model field of ssbo to set the object's model_base
     279   // currently, the passed in model is useless since it gets overridden in updateObject() anyway
    270280   size_t numVertices = pipeline.getNumVertices();
    271281
     
    275285
    276286   objects.push_back({ vertices, indices, ssbo, mat4(1.0f), mat4(1.0f) });
    277    centerObject(objects.back());
    278 
    279    bool storageBufferResized = pipeline.addObject(vertices, indices, ssbo, commandPool, graphicsQueue);
     287
     288   SceneObject<VertexType, SSBOType>& obj = objects.back();
     289   centerObject(obj);
     290
     291   bool storageBufferResized = pipeline.addObject(obj.vertices, obj.indices, obj.ssbo, commandPool, graphicsQueue);
    280292
    281293   if (pipelinesCreated) {
     
    304316
    305317   obj.ssbo.model = obj.model_transform * obj.model_base;
    306 
    307    // could probably re-calculate the object center here based on model
    308    // I think the center should be calculated by using model * vec3(0, 0, 0)
    309    // model_base is currently only used to set the original location of the ship and asteroids
     318   obj.center = vec3(obj.ssbo.model * vec4(0.0f, 0.0f, 0.0f, 1.0f));
    310319
    311320   pipeline.updateObject(index, obj.ssbo);
     
    379388   }
    380389
    381    object.radius = std::max(center.x, center.y);
    382    object.radius = std::max(object.radius, center.z);
     390   object.radius = std::max(max_x - center.x, max_y - center.y);
     391   object.radius = std::max(object.radius, max_z - center.z);
     392
    383393   object.center = vec3(0.0f, 0.0f, 0.0f);
    384394}
Note: See TracChangeset for help on using the changeset viewer.