source: trunk/VUT/GtpVisibilityPreprocessor/src/RayInfo.cpp @ 432

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