00001 /* 00002 * $Id: geometry.h 650 2008-12-23 20:25:55Z misek $ 00003 * 00004 * Description : One line description of file. 00005 * Author : Vaclav Kyba <mail/Jabber: vaseo1@gmail.com> <ICQ: 98576293> 00006 * 00007 * Purpose : 00008 * Long description of what the file is for. 00009 */ 00010 00011 00012 #ifndef __GEOMETRY__H__ 00013 #define __GEOMETRY__H__ 00014 00015 #include "moddefs.h" 00016 #include "bvolumes.h" 00017 #include <vector> 00018 00019 00020 namespace VRUT 00021 { 00023 struct RayIntersectionInfo 00024 { 00026 NODE_ID nodeID; 00028 float dist; 00030 VECTOR3 intersection; 00032 VECTOR3 normal; 00034 size_t geometryID; 00036 float u,v; 00037 }; 00038 00039 00041 class Geometry 00042 { 00043 protected: 00045 wxString name; 00047 AABB aabb; 00048 00049 public: 00051 enum GEOMETRY_TYPE 00052 { 00053 GEOMETRY_UNKNOWN, 00054 GEOMETRY_TRIANGLE 00055 } type; 00056 00058 Geometry(const wxString & _name) : name(CloneWxString(_name)), type(GEOMETRY_UNKNOWN) {} 00060 Geometry(const Geometry & g) : name(CloneWxString(g.name)), type(g.type), aabb(g.aabb) {} 00062 virtual ~Geometry() {} 00063 00065 const wxString GetName() const 00066 { 00067 return name; 00068 } 00070 const AABB & GetAABB() const 00071 { 00072 return aabb; 00073 } 00075 virtual void BuildAABB() = 0; 00078 virtual bool Intersects(const Ray & ray, float * dist = (float *)NULL) const = 0; 00079 00080 00083 virtual bool CastRay(const Ray & ray, RayIntersectionInfo &info) const { 00084 // not pure virtual for now ! 00085 return false; 00086 } 00087 00089 virtual std::vector<Triangle> Triangulate() const = 0; 00090 00092 virtual void AddBox(const vector3 &position, const vector3 &size) = 0; 00093 00095 virtual wxString ToString() const 00096 { 00097 return wxString::Format(wxT("Geometry type: %i\n"), unsigned(type)); 00098 } 00100 virtual Geometry * Clone() const = 0; 00101 00102 friend class Scene; 00103 }; 00104 }; 00105 00106 #endif