Index: vulkan-game.cpp
===================================================================
--- vulkan-game.cpp	(revision 44f23af8016482279566b636d38266b620bec156)
+++ vulkan-game.cpp	(revision 0807aeb7700bc40b0b01bbd8a42ddd4065e0b699)
@@ -2,5 +2,4 @@
 
 #include <array>
-#include <chrono>
 #include <iostream>
 #include <set>
@@ -32,4 +31,6 @@
 
 void VulkanGame::run(int width, int height, unsigned char guiFlags) {
+   seedRandomNums();
+
    cout << "DEBUGGING IS " << (ENABLE_VALIDATION_LAYERS ? "ON" : "OFF") << endl;
 
@@ -586,12 +587,14 @@
    bool quit = false;
 
-   curTime = SDL_GetPerformanceCounter();
+   this->startTime = high_resolution_clock::now();
+   this->curTime = duration<float, seconds::period>(high_resolution_clock::now() - this->startTime).count();
+
+   lastSpawn_asteroid = this->curTime;
 
    while (!quit) {
 
-      prevTime = curTime;
-      curTime = SDL_GetPerformanceCounter();
-
-      elapsedTime = (double)((curTime - prevTime) * 1000 / (double)SDL_GetPerformanceFrequency());
+      this->prevTime = this->curTime;
+      this->curTime = duration<float, seconds::period>(high_resolution_clock::now() - this->startTime).count();
+      this->elapsedTime = this->curTime - this->prevTime;
 
       gui->processEvents();
@@ -629,76 +632,4 @@
                         mat4(1.0f)
                      }, true);
-               } else if (e.key.keycode == SDL_SCANCODE_Z) {
-                  addObject(asteroidObjects, asteroidPipeline,
-                     addObjectIndex<AsteroidVertex>(asteroidObjects.size(),
-                     addVertexNormals<AsteroidVertex>({
-
-                        // front
-                        {{ 1.0f,  1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{-1.0f,  1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{-1.0f, -1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{ 1.0f,  1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{-1.0f, -1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{ 1.0f, -1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
-
-                        // top
-                        {{ 1.0f,  1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{-1.0f,  1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{-1.0f,  1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{ 1.0f,  1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{-1.0f,  1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{ 1.0f,  1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
-
-                        // bottom
-                        {{ 1.0f, -1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{-1.0f, -1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{ 1.0f, -1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{ 1.0f, -1.0f, -1.0}, {0.4f, 0.4f, 0.4f}},
-
-                        // back
-                        {{ 1.0f,  1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{-1.0f,  1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{ 1.0f,  1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{ 1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
-
-                        // right
-                        {{ 1.0f,  1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{ 1.0f,  1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{ 1.0f, -1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{ 1.0f,  1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{ 1.0f, -1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{ 1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
-
-                        // left
-                        {{-1.0f,  1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{-1.0f,  1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{-1.0f,  1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
-                        {{-1.0f, -1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
-                     })), {
-                        0,  1,  2,  3,  4,  5,
-                        6,  7,  8,  9, 10, 11,
-                        12, 13, 14, 15, 16, 17,
-                        18, 19, 20, 21, 22, 23,
-                        24, 25, 26, 27, 28, 29,
-                        30, 31, 32, 33, 34, 35,
-                     }, {
-                        mat4(1.0f),
-                        10.0f,
-                        0
-                     }, true);
-
-                  // translate(mat4(1.0f), vec3(getRandomNum(-1.3f, 1.3f), -1.2f, getRandomNum(-5.5f, -4.5f))) *
-                  asteroidObjects.back().model_base =
-                     translate(mat4(1.0f), vec3(getRandomNum(-1.3f, 1.3f), -1.2f, -2.0f)) *
-                     rotate(mat4(1.0f), radians(60.0f), vec3(1.0f, 1.0f, -1.0f)) *
-                     scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f));
-
-                  updateObject(asteroidObjects, asteroidPipeline, asteroidObjects.size() - 1);
                } else {
                   cout << "Key event detected" << endl;
@@ -725,14 +656,11 @@
       // Check which keys are held down
 
-      float shipSpeed = 0.0005f;
-      float asteroidSpeed = 0.002f;
-
       if (gui->keyPressed(SDL_SCANCODE_LEFT)) {
-         shipObjects[0].model_transform = translate(mat4(1.0f), vec3(-shipSpeed * elapsedTime, 0.0f, 0.0f))
+         shipObjects[0].model_transform = translate(mat4(1.0f), vec3(-this->shipSpeed * this->elapsedTime, 0.0f, 0.0f))
             * shipObjects[0].model_transform;
 
          updateObject(shipObjects, shipPipeline, 0);
       } else if (gui->keyPressed(SDL_SCANCODE_RIGHT)) {
-         shipObjects[0].model_transform = translate(mat4(1.0f), vec3(shipSpeed * elapsedTime, 0.0f, 0.0f))
+         shipObjects[0].model_transform = translate(mat4(1.0f), vec3(this->shipSpeed * this->elapsedTime, 0.0f, 0.0f))
             * shipObjects[0].model_transform;
 
@@ -740,7 +668,8 @@
       }
 
+      // TODO: Remove this block of code and correctly update the center of all objects when they are transformed
       if (gui->keyPressed(SDL_SCANCODE_X)) {
          if (asteroidObjects.size() > 0 && !asteroidObjects[0].ssbo.deleted) {
-            asteroidObjects[0].model_transform = translate(mat4(1.0f), vec3(0.0f, 0.0f, asteroidSpeed * elapsedTime))
+            asteroidObjects[0].model_transform = translate(mat4(1.0f), vec3(0.0f, 0.0f, this->asteroidSpeed * this->elapsedTime))
                * asteroidObjects[0].model_transform;
 
@@ -765,15 +694,97 @@
 // where it will run just once per frame
 void VulkanGame::updateScene(uint32_t currentImage) {
-   static auto startTime = chrono::high_resolution_clock::now();
-
-   auto currentTime = chrono::high_resolution_clock::now();
-   float time = chrono::duration<float, chrono::seconds::period>(currentTime - startTime).count();
-
    for (int i = 0; i < modelObjects.size(); i++) {
       modelObjects[i].model_transform =
          translate(mat4(1.0f), vec3(0.0f, -2.0f, -0.0f)) *
-         rotate(mat4(1.0f), time * radians(90.0f), vec3(0.0f, 0.0f, 1.0f));
+         rotate(mat4(1.0f), this->curTime * radians(90.0f), vec3(0.0f, 0.0f, 1.0f));
 
       updateObject(modelObjects, modelPipeline, i);
+   }
+
+   for (int i = 0; i < asteroidObjects.size(); i++) {
+      if (!asteroidObjects[i].ssbo.deleted) {
+         asteroidObjects[i].model_transform =
+            translate(mat4(1.0f), vec3(0.0f, 0.0f, this->asteroidSpeed * this->elapsedTime)) *
+            asteroidObjects[i].model_transform;
+
+         updateObject(asteroidObjects, asteroidPipeline, i);
+      }
+   }
+
+   if (this->curTime - this->lastSpawn_asteroid > this->spawnRate_asteroid) {
+      this->lastSpawn_asteroid = this->curTime;
+
+      addObject(asteroidObjects, asteroidPipeline,
+         addObjectIndex<AsteroidVertex>(asteroidObjects.size(),
+            addVertexNormals<AsteroidVertex>({
+
+               // front
+               {{ 1.0f,  1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{-1.0f,  1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{-1.0f, -1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{ 1.0f,  1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{-1.0f, -1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{ 1.0f, -1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
+
+               // top
+               {{ 1.0f,  1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{-1.0f,  1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{-1.0f,  1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{ 1.0f,  1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{-1.0f,  1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{ 1.0f,  1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
+
+               // bottom
+               {{ 1.0f, -1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{-1.0f, -1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{ 1.0f, -1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{ 1.0f, -1.0f, -1.0}, {0.4f, 0.4f, 0.4f}},
+
+               // back
+               {{ 1.0f,  1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{-1.0f,  1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{ 1.0f,  1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{ 1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
+
+               // right
+               {{ 1.0f,  1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{ 1.0f,  1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{ 1.0f, -1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{ 1.0f,  1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{ 1.0f, -1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{ 1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
+
+               // left
+               {{-1.0f,  1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{-1.0f,  1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{-1.0f,  1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{-1.0f, -1.0f, -1.0f}, {0.4f, 0.4f, 0.4f}},
+               {{-1.0f, -1.0f,  1.0f}, {0.4f, 0.4f, 0.4f}},
+               })), {
+                  0,  1,  2,  3,  4,  5,
+                  6,  7,  8,  9, 10, 11,
+                  12, 13, 14, 15, 16, 17,
+                  18, 19, 20, 21, 22, 23,
+                  24, 25, 26, 27, 28, 29,
+                  30, 31, 32, 33, 34, 35,
+         }, {
+            mat4(1.0f),
+            10.0f,
+            0
+         }, true);
+
+      // translate(mat4(1.0f), vec3(getRandomNum(-1.3f, 1.3f), -1.2f, getRandomNum(-5.5f, -4.5f))) *
+      // translate(mat4(1.0f), vec3(0.0504826f, -1.2f, 1.0f)) *
+      asteroidObjects.back().model_base =
+         translate(mat4(1.0f), vec3(getRandomNum(-1.3f, 1.3f), -1.2f, -2.0f)) *
+         rotate(mat4(1.0f), radians(60.0f), vec3(1.0f, 1.0f, -1.0f)) *
+         scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f));
+
+      updateObject(asteroidObjects, asteroidPipeline, asteroidObjects.size() - 1);
    }
 
