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

Function iSphereIsectRay

src/SB/Core/gc/iMath3.cpp:21–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19}
20
21void iSphereIsectRay(const xSphere* s, const xRay3* r, xIsect* isx)
22{
23 F32 t_in, t_out;
24 U32 num;
25
26 if (!(r->flags & 0x400))
27 {
28 ((xRay3*)r)->min_t = 0.0f; // wait, that's illegal
29 }
30
31 if (!(r->flags & 0x800))
32 {
33 ((xRay3*)r)->max_t = 1.0f;
34 }
35
36 xVec3Sub(&isx->norm, &r->origin, &s->center);
37
38 num = xMathSolveQuadratic(xVec3Dot(&r->dir, &r->dir), 2.0f * xVec3Dot(&isx->norm, &r->dir),
39 xVec3Dot(&isx->norm, &isx->norm) - s->r * s->r, &t_in, &t_out);
40
41 if (num == 0)
42 {
43 isx->penned = 1.0f;
44 isx->contained = 1.0f;
45 }
46 else if (num == 1)
47 {
48 if (t_in < r->min_t || t_in > r->max_t)
49 {
50 isx->dist = t_in;
51 isx->penned = 1.0f;
52 isx->contained = 1.0f;
53 }
54 else
55 {
56 isx->dist = t_in;
57 isx->penned = -1.0f;
58 isx->contained = 1.0f;
59 }
60 }
61 else if (t_in < r->min_t)
62 {
63 if (t_out < r->min_t)
64 {
65 isx->dist = t_out;
66 isx->penned = 1.0f;
67 isx->contained = 1.0f;
68 }
69 else
70 {
71 isx->dist = t_out;
72 isx->penned = -1.0f;
73 isx->contained = -1.0f;
74 }
75 }
76 else
77 {
78 if (t_in <= r->max_t)

Callers 1

xRayHitsBoundFunction · 0.50

Calls 2

xVec3SubFunction · 0.85
xMathSolveQuadraticFunction · 0.50

Tested by

no test coverage detected