// cTriangle.h
// 2/27/04
// Forrest Briggs
// The triangle class stores pointers to its face, edges, and vertices.
// It also stores the triangle's color, and implement's its draw method.
// 3/5/04
// Forrest Briggs
// Added standardization code.
// 3/6/04 
// Forrest Briggs
// added per vertex colors, forward facing check
// 3 / 22 / 04 Forrest Briggs
// Triangle have a material index for texture mapping. 

#ifndef ctriangle_h
#define ctriangle_h

#include "ForwardDeclarations.h"
#include "OGLPlatformSpecific.h"
#include "cEdge.h"
#include "cVertex.h"
#include "cStandardizedTriangle.h"
#include "cColor.h"
#include "cTextureCoord.h"
#include "cTextureImage.h"
#include <vector>

class cTriangle
{
public: 
    cTriangle();
    
    void draw();
    
    // calculate the normal to the triangle assuming the forward face has counterclockwise vertex ordering
    void computeNormal();		
    
    // returns the normal. computeNormal() must already have been called.
    cVector& getNormal();		

    // calculates standardized version of this triangle's vertices and a forward tranformation matrix
    void standardizeVertices(); 	
    
    // return a face with standardized vertices. standardizeVertices must already have been called.
    cStandardizedTriangle& getStandardized();		    
    
    // return the transformation matrix. standardizeVertices must already have been called
    float* getStandardVertexTranform();	
    
    // returns true if the incedent vector is going toward's the triangle's forward face
    bool forwardFacing(cVector incident); 
        

    // we need to draw all of the traingles with the same texture at the same time, so
    // each texture stores a list of all triangles that use it. this function
    // will add this triangle to the appropriate texture's list
    void addToTextureList(vector<cTextureImage*>& textures);
            
    cEdge *e0_, *e1_, *e2_ ;
    cVertex *v0_, *v1_, *v2_; 
    
    //cColor v0Color, v1Color, v2Color;
    //cTextureCoord v0TC, v1TC, v2TC;
    int materialIndex_;		// when we load a milkshape file, we first have to specify
                                // by index which material each triangle has.
                                // later we will add triangles to a list in each texture
                                // of all of the triangles having that texture    
        
    bool hasBeenAddedToCollisionList_;	// used by build collision lists so triangles are never added more than once

private:
    cVector normal_;			// stores the normal of the triangle 

    cStandardizedTriangle standardized_;// stores vertices and edges of the triangle in standardized position
    float vertexTransform_[16];		// the 4x4 matrix to transform the balls path into standardized space
};

#endif // end define ctriangle_h