19 if ((1.1f <= value) || (value <= -1.1f)) {
43 f32 boundarySquaredDistance;
51 leftX = leftPathPoint->
posX;
52 leftZ = leftPathPoint->
posZ;
53 rightX = rightPathPoint->
posX;
54 rightZ = rightPathPoint->
posZ;
56 boundarySquaredDistance = ((rightX - leftX) * (rightX - leftX)) + ((rightZ - leftZ) * (rightZ - leftZ));
59 if (boundarySquaredDistance < 0.01f) {
66 ((2.0f * ((rightX - leftX) * (posX - leftX) + (rightZ - leftZ) * (posZ - leftZ))) / boundarySquaredDistance) -
68 return positionFactor;
77 gPlayers[playerId].pos[0],
gPlayers[playerId].pos[2], pathPointIndex, pathIndex);
98 pathPointOne = &
gTrackPaths[pathIndex][pathPointIndex];
99 pathPointOneX = pathPointOne->
posX;
100 pathPointOneZ = pathPointOne->
posZ;
102 pathPointTwoX = pathPointTwo->
posX;
103 pathPointTwoZ = pathPointTwo->
posZ;
106 zdiff = pathPointTwoZ - pathPointOneZ;
107 xdiff = pathPointTwoX - pathPointOneX;
108 if (xdiff && xdiff) {}
110 segmentLength =
sqrtf((xdiff * xdiff) + (zdiff * zdiff));
111 if (segmentLength < 0.01f) {
116 ((0.5f - (lerpFactor * 0.5f)) * (((offsetDistance * zdiff) / segmentLength) + pathPointOneX)) +
117 ((1.0f - (0.5f - (lerpFactor * 0.5f))) * (((offsetDistance * -zdiff) / segmentLength) + pathPointOneX));
119 ((0.5f - (lerpFactor * 0.5f)) * (((offsetDistance * -xdiff) / segmentLength) + pathPointOneZ)) +
120 ((1.0f - (0.5f - (lerpFactor * 0.5f))) * (((offsetDistance * xdiff) / segmentLength) + pathPointOneZ));
166 temp_f0 = 0.5f - (trackOffset / 2.0f);
167 temp_f12 = 1.0f - temp_f0;
168 gOffsetPosition[0] = ((temp_f0 * (x1 + x3)) / 2.0f) + ((temp_f12 * (x2 + x4)) / 2.0f);
169 gOffsetPosition[2] = ((temp_f0 * (z1 + z3)) / 2.0f) + ((temp_f12 * (z2 + z4)) / 2.0f);
176 f32 considerSquaredDistance;
177 f32 minimumSquaredDistance;
178 s32 considerPathPointIndex;
179 s32 pathPathPointCount;
180 s16 nearestPathPointIndex;
186 considerPathPoint = &pathPathPoints[0];
187 x_dist = (
f32) considerPathPoint->
posX - posX;
188 y_dist = (
f32) considerPathPoint->
posY - posY;
189 z_dist = (
f32) considerPathPoint->
posZ - posZ;
190 minimumSquaredDistance = (x_dist * x_dist) + (y_dist * y_dist) + (z_dist * z_dist);
191 nearestPathPointIndex = 0;
192 for (considerPathPointIndex = 1; considerPathPointIndex < pathPathPointCount;
193 considerPathPoint++, considerPathPointIndex++) {
194 x_dist = (
f32) considerPathPoint->
posX - posX;
195 y_dist = (
f32) considerPathPoint->
posY - posY;
196 z_dist = (
f32) considerPathPoint->
posZ - posZ;
197 considerSquaredDistance = (x_dist * x_dist) + (y_dist * y_dist) + (z_dist * z_dist);
198 if (considerSquaredDistance < minimumSquaredDistance) {
199 nearestPathPointIndex = considerPathPointIndex;
200 minimumSquaredDistance = considerSquaredDistance;
203 return nearestPathPointIndex;
212 f32 considerSquaredDistance;
213 f32 minimumSquaredDistance;
214 s32 considerPathPointIndex;
215 s32 pathPathPointCount;
219 s32 considerPathIndex;
221 s16 nearestPathPointIndex;
223 minimumSquaredDistance = 1000000.0f;
224 temp_t0 = *pathIndex;
225 nearestPathPointIndex = 0;
230 considerPathPoint = &pathPathPoints[0];
231 for (considerPathPointIndex = 0; considerPathPointIndex < pathPathPointCount;
232 considerPathPointIndex++, considerPathPoint++) {
235 x_dist = (
f32) considerPathPoint->
posX - posX;
236 y_dist = (
f32) considerPathPoint->
posY - posY;
237 z_dist = (
f32) considerPathPoint->
posZ - posZ;
238 considerSquaredDistance = (x_dist * x_dist) + (y_dist * y_dist) + (z_dist * z_dist);
239 if (considerSquaredDistance < minimumSquaredDistance) {
240 nearestPathPointIndex = considerPathPointIndex;
242 minimumSquaredDistance = considerSquaredDistance;
247 for (considerPathIndex = 0; considerPathIndex < 4; considerPathIndex++) {
248 if ((considerPathIndex != temp_t0) && (
gSizePath[considerPathIndex] >= 2)) {
250 considerPathPoint = &pathPathPoints[0];
252 for (considerPathPointIndex = 0; considerPathPointIndex < pathPathPointCount;
253 considerPathPointIndex++, considerPathPoint++) {
255 x_dist = (
f32) considerPathPoint->
posX - posX;
256 y_dist = (
f32) considerPathPoint->
posY - posY;
257 z_dist = (
f32) considerPathPoint->
posZ - posZ;
258 considerSquaredDistance = (x_dist * x_dist) + (y_dist * y_dist) + (z_dist * z_dist);
259 if (considerSquaredDistance < minimumSquaredDistance) {
260 nearestPathPointIndex = considerPathPointIndex;
261 var_t4 = considerPathIndex;
263 minimumSquaredDistance = considerSquaredDistance;
273 considerPathPoint = &pathPathPoints[0];
274 x_dist = (
f32) considerPathPoint->
posX - posX;
275 y_dist = (
f32) considerPathPoint->
posY - posY;
276 z_dist = (
f32) considerPathPoint->
posZ - posZ;
277 minimumSquaredDistance = (x_dist * x_dist) + (y_dist * y_dist) + (z_dist * z_dist);
278 nearestPathPointIndex = 0;
279 for (considerPathPointIndex = 1; considerPathPointIndex < pathPathPointCount;
280 considerPathPoint++, considerPathPointIndex++) {
281 x_dist = (
f32) considerPathPoint->
posX - posX;
282 y_dist = (
f32) considerPathPoint->
posY - posY;
283 z_dist = (
f32) considerPathPoint->
posZ - posZ;
284 considerSquaredDistance = (x_dist * x_dist) + (y_dist * y_dist) + (z_dist * z_dist);
285 if (considerSquaredDistance < minimumSquaredDistance) {
286 nearestPathPointIndex = considerPathPointIndex;
289 minimumSquaredDistance = considerSquaredDistance;
296 return nearestPathPointIndex;
306 s16 nearestPathPointIndex;
309 s32 pathPathPointCount;
318 nearestPathPointIndex = -1;
319 minimumDistance = 500.0f * 500.0f;
322 for (searchIndex = pathPointIndex - 3; searchIndex < pathPointIndex + 7; searchIndex++) {
325 considerIndex = (searchIndex + pathPathPointCount) % pathPathPointCount;
326 considerPathPoint = &pathPathPoints[considerIndex];
328 x_dist = considerPathPoint->
posX - posX;
329 y_dist = considerPathPoint->
posY - posY;
330 z_dist = considerPathPoint->
posZ - posZ;
331 squaredDistance = (x_dist * x_dist) + (y_dist * y_dist) + (z_dist * z_dist);
332 if (squaredDistance < minimumDistance) {
333 minimumDistance = squaredDistance;
334 nearestPathPointIndex = considerIndex;
338 return nearestPathPointIndex;
347 s16 nearestPathPointIndex;
351 s32 pathPathPointCount;
360 pathPointFound =
false;
361 nearestPathPointIndex = -1;
362 minimumDistance = 400.0f * 400.0f;
365 for (searchIndex = pathPointIndex - 3; searchIndex < pathPointIndex + 7; searchIndex++) {
368 considerIndex = (searchIndex + pathPathPointCount) % pathPathPointCount;
369 considerPathPoint = &pathPathPoints[considerIndex];
370 x_dist = considerPathPoint->
posX - posX;
371 y_dist = considerPathPoint->
posY - posY;
372 z_dist = considerPathPoint->
posZ - posZ;
373 squaredDistance = (x_dist * x_dist) + (y_dist * y_dist) + (z_dist * z_dist);
374 if (squaredDistance < minimumDistance) {
375 minimumDistance = squaredDistance;
376 nearestPathPointIndex = considerIndex;
377 pathPointFound =
true;
380 if (pathPointFound ==
false) {
381 for (searchIndex = pathPointIndex - 3; searchIndex < pathPointIndex + 7; searchIndex++) {
382 considerIndex = ((searchIndex + pathPathPointCount) % pathPathPointCount);
383 considerPathPoint = &pathPathPoints[considerIndex];
389 if (considerPathPoint && considerPathPoint) {};
392 return nearestPathPointIndex;
398 var_v0 = *pathPointIndex;
402 *pathPointIndex = var_v0;
407 pathPoint = *pathPointIndex;
408 if (pathPoint == 0) {
415 *pathPointIndex = pathPoint;
423 if ((trackSectionId <= 0) || (trackSectionId >= 0x33)) {
456 if (newPathPoint == -1) {
467 return pathPointIndex;
474 if (newPathPoint == -1) {
477 if (newPathPoint == -1) {
487 if (newPathPoint == -1) {
493 player->
pos[0] = posX;
494 player->
pos[1] = posY;
495 player->
pos[2] = posZ;
502 if (newPathPoint == -1) {
516 f32 considerSquaredDistance;
520 Path2D* considerPathPoint;
522 minimumDistance = 250000.0f;
524 for (realIndex = pathPointIndex - 2; realIndex < pathPointIndex + 7; realIndex++) {
525 considerIndex = realIndex;
531 xdiff = considerPathPoint->
x - xPos;
532 zdiff = considerPathPoint->
z - zPos;
533 considerSquaredDistance = (xdiff * xdiff) + (zdiff * zdiff);
534 if (considerSquaredDistance < minimumDistance) {
535 minimumDistance = considerSquaredDistance;
536 minimumIndex = considerIndex;
539 if (minimumIndex == -1) {
540 minimumIndex = pathPointIndex;
557 if (pathPoint == -1) {
568 if (pathPoint == -1) {
582 if (current < target) {
583 current += temp_v0->
step;
584 if (target < current) {
587 }
else if (target < current) {
588 current -= temp_v0->
step;
589 if (current < target) {
607 s32 lookAheadDistance;
612 lookAheadDistance = 6;
618 lookAheadDistance = 1;
621 lookAheadDistance = 7;
626 if (curveCount < 6) {
627 lookAheadDistance = 8;
628 }
else if (curveCount >= 0x15) {
629 lookAheadDistance = 20;
634 if (lookAheadDistance >= 8) {
636 lookAheadDistance = 7;
639 lookAheadDistance = 7;
643 lookAheadDistance = 5;
689 oldPos[0] = position[0];
690 oldPos[1] = position[1];
691 oldPos[2] = position[2];
692 oldPosX = position[0];
693 oldPosY = position[1];
694 oldPosZ = position[2];
695 temp_v0 =
func_8000D2B4(oldPosX, oldPosY, oldPosZ, *pathPointIndex, (
s32) pathIndex);
696 *pathPointIndex = temp_v0;
697 temp_v1 = temp_v0 + arg5;
706 midY = (path[pathPoint1].
posY + path[pathPoint2].
posY) * 0.5f;
707 midX = (pad3 + temp1) * 0.5f;
708 midZ = (pad4 + temp2) * 0.5f;
709 xdiff = midX - oldPosX;
710 ydiff = midY - oldPosY;
711 zdiff = midZ - oldPosZ;
712 distance =
sqrtf((xdiff * xdiff) + (ydiff * ydiff) + (zdiff * zdiff));
713 if (distance > 0.01f) {
714 var_f2 = ((xdiff * speed) / distance) + oldPosX;
715 var_f12 = ((ydiff * speed) / distance) + oldPosY;
716 var_f14 = ((zdiff * speed) / distance) + oldPosZ;
722 position[0] = var_f2;
723 position[1] = var_f12;
724 position[2] = var_f14;
762 temp_v0 =
func_8000D2B4(temp_f20, temp_f22, temp_f24, *pathPointIndex, (
s32) pathIndex);
763 *pathPointIndex = temp_v0;
764 pathPoint1 = ((temp_v0 + pathPointCount) - 3) % pathPointCount;
765 pathPoint2 = ((temp_v0 + pathPointCount) - 4) % pathPointCount;
773 midX = (pad2 + thing1) * 0.5f;
774 midZ = (pad3 + thing2) * 0.5f;
775 xdiff = midX - temp_f20;
776 ydiff = midY - temp_f22;
777 zdiff = midZ - temp_f24;
778 distance =
sqrtf((xdiff * xdiff) + (ydiff * ydiff) + (zdiff * zdiff));
779 if (distance > 0.01f) {
780 var_f2 = ((xdiff * speed) / distance) + temp_f20;
781 var_f12 = ((ydiff * speed) / distance) + temp_f22;
782 var_f14 = ((zdiff * speed) / distance) + temp_f24;
807 f32 farPathPointAverageX;
808 f32 farPathPointAverageZ;
814 s16 newPathPointIndex;
828 *pathPointIndex = newPathPointIndex;
833 farPathPointAverageX = (temp_a0->
x + temp_a2->
x) * 0.5f;
834 farPathPointAverageZ = (temp_a0->
z + temp_a2->
z) * 0.5f;
835 x_dist = farPathPointAverageX - origXPos;
836 y_dist = farPathPointAverageZ - origZPos;
837 distance =
sqrtf((x_dist * x_dist) + (y_dist * y_dist));
838 if (distance > 0.01f) {
839 newX = ((x_dist * speed) / distance) + origXPos;
840 newZ = ((y_dist * speed) / distance) + origZPos;
s16 gCurrentCourseId
Definition code_800029B0.c:30
s16 get_track_section_id(u16 index)
Definition collision.c:509
u16 check_bounding_collision(Collision *collision, f32 boundingBoxSize, f32 posX, f32 posY, f32 posZ)
Definition collision.c:1358
f32 Vec3f[3]
Definition common_structs.h:6
@ COURSE_WARIO_STADIUM
Definition course.h:45
@ COURSE_YOSHI_VALLEY
Definition course.h:35
@ COURSE_TOADS_TURNPIKE
Definition course.h:41
@ COURSE_AWARD_CEREMONY
Definition course.h:51
#define GET_COURSE_AIMaximumSeparation
Definition course.h:87
u16 gPathIndexByPlayerId[12]
Definition cpu_vehicles_camera_path.c:180
u16 gPathCountByPathIndex[4]
Definition cpu_vehicles_camera_path.c:181
s16 * gCurrentTrackSectionTypesPath
Definition cpu_vehicles_camera_path.c:84
u16 D_801631E0[12]
Definition cpu_vehicles_camera_path.c:86
s32 gVehicle2DPathLength
Definition cpu_vehicles_camera_path.c:139
s32 gPlayerPathIndex
Definition cpu_vehicles_camera_path.c:119
s16 gCurrentPlayerLookAhead[12]
Definition cpu_vehicles_camera_path.c:109
s16 get_angle_between_path(Vec3f arg0, Vec3f arg1)
Definition cpu_vehicles_camera_path.c:555
TrackPathPoint * gTrackPaths[4]
Definition cpu_vehicles_camera_path.c:174
s16 * gCurrentTrackConsecutiveCurveCountsPath
Definition cpu_vehicles_camera_path.c:183
TrackPathPoint * gTrackRightPaths[4]
Definition cpu_vehicles_camera_path.c:176
u16 gSelectedPathCount
Definition cpu_vehicles_camera_path.c:162
f32 gTrackPositionFactor[10]
Definition cpu_vehicles_camera_path.c:68
s32 gSizePath[4]
Definition cpu_vehicles_camera_path.c:106
Path2D * gVehicle2DPathPoint
Definition cpu_vehicles_camera_path.c:138
TrackPositionFactorInstruction gPlayerTrackPositionFactorInstruction[10]
Definition cpu_vehicles_camera_path.c:137
f32 gPathStartZ
Definition cpu_vehicles_camera_path.c:120
Vec3f gOffsetPosition
Definition cpu_vehicles_camera_path.c:51
u16 gPlayersTrackSectionId[12]
Definition cpu_vehicles_camera_path.c:100
TrackPathPoint * gTrackLeftPaths[4]
Definition cpu_vehicles_camera_path.c:175
s32 D_80163488
Definition cpu_vehicles_camera_path.c:128
#define PLAYER_EXISTS
Definition defines.h:80
#define PLAYER_HUMAN
Definition defines.h:79
#define PLAYER_CPU
Definition defines.h:77
#define UNUSED
Definition macros.h:23
Player gPlayers[NUM_PLAYERS]
Definition main.c:68
@ RIGHT_LEANING_CURVE
Definition path.h:14
@ LEFT_LEANING_CURVE
Definition path.h:15
s16 update_player_path(f32 posX, f32 posY, f32 posZ, s16 pathPointIndex, Player *player, s32 playerId, s32 pathIndex)
Definition path_utils.inc.c:445
s16 find_closest_vehicles_pathPoint(f32 xPos, UNUSED f32 yPos, f32 zPos, s16 pathPointIndex)
Definition path_utils.inc.c:512
s16 update_path_index_with_track(f32 posX, f32 posY, f32 posZ, s16 pathPointIndex, s32 pathIndex, u16 trackSectionId)
Definition path_utils.inc.c:305
f32 calculate_track_position_factor(f32 posX, f32 posZ, u16 pathPointIndex, s32 pathIndex)
Definition path_utils.inc.c:38
void tweak_path_index_wario_stadium(UNUSED f32 posX, f32 posY, UNUSED f32 posZ, s16 *pathPointIndex, UNUSED s32 arg4)
Definition path_utils.inc.c:395
s16 func_8000D6D0(Vec3f position, s16 *pathPointIndex, f32 speed, f32 arg3, s16 pathIndex, s16 arg5)
Definition path_utils.inc.c:662
s16 func_8000D33C(f32 posX, f32 posY, f32 posZ, s16 pathPointIndex, s32 pathIndex)
Definition path_utils.inc.c:564
f32 cpu_track_position_factor(s32 playerId)
Definition path_utils.inc.c:574
s16 update_vehicle_following_path(Vec3f pos, s16 *pathPointIndex, f32 speed)
Definition path_utils.inc.c:794
void update_player_position_factor(s32 playerId, u16 pathPointIndex, s32 pathIndex)
Definition path_utils.inc.c:71
s16 func_8000D940(Vec3f pos, s16 *pathPointIndex, f32 speed, f32 arg3, s16 pathIndex)
Definition path_utils.inc.c:728
s16 update_path_index(f32 posX, f32 posY, f32 posZ, s16 pathPointIndex, s32 pathIndex)
Definition path_utils.inc.c:346
bool are_in_curve(UNUSED s32 arg0, u16 pathPointIndex)
Definition path_utils.inc.c:9
void set_track_offset_position(u16 pathPointIndex, f32 trackOffset, s16 pathIndex)
Definition path_utils.inc.c:131
s16 func_8000D2B4(f32 posX, f32 posY, f32 posZ, s16 pathPointIndex, s32 pathIndex)
Definition path_utils.inc.c:553
s16 update_path_index_track_section(f32 posX, f32 posY, f32 posZ, Player *player, s32 playerId, s32 *pathIndex)
Definition path_utils.inc.c:418
s16 func_8000D24C(f32 posX, f32 posY, f32 posZ, s32 *pathIndex)
Definition path_utils.inc.c:545
bool is_far_from_path(s32 playerIndex)
Definition path_utils.inc.c:17
s16 find_closest_pathPoint_track_section(f32 posX, f32 posY, f32 posZ, u16 trackSectionId, s32 *pathIndex)
Definition path_utils.inc.c:206
void determine_ideal_cpu_position_offset(s32 playerId, u16 pathPoint)
Definition path_utils.inc.c:597
void calculate_track_offset_position(u16 pathPointIndex, f32 lerpFactor, f32 offsetDistance, s16 pathIndex)
Definition path_utils.inc.c:82
s16 func_8000BD94(f32 posX, f32 posY, f32 posZ, s32 pathIndex)
Definition path_utils.inc.c:172
void adjust_path_at_start_line(UNUSED f32 posX, UNUSED f32 posY, f32 posZ, s16 *pathPointIndex, s32 pathIndex)
Definition path_utils.inc.c:405
Definition common_structs.h:132
u16 meshIndexZX
Definition common_structs.h:139
Definition cpu_vehicles_camera_path.h:47
s16 z
Definition cpu_vehicles_camera_path.h:49
s16 x
Definition cpu_vehicles_camera_path.h:48
Definition common_structs.h:249
s16 unk_0CA
Definition common_structs.h:304
Collision collision
Definition common_structs.h:324
u16 type
Definition common_structs.h:250
Vec3f pos
Definition common_structs.h:259
s16 posX
Definition path.h:7
u16 trackSectionId
Definition path.h:10
s16 posZ
Definition path.h:9
s16 posY
Definition path.h:8
Definition cpu_vehicles_camera_path.h:21
f32 target
Definition cpu_vehicles_camera_path.h:23
f32 step
Definition cpu_vehicles_camera_path.h:24
f32 current
Definition cpu_vehicles_camera_path.h:22
signed int s32
Definition ultratypes.h:15
signed short int s16
Definition ultratypes.h:13
float f32
Definition ultratypes.h:34
unsigned short int u16
Definition ultratypes.h:14