1 | #include "RayInfo.h"
|
---|
2 | #include "Ray.h"
|
---|
3 | #include "VssRay.h"
|
---|
4 | #include "Plane3.h"
|
---|
5 |
|
---|
6 | namespace GtpVisibilityPreprocessor {
|
---|
7 |
|
---|
8 | RayInfo::RayInfo(): mRay(NULL), 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):mRay(r), mMinT(0),
|
---|
19 | #if USE_FIXEDPOINT_T
|
---|
20 | #define FIXEDPOINT_ONE 0x7FFE
|
---|
21 | // mMaxT(0xFFFF)
|
---|
22 | mMaxT(FIXEDPOINT_ONE)
|
---|
23 | #else
|
---|
24 | mMaxT(1.0f)
|
---|
25 | #endif
|
---|
26 | {}
|
---|
27 |
|
---|
28 | RayInfo::RayInfo(VssRay *r, const float _min, const float _max):
|
---|
29 | mRay(r)
|
---|
30 | {
|
---|
31 | SetMinT(_min);
|
---|
32 | SetMaxT(_max);
|
---|
33 | }
|
---|
34 |
|
---|
35 | RayInfo::RayInfo(VssRay *r, const short _min, const float _max):
|
---|
36 | mRay(r), mMinT(_min)
|
---|
37 | {
|
---|
38 | SetMaxT(_max);
|
---|
39 | }
|
---|
40 |
|
---|
41 | RayInfo::RayInfo(VssRay *r, const float _min, const short _max):
|
---|
42 | mRay(r), mMaxT(_max)
|
---|
43 | {
|
---|
44 | SetMinT(_min);
|
---|
45 | }
|
---|
46 |
|
---|
47 | float RayInfo::ExtrapOrigin(const int axis) const
|
---|
48 | {
|
---|
49 | return mRay->GetOrigin(axis) + GetMinT() * mRay->GetDir(axis);
|
---|
50 | }
|
---|
51 |
|
---|
52 | float RayInfo::ExtrapTermination(const int axis) const
|
---|
53 | {
|
---|
54 | return mRay->GetOrigin(axis) + GetMaxT() * mRay->GetDir(axis);
|
---|
55 | }
|
---|
56 |
|
---|
57 | Vector3 RayInfo::ExtrapOrigin() const
|
---|
58 | {
|
---|
59 | return mRay->GetOrigin() + GetMinT() * mRay->GetDir();
|
---|
60 | }
|
---|
61 |
|
---|
62 | Vector3 RayInfo::ExtrapTermination() const
|
---|
63 | {
|
---|
64 | return mRay->GetOrigin() + GetMaxT() * mRay->GetDir();
|
---|
65 | }
|
---|
66 |
|
---|
67 | #if USE_FIXEDPOINT_T
|
---|
68 | float RayInfo::GetMinT () const
|
---|
69 | {
|
---|
70 | return mMinT/(float)(FIXEDPOINT_ONE);
|
---|
71 | }
|
---|
72 |
|
---|
73 | float RayInfo::GetMaxT() const
|
---|
74 | {
|
---|
75 | return mMaxT / (float)(FIXEDPOINT_ONE);
|
---|
76 | }
|
---|
77 |
|
---|
78 | void RayInfo::SetMinT (const float t)
|
---|
79 | {
|
---|
80 | mMinT = (short) (t * (float)(FIXEDPOINT_ONE));
|
---|
81 | }
|
---|
82 |
|
---|
83 | void RayInfo::SetMaxT (const float t)
|
---|
84 | {
|
---|
85 | mMaxT = (short) (t*(float)(FIXEDPOINT_ONE));
|
---|
86 | ++ mMaxT;
|
---|
87 | // if (mMaxT!=0xFFFF)
|
---|
88 | // mMaxT++;
|
---|
89 | }
|
---|
90 | #else
|
---|
91 | float RayInfo::GetMinT () const
|
---|
92 | {
|
---|
93 | return mMinT;
|
---|
94 | }
|
---|
95 |
|
---|
96 | float RayInfo::GetMaxT () const
|
---|
97 | {
|
---|
98 | return mMaxT;
|
---|
99 | }
|
---|
100 |
|
---|
101 | void RayInfo::SetMinT (const float t)
|
---|
102 | {
|
---|
103 | mMinT = t;
|
---|
104 | }
|
---|
105 |
|
---|
106 | void RayInfo::SetMaxT (const float t)
|
---|
107 | {
|
---|
108 | mMaxT = t;
|
---|
109 | }
|
---|
110 | #endif
|
---|
111 |
|
---|
112 |
|
---|
113 | int RayInfo::ComputeRayIntersection(const int axis, const float position, float &t) const
|
---|
114 | {
|
---|
115 | // intersect the ray with the plane
|
---|
116 | const float denom = mRay->GetDir(axis);
|
---|
117 |
|
---|
118 | if (fabs(denom) < 1e-20)
|
---|
119 | //if (denom == 0.0f)
|
---|
120 | return (mRay->GetOrigin(axis) > position) ? 1 : -1;
|
---|
121 |
|
---|
122 | t = (position - mRay->GetOrigin(axis)) / denom;
|
---|
123 |
|
---|
124 | if (t < GetMinT())
|
---|
125 | return (denom > 0) ? 1 : -1;
|
---|
126 |
|
---|
127 | if (t > GetMaxT())
|
---|
128 | return (denom > 0) ? -1 : 1;
|
---|
129 |
|
---|
130 | return 0;
|
---|
131 | }
|
---|
132 |
|
---|
133 |
|
---|
134 | int RayInfo::ComputeRayIntersection(const Plane3 &splitPlane, float &t) const
|
---|
135 | {
|
---|
136 | t = splitPlane.FindT(mRay->GetOrigin(), mRay->GetTermination());
|
---|
137 |
|
---|
138 | if (0)
|
---|
139 | Debug << "t: " << t << " mint " << GetMinT() << " maxt " << GetMaxT()
|
---|
140 | << " orig: " << mRay->GetOrigin() << " term " << mRay->GetTermination() << endl;
|
---|
141 |
|
---|
142 | // NOTE: if plane equals end point of ray, the ray should be classified
|
---|
143 | // non-intersecting, otherwise polygon-plane intersections of bsp tree
|
---|
144 | // approaches are not eliminating any rays intersecting the polygon!
|
---|
145 | const float thresh = 1e-6f;
|
---|
146 |
|
---|
147 | // segment is not intersecting plane: fond out if on front or back side
|
---|
148 | if (t >= (GetMaxT() - thresh))
|
---|
149 | {
|
---|
150 | return splitPlane.Side(ExtrapOrigin());
|
---|
151 | }
|
---|
152 |
|
---|
153 | if (t <= (GetMinT() + thresh))
|
---|
154 | {
|
---|
155 | return splitPlane.Side(ExtrapTermination());
|
---|
156 | }
|
---|
157 |
|
---|
158 | return 0;
|
---|
159 | }
|
---|
160 |
|
---|
161 |
|
---|
162 | float RayInfo::SegmentLength() const
|
---|
163 | {
|
---|
164 | return Distance(ExtrapOrigin(), ExtrapTermination());
|
---|
165 | }
|
---|
166 |
|
---|
167 | float RayInfo::SqrSegmentLength() const
|
---|
168 | {
|
---|
169 | return SqrDistance(ExtrapOrigin(), ExtrapTermination());
|
---|
170 | }
|
---|
171 |
|
---|
172 | } |
---|