| 19 | } |
| 20 | |
| 21 | void 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) |
no test coverage detected