CSC3224_Computer_Games_Development / nclgl / Mesh.h
Mesh.h
Raw
#pragma  once
#include "OGLRenderer.h"
#include <vector>
#include <string>
#include <fstream>

using std::ifstream;
using std::string;

enum  MeshBuffer {
     VERTEX_BUFFER, COLOUR_BUFFER, TEXTURE_BUFFER, NORMAL_BUFFER, TANGENT_BUFFER, INDEX_BUFFER, MAX_BUFFER
};
class  Mesh {
 public:
	 friend class MD5Mesh;
     Mesh(void);
     virtual ~Mesh(void);

	 virtual void Draw();

	 static Mesh* GenerateTriangle();
	 static Mesh* GenerateTrianglePyramid();
	 static Mesh* GenerateQuad();
	 static Mesh* GenerateQuadCube();
	 Mesh* loadMeshFile(const string& filename); // Load Mesh file

     GLuint    type;	//Primitive type for this mesh (GL_TRIANGLES...etc)

	 GLuint texture;

	 void SetTexture(GLuint tex) { texture = tex; }
	 GLuint GetTexture() { return texture; }

	 void SetBumpMap(GLuint tex) { bumpTexture = tex; }
	 GLuint GetBumpMap() { return bumpTexture; }

 protected:
     void      BufferData();				 //Buffers all VBO data into graphics memory. Required before drawing!

     GLuint    arrayObject;					//VAO for this mesh
     GLuint    bufferObject[MAX_BUFFER];    //VBOs for this mesh
     GLuint    numVertices;					//Number of vertices for this mesh
	 GLuint	   numIndices;					//Number of indices for this mesh

     Vector3*     vertices;					//Pointer to vertex position attribute data (badly named...?)
     Vector4*     colours;					//Pointer to vertex colour attribute data

	 Vector2* textureCoords;				//Pointer to vertex texture coordinate attribute data	
	 Vector3* normals;						//Pointer to vertex normals attribute data	
	 Vector3* tangents;						//Pointer to vertex tangents attribute data
	 
	 unsigned int* indices;					//Pointer to vertex indices attribute data



	 void GenerateNormals();
	 void GenerateTangents();
	 Vector3 GenerateTangent(const  Vector3 &a, const  Vector3 &b,
		                               const  Vector3 &c, const  Vector2 &ta,
		                              const  Vector2 &tb, const  Vector2 &tc);
	 GLuint bumpTexture;
};