59 {
60
61#define IR(x) (reinterpret_cast<G3D::uint32 const&>(x))
62
63 Inside = true;
64 const G3D::Vector3& MinB = box.low();
65 const G3D::Vector3& MaxB = box.high();
66 G3D::Vector3 MaxT(-1.0f, -1.0f, -1.0f);
67
68
69 for (int i = 0; i < 3; ++i)
70 {
71 if (origin[i] < MinB[i])
72 {
73 location[i] = MinB[i];
74 Inside = false;
75
76
78 {
79 MaxT[i] = (MinB[i] - origin[i]) / dir[i];
80 }
81 }
82 else if (origin[i] > MaxB[i])
83 {
84 location[i] = MaxB[i];
85 Inside = false;
86
87
89 {
90 MaxT[i] = (MaxB[i] - origin[i]) / dir[i];
91 }
92 }
93 }
94
95 if (Inside)
96 {
97
98 location = origin;
99 return true;
100 }
101
102
103 int WhichPlane = 0;
104 if (MaxT[1] > MaxT[WhichPlane])
105 {
106 WhichPlane = 1;
107 }
108
109 if (MaxT[2] > MaxT[WhichPlane])
110 {
111 WhichPlane = 2;
112 }
113
114
115 if (
IR(MaxT[WhichPlane]) & 0x80000000)
116 {
117
118 return false;
119 }
120
121 for (int i = 0; i < 3; ++i)
122 {
123 if (i != WhichPlane)
124 {
125 location[i] = origin[i] + MaxT[WhichPlane] * dir[i];
126 if ((location[i] < MinB[i]) ||
127 (location[i] > MaxB[i]))
128 {
129
130
131 return false;
132 }
133 }
134 }
135
136
137
138
139
140 return true;
141
142#undef IR
143 }