/////////////////////////////////////////////////////////////////////////
//                                                                     //
// This file contains the declaration of the CDifference class.        //
//                                                                     //
/////////////////////////////////////////////////////////////////////////
#ifndef __CDIFFERENCE_HPP__
#define __CDIFFERENCE_HPP__


#include "CBooleanSurface.hpp"


/////////////////////////////////////////////////////////////////////////
//                                                                     //
// This class is a constructive geometry implementation for boolean    //
// difference of two surfaces.                                         //
//                                                                     //
/////////////////////////////////////////////////////////////////////////
class CDifference : public CBooleanSurface
{
public:
  inline CDifference(const std::string& strName,
                     CSurface* pOrigSurface1,
                     CSurface* pOrigSurface2);
  virtual ~CDifference();


  // Interface implementation
  inline virtual CDifference* Copy() const;


protected:
  // This function describes the boolean operation representing this
  // surface
  virtual bool IsIn(bool surface1, bool surface2) const;

  // This function does the concrete OpenGL drawing of the surface
  virtual void ConcreteDrawGL() const;
};




inline CDifference::CDifference(const std::string& strName,
                                CSurface* pOrigSurface1,
                                CSurface* pOrigSurface2)
  : CBooleanSurface(strName,
                    pOrigSurface1,
                    pOrigSurface2)
{
}
inline CDifference::~CDifference()
{
}
inline CDifference* CDifference::Copy() const
{
  return new CDifference(*this);
}

inline bool CDifference::IsIn(bool surface1, bool surface2) const
{
  return (surface1 && !surface2);
}
inline void CDifference::ConcreteDrawGL() const
{
  drawInside(pSurface2.get(),
             pSurface1.get(),
             GL_FRONT,
             GL_NOTEQUAL);

  drawFixup(pSurface1.get());

  drawInside(pSurface1.get(),
             pSurface2.get(),
             GL_BACK,
             GL_EQUAL);
}




#endif // __CDIFFERENCE_HPP__
