Index: vulkan-game.cpp
===================================================================
--- vulkan-game.cpp	(revision 0fe84333f0e448837677f6a2bd0c3f62b0a1d8c8)
+++ vulkan-game.cpp	(revision 3e8cc8b7aef266654d80c142b7d4436950ceba1f)
@@ -25,4 +25,5 @@
    object_VP_mats = {};
    ship_VP_mats = {};
+   asteroid_VP_mats = {};
 }
 
@@ -196,4 +197,5 @@
    createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
       uniformBuffers_scenePipeline, uniformBuffersMemory_scenePipeline, uniformBufferInfoList_scenePipeline);
+   // TODO: Calculate the size of this buffer (and all the other SSBOs) based on the number of objects
    createBufferSet(10 * sizeof(SBO_SceneObject), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
       storageBuffers_scenePipeline, storageBuffersMemory_scenePipeline, storageBufferInfoList_scenePipeline);
@@ -274,4 +276,5 @@
       addObjectIndex<ShipVertex>(shipObjects.size(),
       addVertexNormals<ShipVertex>({
+
          //back
          {{ -0.5f,   0.3f,   0.0f}, {0.0f, 0.0f, 0.3f}},
@@ -506,4 +509,85 @@
    shipPipeline.createDescriptorSets(swapChainImages);
 
+   asteroidPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&AsteroidVertex::pos));
+   asteroidPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&AsteroidVertex::color));
+   asteroidPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&AsteroidVertex::normal));
+   asteroidPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&AsteroidVertex::objIndex));
+
+   createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
+      uniformBuffers_asteroidPipeline, uniformBuffersMemory_asteroidPipeline, uniformBufferInfoList_asteroidPipeline);
+   createBufferSet(10 * sizeof(SBO_Asteroid), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
+      storageBuffers_asteroidPipeline, storageBuffersMemory_asteroidPipeline, storageBufferInfoList_asteroidPipeline);
+
+   asteroidPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
+      VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_asteroidPipeline);
+   asteroidPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
+      VK_SHADER_STAGE_VERTEX_BIT, &storageBufferInfoList_asteroidPipeline);
+
+   addObject(asteroidObjects, asteroidPipeline,
+      centerObject<AsteroidVertex>(
+      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,
+      });
+
+   asteroidPipeline.createDescriptorSetLayout();
+   asteroidPipeline.createPipeline("shaders/asteroid-vert.spv", "shaders/asteroid-frag.spv");
+   asteroidPipeline.createDescriptorPool(swapChainImages);
+   asteroidPipeline.createDescriptorSets(swapChainImages);
+
    cout << "Created all the graphics pipelines" << endl;
 
@@ -515,4 +599,13 @@
       translate(mat4(1.0f), vec3(0.0f, -1.2f, 1.65f)) *
       scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f));
+
+   //vec3 pos = vec3(getRandomNum(-1.3f, 1.3f), -1.2f, getRandomNum(-5.5f, -4.5f));
+   vec3 pos = vec3(getRandomNum(-1.3f, 1.3f), -1.2f, -2.0f);
+
+   asteroidObjects[0].model_base =
+      translate(mat4(1.0f), pos) *
+      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));
+   asteroidObjects[0].model_transform = mat4(1.0); // Might not be needed
 }
 
@@ -526,4 +619,7 @@
    shipPipeline = GraphicsPipeline_Vulkan<ShipVertex>(physicalDevice, device, renderPass,
       { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 138, 138);
+
+   asteroidPipeline = GraphicsPipeline_Vulkan<AsteroidVertex>(physicalDevice, device, renderPass,
+      { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 24, 36);
 }
 
@@ -550,4 +646,7 @@
    ship_VP_mats.view = view;
    ship_VP_mats.proj = proj;
+
+   asteroid_VP_mats.view = view;
+   asteroid_VP_mats.proj = proj;
 }
 
@@ -624,4 +723,7 @@
       }
 
+      // this code moves the asteroids
+      transformObject(asteroidObjects[0], translate(mat4(1.0f), vec3(0.0f, 0.0f, 0.04f)));
+
       renderUI();
       renderScene();
@@ -647,4 +749,7 @@
    so_Ship.model = shipObjects[0].model_transform * shipObjects[0].model_base;
 
+   so_Asteroid.model = asteroidObjects[0].model_transform * asteroidObjects[0].model_base;
+   so_Asteroid.hp = 10.0;
+
    VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_scenePipeline[currentImage], object_VP_mats);
 
@@ -654,4 +759,8 @@
 
    VulkanUtils::copyDataToMemory(device, storageBuffersMemory_shipPipeline[currentImage], so_Ship);
+
+   VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_asteroidPipeline[currentImage], asteroid_VP_mats);
+
+   VulkanUtils::copyDataToMemory(device, storageBuffersMemory_asteroidPipeline[currentImage], so_Asteroid);
 }
 
@@ -757,4 +866,5 @@
    overlayPipeline.cleanupBuffers();
    shipPipeline.cleanupBuffers();
+   asteroidPipeline.cleanupBuffers();
 
    for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
@@ -1237,4 +1347,5 @@
       modelPipeline.createRenderCommands(commandBuffers[i], i);
       shipPipeline.createRenderCommands(commandBuffers[i], i);
+      asteroidPipeline.createRenderCommands(commandBuffers[i], i);
 
       // Always render this pipeline last
@@ -1335,4 +1446,14 @@
    shipPipeline.createDescriptorSets(swapChainImages);
 
+   createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
+      uniformBuffers_asteroidPipeline, uniformBuffersMemory_asteroidPipeline, uniformBufferInfoList_asteroidPipeline);
+   createBufferSet(10 * sizeof(SBO_Asteroid), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
+      storageBuffers_asteroidPipeline, storageBuffersMemory_asteroidPipeline, storageBufferInfoList_asteroidPipeline);
+
+   asteroidPipeline.updateRenderPass(renderPass);
+   asteroidPipeline.createPipeline("shaders/asteroid-vert.spv", "shaders/asteroid-frag.spv");
+   asteroidPipeline.createDescriptorPool(swapChainImages);
+   asteroidPipeline.createDescriptorSets(swapChainImages);
+
    createCommandBuffers();
 }
@@ -1350,4 +1471,5 @@
    overlayPipeline.cleanup();
    shipPipeline.cleanup();
+   asteroidPipeline.cleanup();
 
    vkDestroyRenderPass(device, renderPass, nullptr);
@@ -1378,3 +1500,13 @@
       vkFreeMemory(device, storageBuffersMemory_shipPipeline[i], nullptr);
    }
-}
+
+   for (size_t i = 0; i < uniformBuffers_asteroidPipeline.size(); i++) {
+      vkDestroyBuffer(device, uniformBuffers_asteroidPipeline[i], nullptr);
+      vkFreeMemory(device, uniformBuffersMemory_asteroidPipeline[i], nullptr);
+   }
+
+   for (size_t i = 0; i < storageBuffers_asteroidPipeline.size(); i++) {
+      vkDestroyBuffer(device, storageBuffers_asteroidPipeline[i], nullptr);
+      vkFreeMemory(device, storageBuffersMemory_asteroidPipeline[i], nullptr);
+   }
+}
