Changeset 2ba5617 in opengl-game
- Timestamp:
- Mar 26, 2020, 3:41:42 AM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- bf4744d
- Parents:
- 2ff4d3e
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
r2ff4d3e r2ba5617 683 683 } 684 684 685 // TODO: Remove this block of code and correctly update the center of all objects when they are transformed686 if (gui->keyPressed(SDL_SCANCODE_X)) {687 if (asteroidObjects.size() > 0 && !asteroidObjects[0].ssbo.deleted) {688 asteroidObjects[0].model_transform = translate(mat4(1.0f), vec3(0.0f, 0.0f, this->asteroidSpeed * this->elapsedTime))689 * asteroidObjects[0].model_transform;690 691 vec3 obj_center = vec3(asteroid_VP_mats.view * vec4(asteroidObjects[0].center, 1.0f));692 693 float closest = obj_center.z - asteroidObjects[0].radius;694 cout << closest << " ? " << -NEAR_CLIP << endl;695 696 updateObject(asteroidObjects, asteroidPipeline, 0);697 }698 }699 700 685 renderUI(); 701 686 renderScene(); … … 717 702 } 718 703 719 for (int i = 0; i < asteroidObjects.size(); i++) { 720 if (!asteroidObjects[i].ssbo.deleted) { 721 asteroidObjects[i].model_transform = 722 translate(mat4(1.0f), vec3(0.0f, 0.0f, this->asteroidSpeed * this->elapsedTime)) * 723 asteroidObjects[i].model_transform; 704 for (int i = 0; i < this->asteroidObjects.size(); i++) { 705 if (!this->asteroidObjects[i].ssbo.deleted) { 706 vec3 objCenter = vec3(viewMat * vec4(this->asteroidObjects[i].center, 1.0f)); 707 708 if ((objCenter.z - this->asteroidObjects[i].radius) > -NEAR_CLIP) { 709 this->asteroidObjects[i].ssbo.deleted = true; 710 } else { 711 this->asteroidObjects[i].model_transform = 712 translate(mat4(1.0f), vec3(0.0f, 0.0f, this->asteroidSpeed * this->elapsedTime)) * 713 this->asteroidObjects[i].model_transform; 714 } 724 715 725 716 updateObject(asteroidObjects, asteroidPipeline, i); … … 794 785 }, true); 795 786 796 // translate(mat4(1.0f), vec3(getRandomNum(-1.3f, 1.3f), -1.2f, getRandomNum(-5.5f, -4.5f))) * 797 // translate(mat4(1.0f), vec3(0.0504826f, -1.2f, 1.0f)) * 787 // This accounts for the scaling in model_base. 788 // Dividing by 8 instead of 10 since the bounding radius algorithm 789 // under-calculates the true value. 790 // TODO: Figure out the best way to take scaling into account when calculating the radius 791 // Keep in mind that the main complicating factor is the currently poor radius calculation 792 asteroidObjects.back().radius /= 8.0f; 793 798 794 asteroidObjects.back().model_base = 799 translate(mat4(1.0f), vec3(getRandomNum(-1.3f, 1.3f), -1.2f, -2.0f)) *795 translate(mat4(1.0f), vec3(getRandomNum(-1.3f, 1.3f), -1.2f, getRandomNum(-5.5f, -4.5f))) * 800 796 rotate(mat4(1.0f), radians(60.0f), vec3(1.0f, 1.0f, -1.0f)) * 801 797 scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f)); -
vulkan-game.hpp
r2ff4d3e r2ba5617 61 61 mat4 model_base; 62 62 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 65 65 }; 66 66 … … 159 159 // Or maybe create a higher level wrapper around GraphicsPipeline_Vulkan to hold things like 160 160 // 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 161 164 162 165 GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject> modelPipeline; … … 263 266 // and to change the model matrix later by setting model_transform and then calling updateObject() 264 267 // 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 265 273 template<class VertexType, class SSBOType> 266 274 void VulkanGame::addObject(vector<SceneObject<VertexType, SSBOType>>& objects, … … 268 276 const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType ssbo, 269 277 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 270 280 size_t numVertices = pipeline.getNumVertices(); 271 281 … … 275 285 276 286 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); 280 292 281 293 if (pipelinesCreated) { … … 304 316 305 317 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)); 310 319 311 320 pipeline.updateObject(index, obj.ssbo); … … 379 388 } 380 389 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 383 393 object.center = vec3(0.0f, 0.0f, 0.0f); 384 394 }
Note:
See TracChangeset
for help on using the changeset viewer.