/////////////////////////////////////////////////////////////////////////
//                                                                     //
// This file contains the declaration of the CTriangle class.          //
//                                                                     //
/////////////////////////////////////////////////////////////////////////
#ifndef __CTRIANGLE_HPP__
#define __CTRIANGLE_HPP__


// Define this to use the algorithm seen in the course
#define USE_INF4702_RAY_TRIANGLE_ALGORITHM 0


#include "CVector.hpp"
#include "CConcreteSurface.hpp"


/////////////////////////////////////////////////////////////////////////
//                                                                     //
// This class is an implementation of the CSurface interface that      //
// represents a triangle in the scene.                                 //
//                                                                     //
/////////////////////////////////////////////////////////////////////////
class CTriangle : public CConcreteSurface
{
public:
  CTriangle(const std::string& strName);

  // Interface implementation
  inline virtual CTriangle* Copy() const;
  virtual void Preprocess();
  virtual void Normal(const CVector& hit, CVector& normal) const;

  // For shader generation
  virtual void GenerateShaderForObject(std::ostream& o) const;
  static  void generateShaderForClass(std::ostream& o);

protected:
  virtual int  Intersect(const CRay& ray, hitcontainer& hits) const;
  virtual void ConcreteDrawGL() const;

private:
  ////////////////
  // Propreties //
  ////////////////

  // Vertices of the triangle
  CVector m_PropVertex0;
  CVector m_PropVertex1;
  CVector m_PropVertex2;

  // Helper variables that don't need to be computed at every
  // intersection
  CVector m_Normal;
#if USE_INF4702_RAY_TRIANGLE_ALGORITHM
  real_t  m_D;
  real_t  m_T1;
  real_t  m_T2;
  enum eDirection { DIRECTION_X, DIRECTION_Y, DIRECTION_Z };
  eDirection m_MaxDirection;
#endif
};




inline CTriangle* CTriangle::Copy() const
{
  return new CTriangle(*this);
}

#endif // __CTRIANGLE_HPP__
