Index: new-game.cpp
===================================================================
--- new-game.cpp	(revision 19c93388b7ef3df32ba98d9fe3532b13307c592b)
+++ new-game.cpp	(revision df652d5289289364aaa3a6d68ef5c3c7d339b37b)
@@ -19,4 +19,5 @@
 #include <string>
 #include <array>
+#include <vector>
 
 using namespace std;
@@ -24,4 +25,14 @@
 
 #define ONE_DEG_IN_RAD (2.0 * M_PI) / 360.0 // 0.017444444
+
+struct SceneObject {
+   mat4 model_mat;
+   bool clicked;
+};
+
+struct ObjectFace {
+   unsigned int objectId;
+   array<vec3, 3> points;
+};
 
 const bool FULLSCREEN = false;
@@ -31,22 +42,13 @@
 vec3 cam_pos;
 
-array<vec3, 3> triangle_face;
-
-array<vec3,3> colored_triangle;
-array<vec3, 3> square_triangle1;
-array<vec3, 3> square_triangle2;
-
-bool clicked = false;
 int colors_i = 0;
-
-bool clicked_square = false;
-
-mat4 model_mat;
-mat4 model_mat2;
 
 mat4 view_mat;
 mat4 proj_mat;
 
-bool insideTriangle(vec3 p, array<vec3, 3> triangle);
+vector<SceneObject> objects;
+vector<ObjectFace> faces;
+
+bool insideTriangle(vec3 p, ObjectFace* face);
 
 GLuint loadShader(GLenum type, string file);
@@ -64,4 +66,5 @@
 
 void mouse_button_callback(GLFWwindow* window, int button, int action, int mods) {
+   /*
    double mouse_x, mouse_y;
    glfwGetCursorPos(window, &mouse_x, &mouse_y);
@@ -85,5 +88,5 @@
       vec3 ray_world = normalize((inverse(view_mat) * ray_eye).xyz());
 
-      /* LATEST NOTES:
+      / * LATEST NOTES:
        *
        * Normalizing the world ray caused issues, although it should make sense with the projection
@@ -92,5 +95,5 @@
        * Now, I need to figure out the correct intersection test in 2D space
        * Also, need to check that the global triangle points are correct
-       */
+       * /
 
       // since ray_world is the end result we want anyway, we probably don't need to add cam_pos to
@@ -99,5 +102,5 @@
       vec3 click_point = cam_pos + ray_world;
 
-      /* Now, we need to generate the constants for the equations describing
+      / * Now, we need to generate the constants for the equations describing
        * a 3D line:
        *   (x - x0) / a = (y - y0) / b = (z - z0) / c
@@ -105,5 +108,5 @@
        * The line goes through the camera position, so
        * cam_pos = <x0, y0, z0>
-       */
+       * /
 
       // upper right corner is 1, 1 in opengl
@@ -121,8 +124,8 @@
       cout << "(z - " << cam_pos.z << ") / " << c << endl;;
 
-      /* Now, we need to generate the constants for the equations describing
+      / * Now, we need to generate the constants for the equations describing
        * a 3D plane:
        * dx + ey +fz +g = 0
-       */
+       * /
 
       vec3 fp1 = triangle_face[0];
@@ -157,4 +160,5 @@
       cout << (clicked ? "true" : "false")  << endl;
    }
+   */
 }
 
@@ -180,4 +184,7 @@
  *       -An array of 3 points representing the face
  *       -The object struct represnting the object the face is a part of
+ *
+ *       -Really, all I need to pass in are the world ray and an ObjectFace reference
+ *       -The world ray will first need to be multiplied by the view and projection matrices before being passed in
  */
 
@@ -185,4 +192,7 @@
    double mouse_x, mouse_y;
    glfwGetCursorPos(window, &mouse_x, &mouse_y);
+
+   ObjectFace* face = &faces[0];
+   SceneObject* obj = &objects[face->objectId];
 
    if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) {
@@ -207,5 +217,5 @@
       vec4 ray_clip = vec4(x, y, NEAR_CLIP, 1.0f); // this should have a z equal to the near clipping plane
       vec4 ray_eye = ray_clip;
-      vec3 ray_world = (inverse(model_mat) * inverse(view_mat) * ray_eye).xyz();
+      vec3 ray_world = (inverse(obj->model_mat) * inverse(view_mat) * ray_eye).xyz();
 
       /* LATEST NOTES:
@@ -220,5 +230,5 @@
 
       vec4 cam_pos_origin = vec4(x, y, 0.0f, 1.0f);
-      vec3 cam_pos_temp = (inverse(model_mat) * inverse(view_mat) * cam_pos_origin).xyz();
+      vec3 cam_pos_temp = (inverse(obj->model_mat) * inverse(view_mat) * cam_pos_origin).xyz();
 
       ray_world = ray_world-cam_pos_temp;
@@ -228,7 +238,7 @@
       cout << "Camera -> (" << cam_pos_temp.x << "," << cam_pos_temp.y << "," << cam_pos_temp.z << ")" << endl;
 
-      vec3 fp1 = triangle_face[0];
-      vec3 fp2 = triangle_face[1];
-      vec3 fp3 = triangle_face[2];
+      vec3 fp1 = face->points[0];
+      vec3 fp2 = face->points[1];
+      vec3 fp3 = face->points[2];
 
       cout << "Points on the plane" << endl;
@@ -263,8 +273,6 @@
       printVector("Intersection", intersection);
 
-      clicked = insideTriangle(intersection, triangle_face);
-      cout << (clicked ? "true" : "false") << endl;
-
-      clicked_square = !clicked_square;
+      obj->clicked = insideTriangle(intersection, face);
+      cout << (obj->clicked ? "true" : "false") << endl;
    }
 }
@@ -312,4 +320,6 @@
    }
 
+   bool squareSelected = false;
+
    glfwSetMouseButtonCallback(window, mouse_button_callback_new);
 
@@ -318,4 +328,5 @@
    glewInit();
 
+   // Check if we might ever need this. If not, remove it.
    // glViewport(0, 0, width*2, height*2);
 
@@ -414,5 +425,20 @@
    // initialize global variables for click intersection tests
 
-   colored_triangle = {
+   mat4 T_model, R_model;
+
+   // triangle
+   objects.push_back(SceneObject());
+   objects[0].clicked = false;
+
+   /*
+   mat4 R_model = rotate(mat4(), 4.0f, vec3(0.0f, 1.0f, 0.0f));
+   */
+   T_model = translate(mat4(), vec3(0.5f, 0.0f, 0.0f));
+   R_model = rotate(mat4(), 0.0f, vec3(0.0f, 1.0f, 0.0f));
+   objects[0].model_mat = T_model*R_model;
+
+   faces.push_back(ObjectFace());
+   faces[0].objectId = 0;
+   faces[0].points = {
       vec3(points[0], points[1], points[2]),
       vec3(points[3], points[4], points[5]),
@@ -420,5 +446,16 @@
    };
 
-   square_triangle1 = {
+   // square
+   objects.push_back(SceneObject());
+   objects[1].clicked = false;
+
+   // mat4 T_model2 = translate(mat4(), vec3(-1.0f, 0.0f, 0.0f));
+   T_model = translate(mat4(), vec3(-0.5f, 0.0f, 0.0f));
+   R_model = rotate(mat4(), 0.0f, vec3(0.0f, 1.0f, 0.0f));
+   objects[1].model_mat = T_model*R_model;
+
+   faces.push_back(ObjectFace());
+   faces[1].objectId = 1;
+   faces[1].points = {
       vec3(points2[0], points2[1], points2[2]),
       vec3(points2[3], points2[4], points2[5]),
@@ -426,23 +463,11 @@
    };
 
-   square_triangle2 = {
+   faces.push_back(ObjectFace());
+   faces[2].objectId = 1;
+   faces[2].points = {
       vec3(points2[9], points2[10], points2[11]),
       vec3(points2[12], points2[13], points2[14]),
       vec3(points2[15], points2[16], points2[17]),
    };
-
-   triangle_face = colored_triangle;
-
-   /*
-   mat4 R_model = rotate(mat4(), 4.0f, vec3(0.0f, 1.0f, 0.0f));
-   */
-   mat4 T_model = translate(mat4(), vec3(0.5f, 0.0f, 0.0f));
-   mat4 R_model = rotate(mat4(), 0.0f, vec3(0.0f, 1.0f, 0.0f));
-   model_mat = T_model*R_model;
-
-   // mat4 T_model2 = translate(mat4(), vec3(-1.0f, 0.0f, 0.0f));
-   mat4 T_model2 = translate(mat4(), vec3(-0.5f, 0.0f, 0.0f));
-   mat4 R_model2 = rotate(mat4(), 0.0f, vec3(0.0f, 1.0f, 0.0f));
-   model_mat2 = T_model2*R_model2;
 
    GLuint points_vbo = 0;
@@ -550,10 +575,10 @@
 
    glUseProgram(shader_program);
-   glUniformMatrix4fv(model_test_loc, 1, GL_FALSE, value_ptr(model_mat));
+   glUniformMatrix4fv(model_test_loc, 1, GL_FALSE, value_ptr(objects[0].model_mat));
    glUniformMatrix4fv(view_test_loc, 1, GL_FALSE, value_ptr(view_mat));
    glUniformMatrix4fv(proj_test_loc, 1, GL_FALSE, value_ptr(proj_mat));
 
    glUseProgram(shader_program2);
-   glUniformMatrix4fv(model_mat_loc, 1, GL_FALSE, value_ptr(model_mat2));
+   glUniformMatrix4fv(model_mat_loc, 1, GL_FALSE, value_ptr(objects[1].model_mat));
    glUniformMatrix4fv(view_mat_loc, 1, GL_FALSE, value_ptr(view_mat));
    glUniformMatrix4fv(proj_mat_loc, 1, GL_FALSE, value_ptr(proj_mat));
@@ -571,5 +596,5 @@
       }
 
-      if (clicked) {
+      if (objects[0].clicked) {
          glBindBuffer(GL_ARRAY_BUFFER, colors_vbo);
 
@@ -581,6 +606,4 @@
             colors_i = 0;
          }
-
-         clicked = false;
       }
 
@@ -596,5 +619,5 @@
       // this is temporary.
       // It's needed to offset the code for the recoloring of the square working during click detection
-      glUniformMatrix4fv(model_test_loc, 1, GL_FALSE, value_ptr(model_mat));
+      glUniformMatrix4fv(model_test_loc, 1, GL_FALSE, value_ptr(objects[0].model_mat));
 
       glBindVertexArray(vao);
@@ -602,10 +625,14 @@
       glDrawArrays(GL_TRIANGLES, 0, numPoints);
 
-      if (clicked_square) {
+      if (objects[1].clicked) {
+         squareSelected = !squareSelected;
+      }
+
+      if (squareSelected) {
          glUseProgram(shader_program);
 
          // this is temporary.
          // It's needed to get the recoloring of the square working during click detection
-         glUniformMatrix4fv(model_test_loc, 1, GL_FALSE, value_ptr(model_mat2));
+         glUniformMatrix4fv(model_test_loc, 1, GL_FALSE, value_ptr(objects[1].model_mat));
 
          glBindVertexArray(vao2);
@@ -623,4 +650,8 @@
 
       glDrawArrays(GL_TRIANGLES, 0, numPoints2);
+
+      for (vector<SceneObject>::iterator it = objects.begin(); it != objects.end(); it++) {
+         it->clicked = false;
+      }
 
       glfwPollEvents();
@@ -724,8 +755,8 @@
 }
 
-bool insideTriangle(vec3 p, array<vec3,3> triangle) {
-   vec3 v21 = triangle[1]-triangle[0];
-   vec3 v31 = triangle[2]-triangle[0];
-   vec3 pv1 = p-triangle[0];
+bool insideTriangle(vec3 p, ObjectFace* face) {
+   vec3 v21 = face->points[1]- face->points[0];
+   vec3 v31 = face->points[2]- face->points[0];
+   vec3 pv1 = p- face->points[0];
 
    float y = (pv1.y*v21.x - pv1.x*v21.y) / (v31.y*v21.x - v31.x*v21.y);
