Index: new-game.cpp
===================================================================
--- new-game.cpp	(revision c94a6992fa19a8b74c4b71752d80b955a78dca01)
+++ new-game.cpp	(revision 5527206502829c29f53f8d93fccca370379e0da1)
@@ -25,4 +25,6 @@
 
 #include <cstdio>
+#include <cstdlib>
+#include <ctime>
 #include <iostream>
 #include <fstream>
@@ -72,41 +74,4 @@
 };
 
-#define NUM_KEYS (512)
-#define ONE_DEG_IN_RAD ((2.0f * M_PI) / 360.0f) // 0.017444444 (maybe make this a const instead)
-
-const int KEY_STATE_UNCHANGED = -1;
-const bool FULLSCREEN = false;
-const bool SHOW_FPS = false;
-const bool DISABLE_VSYNC = false; // disable vsync to see real framerate
-unsigned int MAX_UNIFORMS = 0; // Requires OpenGL constants only available at runtime, so it can't be const
-
-int key_state[NUM_KEYS];
-bool key_pressed[NUM_KEYS];
-
-int width = 640;
-int height = 480;
-
-double fps;
-
-vec3 cam_pos;
-
-mat4 view_mat;
-mat4 proj_mat;
-
-// TODO: Consider using a list instead since it will make element deletion more efficient
-vector<SceneObject> objects;
-queue<Event> events;
-
-SceneObject* clickedObject = NULL;
-SceneObject* selectedObject = NULL;
-
-float NEAR_CLIP = 0.1f;
-float FAR_CLIP = 100.0f;
-
-// Should really have some array or struct of UI-related variables
-bool isRunning = true;
-
-ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
-
 void glfw_error_callback(int error, const char* description);
 
@@ -188,4 +153,43 @@
                   GLuint model_mat_idx_vbo);
 
+float getRandomNum(float low, float high);
+
+#define NUM_KEYS (512)
+#define ONE_DEG_IN_RAD ((2.0f * M_PI) / 360.0f) // 0.017444444 (maybe make this a const instead)
+
+const int KEY_STATE_UNCHANGED = -1;
+const bool FULLSCREEN = false;
+const bool SHOW_FPS = false;
+const bool DISABLE_VSYNC = false; // disable vsync to see real framerate
+unsigned int MAX_UNIFORMS = 0; // Requires OpenGL constants only available at runtime, so it can't be const
+
+int key_state[NUM_KEYS];
+bool key_pressed[NUM_KEYS];
+
+int width = 640;
+int height = 480;
+
+double fps;
+
+vec3 cam_pos;
+
+mat4 view_mat;
+mat4 proj_mat;
+
+// TODO: Consider using a list instead since it will make element deletion more efficient
+vector<SceneObject> objects;
+queue<Event> events;
+
+SceneObject* clickedObject = NULL;
+SceneObject* selectedObject = NULL;
+
+float NEAR_CLIP = 0.1f;
+float FAR_CLIP = 100.0f;
+
+// Should really have some array or struct of UI-related variables
+bool isRunning = true;
+
+ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
+
 int main(int argc, char* argv[]) {
    cout << "New OpenGL Game" << endl;
@@ -231,4 +235,6 @@
    glewExperimental = GL_TRUE;
    glewInit();
+
+   srand(time(0));
 
    /*
@@ -816,4 +822,5 @@
       model_mat_idx_vbo);
 
+   /*
    spawnAsteroid(vec3(0.0f, -1.2f, -21.5f), color_sp,
       shaderBufferInfo,
@@ -861,4 +868,5 @@
       ubo,
       model_mat_idx_vbo);
+   */
 
    GLuint vao = 0;
@@ -964,4 +972,5 @@
    int frame_count = 0;
    double elapsed_seconds_fps = 0.0f;
+   double elapsed_seconds_spawn = 0.0f;
    double previous_seconds = glfwGetTime();
 
@@ -991,4 +1000,19 @@
 
          frame_count++;
+      }
+
+      elapsed_seconds_spawn += elapsed_seconds;
+      if (elapsed_seconds_spawn > 0.5f) {
+         spawnAsteroid(vec3(getRandomNum(-1.3f, 1.3f), getRandomNum(-3.0f, -1.0f), getRandomNum(-5.5f, -4.5f)), color_sp,
+            shaderBufferInfo,
+            points_vbo,
+            colors_vbo,
+            selected_colors_vbo,
+            texcoords_vbo,
+            normals_vbo,
+            ubo,
+            model_mat_idx_vbo);
+
+         elapsed_seconds_spawn = 0.0f;
       }
 
@@ -1049,10 +1073,8 @@
          }
 
-         if (key_pressed[GLFW_KEY_DOWN]) {
-            transformObject(objects[1], translate(mat4(), vec3(0.0f, 0.0f, 0.03f)), ubo);
-            transformObject(objects[2], translate(mat4(), vec3(0.0f, 0.0f, 0.06f)), ubo);
-            transformObject(objects[3], translate(mat4(), vec3(0.0f, 0.0f, 0.04f)), ubo);
-            transformObject(objects[4], translate(mat4(), vec3(0.0f, 0.0f, 0.06f)), ubo);
-            transformObject(objects[5], translate(mat4(), vec3(0.0f, 0.0f, 0.04f)), ubo);
+         for (int i = 1; i < objects.size(); i++) {
+            if (!objects[i].deleted) {
+               transformObject(objects[i], translate(mat4(), vec3(0.0f, 0.0f, 0.04f)), ubo);
+            }
          }
 
@@ -1871,2 +1893,6 @@
                   model_mat_idx_vbo);
 }
+
+float getRandomNum(float low, float high) {
+   return low + ((float)rand()/RAND_MAX) * (high-low);
+}
