Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef RayIntersector_INCLUDE_ONCE
00033 #define RayIntersector_INCLUDE_ONCE
00034
00035 #include <vlCore/Ray.hpp>
00036 #include <vlGraphics/Actor.hpp>
00037 #include <vlGraphics/Geometry.hpp>
00038 #include <vlCore/Vector4.hpp>
00039 #include <vlCore/Matrix4.hpp>
00040 #include <vlGraphics/Frustum.hpp>
00041
00042 namespace vl
00043 {
00044 class SceneManager;
00045
00046
00047
00050 class RayIntersection: public Object
00051 {
00052 public:
00053 virtual const char* className() { return "vl::RayIntersection"; }
00054 RayIntersection(): mActor(NULL), mDistance(0.0f)
00055 {
00056 VL_DEBUG_SET_OBJECT_NAME()
00057 }
00058
00060 void setActor(Actor* a) { mActor = a; }
00062 const Actor* actor() const { return mActor; }
00064 Actor* actor() { return mActor; }
00065
00067 const vec3& intersectionPoint() const { return mIntersectionPoint; }
00069 void setIntersectionPoint(const vec3& v) { mIntersectionPoint = v; }
00070
00072 float distance() const { return mDistance; }
00074 void setDistance(float dist) { mDistance = dist; }
00075
00076 protected:
00077 vec3 mIntersectionPoint;
00078 Actor* mActor;
00079 float mDistance;
00080 };
00081
00082
00083
00086 class RayIntersectionGeometry: public RayIntersection
00087 {
00088 public:
00089 virtual const char* className() { return "vl::RayIntersectionGeometry"; }
00090 RayIntersectionGeometry(): mGeometry(NULL), mDrawCalls(NULL), mTriangleIndex(-1)
00091 {
00092 VL_DEBUG_SET_OBJECT_NAME()
00093 memset(mTriangle, 0xFF, sizeof(mTriangle));
00094 }
00095
00097 Geometry* geometry() { return mGeometry; }
00099 const Geometry* geometry() const { return mGeometry; }
00101 DrawCall* drawCalls() { return mDrawCalls; }
00103 const DrawCall* drawCalls() const { return mDrawCalls; }
00105 int triangleIndex() const { return mTriangleIndex; }
00107 int* triangle() const;
00108
00110 void setGeometry(Geometry* g) { mGeometry = g; }
00112 void setPrimitives(DrawCall* p) { mDrawCalls = p; }
00114 void setTriangleIndex(int t_idx) { mTriangleIndex = t_idx; }
00116 void setTriangle(int a, int b, int c) { mTriangle[0] = a; mTriangle[0] = b; mTriangle[0] = c; }
00117
00118 protected:
00119 vec3 mIntersectionPoint;
00120 Geometry* mGeometry;
00121 DrawCall* mDrawCalls;
00122 int mTriangleIndex;
00123 int mTriangle[3];
00124 float mDistance;
00125 };
00126
00127
00128
00131 class VLGRAPHICS_EXPORT RayIntersector: public Object
00132 {
00133 public:
00134 virtual const char* className() { return "vl::RayIntersector"; }
00135 RayIntersector()
00136 {
00137 VL_DEBUG_SET_OBJECT_NAME()
00138 mActors = new ActorCollection;
00139 }
00140
00142 const ActorCollection* actors() const { return mActors.get(); }
00144 ActorCollection* actors() { return mActors.get(); }
00145
00147 const Ray& ray() const { return mRay; }
00149 void setRay(const Ray& ray) { mRay = ray; }
00150
00152 const Frustum& frustum() const { return mFrustum; }
00154 void setFrustum(const Frustum& frustum) { mFrustum = frustum; }
00155
00157 const std::vector< ref<RayIntersection> >& intersections() const { return mIntersections; }
00158
00163 void intersect();
00164
00174 void intersect(const Ray& ray, SceneManager* scene_manager);
00175
00176 protected:
00177 static bool sorter(const ref<RayIntersection>& a, const ref<RayIntersection>& b) { return a->distance() < b->distance(); }
00178
00179 void intersect(Actor* act);
00180 void intersectGeometry(Actor* act, Geometry* geom);
00181
00182
00183 template<class T>
00184 void intersectTriangle(const T& a, const T& b, const T& c, Actor*, Geometry* geom, DrawCall* prim, int prim_idx);
00185
00186 protected:
00187 Frustum mFrustum;
00188 std::vector< ref<RayIntersection> > mIntersections;
00189 ref<ActorCollection> mActors;
00190 Ray mRay;
00191 };
00192 }
00193
00194 #endif