140 int32_t turn_acceleration_gate = 0;
147 struct Math_Vec3I32 *actor_velocity = initial_actor_velocity;
148 int32_t vertical_velocity_component = actor->
velocity.
y;
150 if (!outside_bridge_game_mode)
169 vertical_velocity_component = 0;
171 initial_actor_velocity = &actor->
velocity;
176 int32_t drag_or_normalization_bits;
177 int32_t acceleration_q12;
178 int32_t inout_speed_limit_q12;
183 drag_or_normalization_bits = controller_record->
param_accel_3;
185 vertical_velocity_component = 0;
190 drag_or_normalization_bits = controller_record->
param_accel_1;
192 initial_actor_velocity->
y = 0;
199 if (ground_jump_velocity)
205 button_bits |= landing_button_mask;
210 int16_t saved_turn_step = (int16_t)controller_record->
turn_step;
226 turn_acceleration_gate = -1;
228 controller_record->
turn_step = (int32_t)saved_turn_step;
230 int64_t initial_x_squared_wide = (int64_t)actor_velocity->
x * actor_velocity->
x;
231 int64_t initial_y_squared_wide = (int64_t)actor_velocity->
y * actor_velocity->
y;
235 int64_t initial_z_squared_wide = (int64_t)actor_velocity->
z * actor_velocity->
z;
236 int32_t initial_actor_speed =
239 int32_t steering_magnitude = initial_actor_speed;
246 if (speed_jump_modifier)
248 int64_t modified_speed_limit_wide = (int64_t)speed_jump_modifier->
speed_multiplier_q12 * inout_speed_limit_q12;
256 int32_t acceleration_reduction_q12 = 0;
261 if (!acceleration_drag_modifier)
262 drag_q12 = drag_or_normalization_bits;
271 int64_t modified_drag_wide = (int64_t)acceleration_drag_modifier->
drag_multiplier_q12 * drag_or_normalization_bits;
298 int64_t modified_jump_speed_wide = (int64_t)jump_multiplier_q12 * initial_jump_speed_limit;
305 int32_t speed_after_drag = initial_actor_speed - drag_q12;
307 steering_magnitude = speed_after_drag;
309 if (speed_after_drag <= 0)
311 steering_magnitude = 0;
319 int32_t speed_before_drag = speed_after_drag + drag_q12;
320 int64_t dragged_velocity_x_wide = (int64_t)((int64_t)steering_magnitude *
PHYSICS_FIXED_ONE) / speed_before_drag * actor_velocity->
x;
324 int64_t dragged_velocity_y_wide = (int64_t)((int64_t)steering_magnitude *
PHYSICS_FIXED_ONE) / speed_before_drag * actor_velocity->
y;
327 drag_or_normalization_bits = ((int64_t)steering_magnitude *
PHYSICS_FIXED_ONE) / speed_before_drag;
329 int64_t dragged_velocity_z_wide = (int64_t)drag_or_normalization_bits * actor_velocity->
z;
334 int64_t input_x_squared_wide = (int64_t)inout_velocity->
x * inout_velocity->
x;
335 int64_t input_y_squared_wide = (int64_t)inout_velocity->
y * inout_velocity->
y;
336 int64_t input_z_squared_wide = (int64_t)inout_velocity->
z * inout_velocity->
z;
337 int32_t input_magnitude_squared_q12 = ((int32_t)((int64_t)((uint64_t)input_z_squared_wide + (uint64_t)input_x_squared_wide + (uint64_t)input_y_squared_wide) >>
PHYSICS_FIXED_FRACTION_BITS));
339 if (input_magnitude_squared_q12 <= 1)
345 inout_velocity->
z = 0;
346 inout_velocity->
x = 0;
350 controller_record->
input.
axis.
x = inout_velocity->
x;
351 controller_record->
input.
axis.
y = inout_velocity->
z;
355 int32_t input_magnitude_q12 =
Math_SqrtFP12(input_magnitude_squared_q12);
357 turn_acceleration_gate = input_magnitude_q12 <
PHYSICS_FIXED_HALF ? 1 - turn_acceleration_gate : 0;
359 int32_t input_x_before_normalize = inout_velocity->
x;
360 int32_t input_z_before_normalize = inout_velocity->
z;
362 inout_velocity->
x = ((int64_t)input_x_before_normalize *
PHYSICS_FIXED_ONE) / input_magnitude_q12;
363 inout_velocity->
z = ((int64_t)input_z_before_normalize *
PHYSICS_FIXED_ONE) / input_magnitude_q12;
365 int64_t input_scaled_speed_limit_wide = (int64_t)input_magnitude_q12 * inout_speed_limit_q12;
371 inout_velocity_q12 = inout_velocity;
372 moving_actor = actor;
378 inout_velocity_q12 = inout_velocity;
387 inout_velocity_q12->
x = (int32_t)m02;
392 acceleration_reduction_q12 = 0;
393 inout_velocity_q12->
z = (int32_t)m22;
396 int32_t steering_x = inout_velocity_q12->
x;
398 if (!(steering_x || inout_velocity_q12->
z) || !acceleration_q12)
401 inout_velocity_q12->
x = actor_velocity->
x;
402 inout_velocity_q12->
y = actor_velocity->
y;
403 inout_velocity_q12->
z = actor_velocity->
z;
413 inout_velocity_q12->
x = actor_velocity->
x;
414 inout_velocity_q12->
y = actor_velocity->
y;
415 inout_velocity_q12->
z = actor_velocity->
z;
421 inout_velocity_q12->
x = (int32_t)moving_actor->
rot_mat.
m02;
422 inout_velocity_q12->
z = (int32_t)moving_actor->
rot_mat.
m22;
425 int64_t acceleration_x_wide = (int64_t)acceleration_q12 * inout_velocity_q12->
x;
429 int64_t acceleration_y_wide = (int64_t)acceleration_q12 * inout_velocity_q12->
y;
430 int32_t steering_z = inout_velocity_q12->
z;
434 int64_t acceleration_z_wide = (int64_t)acceleration_q12 * steering_z;
436 int32_t acceleration_x_q12 = inout_velocity_q12->
x;
438 inout_velocity_q12->
z = acceleration_z_q12;
439 inout_velocity_q12->
x = acceleration_x_q12 + actor_velocity->
x;
440 inout_velocity_q12->
y += actor_velocity->
y;
441 inout_velocity_q12->
z = actor_velocity->
z + acceleration_z_q12;
450 inout_velocity_q12, &inout_speed_limit_q12),
451 &vertical_velocity_component);
455 int32_t ground_normal_up_q12;
466 ground_normal_up_q12 = (int32_t)face_plane->
normal.
y;
476 int32_t ground_normal_local_z = (int32_t)world_ground_normal->
z;
477 int32_t ground_normal_local_y = (int32_t)world_ground_normal->
y;
478 int32_t ground_normal_local_x = (int32_t)world_ground_normal->
x;
479 int32_t ground_normal_y_from_x = (int32_t)ground_collision_node->
transform_matrix.
m10 * ground_normal_local_x;
483 slope_normal.
z = (int16_t)((
486 world_ground_normal = &slope_normal;
489 int64_t slope_force_scale_wide = (int64_t)acceleration_reduction_q12 * controller_record->
param_CC * 3;
493 int64_t slope_force_x_wide = (int64_t)slope_force_q12 * (int32_t)world_ground_normal->
x;
495 int64_t slope_force_z_wide = (int64_t)slope_force_q12 * (int32_t)world_ground_normal->
z;
496 int32_t slope_force_x = (int32_t)slope_force_x_word;
497 int64_t slope_force_x_squared_wide = (int64_t)slope_force_x * slope_force_x;
499 int64_t slope_force_z_squared_wide = (int64_t)slope_force_z * slope_force_z;
503 int32_t velocity_z_with_slope = inout_velocity_q12->
z + slope_force_z;
505 inout_velocity_q12->
x += slope_force_x;
506 inout_velocity_q12->
z = velocity_z_with_slope;
512 inout_speed_limit_q12 = steering_magnitude;
516 int64_t candidate_x_squared_wide = (int64_t)inout_velocity->
x * inout_velocity->
x;
517 int64_t candidate_y_squared_wide = (int64_t)inout_velocity->
y * inout_velocity->
y;
518 int64_t candidate_z_squared_wide = (int64_t)inout_velocity->
z * inout_velocity->
z;
519 int32_t speed_squared_q12 = ((int32_t)((int64_t)((uint64_t)candidate_z_squared_wide + (uint64_t)candidate_x_squared_wide + (uint64_t)candidate_y_squared_wide) >>
PHYSICS_FIXED_FRACTION_BITS));
520 int64_t speed_limit_squared_wide = (int64_t)inout_speed_limit_q12 * inout_speed_limit_q12;
524 if (speed_squared_q12 <= speed_limit_squared_q12)
525 movement_velocity = inout_velocity;
530 int32_t clamp_speed_q12 = inout_speed_limit_q12;
532 movement_velocity = inout_velocity;
536 int64_t clamped_velocity_x_wide = (int64_t)steering_magnitude * movement_velocity->
x;
540 int64_t clamped_velocity_y_wide = (int64_t)steering_magnitude * movement_velocity->
y;
542 speed_squared_q12 = movement_velocity->
z;
545 int64_t clamped_velocity_z_wide = (int64_t)steering_magnitude * speed_squared_q12;
549 movement_velocity->
z = speed_limit_squared_q12;
554 uint16_t facing_delta;
575 if ((int16_t)facing_delta >= 0)
586 next_roll_angle += 0x20;
595 int32_t velocity_y_before_impulse = movement_velocity->
y;
599 int32_t velocity_z_before_impulse = movement_velocity->
z;
608 actor_velocity->
x = movement_velocity->
x;
609 actor_velocity->
y = movement_velocity->
y;
610 actor_velocity->
z = movement_velocity->
z;
616 actor_velocity->y += vertical_velocity_component;
618 int32_t vertical_velocity_before_gravity = integration_actor->velocity.y;
620 if (!controller_record->jump_phase_ticks)
622 if (vertical_velocity_before_gravity >= controller_record->movement_param_44)
624 int32_t velocity_y_after_gravity = vertical_velocity_before_gravity + controller_record->param_CC;
626 integration_actor->velocity.y = velocity_y_after_gravity;
628 int32_t terminal_fall_velocity = controller_record->movement_param_44;
630 if (velocity_y_after_gravity < terminal_fall_velocity)
631 integration_actor->velocity.y = terminal_fall_velocity;
634 else if (vertical_velocity_before_gravity <= controller_record->movement_param_40)
638 int32_t jump_velocity_boost;
641 jump_velocity_boost = 0;
643 jump_velocity_boost = controller_record->
param_C8;
645 int32_t velocity_y_after_jump_boost = integration_actor->
velocity.
y + jump_velocity_boost;
647 integration_actor->
velocity.
y = velocity_y_after_jump_boost;
651 if (velocity_y_after_jump_boost > jump_speed_limit)
652 integration_actor->
velocity.
y = jump_speed_limit;
655 else if ((movement_velocity->x || movement_velocity->z) && (integration_actor->child_actor->contact_basis.m00 !=
PHYSICS_Q14_ONE || movement_velocity->y))
657 if (movement_velocity->y)
659 int64_t untilted_x_squared_wide = (int64_t)inout_velocity->x * inout_velocity->x;
660 int64_t untilted_y_squared_wide = (int64_t)inout_velocity->y * inout_velocity->y;
661 int64_t untilted_z_squared_wide = (int64_t)inout_velocity->z * inout_velocity->z;
664 Math_SqrtFP12(((int32_t)((int64_t)((uint64_t)untilted_z_squared_wide + (uint64_t)untilted_x_squared_wide + (uint64_t)untilted_y_squared_wide) >> PHYSICS_FIXED_FRACTION_BITS)));
665 inout_velocity->y = 0;
667 int64_t horizontal_x_squared_wide = (int64_t)inout_velocity->x * inout_velocity->x;
668 int64_t horizontal_y_squared_wide = (int64_t)inout_velocity->y * inout_velocity->y;
669 int64_t horizontal_z_squared_wide = (int64_t)inout_velocity->z * inout_velocity->z;
670 int32_t horizontal_speed =
671 Math_SqrtFP12(((int32_t)((int64_t)((uint64_t)horizontal_z_squared_wide + (uint64_t)horizontal_x_squared_wide + (uint64_t)horizontal_y_squared_wide) >> PHYSICS_FIXED_FRACTION_BITS)));
673 if (horizontal_speed)
675 steering_magnitude <<= 4;
677 int32_t horizontal_restore_scale_q16 = ((int64_t)steering_magnitude * PHYSICS_FIXED_ONE) / horizontal_speed;
678 int64_t restored_horizontal_x_wide = (int64_t)horizontal_restore_scale_q16 * inout_velocity->x;
680 inout_velocity->x = ((int32_t)((uint64_t)restored_horizontal_x_wide >> PHYSICS_FIXED_FRACTION_BITS)) >> 4;
682 int64_t restored_horizontal_y_wide = (int64_t)horizontal_restore_scale_q16 * inout_velocity->y;
683 int32_t horizontal_velocity_z = inout_velocity->z;
685 inout_velocity->y = ((int32_t)((uint64_t)restored_horizontal_y_wide >> PHYSICS_FIXED_FRACTION_BITS)) >> 4;
687 int64_t restored_horizontal_z_wide = (int64_t)horizontal_restore_scale_q16 * horizontal_velocity_z;
689 inout_velocity->z = ((int32_t)((uint64_t)restored_horizontal_z_wide >> PHYSICS_FIXED_FRACTION_BITS)) >> 4;
692 *(struct Math_Vec3I32 *)inout_velocity = (struct Math_Vec3I32){
697 integration_actor = actor;
702 int32_t tilt_x_squared = tilt_x_q14 * tilt_x_q14;
703 int32_t tilt_y_q14 = (int32_t)ground_tilt_child->target_tilt_q14.y;
704 int32_t tilt_y_squared = tilt_y_q14 * tilt_y_q14;
705 int32_t tilt_z_q14 = (int32_t)ground_tilt_child->target_tilt_q14.z;
706 int32_t tilt_xy = tilt_y_q14 * tilt_x_q14;
707 int32_t tilt_zy = tilt_z_q14 * tilt_y_q14;
708 int32_t tilt_w_q14 = (int32_t)ground_tilt_child->target_tilt_q14.w;
709 int32_t tilt_zx = tilt_z_q14 * tilt_x_q14;
710 int32_t tilt_wx = tilt_w_q14 * tilt_x_q14;
711 int32_t tilt_wz = tilt_w_q14 * tilt_z_q14;
712 int32_t tilt_wy = tilt_w_q14 * tilt_y_q14;
725 int64_t tilted_x_from_x_wide = (int64_t)(int32_t)ground_tilt_rotation_q12.m00 * inout_velocity->x;
726 int64_t tilted_x_from_y_wide = (int64_t)(int32_t)ground_tilt_rotation_q12.m01 * inout_velocity->y;
727 int64_t tilted_x_from_z_wide = (int64_t)(int32_t)ground_tilt_rotation_q12.m02 * inout_velocity->z;
729 actor_velocity->x = ((int32_t)((int64_t)((uint64_t)tilted_x_from_z_wide + (uint64_t)tilted_x_from_x_wide + (uint64_t)tilted_x_from_y_wide) >>
PHYSICS_FIXED_FRACTION_BITS));
731 int64_t tilted_y_from_x_wide = (int64_t)(int32_t)ground_tilt_rotation_q12.m10 * inout_velocity->x;
732 int64_t tilted_y_from_y_wide = (int64_t)(int32_t)ground_tilt_rotation_q12.m11 * inout_velocity->y;
733 int64_t tilted_y_from_z_wide = (int64_t)(int32_t)ground_tilt_rotation_q12.m12 * inout_velocity->z;
735 actor_velocity->y = ((int32_t)((int64_t)((uint64_t)tilted_y_from_z_wide + (uint64_t)tilted_y_from_x_wide + (uint64_t)tilted_y_from_y_wide) >>
PHYSICS_FIXED_FRACTION_BITS));
737 int64_t tilted_z_from_x_wide = (int64_t)(int32_t)ground_tilt_rotation_q12.m20 * inout_velocity->x;
738 int64_t tilted_z_from_y_wide = (int64_t)(int32_t)ground_tilt_rotation_q12.m21 * inout_velocity->y;
743 int64_t tilted_z_from_z_wide = (int64_t)(int32_t)ground_tilt_rotation_q12.m22 * inout_velocity->z;
745 actor_velocity->z = ((int32_t)((int64_t)((uint64_t)tilted_z_from_z_wide + (uint64_t)tilted_z_from_x_wide + (uint64_t)tilted_z_from_y_wide) >>
PHYSICS_FIXED_FRACTION_BITS));