32 eHitDepth = cHitDepth =
fabsf(*hitDepth);
36 colliderID =
test_ray_colliders(ignoreFlags, sx, sy, sz, 0.0f, -1.0f, 0.0f, &cHitX, &cHitY, &cHitZ, &cHitDepth, &cHitNx, &cHitNy, &cHitNz);
38 entityID =
test_ray_entities(*startX, *startY, *startZ, 0.0f, -1.0f, 0.0f, &eHitX, &eHitY, &eHitZ, &eHitDepth, &eHitNx, &eHitNy, &eHitNz);
41 if (eHitDepth < cHitDepth) {
42 cHitDepth = eHitDepth;
56 *hitDepth = cHitDepth;
90 f32 theta, sinTheta, minDepth, hitYAhead, hitYBehindRight;
100 hitYBehindLeft = hitYBehindRight = hitYAhead = -32767.0f;
101 minDepth =
fabsf(*hitDepth);
106 deltaX = radius * sinTheta;
107 deltaZ = -radius * cosTheta;
112 originalDepth = depth = minDepth;
114 colliderID =
npc_raycast_down(ignoreFlags, &startX, &startY, &startZ, &depth);
116 if (depth <= minDepth) {
129 deltaX = radius * sinTheta;
130 deltaZ = -radius * cosTheta;
135 depth = originalDepth;
137 colliderID =
npc_raycast_down(ignoreFlags, &startX, &startY, &startZ, &depth);
139 if (depth <= minDepth) {
140 hitYBehindRight = startY;
152 deltaX = radius * sinTheta;
153 deltaZ = -radius * cosTheta;
158 depth = originalDepth;
160 colliderID =
npc_raycast_down(ignoreFlags, &startX, &startY, &startZ, &depth);
162 if (depth <= minDepth) {
163 hitYBehindLeft = startY;
173 *posY = MAX(hitYBehindRight, hitYAhead);
174 if (*posY < hitYBehindLeft) {
175 *posY = hitYBehindLeft;
177 *hitDepth = minDepth;
201 f32 theta, sinTheta, minDepth, hitYAhead, hitYBehind, radius;
203 hasCollision = FALSE;
213 hitYUnused = hitYBehind = hitYAhead = -32767.0f;
216 minDepth =
fabsf(*hitDepth);
223 deltaX = radius * sinTheta;
224 deltaZ = -radius * cosTheta;
229 originalDepth = depth = minDepth;
231 colliderID =
npc_raycast_down(ignoreFlags, &startX, &startY, &startZ, &depth);
233 if (depth <= minDepth) {
246 deltaX = radius * sinTheta;
247 deltaZ = -radius * cosTheta;
252 depth = originalDepth;
254 colliderID =
npc_raycast_down(ignoreFlags, &startX, &startY, &startZ, &depth);
256 if (depth <= minDepth) {
267 *posY = MAX(hitYBehind, hitYAhead);
268 if (*posY < hitYUnused) {
271 *hitDepth = minDepth;
298 eHitDepth = cHitDepth = *hitDepth;
302 ret =
test_ray_colliders(ignoreFlags, sx, sy, sz, 0.0f, 1.0f, 0.0f, &cHitX, &cHitY, &cHitZ, &cHitDepth, &cHitNx, &cHitNy, &cHitNz);
305 entityID =
test_ray_entities(sx, sy, sz, 0.0f, 1.0f, 0.0f, &eHitX, &eHitY, &eHitZ, &eHitDepth, &eHitNx, &eHitNy, &eHitNz);
308 cHitDepth = eHitDepth;
323 *hitDepth = cHitDepth;
351 colliderID =
test_ray_colliders(ignoreFlags, sx, sy, sz, 0.0f, 1.0f, 0.0f, &hitX, &hitY, &hitZ, &hitDepth, &hitNx, &hitNy, &hitNz);
352 if (colliderID >
NO_COLLIDER && *length > hitDepth) {
361 entityID =
test_ray_entities(*x, *y, *z, 0.0f, 1.0f, 0.0f, &hitX, &hitY, &hitZ, &hitDepth, &hitNx, &hitNy, &hitNz);
365 if (entityID >
NO_COLLIDER && *length > hitDepth) {
389 deltaX = radius *
sin_rad(theta);
390 deltaZ = -radius *
cos_rad(theta);
444 f32* hitY, f32* hitZ, f32* outDepth, f32* hitNx, f32* hitNy, f32* hitNz) {
450 hitX, hitY, hitZ, outDepth, hitNx, hitNy, hitNz);
456 hitX, hitY, hitZ, outDepth, hitNx, hitNy, hitNz);
462 hitX, hitY, hitZ, outDepth, hitNx, hitNy, hitNz);
472 f32 dotProduct = (aX * bX) + (aZ * bZ);
474 *outX = (aX - (dotProduct * bX)) * 0.5f;
475 *outZ = (aZ - (dotProduct * bZ)) * 0.5f;
483 f32 hitX, hitY, hitZ;
484 f32 outSinTheta, outCosTheta;
485 f32 temp_f0, temp_f20, temp_f22;
487 f32 inverseOutCosTheta;
494 aX = length * outSinTheta;
495 temp_f22 = length + radius + (radius * 0.5f);
496 inverseOutCosTheta = -outCosTheta;
497 outCosTheta = inverseOutCosTheta;
499 aZ = length * inverseOutCosTheta;
501 *z - (radius * inverseOutCosTheta * 0.5f), outSinTheta,
502 0.0f, inverseOutCosTheta, &hitX, &hitY, &hitZ, &hitDepth, &bX, &hitNy, &bZ);
505 if (raycastHitID >
NO_COLLIDER && hitDepth <= temp_f22) {
507 if (temp_f0 > 60.0f && temp_f0 < 90.0f) {
511 temp_f20 = hitDepth - (length + radius + (radius * 0.5f));
512 a = temp_f20 * outSinTheta;
513 b = temp_f20 * outCosTheta;
518 hitResult = raycastHitID;
535 f32 hitNx, hitNy, hitNz;
536 f32 hitX, hitY, hitZ;
542 cosTheta = -cosTheta;
543 originalDepth = length + radius + (radius * 0.5f);
544 depth = originalDepth;
545 temp1 = length * dirY;
546 temp2 = length * cosTheta;
548 hitID =
npc_raycast_general(ignoreFlags, *x - (radius * dirY * 0.5f), *y, *z - (radius * cosTheta * 0.5f), dirY,
549 0.0f, cosTheta, &hitX, &hitY, &hitZ, &depth, &hitNx, &hitNy, &hitNz);
551 if (hitID >
NO_COLLIDER && depth <= originalDepth) {
552 f32 depthDiff = depth - originalDepth;
553 f32 cosThetaTemp = cosTheta;
555 *x += depthDiff * dirY;
556 *z += depthDiff * cosThetaTemp;
569 f32 yTemp = *y + height - 1.0f;
592 f32 tempY = *y + 10.01f;
605 f32 tempY = *y + 10.01f;
628 startY = *y + height - 1.0f;
646 startY = *y + 15.01f;
655 startY = *y + 10.01f;
Vec3f playerGroundTraceNormal
Vec3f playerGroundTraceAngles
#define npc_raycast_down_sides
@ COLLISION_ONLY_ENTITIES
@ COLLISION_IGNORE_ENTITIES
s32 test_ray_entities(f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 dirZ, f32 *hitX, f32 *hitY, f32 *hitZ, f32 *hitDepth, f32 *hitNx, f32 *hitNy, f32 *hitNz)
Test a general ray from a given starting position and direction against all entities.
s32 test_ray_colliders(s32 ignoreFlags, f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 dirZ, f32 *hitX, f32 *hitY, f32 *hitZ, f32 *hitDepth, f32 *hitNx, f32 *hitNy, f32 *hitNz)
void sin_cos_rad(f32 rad, f32 *outSinTheta, f32 *outCosTheta)
HitID npc_raycast_up_corner(s32 ignoreFlags, f32 *x, f32 *y, f32 *z, f32 *length)
s32 NpcHitQueryBehindLeftY
b32 npc_test_move_simple_without_slipping(s32 ignoreFlags, f32 *x, f32 *y, f32 *z, f32 length, f32 yaw, f32 height, f32 radius)
PlayerStatus * gPlayerStatusPtr
HitID npc_raycast_down(s32 ignoreFlags, f32 *startX, f32 *startY, f32 *startZ, f32 *hitDepth)
b32 npc_test_move_simple_with_slipping(s32 ignoreFlags, f32 *x, f32 *y, f32 *z, f32 length, f32 yaw, f32 height, f32 radius)
s32 npc_test_move_without_slipping(s32 ignoreFlags, f32 *x, f32 *y, f32 *z, f32 length, f32 yaw, f32 radius)
s32 NpcHitQueryColliderID
s32 NpcHitQueryBehindRightY
s32 NpcHitQueryAheadCollider
b32 npc_raycast_up(s32 ignoreFlags, f32 *startX, f32 *startY, f32 *startZ, f32 *hitDepth)
void npc_get_slip_vector(f32 *outX, f32 *outZ, f32 aX, f32 aZ, f32 bX, f32 bZ)
b32 npc_raycast_down_around(s32 ignoreFlags, f32 *posX, f32 *posY, f32 *posZ, f32 *hitDepth, f32 yaw, f32 radius)
HitID npc_raycast_up_corners(s32 ignoreFlags, f32 *posX, f32 *posY, f32 *posZ, f32 *hitDepth, f32 yaw, f32 radius)
s32 NpcHitQueryBehindCollider
HitID npc_raycast_general(s32 flags, f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 dirZ, f32 *hitX, f32 *hitY, f32 *hitZ, f32 *outDepth, f32 *hitNx, f32 *hitNy, f32 *hitNz)
HitID npc_test_move_with_slipping(s32 ignoreFlags, f32 *x, f32 *y, f32 *z, f32 length, f32 yaw, f32 radius)
b32 npc_test_move_taller_with_slipping(s32 ignoreFlags, f32 *x, f32 *y, f32 *z, f32 length, f32 yaw, f32 height, f32 radius)
s32 npc_test_move_complex_with_slipping(s32 ignoreFlags, f32 *x, f32 *y, f32 *z, f32 length, f32 yaw, f32 height, f32 radius)
#define COLLISION_WITH_ENTITY_BIT
GameStatus * gGameStatusPtr
PlayerStatus gPlayerStatus