| 204 | } |
| 205 | |
| 206 | RpCollisionTriangle* sphereHitsEnvCB(RpIntersection* isx, RpWorldSector* sector, |
| 207 | RpCollisionTriangle* tri, F32 dist, void* data) |
| 208 | { |
| 209 | xCollis* coll = (xCollis*)data; |
| 210 | F32 radius = isx->t.line.end.x; |
| 211 | xVec3* center; |
| 212 | xVec3 tohit; |
| 213 | F32 scale; |
| 214 | |
| 215 | if (coll->flags == 0) |
| 216 | { |
| 217 | coll->flags |= 1; |
| 218 | return NULL; |
| 219 | } |
| 220 | |
| 221 | dist = FLOAT_MAX; |
| 222 | properSphereIsectTri((xVec3*)&isx->t.line.start, radius, &tohit, &dist, tri); |
| 223 | |
| 224 | if (dist < 0.0f) |
| 225 | { |
| 226 | return tri; |
| 227 | } |
| 228 | if (0.0f == dist) |
| 229 | { |
| 230 | return tri; |
| 231 | } |
| 232 | if (dist >= radius) |
| 233 | { |
| 234 | return tri; |
| 235 | } |
| 236 | if (dist >= coll->dist) |
| 237 | { |
| 238 | return tri; |
| 239 | } |
| 240 | |
| 241 | coll->dist = dist; |
| 242 | if (coll->flags & 0x200) |
| 243 | { |
| 244 | xVec3Copy(&coll->norm, (xVec3*)&tri->normal); |
| 245 | } |
| 246 | if (coll->flags & 0x400) |
| 247 | { |
| 248 | xVec3Copy(&coll->tohit, &tohit); |
| 249 | } |
| 250 | if (coll->flags & 0x800) |
| 251 | { |
| 252 | scale = 1.0f - (radius / coll->dist); |
| 253 | scale -= 1e-5f; |
| 254 | xVec3Copy(&coll->depen, &tohit); |
| 255 | xVec3SMulBy(&coll->depen, scale); |
| 256 | } |
| 257 | if (coll->flags & 0x1000) |
| 258 | { |
| 259 | xVec3Normalize(&coll->hdng, &tohit); |
| 260 | } |
| 261 | coll->flags |= 1; |
| 262 | return tri; |
| 263 | } |
no test coverage detected