[1520] | 1 | #ifndef _RayCaster_H__
|
---|
| 2 | #define _RayCaster_H__
|
---|
| 3 |
|
---|
| 4 | #include "Containers.h"
|
---|
| 5 | #include <string>
|
---|
[1528] | 6 | #include "Vector3.h"
|
---|
| 7 |
|
---|
[1520] | 8 | using namespace std;
|
---|
| 9 |
|
---|
| 10 |
|
---|
| 11 | namespace GtpVisibilityPreprocessor {
|
---|
| 12 |
|
---|
| 13 |
|
---|
| 14 | class Intersectable;
|
---|
| 15 | class VssRay;
|
---|
| 16 | class SimpleRayContainer;
|
---|
| 17 | class AxisAlignedBox3;
|
---|
[1528] | 18 | //class Vector3;
|
---|
[1520] | 19 | struct VssRayContainer;
|
---|
| 20 | class Preprocessor;
|
---|
[1528] | 21 | struct SimpleRay;
|
---|
[1520] | 22 |
|
---|
[1528] | 23 |
|
---|
[1520] | 24 | /** This class provides an interface for ray casting.
|
---|
| 25 | */
|
---|
| 26 | class RayCaster
|
---|
| 27 | {
|
---|
[1528] | 28 |
|
---|
[1520] | 29 | public:
|
---|
| 30 |
|
---|
| 31 | enum {
|
---|
| 32 | INTERNAL_RAYCASTER = 0,
|
---|
| 33 | INTEL_RAYCASTER
|
---|
| 34 | };
|
---|
| 35 |
|
---|
| 36 | RayCaster(const Preprocessor &preprocessor);
|
---|
| 37 |
|
---|
[1521] | 38 | virtual ~RayCaster();
|
---|
[1520] | 39 |
|
---|
| 40 | virtual int Type() const = 0;
|
---|
| 41 |
|
---|
[1521] | 42 | /** Wrapper for casting single ray.
|
---|
[1545] | 43 | @returns ray or NULL if invalid
|
---|
[1521] | 44 | */
|
---|
[1932] | 45 | VssRay *CastRay(const SimpleRay &simpleRay,
|
---|
[1990] | 46 | const AxisAlignedBox3 &box,
|
---|
| 47 | const bool keepOrigin);
|
---|
[1521] | 48 |
|
---|
[1932] | 49 | virtual int CastRay(const SimpleRay &simpleRay,
|
---|
| 50 | VssRayContainer &vssRays,
|
---|
| 51 | const AxisAlignedBox3 &box,
|
---|
| 52 | const bool castDoubleRay,
|
---|
[1990] | 53 | const bool pruneInvalidRays = true,
|
---|
| 54 | const bool keepOrigin = false
|
---|
[1932] | 55 | ) = 0;
|
---|
[1520] | 56 |
|
---|
[1990] | 57 | virtual void CastRays16(
|
---|
[1932] | 58 | SimpleRayContainer &rays,
|
---|
| 59 | VssRayContainer &vssRays,
|
---|
| 60 | const AxisAlignedBox3 &sbox,
|
---|
| 61 | const bool castDoubleRay,
|
---|
[1990] | 62 | const bool pruneInvalidRays = true,
|
---|
| 63 | const bool keepOrigin = false
|
---|
[1932] | 64 | ) = 0;
|
---|
[1974] | 65 |
|
---|
| 66 |
|
---|
| 67 | virtual void
|
---|
| 68 | SortRays(SimpleRayContainer &rays);
|
---|
| 69 |
|
---|
[1520] | 70 |
|
---|
| 71 |
|
---|
| 72 | protected:
|
---|
[1984] | 73 | void _SortRays(SimpleRayContainer &rays,
|
---|
| 74 | const int l,
|
---|
| 75 | const int r,
|
---|
| 76 | const int depth,
|
---|
| 77 | float box[12]);
|
---|
| 78 |
|
---|
[1974] | 79 | struct Intersection
|
---|
[1528] | 80 | {
|
---|
| 81 | Intersection(): mObject(NULL), mFaceId(0)
|
---|
| 82 | {}
|
---|
[1520] | 83 |
|
---|
[1528] | 84 | Intersection(const Vector3 &p, const Vector3 &n, Intersectable *o, const int f):
|
---|
[1824] | 85 | mPoint(p), mNormal(n), mObject(o), mFaceId(f)
|
---|
[1528] | 86 | {}
|
---|
| 87 |
|
---|
| 88 | Intersection(const Vector3 &p): mPoint(p), mObject(NULL), mFaceId(0)
|
---|
| 89 | {}
|
---|
| 90 | Vector3 mPoint;
|
---|
| 91 | Vector3 mNormal;
|
---|
| 92 | Intersectable *mObject;
|
---|
| 93 | int mFaceId;
|
---|
| 94 | };
|
---|
| 95 |
|
---|
[1824] | 96 |
|
---|
[1932] | 97 | int ProcessRay(const SimpleRay &ray,
|
---|
| 98 | Intersection &hitA,
|
---|
| 99 | Intersection &hitB,
|
---|
| 100 | VssRayContainer &vssRays,
|
---|
| 101 | const AxisAlignedBox3 &box,
|
---|
| 102 | const bool castDoubleRay,
|
---|
[1990] | 103 | const bool pruneInvalidRays = true,
|
---|
| 104 | const bool keepOrigin = false);
|
---|
[1520] | 105 |
|
---|
[1528] | 106 | /** Checks if ray is valid.
|
---|
| 107 | I.e., the ray is in valid view space.
|
---|
| 108 | @note: clamps the ray to valid view space.
|
---|
| 109 | */
|
---|
| 110 | bool ValidateRay(const Vector3 &origin,
|
---|
| 111 | const Vector3 &direction,
|
---|
| 112 | const AxisAlignedBox3 &box,
|
---|
| 113 | Intersection &hit);
|
---|
[1942] | 114 |
|
---|
[1990] | 115 | bool
|
---|
| 116 | ClipToViewSpaceBox(const Vector3 &origin,
|
---|
| 117 | const Vector3 &termination,
|
---|
| 118 | Vector3 &clippedOrigin,
|
---|
| 119 | Vector3 &clippedTermination);
|
---|
[1520] | 120 |
|
---|
| 121 | const Preprocessor &mPreprocessor;
|
---|
| 122 | };
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | #endif
|
---|