[420] | 1 | #include "RayInfo.h"
|
---|
| 2 | #include "Ray.h"
|
---|
| 3 | #include "VssRay.h"
|
---|
| 4 |
|
---|
| 5 | RayInfo::RayInfo(): mRay(NULL)
|
---|
| 6 | {}
|
---|
| 7 |
|
---|
| 8 | RayInfo::RayInfo(VssRay *r):mRay(r), mMinT(0),
|
---|
| 9 | #if USE_FIXEDPOINT_T
|
---|
| 10 | #define FIXEDPOINT_ONE 0x7FFE
|
---|
| 11 | // mMaxT(0xFFFF)
|
---|
| 12 | mMaxT(FIXEDPOINT_ONE)
|
---|
| 13 | #else
|
---|
| 14 | mMaxT(1.0f)
|
---|
| 15 | #endif
|
---|
| 16 | {}
|
---|
| 17 |
|
---|
| 18 | RayInfo::RayInfo(VssRay *r, const float _min, const float _max):
|
---|
| 19 | mRay(r)
|
---|
| 20 | {
|
---|
| 21 | SetMinT(_min);
|
---|
| 22 | SetMaxT(_max);
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | RayInfo::RayInfo(VssRay *r, const short _min, const float _max):
|
---|
| 26 | mRay(r), mMinT(_min)
|
---|
| 27 | {
|
---|
| 28 | SetMaxT(_max);
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | RayInfo::RayInfo(VssRay *r, const float _min, const short _max):
|
---|
| 32 | mRay(r), mMaxT(_max)
|
---|
| 33 | {
|
---|
| 34 | SetMinT(_min);
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | float RayInfo::ExtrapOrigin(const int axis) const
|
---|
| 38 | {
|
---|
| 39 | return mRay->GetOrigin(axis) + GetMinT()*mRay->GetDir(axis);
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | float RayInfo::ExtrapTermination(const int axis) const
|
---|
| 43 | {
|
---|
| 44 | return mRay->GetOrigin(axis) + GetMaxT()*mRay->GetDir(axis);
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | #if USE_FIXEDPOINT_T
|
---|
| 48 | float RayInfo::GetMinT () const
|
---|
| 49 | {
|
---|
| 50 | return mMinT/(float)(FIXEDPOINT_ONE);
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | float RayInfo::GetMaxT() const
|
---|
| 54 | {
|
---|
| 55 | return mMaxT / (float)(FIXEDPOINT_ONE);
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | void RayInfo::SetMinT (const float t)
|
---|
| 59 | {
|
---|
| 60 | mMinT = (short) (t * (float)(FIXEDPOINT_ONE));
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | void RayInfo::SetMaxT (const float t)
|
---|
| 64 | {
|
---|
| 65 | mMaxT = (short) (t*(float)(FIXEDPOINT_ONE));
|
---|
| 66 | ++ mMaxT;
|
---|
| 67 | // if (mMaxT!=0xFFFF)
|
---|
| 68 | // mMaxT++;
|
---|
| 69 | }
|
---|
| 70 | #else
|
---|
| 71 | float RayInfo::GetMinT () const
|
---|
| 72 | {
|
---|
| 73 | return mMinT;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | float RayInfo::GetMaxT () const
|
---|
| 77 | {
|
---|
| 78 | return mMaxT;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | void RayInfo::SetMinT (const float t)
|
---|
| 82 | {
|
---|
| 83 | mMinT = t;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | void RayInfo::SetMaxT (const float t)
|
---|
| 87 | {
|
---|
| 88 | mMaxT = t;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | #endif
|
---|
| 92 |
|
---|
| 93 | int RayInfo::ComputeRayIntersection(const int axis, const float position, float &t) const
|
---|
| 94 | {
|
---|
| 95 | // intersect the ray with the plane
|
---|
| 96 | const float denom = mRay->GetDir(axis);
|
---|
| 97 |
|
---|
| 98 | if (fabs(denom) < 1e-20)
|
---|
| 99 | //if (denom == 0.0f)
|
---|
| 100 | return (mRay->GetOrigin(axis) > position) ? 1 : -1;
|
---|
| 101 |
|
---|
| 102 | t = (position - mRay->GetOrigin(axis)) / denom;
|
---|
| 103 |
|
---|
| 104 | if (t < GetMinT())
|
---|
| 105 | return (denom > 0) ? 1 : -1;
|
---|
| 106 |
|
---|
| 107 | if (t > GetMaxT())
|
---|
| 108 | return (denom > 0) ? -1 : 1;
|
---|
| 109 |
|
---|
| 110 | return 0;
|
---|
| 111 | } |
---|