MCPcopy Create free account
hub / github.com/bfbbdecomp/bfbb / properSphereIsectTri

Function properSphereIsectTri

src/SB/Core/gc/iCollide.cpp:154–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152}
153
154static void properSphereIsectTri(const xVec3* center, F32 radius, xVec3* tohit, F32* dist_ptr,
155 RpCollisionTriangle* tri)
156{
157 xVec3 projPoint;
158 F32 dist2plane;
159 F32 dist;
160 F32 dist2;
161 F32 radius2;
162 U32 i;
163 xVec3 vertClosestPoint;
164 F32 vertDist2;
165 xVec3 temp;
166
167 dist = *dist_ptr;
168 dist2plane = xVec3Dot((xVec3*)&tri->normal, center);
169 radius2 = xVec3Dot((xVec3*)&tri->normal, (xVec3*)&tri->point);
170
171 xVec3SMul(&projPoint, (xVec3*)&tri->normal, radius2 - dist2plane);
172 xVec3Copy(tohit, &projPoint);
173 xVec3AddTo(&projPoint, center);
174
175 if (PointWithinTriangle(&projPoint, (xVec3**)&tri->vertices, (xVec3*)&tri->normal))
176 {
177 dist = iabs(radius2 - dist2plane);
178 }
179 else
180 {
181 dist2 = SQR(dist);
182 for (i = 0; i < 3; i++)
183 {
184 FindNearestPointOnLine(&vertClosestPoint, &projPoint, (xVec3*)tri->vertices[i],
185 (xVec3*)tri->vertices[(i + 1) % 3]);
186 xVec3Sub(&temp, &vertClosestPoint, center);
187 vertDist2 = xVec3Length2(&temp);
188
189 if (vertDist2 < dist2 && vertDist2 < SQR(radius))
190 {
191 dist2 = vertDist2;
192 xVec3Copy(tohit, &temp);
193 }
194 }
195 dist = xsqrt(dist2);
196 }
197 *dist_ptr = dist;
198}
199
200static void _stripped(float* f)
201{

Callers 3

sphereHitsEnvCBFunction · 0.70
sphereHitsEnv3CBFunction · 0.70
sphereHitsEnv4CBFunction · 0.70

Calls 8

xVec3SMulFunction · 0.85
xVec3CopyFunction · 0.85
xVec3AddToFunction · 0.85
xVec3SubFunction · 0.85
xVec3Length2Function · 0.85
xsqrtFunction · 0.85
PointWithinTriangleFunction · 0.70
FindNearestPointOnLineFunction · 0.70

Tested by

no test coverage detected