Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
npc_collision.c File Reference

Go to the source code of this file.

Functions

HitID npc_raycast_down (s32 ignoreFlags, f32 *startX, f32 *startY, f32 *startZ, f32 *hitDepth)
 
b32 npc_raycast_down_around (s32 ignoreFlags, f32 *posX, f32 *posY, f32 *posZ, f32 *hitDepth, f32 yaw, f32 radius)
 
b32 npc_raycast_down_sides (s32 ignoreFlags, f32 *posX, f32 *posY, f32 *posZ, f32 *hitDepth)
 
b32 npc_raycast_up (s32 ignoreFlags, f32 *startX, f32 *startY, f32 *startZ, f32 *hitDepth)
 
HitID npc_raycast_up_corner (s32 ignoreFlags, f32 *x, f32 *y, f32 *z, f32 *length)
 
HitID npc_raycast_up_corners (s32 ignoreFlags, f32 *posX, f32 *posY, f32 *posZ, f32 *hitDepth, f32 yaw, f32 radius)
 
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)
 
void npc_get_slip_vector (f32 *outX, f32 *outZ, f32 aX, f32 aZ, f32 bX, f32 bZ)
 
HitID npc_test_move_with_slipping (s32 ignoreFlags, f32 *x, f32 *y, f32 *z, f32 length, f32 yaw, f32 radius)
 
s32 npc_test_move_without_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)
 
b32 npc_test_move_simple_with_slipping (s32 ignoreFlags, f32 *x, f32 *y, f32 *z, f32 length, f32 yaw, f32 height, f32 radius)
 
b32 npc_test_move_simple_without_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)
 

Variables

s32 NpcHitQueryBehindRightY
 
s32 NpcHitQueryBehindCollider
 
s32 NpcHitQueryAheadCollider
 
s32 NpcHitQueryAheadY
 
s32 NpcHitQueryBehindLeftY
 
s32 NpcHitQueryColliderID
 
PlayerStatusgPlayerStatusPtr = &gPlayerStatus
 

Function Documentation

◆ npc_raycast_down()

HitID npc_raycast_down ( s32 ignoreFlags,
f32 * startX,
f32 * startY,
f32 * startZ,
f32 * hitDepth )

Definition at line 13 of file npc_collision.c.

13 {
14 f32 cHitX;
15 f32 cHitY;
16 f32 cHitZ;
17 f32 cHitDepth;
18 f32 cHitNx;
19 f32 cHitNy;
20 f32 cHitNz;
21 f32 eHitX;
22 f32 eHitY;
23 f32 eHitZ;
24 f32 eHitDepth;
25 f32 eHitNx;
26 f32 eHitNy;
27 f32 eHitNz;
28 s32 entityID;
29 s32 colliderID;
30 f32 sx, sy, sz;
31
32 eHitDepth = cHitDepth = fabsf(*hitDepth);
33 sx = *startX;
34 sy = *startY;
35 sz = *startZ;
36 colliderID = test_ray_colliders(ignoreFlags, sx, sy, sz, 0.0f, -1.0f, 0.0f, &cHitX, &cHitY, &cHitZ, &cHitDepth, &cHitNx, &cHitNy, &cHitNz);
37 if (!(ignoreFlags & COLLISION_IGNORE_ENTITIES)) {
38 entityID = test_ray_entities(*startX, *startY, *startZ, 0.0f, -1.0f, 0.0f, &eHitX, &eHitY, &eHitZ, &eHitDepth, &eHitNx, &eHitNy, &eHitNz);
39 if (entityID > NO_COLLIDER) {
40 colliderID = entityID | COLLISION_WITH_ENTITY_BIT;
41 if (eHitDepth < cHitDepth) {
42 cHitDepth = eHitDepth;
43 cHitX = eHitX;
44 cHitY = eHitY;
45 cHitZ = eHitZ;
46 cHitNx = eHitNx;
47 cHitNy = eHitNy;
48 cHitNz = eHitNz;
49 }
50 }
51 if (colliderID <= NO_COLLIDER) {
52 return colliderID;
53 }
54 }
55
56 *hitDepth = cHitDepth;
57 *startX = cHitX;
58 *startY = cHitY;
59 *startZ = cHitZ;
60
61 if (colliderID <= NO_COLLIDER) {
62 return colliderID;
63 }
64
68 gGameStatusPtr->playerGroundTraceAngles.x = -atan2(0.0f, 0.0f, cHitNz * 100.0f, cHitNy * 100.0f);
70 gGameStatusPtr->playerGroundTraceAngles.z = -atan2(0.0f, 0.0f, cHitNx * 100.0f, cHitNy * 100.0f);
71
72 return colliderID;
73}
Vec3f playerGroundTraceNormal
Vec3f playerGroundTraceAngles
#define atan2
@ COLLISION_IGNORE_ENTITIES
Definition enums.h:4698
f32 fabsf(f32 f)
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.
Definition collision.c:947
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)
Definition collision.c:768
#define COLLISION_WITH_ENTITY_BIT
Definition macros.h:152
#define NO_COLLIDER
Definition macros.h:156
GameStatus * gGameStatusPtr
Definition main_loop.c:32

Referenced by npc_raycast_down_around(), and npc_raycast_down_sides().

◆ npc_raycast_down_around()

b32 npc_raycast_down_around ( s32 ignoreFlags,
f32 * posX,
f32 * posY,
f32 * posZ,
f32 * hitDepth,
f32 yaw,
f32 radius )

Definition at line 76 of file npc_collision.c.

76 {
77 f32 startX;
78 f32 startY;
79 f32 startZ;
80 f32 depth;
81 f32 x;
82 f32 y;
83 f32 z;
84 f32 originalDepth;
85 f32 hitYBehindLeft;
86 s32 hasCollision;
87 f32 cosTheta;
88 s32 colliderID;
89 f32 deltaX,deltaZ;
90 f32 theta, sinTheta, minDepth, hitYAhead, hitYBehindRight;
91
92 hasCollision = FALSE;
93 x = *posX;
94 y = *posY;
95 z = *posZ;
96 NpcHitQueryAheadY = *posY;
99 radius /= 2.5;
100 hitYBehindLeft = hitYBehindRight = hitYAhead = -32767.0f;
101 minDepth = fabsf(*hitDepth);
102
103 theta = DEG_TO_RAD(clamp_angle(yaw + 0.0f));
104 sinTheta = sin_rad(theta);
105 cosTheta = cos_rad(theta);
106 deltaX = radius * sinTheta;
107 deltaZ = -radius * cosTheta;
108
109 startX = x + deltaX;
110 startY = y;
111 startZ = z + deltaZ;
112 originalDepth = depth = minDepth;
113
114 colliderID = npc_raycast_down(ignoreFlags, &startX, &startY, &startZ, &depth);
115 if (colliderID > NO_COLLIDER) {
116 if (depth <= minDepth) {
117 hitYAhead = startY;
118 NpcHitQueryColliderID = colliderID;
119 NpcHitQueryAheadCollider = colliderID;
120 NpcHitQueryAheadY = hitYAhead;
121 minDepth = depth;
122 hasCollision = TRUE;
123 }
124 }
125
126 theta = DEG_TO_RAD(clamp_angle(yaw + 120.0f));
127 sinTheta = sin_rad(theta);
128 cosTheta = cos_rad(theta);
129 deltaX = radius * sinTheta;
130 deltaZ = -radius * cosTheta;
131
132 startX = x + deltaX;
133 startY = y;
134 startZ = z + deltaZ;
135 depth = originalDepth;
136
137 colliderID = npc_raycast_down(ignoreFlags, &startX, &startY, &startZ, &depth);
138 if (colliderID > NO_COLLIDER) {
139 if (depth <= minDepth) {
140 hitYBehindRight = startY;
141 NpcHitQueryColliderID = colliderID;
142 NpcHitQueryBehindCollider = colliderID;
143 NpcHitQueryBehindRightY = hitYBehindRight;
144 minDepth = depth;
145 hasCollision = TRUE;
146 }
147 }
148
149 theta = DEG_TO_RAD(clamp_angle(yaw - 120.0f));
150 sinTheta = sin_rad(theta);
151 cosTheta = cos_rad(theta);
152 deltaX = radius * sinTheta;
153 deltaZ = -radius * cosTheta;
154
155 startX = x + deltaX;
156 startY = y;
157 startZ = z + deltaZ;
158 depth = originalDepth;
159
160 colliderID = npc_raycast_down(ignoreFlags, &startX, &startY, &startZ, &depth);
161 if (colliderID > NO_COLLIDER) {
162 if (depth <= minDepth) {
163 hitYBehindLeft = startY;
164 NpcHitQueryColliderID = colliderID;
165 NpcHitQueryBehindCollider = colliderID;
166 NpcHitQueryBehindLeftY = hitYBehindLeft;
167 minDepth = depth;
168 hasCollision = TRUE;
169 }
170 }
171
172 if (hasCollision) {
173 *posY = MAX(hitYBehindRight, hitYAhead);
174 if (*posY < hitYBehindLeft) {
175 *posY = hitYBehindLeft;
176 }
177 *hitDepth = minDepth;
178 return TRUE;
179 }
180
181 *posY = startY;
182 return FALSE;
183}
#define clamp_angle
f32 cos_rad(f32 x)
Definition 43F0.c:717
f32 sin_rad(f32 x)
Definition 43F0.c:713
s32 NpcHitQueryBehindLeftY
HitID npc_raycast_down(s32 ignoreFlags, f32 *startX, f32 *startY, f32 *startZ, f32 *hitDepth)
s32 NpcHitQueryColliderID
s32 NpcHitQueryBehindRightY
s32 NpcHitQueryAheadCollider
s32 NpcHitQueryAheadY
s32 NpcHitQueryBehindCollider
#define DEG_TO_RAD(deg)
Definition macros.h:134

Referenced by func_80262130(), npc_try_apply_gravity(), npc_try_snap_to_ground(), partner_flying_follow_player(), partner_flying_update_motion(), partner_get_out(), partner_move_to_goal(), partner_walking_follow_player(), test_for_water_level(), update_item_entity_collectable(), and update_riding_physics().

◆ npc_raycast_down_sides()

b32 npc_raycast_down_sides ( s32 ignoreFlags,
f32 * posX,
f32 * posY,
f32 * posZ,
f32 * hitDepth )

Definition at line 186 of file npc_collision.c.

186 {
187 f32 startX;
188 f32 startY;
189 f32 startZ;
190 f32 depth;
191 f32 x;
192 f32 y;
193 f32 z;
194 f32 originalDepth;
195 f32 hitYUnused;
196 s32 hasCollision;
197 f32 cosTheta;
198 s32 colliderID;
199 f32 deltaX,deltaZ;
200 f32 yaw;
201 f32 theta, sinTheta, minDepth, hitYAhead, hitYBehind, radius;
202
203 hasCollision = FALSE;
204
205 x = *posX;
206 y = *posY;
207 z = *posZ;
208
212
213 hitYUnused = hitYBehind = hitYAhead = -32767.0f;
214 yaw = 0.0f;
215
216 minDepth = fabsf(*hitDepth);
217 theta = DEG_TO_RAD(clamp_angle(yaw));
218 sinTheta = sin_rad(theta);
219 cosTheta = cos_rad(theta);
220
221 radius = 10.0f;
222
223 deltaX = radius * sinTheta;
224 deltaZ = -radius * cosTheta;
225
226 startX = x + deltaX;
227 startY = y;
228 startZ = z + deltaZ;
229 originalDepth = depth = minDepth;
230
231 colliderID = npc_raycast_down(ignoreFlags, &startX, &startY, &startZ, &depth);
232 if (colliderID > NO_COLLIDER) {
233 if (depth <= minDepth) {
234 hitYAhead = startY;
235 NpcHitQueryColliderID = colliderID;
236 NpcHitQueryAheadCollider = colliderID;
237 NpcHitQueryAheadY = hitYAhead;
238 minDepth = depth;
239 hasCollision = TRUE;
240 }
241 }
242
243 theta = DEG_TO_RAD(clamp_angle(yaw + 180.0f));
244 sinTheta = sin_rad(theta);
245 cosTheta = cos_rad(theta);
246 deltaX = radius * sinTheta;
247 deltaZ = -radius * cosTheta;
248
249 startX = x + deltaX;
250 startY = y;
251 startZ = z + deltaZ;
252 depth = originalDepth;
253
254 colliderID = npc_raycast_down(ignoreFlags, &startX, &startY, &startZ, &depth);
255 if (colliderID > NO_COLLIDER) {
256 if (depth <= minDepth) {
257 hitYBehind = startY;
258 NpcHitQueryColliderID = colliderID;
259 NpcHitQueryBehindCollider = colliderID;
260 NpcHitQueryBehindRightY = hitYBehind;
261 minDepth = depth;
262 hasCollision = TRUE;
263 }
264 }
265
266 if (hasCollision) {
267 *posY = MAX(hitYBehind, hitYAhead);
268 if (*posY < hitYUnused) {
269 *posY = hitYUnused;
270 }
271 *hitDepth = minDepth;
272 return TRUE;
273 }
274
275 return FALSE;
276}

◆ npc_raycast_up()

b32 npc_raycast_up ( s32 ignoreFlags,
f32 * startX,
f32 * startY,
f32 * startZ,
f32 * hitDepth )

Definition at line 278 of file npc_collision.c.

278 {
279 f32 cHitX;
280 f32 cHitY;
281 f32 cHitZ;
282 f32 cHitDepth;
283 f32 cHitNx;
284 f32 cHitNy;
285 f32 cHitNz;
286 f32 eHitX;
287 f32 eHitY;
288 f32 eHitZ;
289 f32 eHitDepth;
290 f32 eHitNx;
291 f32 eHitNy;
292 f32 eHitNz;
293 s32 entityID;
294 s32 colliderID;
295 f32 sx, sy, sz;
296 s32 ret;
297
298 eHitDepth = cHitDepth = *hitDepth;
299 sx = *startX;
300 sy = *startY;
301 sz = *startZ;
302 ret = test_ray_colliders(ignoreFlags, sx, sy, sz, 0.0f, 1.0f, 0.0f, &cHitX, &cHitY, &cHitZ, &cHitDepth, &cHitNx, &cHitNy, &cHitNz);
303 colliderID = ret;
304 if (!(ignoreFlags & COLLISION_IGNORE_ENTITIES)) {
305 entityID = test_ray_entities(sx, sy, sz, 0.0f, 1.0f, 0.0f, &eHitX, &eHitY, &eHitZ, &eHitDepth, &eHitNx, &eHitNy, &eHitNz);
306 ret = entityID | COLLISION_WITH_ENTITY_BIT;
307 if (entityID > NO_COLLIDER) {
308 cHitDepth = eHitDepth;
309 cHitX = eHitX;
310 cHitY = eHitY;
311 cHitZ = eHitZ;
312 cHitNx = eHitNx;
313 cHitNy = eHitNy;
314 cHitNz = eHitNz;
315 } else {
316 ret = colliderID;
317 }
318 }
319
320 if (ret <= NO_COLLIDER) {
321 return FALSE;
322 } else {
323 *hitDepth = cHitDepth;
324 *startX = cHitX;
325 *startY = cHitY;
326 *startZ = cHitZ;
328 return TRUE;
329 }
330}

Referenced by partner_flying_update_motion(), and update_item_entity_collectable().

◆ npc_raycast_up_corner()

HitID npc_raycast_up_corner ( s32 ignoreFlags,
f32 * x,
f32 * y,
f32 * z,
f32 * length )

Definition at line 332 of file npc_collision.c.

332 {
333 f32 hitX;
334 f32 hitY;
335 f32 hitZ;
336 f32 hitDepth;
337 f32 hitNx;
338 f32 hitNy;
339 f32 hitNz;
340 s32 colliderID;
341 s32 entityID;
342 f32 sx, sy, sz;
343 f32 sx2, sy2, sz2;
344 HitID ret = NO_COLLIDER;
345
346 // needed to match
347 sx2 = sx = *x;
348 sy2 = sy = *y;
349 sz2 = sz = *z;
350 hitDepth = *length;
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) {
353 *length = hitDepth;
354 ret = colliderID;
355 *x = sx = sx2;
356 *y = sy = sy2;
357 *z = sz = sz2;
358 }
359
360 hitDepth = 10.0f;
361 entityID = test_ray_entities(*x, *y, *z, 0.0f, 1.0f, 0.0f, &hitX, &hitY, &hitZ, &hitDepth, &hitNx, &hitNy, &hitNz);
362 sx = sx2;
363 sy = sy2;
364 sz = sz2;
365 if (entityID > NO_COLLIDER && *length > hitDepth) {
366 ret = entityID | COLLISION_WITH_ENTITY_BIT;
367 *length = hitDepth;
368 *x = sx;
369 *y = sy;
370 *z = sz;
371 }
372
373 return ret;
374}
s32 HitID

Referenced by npc_raycast_up_corners().

◆ npc_raycast_up_corners()

HitID npc_raycast_up_corners ( s32 ignoreFlags,
f32 * posX,
f32 * posY,
f32 * posZ,
f32 * hitDepth,
f32 yaw,
f32 radius )

Definition at line 376 of file npc_collision.c.

376 {
377 f32 startX;
378 f32 startY;
379 f32 startZ;
380 f32 depth;
381 f32 theta;
382 f32 deltaZ;
383 f32 deltaX;
384 f32 x,y,z;
385 s32 ret;
386 s32 hitID;
387
388 theta = DEG_TO_RAD(yaw);
389 deltaX = radius * sin_rad(theta);
390 deltaZ = -radius * cos_rad(theta);
391
392 x = *posX;
393 y = *posY;
394 z = *posZ;
395
396 depth = *hitDepth;
397 startX = x + deltaX;
398 startY = y;
399 startZ = z + deltaZ;
400
401 ret = NO_COLLIDER;
402 hitID = npc_raycast_up_corner(ignoreFlags, &startX, &startY, &startZ, &depth);
403
404 if (hitID <= NO_COLLIDER) {
405 startX = x - deltaX;
406 startY = y;
407 startZ = z - deltaZ;
408 hitID = npc_raycast_up_corner(ignoreFlags, &startX, &startY, &startZ, &depth);
409 }
410
411 if (hitID <= NO_COLLIDER) {
412 startX = x + deltaZ;
413 startY = y;
414 startZ = z + deltaX;
415 hitID = npc_raycast_up_corner(ignoreFlags, &startX, &startY, &startZ, &depth);
416 }
417
418 if (hitID <= NO_COLLIDER) {
419 startX = x - deltaZ;
420 startY = y;
421 startZ = z - deltaX;
422 hitID = npc_raycast_up_corner(ignoreFlags, &startX, &startY, &startZ, &depth);
423 }
424
425 if (hitID > NO_COLLIDER) {
426 *posX = startX;
427 *posY = startY;
428 *posZ = startZ;
429 *hitDepth = depth;
430 ret = hitID;
431 }
432
433 if (ret <= NO_COLLIDER) {
434 *posX = startX;
435 *posY = startY;
436 *posZ = startZ;
437 *hitDepth = 0;
438 }
439
440 return ret;
441}
HitID npc_raycast_up_corner(s32 ignoreFlags, f32 *x, f32 *y, f32 *z, f32 *length)

Referenced by update_riding_physics().

◆ npc_raycast_general()

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 )

Definition at line 443 of file npc_collision.c.

444 {
445 s32 entityID;
446 HitID ret = NO_COLLIDER;
447
449 entityID = test_ray_entities(startX, startY, startZ, dirX, dirY, dirZ,
450 hitX, hitY, hitZ, outDepth, hitNx, hitNy, hitNz);
451 if (entityID > NO_COLLIDER) {
452 ret = entityID | COLLISION_WITH_ENTITY_BIT;
453 }
454 } else {
455 ret = test_ray_colliders(flags, startX, startY, startZ, dirX, dirY, dirZ,
456 hitX, hitY, hitZ, outDepth, hitNx, hitNy, hitNz);
458 return ret;
459 }
460
461 entityID = test_ray_entities(startX, startY, startZ, dirX, dirY, dirZ,
462 hitX, hitY, hitZ, outDepth, hitNx, hitNy, hitNz);
463 if (entityID > NO_COLLIDER) {
464 ret = entityID | COLLISION_WITH_ENTITY_BIT;
465 }
466 }
467
468 return ret;
469}
s8 flags
Definition demo_api.c:15
@ COLLISION_ONLY_ENTITIES
Definition enums.h:4700

Referenced by npc_test_move_with_slipping(), and npc_test_move_without_slipping().

◆ npc_get_slip_vector()

void npc_get_slip_vector ( f32 * outX,
f32 * outZ,
f32 aX,
f32 aZ,
f32 bX,
f32 bZ )

Definition at line 471 of file npc_collision.c.

471 {
472 f32 dotProduct = (aX * bX) + (aZ * bZ);
473
474 *outX = (aX - (dotProduct * bX)) * 0.5f;
475 *outZ = (aZ - (dotProduct * bZ)) * 0.5f;
476}

Referenced by npc_test_move_with_slipping().

◆ npc_test_move_with_slipping()

HitID npc_test_move_with_slipping ( s32 ignoreFlags,
f32 * x,
f32 * y,
f32 * z,
f32 length,
f32 yaw,
f32 radius )

Definition at line 478 of file npc_collision.c.

478 {
479 f32 outX, outY;
480 f32 bX, bZ;
481 f32 hitNy;
482 f32 hitDepth;
483 f32 hitX, hitY, hitZ;
484 f32 outSinTheta, outCosTheta;
485 f32 temp_f0, temp_f20, temp_f22;
486 f32 aX, aZ;
487 f32 inverseOutCosTheta;
488 s32 raycastHitID;
489 s32 phi_s5;
490 s32 hitResult = NO_COLLIDER;
491 f32 a, b;
492
493 sin_cos_rad(DEG_TO_RAD(yaw), &outSinTheta, &outCosTheta);
494 aX = length * outSinTheta;
495 temp_f22 = length + radius + (radius * 0.5f);
496 inverseOutCosTheta = -outCosTheta;
497 outCosTheta = inverseOutCosTheta;
498 hitDepth = temp_f22;
499 aZ = length * inverseOutCosTheta;
500 raycastHitID = npc_raycast_general(ignoreFlags, *x - (radius * outSinTheta * 0.5f), *y,
501 *z - (radius * inverseOutCosTheta * 0.5f), outSinTheta,
502 0.0f, inverseOutCosTheta, &hitX, &hitY, &hitZ, &hitDepth, &bX, &hitNy, &bZ);
503 phi_s5 = FALSE;
504
505 if (raycastHitID > NO_COLLIDER && hitDepth <= temp_f22) {
506 temp_f0 = atan2(0.0f, 0.0f, sqrtf(SQ(bX) + SQ(bZ)), -hitNy);
507 if (temp_f0 > 60.0f && temp_f0 < 90.0f) {
508 phi_s5 = TRUE;
509 }
510
511 temp_f20 = hitDepth - (length + radius + (radius * 0.5f));
512 a = temp_f20 * outSinTheta;
513 b = temp_f20 * outCosTheta;
514 npc_get_slip_vector(&outX, &outY, aX, aZ, bX, bZ);
515 *x += a + outX;
516 *z += b + outY;
517 NpcHitQueryColliderID = raycastHitID;
518 hitResult = raycastHitID;
519 }
520
521 if (!phi_s5) {
522 *x += aX;
523 *z += aZ;
524 }
525
526 return hitResult;
527}
#define sqrtf
void sin_cos_rad(f32 rad, f32 *outSinTheta, f32 *outCosTheta)
Definition 43F0.c:706
void npc_get_slip_vector(f32 *outX, f32 *outZ, f32 aX, f32 aZ, f32 bX, f32 bZ)
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)
#define SQ(x)
Definition macros.h:166

Referenced by npc_test_move_complex_with_slipping(), npc_test_move_simple_with_slipping(), and npc_test_move_taller_with_slipping().

◆ npc_test_move_without_slipping()

s32 npc_test_move_without_slipping ( s32 ignoreFlags,
f32 * x,
f32 * y,
f32 * z,
f32 length,
f32 yaw,
f32 radius )

Definition at line 529 of file npc_collision.c.

529 {
530 s32 ret = NO_COLLIDER;
531 f32 depth;
532 f32 originalDepth;
533 f32 dirY;
534 f32 cosTheta;
535 f32 hitNx, hitNy, hitNz;
536 f32 hitX, hitY, hitZ;
537 s32 hitID;
538 f32 temp1;
539 f32 temp2;
540
541 sin_cos_rad(DEG_TO_RAD(yaw), &dirY, &cosTheta);
542 cosTheta = -cosTheta;
543 originalDepth = length + radius + (radius * 0.5f);
544 depth = originalDepth;
545 temp1 = length * dirY;
546 temp2 = length * cosTheta;
547
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);
550
551 if (hitID > NO_COLLIDER && depth <= originalDepth) {
552 f32 depthDiff = depth - originalDepth;
553 f32 cosThetaTemp = cosTheta; // needed to match
554
555 *x += depthDiff * dirY;
556 *z += depthDiff * cosThetaTemp;
557 NpcHitQueryColliderID = hitID;
558 ret = hitID;
559 }
560
561 *x += temp1;
562 *z += temp2;
563 return ret;
564}

Referenced by npc_test_move_simple_without_slipping().

◆ npc_test_move_taller_with_slipping()

b32 npc_test_move_taller_with_slipping ( s32 ignoreFlags,
f32 * x,
f32 * y,
f32 * z,
f32 length,
f32 yaw,
f32 height,
f32 radius )

Definition at line 566 of file npc_collision.c.

567 {
568 f32 xTemp = *x;
569 f32 yTemp = *y + height - 1.0f;
570 f32 zTemp = *z;
571 s32 ret;
572
573 radius *= 0.5f;
574 if (npc_test_move_with_slipping(ignoreFlags, &xTemp, &yTemp, &zTemp, fabsf(length), yaw, radius) <= NO_COLLIDER) {
575 xTemp = *x;
576 yTemp = *y + 10.01f;
577 zTemp = *z;
578 ret = npc_test_move_with_slipping(ignoreFlags, &xTemp, &yTemp, &zTemp, fabsf(length), yaw, radius) > NO_COLLIDER;
579 *x = xTemp;
580 *z = zTemp;
581 } else {
582 ret = TRUE;
583 *x = xTemp;
584 *z = zTemp;
585 }
586 return ret;
587}
HitID npc_test_move_with_slipping(s32 ignoreFlags, f32 *x, f32 *y, f32 *z, f32 length, f32 yaw, f32 radius)

Referenced by apply_riding_static_collisions(), blast_affect_entities(), check_conversation_trigger(), Entity_BoardedFloor_update_fragments(), entity_BombableRock_update_fragments(), entity_shattering_idle(), entity_WoodenCrate_update_fragments(), FlyingMagikoopaAI_15(), npc_do_world_collision(), partner_flying_follow_player(), test_first_strike(), test_first_strike(), update_encounters_neutral(), update_riding_physics(), and update_riding_physics().

◆ npc_test_move_simple_with_slipping()

b32 npc_test_move_simple_with_slipping ( s32 ignoreFlags,
f32 * x,
f32 * y,
f32 * z,
f32 length,
f32 yaw,
f32 height,
f32 radius )

Definition at line 589 of file npc_collision.c.

590 {
591 f32 tempX = *x;
592 f32 tempY = *y + 10.01f;
593 f32 tempZ = *z;
594 s32 hitID = npc_test_move_with_slipping(ignoreFlags, &tempX, &tempY, &tempZ, fabsf(length), yaw, radius * 0.5f);
595
596 *x = tempX;
597 *z = tempZ;
598
599 return hitID > NO_COLLIDER;
600}

Referenced by ai_check_fwd_collisions(), apply_riding_static_collisions(), basic_ai_chase(), basic_ai_check_player_dist(), basic_ai_loiter(), basic_ai_wander(), CleftAI_Tackle(), HoppingAI_Chase(), HoppingAI_Hop(), HoppingAI_HopInit(), npc_do_world_collision(), PiranhaPlantAI_10(), UnkNpcAIFunc12(), and update_item_entity_collectable().

◆ npc_test_move_simple_without_slipping()

b32 npc_test_move_simple_without_slipping ( s32 ignoreFlags,
f32 * x,
f32 * y,
f32 * z,
f32 length,
f32 yaw,
f32 height,
f32 radius )

Definition at line 602 of file npc_collision.c.

603 {
604 f32 tempX = *x;
605 f32 tempY = *y + 10.01f;
606 f32 tempZ = *z;
607 s32 hitID = npc_test_move_without_slipping(ignoreFlags, &tempX, &tempY, &tempZ, fabsf(length), yaw, radius * 0.5f);
608
609 *x = tempX;
610 *z = tempZ;
611
612 return hitID > NO_COLLIDER;
613}
s32 npc_test_move_without_slipping(s32 ignoreFlags, f32 *x, f32 *y, f32 *z, f32 length, f32 yaw, f32 radius)

Referenced by AvoidPlayerAI_ChaseInit().

◆ npc_test_move_complex_with_slipping()

s32 npc_test_move_complex_with_slipping ( s32 ignoreFlags,
f32 * x,
f32 * y,
f32 * z,
f32 length,
f32 yaw,
f32 height,
f32 radius )

Definition at line 618 of file npc_collision.c.

619 {
620 f32 startX;
621 f32 startY;
622 f32 startZ;
623 s32 ret = 0;
624 s32 hitID;
625
626 radius *= 0.5f;
627 startX = *x;
628 startY = *y + height - 1.0f;
629 startZ = *z;
630 if (npc_test_move_with_slipping(ignoreFlags, &startX, &startY, &startZ, fabsf(length), yaw, radius) > NO_COLLIDER) {
631 *x = startX;
632 *z = startZ;
633 ret = 4;
634 }
635
636 startX = *x;
637 startY = *y + 20.0f;
638 startZ = *z;
639 if (npc_test_move_with_slipping(ignoreFlags, &startX, &startY, &startZ, fabsf(length), yaw, radius) > NO_COLLIDER) {
640 *x = startX;
641 *z = startZ;
642 ret = 3;
643 }
644
645 startX = *x;
646 startY = *y + 15.01f;
647 startZ = *z;
648 if (npc_test_move_with_slipping(ignoreFlags, &startX, &startY, &startZ, fabsf(length), yaw, radius) > NO_COLLIDER) {
649 *x = startX;
650 *z = startZ;
651 ret = 2;
652 }
653
654 startX = *x;
655 startY = *y + 10.01f;
656 startZ = *z;
657 hitID = npc_test_move_with_slipping(ignoreFlags, &startX, &startY, &startZ, fabsf(length), yaw, radius);
658 *x = startX;
659 *z = startZ;
660 if (hitID > NO_COLLIDER) {
661 ret = 1;
662 }
663
664 return ret;
665}

Referenced by apply_riding_static_collisions(), npc_do_world_collision(), update_item_entity_collectable(), and update_riding_physics().

Variable Documentation

◆ NpcHitQueryBehindRightY

s32 NpcHitQueryBehindRightY

Definition at line 3 of file npc_collision.c.

Referenced by npc_raycast_down_around(), and npc_raycast_down_sides().

◆ NpcHitQueryBehindCollider

s32 NpcHitQueryBehindCollider

Definition at line 4 of file npc_collision.c.

Referenced by func_80262130(), npc_raycast_down_around(), and npc_raycast_down_sides().

◆ NpcHitQueryAheadCollider

s32 NpcHitQueryAheadCollider

Definition at line 5 of file npc_collision.c.

Referenced by func_80262130(), npc_raycast_down_around(), and npc_raycast_down_sides().

◆ NpcHitQueryAheadY

s32 NpcHitQueryAheadY

Definition at line 6 of file npc_collision.c.

Referenced by npc_raycast_down_around(), and npc_raycast_down_sides().

◆ NpcHitQueryBehindLeftY

s32 NpcHitQueryBehindLeftY

Definition at line 7 of file npc_collision.c.

Referenced by npc_raycast_down_around(), and npc_raycast_down_sides().

◆ NpcHitQueryColliderID

◆ gPlayerStatusPtr

PlayerStatus* gPlayerStatusPtr = &gPlayerStatus

Definition at line 10 of file npc_collision.c.

Referenced by AvoidPlayerAI_ChaseInit(), basic_ai_chase(), basic_ai_chase_init(), basic_ai_loiter(), basic_ai_wander(), can_trigger_loading_zone(), clear_conversation_prompt(), clear_interact_prompt(), clear_ispy_icon(), clear_pulse_stone_icon(), CleftAI_Ambush(), CleftAI_CanSeePlayer(), CleftAI_FindPlayer(), CleftAI_PreAmbush(), CleftAI_ReturnHome(), CleftAI_RevUp(), ClubbaNappingAI_Loiter(), ClubbaNappingAI_ReturnHome(), ClubbaNappingAI_Sleep(), collision_check_player_intersecting_world(), entity_get_collision_flags(), entity_HiddenPanel_flip_over(), entity_SaveBlock_pause_game(), entity_SaveBlock_save_data(), FlyingAI_ChaseInit(), FlyingAI_JumpInit(), FlyingAI_Loiter(), FlyingAI_LosePlayer(), FlyingAI_Wander(), FlyingMagikoopaAI_15(), FlyingMagikoopaAI_17(), FlyingNoAttackAI_12(), FlyingNoAttackAI_13(), func_800E4404(), GuardAI_ChaseInit(), GuardAI_Idle(), GuardAI_ReturnHome(), HoppingAI_ChaseInit(), HoppingAI_Hop(), HoppingAI_Loiter(), interact_inspect_dismiss(), MagikoopaAI_10(), MagikoopaAI_CanShootSpell(), MeleeHitbox_CanSeePlayer(), ParatroopaAI_Windup(), partner_handle_after_battle(), PatrolAI_ChaseInit(), PatrolAI_Loiter(), phys_update_lava_reset(), PiranhaPlantAI_10(), ProjectileHitbox_GetUsableProjectileID(), render_conversation_prompt(), render_entities(), render_interact_prompt(), render_ispy_icon(), render_pulse_stone_icon(), SentinelAI_Chase(), SentinelAI_ChaseInit(), SentinelAI_Descend(), SentinelAI_DescendInit(), set_script_owner_npc_anim(), state_step_battle(), sync_held_position(), UnkDistFunc(), update_camera_lead_amount(), and update_player_shadow().