Browse Source

Refactored vector class into template.

angel 7 years ago
parent
commit
aea3239e58

+ 4 - 4
include/camera.h

@@ -2,7 +2,7 @@
 #define CAMERA_H
 
 #include "matrix.h"
-#include "vector3.h"
+#include "vector3D.h"
 
 
 struct Camera{
@@ -15,9 +15,9 @@ struct Camera{
     Matrix4 projectionMatrix;
 
     //Position and direction of camera, used to build view matrix
-    Vector3 position{0,0,8};
-    Vector3 target{0,0,0};
-    Vector3 up{0,1,0};
+    Vector3f position{0,0,8};
+    Vector3f target{0,0,0};
+    Vector3f up{0,1,0};
 
     //Variables that determine frustrum (Future class?)
     //Used to build projection matrix

+ 7 - 7
include/matrix.h

@@ -2,14 +2,14 @@
 #define MATRIX_H
 
 #include <array>
-#include <vector3.h>
+#include <vector3D.h>
 
 //Data struct holding all of the data you need to make a transform matrix
 struct TransformParameters{
-    TransformParameters() :scaling(Vector3(1,1,1)) {};
-    Vector3 translation;
-    Vector3 rotation;
-    Vector3 scaling;
+    TransformParameters() :scaling(Vector3f(1,1,1)) {};
+    Vector3f translation;
+    Vector3f rotation;
+    Vector3f scaling;
 };
 
 //Matrices are stored in memory in row major order, but operations are done as if it was
@@ -21,7 +21,7 @@ class Matrix4{
             return mMatrix[y*4 + x];
         }
         Matrix4 operator* (Matrix4 &rhs);
-        Vector3 matMultVec(Vector3 &vec); 
+        Vector3f matMultVec(Vector3f &vec); 
         
         //Named constructor idiom to build the basic matrices we need for 
         //transformation.
@@ -38,7 +38,7 @@ class Matrix4{
         Matrix4 static transformMatrix(TransformParameters transform);
 
         //Inverse Camera transformation matrix (the world from the camera's eyes)
-        Matrix4 static lookAt(Vector3& position, Vector3& target, Vector3& temp);
+        Matrix4 static lookAt(Vector3f& position, Vector3f& target, Vector3f& temp);
 
         //3D projection matrix. When applied results in the camera frustrum area being 
         //defined as X[-1,1] Y[-1,1] Z[1,0] 

+ 6 - 6
include/mesh.h

@@ -1,20 +1,20 @@
 #ifndef MESH_H
 #define MESH_H
 
-#include "vector3.h"
+#include "vector3D.h"
 #include <vector>
 
 //Struct containing information relevant to the renderer about the vertices, normals and
 //texture coordinates of a model. Also keeps track of useful stuff for iterations.
 struct Mesh{
     int numVertices = 0;
-    std::vector<Vector3> vertices;
-    std::vector<Vector3> normals;
+    std::vector<Vector3f> vertices;
+    std::vector<Vector3f> normals;
 
     int numFaces = 0;
-    std::vector<Vector3> vertexIndices;
-    std::vector<Vector3> textureIndices;
-    std::vector<Vector3> normalsIndices;
+    std::vector<Vector3i> vertexIndices;
+    std::vector<Vector3i> textureIndices;
+    std::vector<Vector3i> normalsIndices;
 
     //Simple mesh description for debugging.
     void describeMesh();

+ 7 - 7
include/rasterizer.h

@@ -3,7 +3,7 @@
 
 #include "SDL.h"
 #include "buffer.h"
-#include "vector3.h"
+#include "vector3D.h"
 #include "shader.h"
 
 //Takes in vertex data, rasterizes the surface and applies the fragment shader at
@@ -15,22 +15,22 @@ class Rasterizer{
         static void testPattern(Buffer<Uint32> *pixelBuffer);
 
         //Bresenham's line drawing algorithm using only int arithmetic
-        static void drawLine(Vector3 &vertex1, Vector3 &vertex2, const Uint32 &color, Buffer<Uint32> *pixelBuffer);
+        static void drawLine(Vector3f &vertex1, Vector3f &vertex2, const Uint32 &color, Buffer<Uint32> *pixelBuffer);
 
         //Draws wireframe rendering of triangle by calling the line drawer for each
         //Line in a triangle.(AB, BC, AC)
-        static void drawWireFrame(Vector3 *vertices, IShader &shader, Buffer<Uint32> *pixelBuffer);
+        static void drawWireFrame(Vector3f *vertices, IShader &shader, Buffer<Uint32> *pixelBuffer);
 
         //Proper triangle rasterization with vertex interpolation.
-        static void drawTriangles(Vector3 *vertices, IShader &shader, Buffer<Uint32> *pixelBuffer, Buffer<float> *zBuffer);
+        static void drawTriangles(Vector3f *vertices, IShader &shader, Buffer<Uint32> *pixelBuffer, Buffer<float> *zBuffer);
 
         //Transforms coordinates from NDC to pixel values(Integers)
-        static void viewportTransform(Buffer<Uint32> *pixelBuffer, Vector3 *vertices,std::array<int, 3>   &xV,std::array<int, 3>   &yV, Vector3  &zV);
+        static void viewportTransform(Buffer<Uint32> *pixelBuffer, Vector3f *vertices,std::array<int, 3>   &xV,std::array<int, 3>   &yV, Vector3f  &zV);
 
         //Given a set of vertex values, the triangle area in screen space
         //and a target point returns the barycentric coordinates calculated using
-        //Edge functions
-        static void barycentric(Vector3 &lambdas, float InvArea, int x, int y,
+        //Edge functions.
+        static void barycentric(Vector3f &lambdas, float InvArea, int x, int y,
                          std::array<int, 3>   &xV, std::array<int, 3>   &yV);
 
     private:

+ 10 - 10
include/shader.h

@@ -1,7 +1,7 @@
 #ifndef SHADER_H
 #define SHADER_H
 
-#include "vector3.h"
+#include "vector3D.h"
 #include "matrix.h"
 #include "rasterizer.h"
 #include <array>
@@ -9,21 +9,21 @@
 //Shader Interface for a class that emulates modern GPU fragment and vertex shaders
 struct IShader {
     virtual ~IShader() {};
-    virtual Vector3 vertex(Vector3 &vertex, Matrix4 &MVP, Vector3 &normals, Vector3 &light, int i) = 0;
-    virtual bool fragment(Vector3 &bari, Vector3 &color, float &depth, Vector3 &zVerts) = 0;
+    virtual Vector3f vertex(Vector3f &vertex, Matrix4 &MVP, Vector3f &normals, Vector3f &light, int i) = 0;
+    virtual bool fragment(Vector3f &bari, Vector3f &color, float &depth, Vector3f &zVerts) = 0;
 };
 
 //Simplest shader. Calculates light intensity per triangle.
 struct FlatShader : public IShader {
     float varIntensity;
-    Vector3 rgb{255,255,255};
+    Vector3f rgb{255,255,255};
 
-    Vector3 vertex(Vector3 &vertex, Matrix4 &MVP, Vector3 &normals, Vector3 &light, int index) override{
+    Vector3f vertex(Vector3f &vertex, Matrix4 &MVP, Vector3f &normals, Vector3f &light, int index) override{
         varIntensity = std::max(0.0f,normals.dotProduct(light));
         return MVP.matMultVec(vertex); //Transforms verts into projected space
     }
 
-    bool fragment(Vector3 &bari, Vector3 &color, float &depth, Vector3 &zVerts) override{
+    bool fragment(Vector3f &bari, Vector3f &color, float &depth, Vector3f &zVerts) override{
         depth = bari.dotProduct(zVerts);
         color = rgb*varIntensity;
         return false;
@@ -34,15 +34,15 @@ struct FlatShader : public IShader {
 //More Complex shader that calculates a per-vertex intensity and interpolates 
 //through the fragments of the triangle
 struct GouraudShader : public IShader {
-    Vector3 varying_intensity;
-    Vector3 rgb{255,255,255};
+    Vector3f varying_intensity;
+    Vector3f rgb{255,255,255};
 
-    Vector3 vertex(Vector3 &vertex, Matrix4 &MVP, Vector3 &normals, Vector3 &light, int index) override{
+    Vector3f vertex(Vector3f &vertex, Matrix4 &MVP, Vector3f &normals, Vector3f &light, int index) override{
         varying_intensity.data[index] = std::max(0.0f, normals.dotProduct(light));
         return MVP.matMultVec(vertex);
     }
 
-    bool fragment(Vector3 &bari, Vector3 &color, float &depth, Vector3 &zVerts) override{
+    bool fragment(Vector3f &bari, Vector3f &color, float &depth, Vector3f &zVerts) override{
         float intensity = bari.y*varying_intensity.x + bari.z*varying_intensity.y + bari.x*varying_intensity.z;
         color = rgb * intensity;
         depth = bari.dotProduct(zVerts);

+ 2 - 2
include/softwareRenderer.h

@@ -33,10 +33,10 @@ class SoftwareRenderer {
         bool createBuffers(int w, int h);
 
         //Primitive building methods
-        void buildTri(Vector3 &f, Vector3 *trianglePrim, std::vector<Vector3> &verts);
+        void buildTri(Vector3i &f, Vector3f *trianglePrim, std::vector<Vector3f> &vals);
 
         //Culling methods
-        bool backFaceCulling(Vector3 *trianglePrim);
+        bool backFaceCulling(Vector3f *trianglePrim);
 
         //Pointer to the scene's target camera
         Camera * mCamera;

+ 0 - 40
include/vector3.h

@@ -1,40 +0,0 @@
-#ifndef VECTOR3_H
-#define VECTOR3_H
-
-#include <string>
-
-//Basic 3D vector class for general calculations
-//Should probably be made a template at some point 
-struct Vector3{
-    //I know this is undefined behaviour and really not recommended but
-    //Using an operator overload for looping was slowing down my program 20%
-    union {
-            //Anonymous struct and array union hack
-            float data[3];
-            struct {
-                float x;
-                float y;
-                float z;
-            };
-        };
-    
-    Vector3(float x1, float y1, float z1) : x(x1), y(y1), z(z1) {};
-    Vector3(): x(0.0f), y(0.0f), z(0.0f) {};
-
-    //Scalar operations
-    Vector3 &operator-(); //Negate components of vector
-    Vector3 operator*(float rhs); //Scalar vector multiplication
-
-    //Vector operations
-    Vector3 operator-(Vector3 &rhs);
-    Vector3 operator+(Vector3 &rhs);
-    Vector3 crossProduct(Vector3 &rhs);
-    Vector3 &normalized();
-    float   dotProduct(Vector3 &rhs);
-    float length();
-    
-    //Print for debugging purposes
-    void print();
-};
-
-#endif

+ 88 - 0
include/vector3D.h

@@ -0,0 +1,88 @@
+#ifndef VECTOR3D_H
+#define VECTOR3D_H
+
+#include <string>
+#include <type_traits>
+#include "math.h"
+
+//Basic 3D vector class for general calculations
+template<typename T>
+struct Vector3{
+    //I know this is undefined behaviour and really not recommended but
+    //Using an operator overload for looping was slowing down my program 20%
+    union {
+        //Anonymous struct and array union hack
+        T data[3];
+        struct {
+            T x;
+            T y;
+            T z;
+        };
+    };
+    //W component only ever used in perspective projection and clipping,
+    //Just imagine it isn't here
+    T w;
+
+    //Constructors
+    Vector3(): x(0), y(0), z(0), w(1) {};
+    Vector3(T val): x(val), y(val), z(val), w(1) {};
+    Vector3(T x1, T y1, T z1) : x(x1), y(y1), z(z1), w(1) {};
+    
+    //Scalar-vector operations
+    Vector3 &operator-(){//Negate components of vector
+        x = -x;
+        y = -y;
+        z = -z;
+        return *this;
+    }; 
+    Vector3 operator*(const T &rhs) const //Scalar-vector multiplication
+    {return Vector3(x*rhs, y*rhs, z*rhs);}
+
+    //Vector-vector operations
+    Vector3 operator-(const Vector3 &rhs) const
+    {return Vector3(x - rhs.x, y - rhs.y, z - rhs.z);}
+
+    Vector3 operator+(const Vector3 &rhs) const
+    {return Vector3(x + rhs.x, y + rhs.y, z + rhs.z);}
+
+    Vector3 crossProduct(const Vector3 &r) const
+    {return Vector3( (y*r.z - z*r.y), (z*r.x - x*r.z), (x*r.y - y*r.x) );}
+
+    T   dotProduct(const Vector3 &rhs) const
+    {return x*rhs.x + y*rhs.y + z*rhs.z;}
+
+    T length() const
+    {return std::sqrt(x*x + y*y + z*z);}
+
+    Vector3 &normalized()
+    {
+        T len = length();
+        if( len > 0){
+            T factor = 1 / len;
+            x *= factor;
+            y *= factor;
+            z *= factor;
+        }
+
+        return *this;
+    }
+    
+    //Print for debugging purposes
+    void print(){
+        std::string str;
+        if(std::is_same<T,float>::value){
+            str = "Vec: (%2.1f, %2.1f,%2.1f)\n";
+            
+        }
+        else if(std::is_same<T,int>::value) {
+            str = "Vec: (%d, %d,%d)\n";    
+        }
+        printf(str.c_str(),x,y,z);
+    }
+};
+
+//Shorthands for the common vector types we use
+typedef Vector3<float> Vector3f; 
+typedef Vector3<int> Vector3i; 
+
+#endif

+ 7 - 7
src/matrix.cpp

@@ -1,8 +1,8 @@
 #include "matrix.h"
 #include <math.h>
 
-Vector3 Matrix4::matMultVec(Vector3 &vec){
-    Vector3 newVec(0,0,0);
+Vector3f Matrix4::matMultVec(Vector3f &vec){
+    Vector3f newVec(0,0,0);
     float w2 = 0;
     newVec.x = vec.x*(*this)(0,0)+
                vec.y*(*this)(0,1)+
@@ -150,11 +150,11 @@ Matrix4 Matrix4::transformMatrix(TransformParameters transform){
     return  translationMatrix*(temp);
 }
 
-Matrix4 Matrix4::lookAt(Vector3& position, Vector3& target, Vector3& temp){
-    //Gram–Schmidt_process
-    Vector3 forward = (position - target).normalized();
-    Vector3 side    = (temp.crossProduct(forward)).normalized();
-    Vector3 up      = forward.crossProduct(side);
+Matrix4 Matrix4::lookAt(Vector3f& position, Vector3f& target, Vector3f& temp){
+    //Gram–Schmidt process
+    Vector3f forward = (position - target).normalized();
+    Vector3f side    = (temp.crossProduct(forward)).normalized();
+    Vector3f up      = forward.crossProduct(side);
 
     //We will now build the inverse transform from the world position to the camera
     //The idea is that we don't care where the camera is, we only care about what

+ 1 - 2
src/mesh.cpp

@@ -2,8 +2,7 @@
 
 void Mesh::describeMesh(){
     for(int i = 0; i < numVertices; ++i){
-        Vector3 vertex = vertices[i];
-        printf("Vertex  %2.1d: %f, %f, %f \n",i,vertex.x, vertex.y, vertex.z);
+        printf("Vertex  %2.1d: %f, %f, %f \n",i,vertices[i].x, vertices[i].y, vertices[i].z);
     }
     printf("Meshsize is: %d \n", numVertices);
 }

+ 2 - 2
src/model.cpp

@@ -1,5 +1,5 @@
 #include "model.h"
-#include "vector3.h"
+#include "vector3D.h"
 #include <limits>
 
 Model::Model(std::string path, TransformParameters &initParameters){
@@ -15,7 +15,7 @@ Mesh * Model::getMesh(){
 void Model::initPosition(TransformParameters initVals){
     Matrix4 modelMatrix = Matrix4::transformMatrix(initVals);
     int size = mMesh.numVertices;
-    std::vector<Vector3> * vertices = &mMesh.vertices;
+    std::vector<Vector3f> * vertices = &mMesh.vertices;
 
     //Applying the multiplication
     for (int i = 0;i < size; ++i){

+ 4 - 4
src/objParser.cpp

@@ -21,7 +21,7 @@ bool OBJ::fileExists(std::string &path){
 //Main OBJ parsing function
 void OBJ::loadFileData(Mesh &mesh, std::ifstream &file){
     std::string line, key, x ,y ,z;
-    Vector3 indices[3];
+    Vector3i indices[3];
     char delimeter = '/';
     while(!file.eof()){
         std::getline(file,line);
@@ -29,12 +29,12 @@ void OBJ::loadFileData(Mesh &mesh, std::ifstream &file){
         iss >> key;
         if(key == "v"){ //Vertex data
             iss >> x >> y >> z;
-            Vector3 vertex(std::stof(x),std::stof(y),std::stof(z));
+            Vector3f vertex(std::stof(x),std::stof(y),std::stof(z));
             mesh.vertices.push_back(vertex);
         }
         else if(key == "vn"){ //Normal data
             iss >> x >> y >> z;
-            Vector3 normal(std::stof(x),std::stof(y),std::stof(z));
+            Vector3f normal(std::stof(x),std::stof(y),std::stof(z));
             mesh.normals.push_back(normal);
         }
         else if(key == "f"){ //index data
@@ -44,7 +44,7 @@ void OBJ::loadFileData(Mesh &mesh, std::ifstream &file){
             std::vector<std::string> splitZ = splitStr(z,delimeter);
             for(int i = 0; i < splitX.size(); ++i){
                 //Subtracted by 1 because OBJ files count indices starting by 1
-                indices[i] = Vector3(std::stof(splitX[i])-1,std::stof(splitY[i])-1,std::stof(splitZ[i])-1);
+                indices[i] = Vector3i(std::stoi(splitX[i])-1,std::stoi(splitY[i])-1,std::stoi(splitZ[i])-1);
             }
             printf("\n");
             mesh.vertexIndices.push_back(indices[0]);

+ 8 - 8
src/rasterizer.cpp

@@ -29,7 +29,7 @@ void Rasterizer::testPattern(Buffer<Uint32> *pixelBuffer){
 
 }
 
-void Rasterizer::drawLine(Vector3 &vertex1, Vector3 &vertex2,const Uint32 &color, Buffer<Uint32> *pixelBuffer ){
+void Rasterizer::drawLine(Vector3f &vertex1, Vector3f &vertex2,const Uint32 &color, Buffer<Uint32> *pixelBuffer ){
     //NDC to viewport transform
     int x1 = (vertex1.x + 1 ) * pixelBuffer->mWidth * 0.5;
     int y1 = (-vertex1.y + 1 ) * pixelBuffer->mHeight * 0.5;
@@ -72,19 +72,19 @@ void Rasterizer::drawLine(Vector3 &vertex1, Vector3 &vertex2,const Uint32 &color
     } 
 }
 
-void Rasterizer::drawWireFrame(Vector3 *vertices, IShader &shader, Buffer<Uint32> *pixelBuffer){
+void Rasterizer::drawWireFrame(Vector3f *vertices, IShader &shader, Buffer<Uint32> *pixelBuffer){
     drawLine(vertices[0], vertices[1], red, pixelBuffer);
     drawLine(vertices[1], vertices[2], green, pixelBuffer);
     drawLine(vertices[0], vertices[2], blue, pixelBuffer);
 }  
 
 //Draws triangles using baricentric coordinates,
-void Rasterizer::drawTriangles(Vector3 *vertices, IShader &shader, Buffer<Uint32> *pixelBuffer, Buffer<float> *zBuffer){
+void Rasterizer::drawTriangles(Vector3f *vertices, IShader &shader, Buffer<Uint32> *pixelBuffer, Buffer<float> *zBuffer){
 
     //Converting to viewport space 
     std::array<int, 3>   xVerts;
     std::array<int, 3>   yVerts;
-    Vector3 zVerts;
+    Vector3f zVerts;
     Rasterizer::viewportTransform(pixelBuffer, vertices, xVerts, yVerts, zVerts);
 
     //Finding triangle bounding box limits clips it to the screen dimension
@@ -106,8 +106,8 @@ void Rasterizer::drawTriangles(Vector3 *vertices, IShader &shader, Buffer<Uint32
                             - (xVerts[1]-xVerts[0])*(yVerts[2]-yVerts[0]));     
     //Per fragment variables            
     float depth = 0;
-    Vector3 lambdas;
-    Vector3 rgbVals;
+    Vector3f lambdas;
+    Vector3f rgbVals;
 
     //Iterating through triangle bounding box
     for(int y = yMin; y <= yMax; ++y){
@@ -133,7 +133,7 @@ void Rasterizer::drawTriangles(Vector3 *vertices, IShader &shader, Buffer<Uint32
     }
 }  
 
-void Rasterizer::viewportTransform(Buffer<Uint32> *pixelBuffer, Vector3 *vertices,std::array<int, 3>   &xV,std::array<int, 3>   &yV, Vector3   &zV){
+void Rasterizer::viewportTransform(Buffer<Uint32> *pixelBuffer, Vector3f *vertices,std::array<int, 3>   &xV,std::array<int, 3>   &yV, Vector3f   &zV){
     for(int i = 0; i < 3; ++i){
         xV[i] = (int)((vertices[i].x + 1 ) * pixelBuffer->mWidth * 0.5);
         yV[i] = (int)((-vertices[i].y + 1 ) * pixelBuffer->mHeight * 0.5);
@@ -142,7 +142,7 @@ void Rasterizer::viewportTransform(Buffer<Uint32> *pixelBuffer, Vector3 *vertice
 }
 
 //Calculates baricentric coordinates of triangles using the cross
-void Rasterizer::barycentric(Vector3 &lambdas, float invArea, int x, int y,  
+void Rasterizer::barycentric(Vector3f &lambdas, float invArea, int x, int y,  
                         std::array<int, 3>   &xVerts, std::array<int, 3>   &yVerts){
     for(int i = 0; i < 3; ++i){
         int i2 = (i+1)%3;

+ 1 - 1
src/scene.cpp

@@ -35,7 +35,7 @@ bool Scene::loadSceneModels(std::string &path){
     }
     else{
         TransformParameters initParameters;
-        initParameters.translation = Vector3(0, -1.5, 0);
+        initParameters.translation = Vector3f(0, -1.5, 0);
         modelsInScene.push_back(new Model(fullPath, initParameters));
         return false;
     }

+ 17 - 16
src/softwareRenderer.cpp

@@ -23,21 +23,21 @@ void SoftwareRenderer::shutDown(){
 void SoftwareRenderer::drawTriangularMesh(Mesh* triMesh){
 
     //Getting the vertices, faces 
-    std::vector<Vector3> * vIndices = &triMesh->vertexIndices;
-    std::vector<Vector3> * nIndices = &triMesh->normalsIndices;
-    std::vector<Vector3> * vertices = &triMesh->vertices;
-    std::vector<Vector3> * normals = &triMesh->normals;
+    std::vector<Vector3i> * vIndices = &triMesh->vertexIndices;
+    std::vector<Vector3i> * nIndices = &triMesh->normalsIndices;
+    std::vector<Vector3f> * vertices = &triMesh->vertices;
+    std::vector<Vector3f> * normals = &triMesh->normals;
     int numFaces = triMesh->numFaces;
 
     //Array grouping vertices together into triangle
-    Vector3 trianglePrimitive[3];
-    Vector3 normalPrim[3];
+    Vector3f trianglePrimitive[3];
+    Vector3f normalPrim[3];
 
     //Initializing shader
     GouraudShader shader;
 
     //Basic light direction
-    Vector3 lightDir{1,0,0};
+    Vector3f lightDir{1,0,0};
 
     //Building ModelViewProjection matrix
     Matrix4 MVP = (mCamera->projectionMatrix)*(mCamera->viewMatrix);
@@ -45,8 +45,9 @@ void SoftwareRenderer::drawTriangularMesh(Mesh* triMesh){
     //Iterate through every triangle
     for (int j = 0; j < numFaces; ++j){
         //Current vertex and normal indices
-        Vector3 f = (*vIndices)[j];
-        Vector3 n = (*nIndices)[j];
+        Vector3i f = (*vIndices)[j];
+        Vector3i n = (*nIndices)[j];
+        f.print();
 
         //Pack vertex and normal data together into an array
         buildTri(f,trianglePrimitive, *vertices);
@@ -101,20 +102,20 @@ bool SoftwareRenderer::createBuffers(int w, int h){
     return success;
 }
 
-void SoftwareRenderer::buildTri(Vector3 &index, Vector3 *primitive, std::vector<Vector3> &vals){
+void SoftwareRenderer::buildTri(Vector3i &index, Vector3f *primitive, std::vector<Vector3f> &vals){
     for(int i = 0; i < 3; ++i){
-        primitive[i] = vals[(int)index.data[i]];
+        primitive[i] = vals[index.data[i]];
     }
 }
 
-bool SoftwareRenderer::backFaceCulling(Vector3 *trianglePrim){
+bool SoftwareRenderer::backFaceCulling(Vector3f *trianglePrim){
         //Triangle surface normal 
         //Should probably be calculated on load next time
-        Vector3 N1 = trianglePrim[1] - trianglePrim[0];
-        Vector3 N2 = trianglePrim[2] - trianglePrim[0];
-        Vector3 N  = (N2.crossProduct(N1)).normalized();
+        Vector3f N1 = trianglePrim[1] - trianglePrim[0];
+        Vector3f N2 = trianglePrim[2] - trianglePrim[0];
+        Vector3f N  = (N2.crossProduct(N1)).normalized();
 
-        Vector3 view_dir =  trianglePrim[0] - mCamera->position;
+        Vector3f view_dir =  trianglePrim[0] - mCamera->position;
         view_dir = view_dir.normalized();
 
         //Returns false if the triangle cannot see the camera

+ 0 - 68
src/vector3.cpp

@@ -1,68 +0,0 @@
-#include "vector3.h"
-#include "math.h"
-
-//Scalar-vector stuff
-Vector3 &Vector3::operator-(){
-    x = -x;
-    y = -y;
-    z = -z;
-    return *this;
-}
-
-Vector3 Vector3::operator*(float rhs){
-    return Vector3(this->x * rhs,
-                   this->y * rhs,
-                   this->z * rhs);
-}
-
-//Vector-vector operations
-Vector3 Vector3::operator-(Vector3 &rhs){
-    return Vector3(this->x - rhs.x,
-                   this->y - rhs.y,
-                   this->z - rhs.z
-    );
-}
-
-Vector3 Vector3::operator+(Vector3 &rhs){
-    return Vector3(this->x + rhs.x,
-                   this->y + rhs.y,
-                   this->z + rhs.z
-    );
-}
-
-Vector3 Vector3::crossProduct(Vector3 &rhs){
-    Vector3 temp;
-    temp.x = ((this->y)*rhs.z) - (this->z)*rhs.y;
-    temp.y = ((this->z)*rhs.x) - (this->x)*rhs.z;
-    temp.z = ((this->x)*rhs.y) - (this->y)*rhs.x;
-    return temp;
-}
-
-Vector3& Vector3::normalized(){
-    float len = this->length();
-    if(len > 0){
-        float factor = 1 / (float)len;
-        this->x*= factor;
-        this->y*= factor;
-        this->z*= factor;
-    }
-    else{
-        //Deal with this more nicely at some point!
-        printf("Your vector is all zeros!!\n");
-    }
-    return *this;
-}     
-
-float Vector3::dotProduct(Vector3 &rhs){
-    return (this->x)*rhs.x + (this->y)*rhs.y + (this->z)*rhs.z;
-}
-
-float Vector3::length(){
-    return std::sqrt((this->x * this->x) +
-                     (this->y * this->y) +
-                     (this->z * this->z));
-}
-
-void Vector3::print(){
-    printf("Vec: %f\t%f\t%f\n",x,y,z);
-}