Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/z_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
void Lib_MemSet(u8* dest, size_t len, u8 val);
f32 Math_CosS(s16 angle);
f32 Math_SinS(s16 angle);
s32 Math_ScaledStepToS(s16* pValue, s16 target, s16 step);
s32 Math_RotationStepToS(s16* pValue, s16 target, s16 step);
s32 Math_StepToS(s16* pValue, s16 target, s16 step);
s32 Math_StepToF(f32* pValue, f32 target, f32 step);
s32 Math_StepUntilAngleS(s16* pValue, s16 limit, s16 step);
Expand Down
7 changes: 5 additions & 2 deletions src/code/z_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ f32 Math_SinS(s16 angle) {

/**
* Changes pValue by step (scaled by the update rate) towards target, setting it equal when the target is reached.
* Returns true when target is reached, false otherwise.
* This is used for rotations, as it handles the fact that XYZ rotations are stored as signed integers, i.e.
* 32,727 is followed by -32,728 when rotating in a circle, and will correctly adjust the step if the change
* crosses this boundary.
* @return true when target is reached, false otherwise.
*/
s32 Math_ScaledStepToS(s16* pValue, s16 target, s16 step) {
s32 Math_RotationStepToS(s16* pValue, s16 target, s16 step) {
if (step != 0) {
f32 updateScale = R_UPDATE_RATE * 0.5f;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ void BgBdanObjects_OctoPlatform_BattleInProgress(BgBdanObjects* this, PlayState*
}

void BgBdanObjects_SinkToFloorHeight(BgBdanObjects* this, PlayState* play) {
s32 cond = Math_ScaledStepToS(&this->dyna.actor.shape.rot.y, this->dyna.actor.home.rot.y, 0x200);
s32 cond = Math_RotationStepToS(&this->dyna.actor.shape.rot.y, this->dyna.actor.home.rot.y, 0x200);

if (Math_StepToF(&this->dyna.actor.world.pos.y, this->dyna.actor.home.pos.y + -125.0f, 3.0f)) {
if (cond) {
Expand Down
4 changes: 2 additions & 2 deletions src/overlays/actors/ovl_Bg_Haka_Gate/z_bg_haka_gate.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,12 @@ void BgHakaGate_FloorOpen(BgHakaGate* this, PlayState* play) {
this->vTimer--;
}
if (this->vTimer == 0) {
if (Math_ScaledStepToS(&this->vOpenAngle, 0, 0x800)) {
if (Math_RotationStepToS(&this->vOpenAngle, 0, 0x800)) {
DynaPoly_EnableCollision(play, &play->colCtx.dyna, this->dyna.bgId);
this->actionFunc = BgHakaGate_FloorClosed;
}
} else {
Math_ScaledStepToS(&this->vOpenAngle, 0x3000, 0x800);
Math_RotationStepToS(&this->vOpenAngle, 0x3000, 0x800);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/overlays/actors/ovl_Bg_Haka_Ship/z_bg_haka_ship.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void BgHakaShip_SetupCrash(BgHakaShip* this, PlayState* play) {
this->counter = 40;
this->actionFunc = BgHakaShip_CrashShake;
}
Math_ScaledStepToS(&this->yOffset, 0, 128);
Math_RotationStepToS(&this->yOffset, 0, 128);
}

void BgHakaShip_CrashShake(BgHakaShip* this, PlayState* play) {
Expand Down
4 changes: 2 additions & 2 deletions src/overlays/actors/ovl_Bg_Haka_Trap/z_bg_haka_trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,13 @@ void BgHakaTrap_FanBlade_ToggleFanGust(BgHakaTrap* this, PlayState* play) {
// world.rot.z is the current angular velocity of the fan
if (this->timer != 0) {
// Fan winds down
if (Math_ScaledStepToS(&this->dyna.actor.world.rot.z, 0, this->dyna.actor.world.rot.z * 0.03f + 5.0f)) {
if (Math_RotationStepToS(&this->dyna.actor.world.rot.z, 0, this->dyna.actor.world.rot.z * 0.03f + 5.0f)) {
this->timer = 40;
this->actionFunc = BgHakaTrap_FanBlade_Idle;
}
} else {
// Fan speeds up
if (Math_ScaledStepToS(&this->dyna.actor.world.rot.z, 0x3A00, this->dyna.actor.world.rot.z * 0.03f + 5.0f)) {
if (Math_RotationStepToS(&this->dyna.actor.world.rot.z, 0x3A00, this->dyna.actor.world.rot.z * 0.03f + 5.0f)) {
this->timer = 100;
this->actionFunc = BgHakaTrap_FanBlade_FullGust;
}
Expand Down
2 changes: 1 addition & 1 deletion src/overlays/actors/ovl_Bg_Haka_Zou/z_bg_haka_zou.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ void BgHakaZou_BirdStatueAnim_Topple(BgHakaZou* this, PlayState* play) {

this->dyna.actor.world.rot.x += this->dyna.actor.world.rot.x / 8.0f;

if (Math_ScaledStepToS(&this->dyna.actor.shape.rot.x, -0x4000, this->dyna.actor.world.rot.x)) {
if (Math_RotationStepToS(&this->dyna.actor.shape.rot.x, -0x4000, this->dyna.actor.world.rot.x)) {
effectPos.x = this->dyna.actor.world.pos.x;
effectPos.y = this->dyna.actor.world.pos.y;

Expand Down
2 changes: 1 addition & 1 deletion src/overlays/actors/ovl_Bg_Hidan_Fwbig/z_bg_hidan_fwbig.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void BgHidanFwbig_WaitForPlayer(BgHidanFwbig* this, PlayState* play) {

void BgHidanFwbig_Move(BgHidanFwbig* this, PlayState* play) {
if (!Player_InCsMode(play)) {
if (Math_ScaledStepToS(&this->actor.shape.rot.y, this->actor.home.rot.y + (this->direction * 0x6390), 0x20)) {
if (Math_RotationStepToS(&this->actor.shape.rot.y, this->actor.home.rot.y + (this->direction * 0x6390), 0x20)) {
this->moveState = FWBIG_RESET;
this->actionFunc = BgHidanFwbig_Lower;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/overlays/actors/ovl_Bg_Jya_Cobra/z_bg_jya_cobra.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ void func_80896ABC(BgJyaCobra* this, PlayState* play) {
Math_StepToS(&this->unk_16E, 21, 10);
}

if (Math_ScaledStepToS(&this->unk_170, this->unk_16A * 0x2000, this->unk_16E)) {
if (Math_RotationStepToS(&this->unk_170, this->unk_16A * 0x2000, this->unk_16E)) {
this->unk_16C = (this->unk_16C + this->unk_16A) & 7;
player->stateFlags2 &= ~PLAYER_STATE2_4;
this->dyna.unk_150 = 0.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/overlays/actors/ovl_Bg_Jya_Kanaami/z_bg_jya_kanaami.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void func_80899950(BgJyaKanaami* this, PlayState* play) {
s32 quakeIndex;

this->unk_168 += 0x20;
if (Math_ScaledStepToS(&this->dyna.actor.world.rot.x, 0x4000, this->unk_168)) {
if (Math_RotationStepToS(&this->dyna.actor.world.rot.x, 0x4000, this->unk_168)) {
func_80899A08(this);
Actor_PlaySfx(&this->dyna.actor, NA_SE_EV_TRAP_BOUND);

Expand Down
2 changes: 1 addition & 1 deletion src/overlays/actors/ovl_Bg_Po_Event/z_bg_po_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ void BgPoEvent_BlockReset(BgPoEvent* this, PlayState* play) {
this->dyna.unk_150 = 0.0f;
}
if (Math_StepToF(&this->dyna.actor.world.pos.y, 493.0f, 1.0f) &&
Math_ScaledStepToS(&this->dyna.actor.shape.rot.z, this->dyna.actor.world.rot.z - 0x4000, 0x400)) {
Math_RotationStepToS(&this->dyna.actor.shape.rot.z, this->dyna.actor.world.rot.z - 0x4000, 0x400)) {

this->index = (this->index + 1) % 4;
this->actionFunc = BgPoEvent_BlockFall;
Expand Down
4 changes: 2 additions & 2 deletions src/overlays/actors/ovl_Bg_Relay_Objects/z_bg_relay_objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ void func_808A939C(BgRelayObjects* this, PlayState* play) {
SET_EVENTCHKINF(EVENTCHKINF_65);
}
if (GET_EVENTCHKINF(EVENTCHKINF_65)) {
Math_ScaledStepToS(&this->dyna.actor.world.rot.y, 0x400, 8);
Math_RotationStepToS(&this->dyna.actor.world.rot.y, 0x400, 8);
} else {
Math_ScaledStepToS(&this->dyna.actor.world.rot.y, 0x80, 8);
Math_RotationStepToS(&this->dyna.actor.world.rot.y, 0x80, 8);
}
this->dyna.actor.shape.rot.y += this->dyna.actor.world.rot.y;
func_800F436C(&this->dyna.actor.projectedPos, NA_SE_EV_WOOD_GEAR - SFX_FLAG,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,16 @@ void BgSpot00Hanebasi_DrawbridgeRiseAndFall(BgSpot00Hanebasi* this, PlayState* p
Actor* childsChild;
s16 angle = 80;

if (Math_ScaledStepToS(&this->dyna.actor.shape.rot.x, this->destAngle, 80)) {
if (Math_RotationStepToS(&this->dyna.actor.shape.rot.x, this->destAngle, 80)) {
this->actionFunc = BgSpot00Hanebasi_DrawbridgeWait;
}

if (this->dyna.actor.shape.rot.x >= -0x27D8) {
child = (BgSpot00Hanebasi*)this->dyna.actor.child;
angle *= 0.4f;
Math_ScaledStepToS(&child->dyna.actor.shape.rot.x, child->destAngle, angle);
Math_RotationStepToS(&child->dyna.actor.shape.rot.x, child->destAngle, angle);
childsChild = child->dyna.actor.child;
Math_ScaledStepToS(&childsChild->shape.rot.x, child->destAngle, angle);
Math_RotationStepToS(&childsChild->shape.rot.x, child->destAngle, angle);
}

if (this->destAngle < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ void BgSpot06Objects_LockSwimToSurface(BgSpot06Objects* this, PlayState* play) {
this->dyna.actor.world.pos.y -= 1.3f;
BgSpot06Objects_LockSpawnWaterRipples(this, play, 0);

if (Math_ScaledStepToS(&this->dyna.actor.shape.rot.x, 0, 0x260) != 0) {
if (Math_RotationStepToS(&this->dyna.actor.shape.rot.x, 0, 0x260) != 0) {
this->dyna.actor.home.pos.x =
this->dyna.actor.world.pos.x - (Math_SinS(this->dyna.actor.shape.rot.y) * 16.0f);
this->dyna.actor.home.pos.z =
Expand All @@ -398,7 +398,7 @@ void BgSpot06Objects_LockSwimToSurface(BgSpot06Objects* this, PlayState* play) {
} else {
BgSpot06Objects_LockSpawnBubbles(this, play, 0);

if (Math_ScaledStepToS(&this->dyna.actor.shape.rot.x, -0x4000, 0x30)) {
if (Math_RotationStepToS(&this->dyna.actor.shape.rot.x, -0x4000, 0x30)) {
this->dyna.actor.home.pos.x = this->dyna.actor.world.pos.x;
this->dyna.actor.home.pos.y = -1993.0f;
this->dyna.actor.home.pos.z = this->dyna.actor.world.pos.z;
Expand Down
Loading