Index: new-game.cpp
===================================================================
--- new-game.cpp	(revision 3effd814070c6d05ee43290be8ebe13ba007c267)
+++ new-game.cpp	(revision 8316333db194c8414031b9c87c994abac7899768)
@@ -98,6 +98,7 @@
 void print4DVector(string label, vec4 v);
 
-void addObjectToSceneDuringInit(SceneObject& obj);
-void addObjectToScene(SceneObject& obj, map<GLuint, BufferInfo>& shaderBufferInfo,
+void initObject(SceneObject& obj);
+void addObjectToScene(SceneObject& obj,
+                  map<GLuint, BufferInfo>& shaderBufferInfo,
                   GLuint points_vbo,
                   GLuint colors_vbo,
@@ -111,5 +112,5 @@
 void calculateObjectBoundingBox(SceneObject& obj);
 
-void addLaserToScene(vec3 start, vec3 end, vec3 color, GLfloat width, GLuint laser_sp);
+SceneObject createLaser(vec3 start, vec3 end, vec3 color, GLfloat width, GLuint laser_sp);
 
 void initializeBuffers(
@@ -394,79 +395,4 @@
    mat4 T_model, R_model;
 
-   // TODO: Confirm there's nothing I need from the commented out models and delete them
-   // (Check to make sure the textured square is drawn correctly)
-
-   /*
-   // triangle
-   obj = SceneObject();
-   obj.shader_program = color_sp;
-   obj.points = {
-       0.0f,  0.5f,  0.0f,
-      -0.5f, -0.5f,  0.0f,
-       0.5f, -0.5f,  0.0f,
-       0.5f, -0.5f,  0.0f,
-      -0.5f, -0.5f,  0.0f,
-       0.0f,  0.5f,  0.0f,
-   };
-   obj.colors = {
-      1.0f, 0.0f, 0.0f,
-      0.0f, 0.0f, 1.0f,
-      0.0f, 1.0f, 0.0f,
-      0.0f, 1.0f, 0.0f,
-      0.0f, 0.0f, 1.0f,
-      1.0f, 0.0f, 0.0f,
-   };
-   obj.texcoords = { 0.0f };
-   obj.selected_colors = {
-      0.0f, 1.0f, 0.0f,
-      0.0f, 1.0f, 0.0f,
-      0.0f, 1.0f, 0.0f,
-      0.0f, 1.0f, 0.0f,
-      0.0f, 1.0f, 0.0f,
-      0.0f, 1.0f, 0.0f,
-   };
-
-   T_model = translate(mat4(1.0f), vec3(0.45f, -1.5f, 0.0f));
-   R_model = rotate(mat4(1.0f), 0.0f, vec3(0.0f, 1.0f, 0.0f));
-   obj.model_base = T_model*R_model;
-
-   addObjectToSceneDuringInit(obj);
-
-   // square
-   obj = SceneObject();
-   obj.shader_program = texture_sp;
-   obj.points = {
-       0.5f,  0.5f,  0.0f,
-      -0.5f,  0.5f,  0.0f,
-      -0.5f, -0.5f,  0.0f,
-       0.5f,  0.5f,  0.0f,
-      -0.5f, -0.5f,  0.0f,
-       0.5f, -0.5f,  0.0f,
-   };
-   obj.colors = { 0.0f };
-   obj.texcoords = {
-      1.0f, 1.0f,
-      0.0f, 1.0f,
-      0.0f, 0.0f,
-      1.0f, 1.0f,
-      0.0f, 0.0f,
-      1.0f, 0.0f
-   };
-   obj.selected_colors = {
-      0.0f, 0.6f, 0.9f,
-      0.0f, 0.6f, 0.9f,
-      0.0f, 0.6f, 0.9f,
-      0.0f, 0.6f, 0.9f,
-      0.0f, 0.6f, 0.9f,
-      0.0f, 0.6f, 0.9f,
-   };
-
-   T_model = translate(mat4(1.0f), vec3(-0.5f, -1.5f, -1.00f));
-   R_model = rotate(mat4(1.0f), 0.5f, vec3(0.0f, 1.0f, 0.0f));
-   obj.model_base = T_model*R_model;
-
-   addObjectToSceneDuringInit(obj);
-   */
-
    // player ship
    obj = SceneObject();
@@ -842,5 +768,5 @@
 
    T_model = translate(mat4(1.0f), vec3(0.0f, -1.2f, 1.65f));
-   R_model = rotate(mat4(1.0f), 20.0f * (float)ONE_DEG_IN_RAD, vec3(1.0f, 0.0f, 0.0f));
+   //R_model = rotate(mat4(1.0f), 20.0f * (float)ONE_DEG_IN_RAD, vec3(1.0f, 0.0f, 0.0f));
    R_model = mat4(1.0f);
    obj.model_base = T_model * R_model * scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f));
@@ -848,8 +774,20 @@
    obj.translate_mat = T_model;
 
-   addObjectToSceneDuringInit(obj);
-
-   addLaserToScene(vec3(0.34f, -2.0f, 1.6f), vec3(0.34f, -2.0f, -3.0f), vec3(0.0f, 1.0f, 0.0f), 0.04f, laser_sp);
-   addLaserToScene(vec3(-0.34f, -2.0f, 1.6f), vec3(-0.34f, -2.0f, -3.0f), vec3(0.0f, 1.0f, 0.0f), 0.04f, laser_sp);
+   initObject(obj);
+   objects.push_back(obj);
+
+   // I could also store SceneObject*, but I have to keep track of when the vector is about to
+   // resize and re-init the pointers when that happens since they'll be invalidated
+   // I would prefer the above apporach, but I should write some helper functions to make it less error-prone
+   unsigned int leftLaserIdx = -1;
+   unsigned int rightLaserIdx = -1;
+
+   obj = createLaser(vec3(0.21f, -1.19f, 1.76f), vec3(0.21f, -1.19f, -3.0f), vec3(0.0f, 1.0f, 0.0f), 0.03f, laser_sp);
+   objects.push_back(obj);
+   leftLaserIdx = objects.size() - 1;
+
+   obj = createLaser(vec3(-0.21f, -1.19f, 1.76f), vec3(-0.21f, -1.19f, -3.0f), vec3(0.0f, 1.0f, 0.0f), 0.03f, laser_sp);
+   objects.push_back(obj);
+   rightLaserIdx = objects.size() - 1;
 
    vector<SceneObject>::iterator obj_it;
@@ -1108,7 +1046,39 @@
          if (key_pressed[GLFW_KEY_RIGHT]) {
             transformObject(objects[0], translate(mat4(1.0f), vec3(0.01f, 0.0f, 0.0f)), ubo);
+            transformObject(objects[leftLaserIdx], translate(mat4(1.0f), vec3(0.01f, 0.0f, 0.0f)), ubo);
+            transformObject(objects[rightLaserIdx], translate(mat4(1.0f), vec3(0.01f, 0.0f, 0.0f)), ubo);
          }
          if (key_pressed[GLFW_KEY_LEFT]) {
             transformObject(objects[0], translate(mat4(1.0f), vec3(-0.01f, 0.0f, 0.0f)), ubo);
+            transformObject(objects[leftLaserIdx], translate(mat4(1.0f), vec3(-0.01f, 0.0f, 0.0f)), ubo);
+            transformObject(objects[rightLaserIdx], translate(mat4(1.0f), vec3(-0.01f, 0.0f, 0.0f)), ubo);
+         }
+         if (key_pressed[GLFW_KEY_Z]) {
+            vec3 offset(objects[0].model_transform * vec4(0.0f, 0.0f, 0.0f, 1.0f));
+
+            SceneObject obj = createLaser(vec3(-0.21f, -1.19f, 1.76f)+offset, vec3(-0.21f, -1.19f, -3.0f)+offset,
+               vec3(0.0f, 1.0f, 0.0f), 0.03f, laser_sp);
+            addObjectToScene(obj, shaderBufferInfo,
+               points_vbo,
+               colors_vbo,
+               selected_colors_vbo,
+               texcoords_vbo,
+               normals_vbo,
+               ubo,
+               model_mat_idx_vbo);
+         }
+         if (key_pressed[GLFW_KEY_X]) {
+            vec3 offset(objects[0].model_transform * vec4(0.0f, 0.0f, 0.0f, 1.0f));
+
+            SceneObject obj = createLaser(vec3(0.21f, -1.19f, 1.76f) + offset, vec3(0.21f, -1.19f, -3.0f) + offset,
+               vec3(0.0f, 1.0f, 0.0f), 0.03f, laser_sp);
+            addObjectToScene(obj, shaderBufferInfo,
+               points_vbo,
+               colors_vbo,
+               selected_colors_vbo,
+               texcoords_vbo,
+               normals_vbo,
+               ubo,
+               model_mat_idx_vbo);
          }
 
@@ -1424,5 +1394,5 @@
 }
 
-void addObjectToSceneDuringInit(SceneObject& obj) {
+void initObject(SceneObject& obj) {
    // Each objects must have at least 3 points, so the size of
    // the points array must be a positive multiple of 9
@@ -1452,21 +1422,21 @@
    }
 
-   calculateObjectBoundingBox(obj);
-
-   obj.bounding_center = vec3(obj.translate_mat * vec4(obj.bounding_center, 1.0f));
-
+   if (obj.type != TYPE_LASER) {
+      calculateObjectBoundingBox(obj);
+
+      obj.bounding_center = vec3(obj.translate_mat * vec4(obj.bounding_center, 1.0f));
+   }
+}
+
+void addObjectToScene(SceneObject& obj,
+   map<GLuint, BufferInfo>& shaderBufferInfo,
+   GLuint points_vbo,
+   GLuint colors_vbo,
+   GLuint selected_colors_vbo,
+   GLuint texcoords_vbo,
+   GLuint normals_vbo,
+   GLuint ubo,
+   GLuint model_mat_idx_vbo) {
    objects.push_back(obj);
-}
-
-void addObjectToScene(SceneObject& obj,
-                  map<GLuint, BufferInfo>& shaderBufferInfo,
-                  GLuint points_vbo,
-                  GLuint colors_vbo,
-                  GLuint selected_colors_vbo,
-                  GLuint texcoords_vbo,
-                  GLuint normals_vbo,
-                  GLuint ubo,
-                  GLuint model_mat_idx_vbo) {
-   addObjectToSceneDuringInit(obj);
 
    BufferInfo* bufferInfo = &shaderBufferInfo[obj.shader_program];
@@ -1484,5 +1454,6 @@
          ubo,
          model_mat_idx_vbo);
-   } else {
+   }
+   else {
       copyObjectDataToBuffers(objects.back(), shaderBufferInfo,
          points_vbo,
@@ -1571,10 +1542,10 @@
 * -Rotate the beam along the x-axis and then along the y-axis and then translate it to put it into its final position
 */
-void addLaserToScene(vec3 start, vec3 end, vec3 color, GLfloat width, GLuint laser_sp) {
+// TODO: Make the color parameter have an effect
+// TODO: Come up with a better way of passing the object back than copying it
+SceneObject createLaser(vec3 start, vec3 end, vec3 color, GLfloat width, GLuint laser_sp) {
    SceneObject obj = SceneObject();
-   obj.id = objects.size(); // currently unused
    obj.type = TYPE_LASER;
    obj.shader_program = laser_sp;
-   obj.deleted = false;
 
    vec3 ray = end - start;
@@ -1623,6 +1594,4 @@
    };
 
-   obj.num_points = obj.points.size() / 3;
-
    float xAxisRotation = asin(ray.y / length);
    float yAxisRotation = atan2(-ray.x, -ray.z);
@@ -1644,7 +1613,8 @@
    obj.model_base = rotate(mat4(1.0f), yAxisRotation, vec3(0.0f, 1.0f, 0.0f)) * obj.model_base;
    obj.model_base = translate(mat4(1.0f), start) * obj.model_base;
-   obj.model_transform = mat4(1.0f);
-
-   objects.push_back(obj);
+
+   initObject(obj);
+
+   return obj;
 }
 
@@ -2100,4 +2070,5 @@
    obj.translate_mat = T;
 
+   initObject(obj);
    addObjectToScene(obj, shaderBufferInfo,
                   points_vbo,
