diff --git a/asm/non_matchings/racer/func_80046524.s b/asm/non_matchings/racer/func_80046524.s index 7ecbc151..a0476955 100644 --- a/asm/non_matchings/racer/func_80046524.s +++ b/asm/non_matchings/racer/func_80046524.s @@ -547,7 +547,7 @@ glabel func_80046524 /* 047840 80046C40 86060160 */ lh $a2, 0x160($s0) /* 047844 80046C44 AFA00010 */ sw $zero, 0x10($sp) /* 047848 80046C48 02002025 */ move $a0, $s0 -/* 04784C 80046C4C 0C014214 */ jal func_80050850 +/* 04784C 80046C4C 0C014214 */ jal apply_vehicle_rotation_offset /* 047850 80046C50 00003825 */ move $a3, $zero /* 047854 80046C54 10000015 */ b .L80046CAC /* 047858 80046C58 820B01D5 */ lb $t3, 0x1d5($s0) @@ -569,7 +569,7 @@ glabel func_80046524 /* 047894 80046C94 44074000 */ mfc1 $a3, $f8 /* 047898 80046C98 44D8F800 */ ctc1 $t8, $31 /* 04789C 80046C9C 0007CC00 */ sll $t9, $a3, 0x10 -/* 0478A0 80046CA0 0C014214 */ jal func_80050850 +/* 0478A0 80046CA0 0C014214 */ jal apply_vehicle_rotation_offset /* 0478A4 80046CA4 00193C03 */ sra $a3, $t9, 0x10 /* 0478A8 80046CA8 820B01D5 */ lb $t3, 0x1d5($s0) .L80046CAC: diff --git a/asm/non_matchings/racer/func_80049794.s b/asm/non_matchings/racer/func_80049794.s index 5f7a38b4..2241f49f 100644 --- a/asm/non_matchings/racer/func_80049794.s +++ b/asm/non_matchings/racer/func_80049794.s @@ -1004,7 +1004,7 @@ glabel func_80049794 /* 04B174 8004A574 8FA500F8 */ lw $a1, 0xf8($sp) /* 04B178 8004A578 01E03825 */ move $a3, $t7 /* 04B17C 8004A57C AFA00010 */ sw $zero, 0x10($sp) -/* 04B180 8004A580 0C014214 */ jal func_80050850 +/* 04B180 8004A580 0C014214 */ jal apply_vehicle_rotation_offset /* 04B184 8004A584 E7AE00DC */ swc1 $f14, 0xdc($sp) /* 04B188 8004A588 920201FE */ lbu $v0, 0x1fe($s0) /* 04B18C 8004A58C C7AE00DC */ lwc1 $f14, 0xdc($sp) diff --git a/asm/non_matchings/racer/func_8004F7F4.s b/asm/non_matchings/racer/func_8004F7F4.s index 3481f936..fe13d6f4 100644 --- a/asm/non_matchings/racer/func_8004F7F4.s +++ b/asm/non_matchings/racer/func_8004F7F4.s @@ -100,7 +100,7 @@ glabel func_8004F7F4 /* 050520 8004F920 AE280074 */ sw $t0, 0x74($s1) /* 050524 8004F924 8FA500C0 */ lw $a1, 0xc0($sp) .L8004F928: -/* 050528 8004F928 0C014214 */ jal func_80050850 +/* 050528 8004F928 0C014214 */ jal apply_vehicle_rotation_offset /* 05052C 8004F92C AFA30010 */ sw $v1, 0x10($sp) /* 050530 8004F930 8FA600C4 */ lw $a2, 0xc4($sp) /* 050534 8004F934 02202025 */ move $a0, $s1 diff --git a/asm/non_matchings/racer/func_80054110.s b/asm/non_matchings/racer/func_80054110.s index de5fae5d..78125c11 100644 --- a/asm/non_matchings/racer/func_80054110.s +++ b/asm/non_matchings/racer/func_80054110.s @@ -77,7 +77,7 @@ glabel func_80054110 /* 054E04 80054204 02002025 */ move $a0, $s0 /* 054E08 80054208 00003025 */ move $a2, $zero /* 054E0C 8005420C 00003825 */ move $a3, $zero -/* 054E10 80054210 0C014214 */ jal func_80050850 +/* 054E10 80054210 0C014214 */ jal apply_vehicle_rotation_offset /* 054E14 80054214 AFA00010 */ sw $zero, 0x10($sp) /* 054E18 80054218 0C01AF6C */ jal get_current_level_header /* 054E1C 8005421C 00000000 */ nop diff --git a/src/racer.c b/src/racer.c index 6acca83f..9e926ae0 100644 --- a/src/racer.c +++ b/src/racer.c @@ -549,7 +549,81 @@ void func_80050754(Object *obj, Object_Racer *obj64, f32 arg2) { GLOBAL_ASM("asm/non_matchings/racer/func_80050754.s") #endif -GLOBAL_ASM("asm/non_matchings/racer/func_80050850.s") +/** + * Applies visual rotational offets to vehicles. + * Examples include planes when on the ground, or when crashing, or hovercraft when braking. + */ +void apply_vehicle_rotation_offset(Object_Racer* obj, s32 max, s16 roll, s16 pitch, s16 yaw) { + s32 diff; + s32 tempAngle; + + if (!obj->unk1F1) { + tempAngle = roll - (obj->unk160 & 0xFFFF); + obj->unk166 = pitch; + if (tempAngle > 0x8000) { + tempAngle += 0xFFFF0001; + } + if (tempAngle < -0x8000) { + tempAngle += 0xFFFF; + } + if (tempAngle > 0) { + diff = max * 0x600; + if (diff < tempAngle) { + tempAngle = diff; + } + obj->unk160 += tempAngle; + } else if (tempAngle < 0) { + diff = -(max * 0x600); + if (tempAngle < diff) { + tempAngle = diff; + } + obj->unk160 += tempAngle; + } + tempAngle = pitch - (obj->unk162 & 0xFFFF); + if (tempAngle > 0x8000) { + tempAngle = tempAngle + 0xFFFF0001; + } + if (tempAngle < -0x8000) { + tempAngle = tempAngle + 0xFFFF; + } + if (tempAngle > 0) { + diff = max * 0x600; + if (diff < tempAngle) { + tempAngle = diff; + } + obj->unk162 += tempAngle; + } else if (tempAngle < 0) { + diff = -(max * 0x600); + if (tempAngle < diff) { + tempAngle = diff; + } + obj->unk162 += tempAngle; + } + tempAngle = yaw - (obj->unk164 & 0xFFFF); + if (tempAngle > 0x8000) { + tempAngle = tempAngle + 0xFFFF0001; + } + if (tempAngle < -0x8000) { + tempAngle = tempAngle + 0xFFFF; + } + if (tempAngle > 0) { + diff = max * 0x600; + if (diff < tempAngle) { + tempAngle = diff; + } + obj->unk164 += tempAngle; + return; + } + if (tempAngle < 0) { + diff = -(max * 0x600); + if (tempAngle < diff) { + tempAngle = diff; + } + obj->unk164 += tempAngle; + } + } +} + GLOBAL_ASM("asm/non_matchings/racer/func_80050A28.s") // Loops for as long as Taj exists. After swapping vehicle once, will remain true until you enter a door.