00001 #ifndef OBJECT_H 00002 #define OBJECT_H 00003 00004 00005 #include <string> 00006 00007 #include "PhysicalObject.h" 00008 #include "Ray.h" 00009 #include "Box.h" 00010 00011 00012 class Shader; 00013 00014 00025 class Object : public PhysicalObject 00026 { 00027 public: 00032 Object(bool enablePhysics); 00033 00036 virtual ~Object(); 00037 00042 virtual Object * createCopy() = 0; 00043 00046 virtual void setShader(Shader * sh) = 0; 00047 00053 bool intersect(Ray & globalRay) const 00054 { 00055 // transform ray to the own coordinate system 00056 Ray local = globalRay; 00057 toLocalCoordinates(local); 00058 00059 // intersect 00060 bool result = doIntersect(local); 00061 if (result) 00062 { 00063 local.setObj(this); 00064 00065 // transform the ray back to the world coordinate system 00066 toGlobalCoordinates(local); 00067 globalRay = local; 00068 } 00069 00070 return result; 00071 } 00072 00075 bool castShadows() const 00076 { 00077 return mCastShadows; 00078 } 00079 00082 virtual void setCastShadows(bool b); 00083 00086 const std::string & name() const 00087 { 00088 return mName; 00089 } 00090 00093 void setName(const std::string & n) 00094 { 00095 mName = n; 00096 } 00097 00100 virtual void dump() const 00101 { 00102 LOG("object \"" << mName << "\" at " << this); 00103 LOG("bbox : [" << mBoundingBox.minVertex() << " .. " << mBoundingBox.maxVertex() << "]"); 00104 LOG("mass : " << mMass); 00105 LOG("pos : " << mPosition); 00106 LOG("scal : " << mScaling); 00107 LOG("rot : " << mRotation); 00108 LOG("v : " << mVelocity); 00109 LOG("w : " << mAngularVelocity); 00110 LOG("t : " << mTime); 00111 LOG("transformation matrix :\n" << mTransform); 00112 LOG("inverse transformation matrix :\n" << mInverseTransform); 00113 } 00114 00119 virtual void writeDump(std::ostream & outs); 00120 00125 virtual void readDump(std::istream & ins); 00126 00127 protected: 00129 Box mBoundingBox; 00130 00132 bool mCastShadows; 00133 00135 unsigned int * mRefCounter; 00136 00138 std::string mName; 00139 00140 00146 Object(const Object & other); 00147 00152 virtual bool doIntersect(Ray & localRay) const = 0; 00153 00156 virtual void calcBounds() = 0; 00157 00161 virtual void buildAccelStructure() = 0; 00162 00163 private: 00166 Object & operator=(const Object &); 00167 }; 00168 00169 #endif 00170