| 423 | } |
| 424 | |
| 425 | U32 zPlatform_PaddleCollide(xCollis* coll, const xVec3* hitsource, const xVec3* hitvel, U32 worldSpaceNorm) |
| 426 | { |
| 427 | zPlatform* plat = (zPlatform*)coll->optr; |
| 428 | if (plat->state != 0) { |
| 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | xVec3 locnorm; |
| 433 | if (worldSpaceNorm) { |
| 434 | xMat3x3Tolocal(&locnorm, (xMat3x3*)plat->model->Mat, &coll->norm); |
| 435 | } else { |
| 436 | locnorm = coll->norm; |
| 437 | } |
| 438 | |
| 439 | xVec3 lochitsrc; |
| 440 | xMat4x3Tolocal(&lochitsrc, (xMat4x3*)plat->model->Mat, hitsource); |
| 441 | |
| 442 | xVec3 lochitvel; |
| 443 | xMat3x3Tolocal(&lochitvel, (xMat3x3*)plat->model->Mat, hitvel); |
| 444 | |
| 445 | if (xabs(locnorm.y) > xabs(locnorm.x) && xabs(locnorm.y) > xabs(locnorm.z)) { |
| 446 | return 0; |
| 447 | } |
| 448 | |
| 449 | if (xabs(lochitvel.y) > xabs(lochitvel.x) && xabs(lochitvel.y) > xabs(lochitvel.z)) { |
| 450 | return 0; |
| 451 | } |
| 452 | |
| 453 | xVec3Normalize(&locnorm, &locnorm); |
| 454 | xVec3Normalize(&lochitvel, &lochitvel); |
| 455 | |
| 456 | F32 hitdot = xVec3Dot(&locnorm, &lochitvel); |
| 457 | if (hitdot > -0.7071f) { |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | xVec3 hitsrcbot, hitsrctop; |
| 462 | hitsrcbot = lochitsrc; |
| 463 | hitsrctop = lochitsrc; |
| 464 | |
| 465 | hitsrcbot.y -= 5.0f; |
| 466 | hitsrctop.y += 5.0f; |
| 467 | |
| 468 | xMat4x3Toworld(&hitsrcbot, (xMat4x3*)plat->model->Mat, &hitsrcbot); |
| 469 | xMat4x3Toworld(&hitsrctop, (xMat4x3*)plat->model->Mat, &hitsrctop); |
| 470 | |
| 471 | xRay3 hitsrcray; |
| 472 | hitsrcray.origin.x = hitsrcbot.x; |
| 473 | hitsrcray.origin.y = hitsrcbot.y; |
| 474 | hitsrcray.origin.z = hitsrcbot.z; |
| 475 | hitsrcray.dir.x = hitsrctop.x - hitsrcbot.x; |
| 476 | hitsrcray.dir.y = hitsrctop.y - hitsrcbot.y; |
| 477 | hitsrcray.dir.z = hitsrctop.z - hitsrcbot.z; |
| 478 | hitsrcray.min_t = 0.0f; |
| 479 | hitsrcray.max_t = xVec3Normalize(&hitsrcray.dir, &hitsrcray.dir); |
| 480 | hitsrcray.flags = XRAY3_USE_MIN | XRAY3_USE_MAX; |
| 481 | |
| 482 | xCollis hitsrccoll; |
no test coverage detected