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


Ignore:
Timestamp:
Mar 26, 2020, 3:41:42 AM (5 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.cpp

    r2ff4d3e r2ba5617  
    683683      }
    684684
    685       // TODO: Remove this block of code and correctly update the center of all objects when they are transformed
    686       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 
    700685      renderUI();
    701686      renderScene();
     
    717702   }
    718703
    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         }
    724715
    725716         updateObject(asteroidObjects, asteroidPipeline, i);
     
    794785         }, true);
    795786
    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
    798794      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))) *
    800796         rotate(mat4(1.0f), radians(60.0f), vec3(1.0f, 1.0f, -1.0f)) *
    801797         scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f));
Note: See TracChangeset for help on using the changeset viewer.