00001 #ifndef PRIMITIVE_H 00002 #define PRIMITIVE_H 00003 00004 00005 #include <cassert> 00006 00007 #include "Box.h" 00008 #include "Shader.h" 00009 #include "TexCoordinate.h" 00010 #include "RGBAColor.h" 00011 00012 00013 class Ray; 00014 00015 00021 class Primitive 00022 { 00023 public: 00026 Primitive() 00027 : mBounds(), 00028 mShader(NULL), 00029 mCastShadows(true) 00030 { 00031 } 00032 00035 virtual ~Primitive() 00036 { 00037 } 00038 00041 virtual bool intersect(Ray & ray) const = 0; 00042 00047 virtual Vec3f normal(const Ray & ray) const = 0; 00048 00051 virtual TexCoordinate texCoord(const Ray & /*ray*/) const 00052 { 00053 return TexCoordinate(); 00054 } 00055 00058 const Shader * shader() const 00059 { 00060 assert(mShader!=0); 00061 return mShader; 00062 } 00063 00066 void setShader(Shader * sh) 00067 { 00068 assert(sh!=0); 00069 mShader = sh; 00070 } 00071 00076 const Box & bounds() const 00077 { 00078 return mBounds; 00079 } 00080 00083 virtual RGBAColor shade(const Ray & ray) const 00084 { 00085 assert(mShader!=0); 00086 return mShader->shade(ray); 00087 } 00088 00091 inline bool castShadows() const 00092 { 00093 return mCastShadows; 00094 } 00095 00098 void setCastShadows(bool cs) 00099 { 00100 mCastShadows = cs; 00101 } 00102 00107 virtual void axes(const Ray & ray, Vec3f & x, Vec3f & y) const = 0; 00108 00109 protected: 00111 Box mBounds; 00112 00114 Shader * mShader; 00115 00117 bool mCastShadows; 00118 00119 00122 virtual void calcBounds() = 0; 00123 }; 00124 00125 #endif 00126