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 VL_INSTRUMENT_CLASS(vl::RayIntersection, Object)
00053
00054 public:
00055 RayIntersection(): mActor(NULL), mDistance(0.0f)
00056 {
00057 VL_DEBUG_SET_OBJECT_NAME()
00058 }
00059
00061 void setActor(Actor* a) { mActor = a; }
00063 const Actor* actor() const { return mActor; }
00065 Actor* actor() { return mActor; }
00066
00068 const vec3& intersectionPoint() const { return mIntersectionPoint; }
00070 void setIntersectionPoint(const vec3& v) { mIntersectionPoint = v; }
00071
00073 real distance() const { return mDistance; }
00075 void setDistance(real dist) { mDistance = dist; }
00076
00077 protected:
00078 vec3 mIntersectionPoint;
00079 Actor* mActor;
00080 real mDistance;
00081 };
00082
00083
00084
00087 class RayIntersectionGeometry: public RayIntersection
00088 {
00089 VL_INSTRUMENT_CLASS(vl::RayIntersectionGeometry, RayIntersection)
00090
00091 public:
00092 RayIntersectionGeometry(): mGeometry(NULL), mDrawCalls(NULL), mTriangleIndex(-1)
00093 {
00094 VL_DEBUG_SET_OBJECT_NAME()
00095 memset(mTriangle, 0xFF, sizeof(mTriangle));
00096 }
00097
00099 Geometry* geometry() { return mGeometry; }
00101 const Geometry* geometry() const { return mGeometry; }
00103 DrawCall* drawCalls() { return mDrawCalls; }
00105 const DrawCall* drawCalls() const { return mDrawCalls; }
00107 int triangleIndex() const { return mTriangleIndex; }
00109 const int* triangle() const { return mTriangle; }
00110
00112 void setGeometry(Geometry* g) { mGeometry = g; }
00114 void setPrimitives(DrawCall* p) { mDrawCalls = p; }
00116 void setTriangleIndex(int t_idx) { mTriangleIndex = t_idx; }
00118 void setTriangle(int a, int b, int c) { mTriangle[0] = a; mTriangle[1] = b; mTriangle[2] = c; }
00119
00120 protected:
00121 vec3 mIntersectionPoint;
00122 Geometry* mGeometry;
00123 DrawCall* mDrawCalls;
00124 int mTriangleIndex;
00125 int mTriangle[3];
00126 float mDistance;
00127 };
00128
00129
00130
00133 class VLGRAPHICS_EXPORT RayIntersector: public Object
00134 {
00135 VL_INSTRUMENT_CLASS(vl::RayIntersector, Object)
00136
00137 public:
00138 RayIntersector()
00139 {
00140 VL_DEBUG_SET_OBJECT_NAME()
00141 mActors = new ActorCollection;
00142 }
00143
00145 const ActorCollection* actors() const { return mActors.get(); }
00147 ActorCollection* actors() { return mActors.get(); }
00148
00150 const Ray& ray() const { return mRay; }
00152 void setRay(const Ray& ray) { mRay = ray; }
00153
00155 const Frustum& frustum() const { return mFrustum; }
00157 void setFrustum(const Frustum& frustum) { mFrustum = frustum; }
00158
00160 const std::vector< ref<RayIntersection> >& intersections() const { return mIntersections; }
00161
00166 void intersect();
00167
00177 void intersect(const Ray& ray, SceneManager* scene_manager);
00178
00179 protected:
00180 static bool sorter(const ref<RayIntersection>& a, const ref<RayIntersection>& b) { return a->distance() < b->distance(); }
00181
00182 void intersect(Actor* act);
00183 void intersectGeometry(Actor* act, Geometry* geom);
00184
00185
00186 template<class T>
00187 void intersectTriangle(const T& a, const T& b, const T& c, int ia, int ib, int ic, Actor*, Geometry* geom, DrawCall* prim, int prim_idx);
00188
00189 protected:
00190 Frustum mFrustum;
00191 std::vector< ref<RayIntersection> > mIntersections;
00192 ref<ActorCollection> mActors;
00193 Ray mRay;
00194 };
00195 }
00196
00197 #endif