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