diff options
| author | engineer124 <47598039+engineer124@users.noreply.github.com> | 2022-01-31 07:55:42 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-30 17:55:42 -0300 |
| commit | bc7249960d13ef37738c3526731d3b2c09091c5b (patch) | |
| tree | fe8fd5a2df7f6a67b061dc7ab7f819d086c1fc16 /src/code | |
| parent | 50a9df78044ea32509415673c1faa8dcb425b5e8 (diff) | |
Rename "Quake2" -> "Distortion" (#588)
* rename `quake2` -> `distortion`
* Small touch-up
* cleanup and better spacing
* PR Feedback from OoT
* missed a small thing
* Name `billboardMtx` using better knowledge of sys_matrix functions thanks to `z_view`
* Add documentation to `SurfaceType_GetConveyorType`
* Cleanup Conveyor Type docs
* update cycle to phase
Diffstat (limited to 'src/code')
| -rw-r--r-- | src/code/z_bgcheck.c | 11 | ||||
| -rw-r--r-- | src/code/z_quake.c | 315 | ||||
| -rw-r--r-- | src/code/z_view.c | 130 |
3 files changed, 255 insertions, 201 deletions
diff --git a/src/code/z_bgcheck.c b/src/code/z_bgcheck.c index 850d5234b..7fa1b755b 100644 --- a/src/code/z_bgcheck.c +++ b/src/code/z_bgcheck.c @@ -4321,17 +4321,18 @@ s32 SurfaceType_IsIgnoredByProjectiles(CollisionContext* colCtx, CollisionPoly* } /** - * CollisionPoly is conveyor enabled - * Returns true if `poly` is a conveyor surface, else false + * SurfaceType Get Conveyor Surface Type + * Return type 0 (CONVEYOR_WATER) if 'poly' is a surface that will only move player underwater + * Return type 1 (CONVEYOR_FLOOR) if `poly` is a surface that must be stood on to move player */ -s32 SurfaceType_IsConveyor(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { +s32 SurfaceType_GetConveyorType(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) { u32 flags; if (BgCheck_GetCollisionHeader(colCtx, bgId) == NULL) { - return true; + return CONVEYOR_FLOOR; } if (poly == NULL) { - return false; + return CONVEYOR_WATER; } flags = poly->flags_vIB & 0x2000; return !!flags; diff --git a/src/code/z_quake.c b/src/code/z_quake.c index e699ff086..d38746bf4 100644 --- a/src/code/z_quake.c +++ b/src/code/z_quake.c @@ -1,7 +1,7 @@ #include "global.h" QuakeRequest sQuakeRequest[4]; -Quake2Context sQuake2Context; +DistortionContext sDistortionContext; static s16 sIsQuakeInitialized = true; static s16 sQuakeRequestCount = 0; @@ -382,58 +382,62 @@ s16 Quake_Calc(Camera* camera, QuakeCamCalc* camData) { return ret; } -void Quake2_Init(GlobalContext* globalCtx) { - sQuake2Context.globalCtx = globalCtx; - View_ClearQuake(&globalCtx->view); - sQuake2Context.type = 0; - sQuake2Context.countdown = 0; - sQuake2Context.state = QUAKE2_INACTIVE; +void Distortion_Init(GlobalContext* globalCtx) { + sDistortionContext.globalCtx = globalCtx; + View_ClearDistortion(&globalCtx->view); + sDistortionContext.type = 0; + sDistortionContext.countdown = 0; + sDistortionContext.state = DISTORTION_INACTIVE; } -void Quake2_SetCountdown(s16 countdown) { - sQuake2Context.countdown = countdown; - sQuake2Context.state = QUAKE2_SETUP; +void Distortion_SetCountdown(s16 countdown) { + sDistortionContext.countdown = countdown; + sDistortionContext.state = DISTORTION_SETUP; } -s16 Quake2_GetCountdown(void) { - return sQuake2Context.countdown; +s16 Distortion_GetCountdown(void) { + return sDistortionContext.countdown; } -s16 Quake2_GetType(void) { - return sQuake2Context.type; +s16 Distortion_GetType(void) { + return sDistortionContext.type; } -void Quake2_SetType(s32 type) { - if (sQuake2Context.type < type) { - sQuake2Context.type = type; +void Distortion_SetType(s32 type) { + if (sDistortionContext.type < type) { + sDistortionContext.type = type; } } -void Quake2_ClearType(s32 type) { - if (sQuake2Context.type == type) { - sQuake2Context.type = 0; +void Distortion_ClearType(s32 type) { + if (sDistortionContext.type == type) { + sDistortionContext.type = 0; } } -s32 Quake2_GetFloorQuake(Player* player) { - if (!SurfaceType_IsConveyor(&sQuake2Context.globalCtx->colCtx, player->actor.floorPoly, player->actor.floorBgId)) { - return SurfaceType_GetConveyorSpeed(&sQuake2Context.globalCtx->colCtx, player->actor.floorPoly, +/** + * Checks that the bg surface is an underwater conveyor type and if so, returns the conveyor speed + */ +s32 Distortion_GetUnderwaterCurrentSpeed(Player* player) { + if (SurfaceType_GetConveyorType(&sDistortionContext.globalCtx->colCtx, player->actor.floorPoly, + player->actor.floorBgId) == CONVEYOR_WATER) { + return SurfaceType_GetConveyorSpeed(&sDistortionContext.globalCtx->colCtx, player->actor.floorPoly, player->actor.floorBgId); } return 0; } -void Quake2_Update(void) { - static s16 angle1 = 0x3F0; - static s16 angle2 = 0x156; +void Distortion_Update(void) { + static s16 depthPhase = 0x3F0; + static s16 screenPlanePhase = 0x156; static s16 countdownMax = 1; f32 xyScaleFactor; f32 zScaleFactor; f32 speedScaleFactor; f32 countdownRatio; f32 waterYScaleFactor; - f32 angle1Speed; - f32 angle2Speed; + f32 depthPhaseStep; + f32 screenPlanePhaseStep; f32 rotX; f32 rotY; f32 rotZ; @@ -442,181 +446,210 @@ void Quake2_Update(void) { f32 zScale; f32 speed; Player* player; - GlobalContext* globalCtx = sQuake2Context.globalCtx; + GlobalContext* globalCtx = sDistortionContext.globalCtx; PosRot playerPosRot; Camera* camera = GET_ACTIVE_CAM(globalCtx); f32 speedRatio = CLAMP_MAX(camera->speedRatio, 1.0f); - if (sQuake2Context.type != 0) { - if (sQuake2Context.type & 0x800) { - sQuake2Context.countdown = 2; - angle1 = 0x3F0; - angle2 = 0x156; - angle1Speed = 0.0f; - angle2Speed = 170.0f; + if (sDistortionContext.type != 0) { + if (sDistortionContext.type & 0x800) { + sDistortionContext.countdown = 2; + depthPhase = 0x3F0; + screenPlanePhase = 0x156; + + depthPhaseStep = 0.0f; + screenPlanePhaseStep = 170.0f; + rotX = 0.0f; rotY = 0.0f; rotZ = 0.0f; + xScale = -0.01f; yScale = 0.01f; zScale = 0.0f; + speed = 0.6f; - xyScaleFactor = zScaleFactor = sQuake2Context.countdown / 60.0f; + xyScaleFactor = zScaleFactor = sDistortionContext.countdown / 60.0f; speedScaleFactor = 1.0f; - } else if (sQuake2Context.type & 0x400) { - if (sQuake2Context.state == QUAKE2_SETUP) { - countdownMax = sQuake2Context.countdown; - angle1 = 0x3F0; - angle2 = 0x156; + } else if (sDistortionContext.type & 0x400) { + if (sDistortionContext.state == DISTORTION_SETUP) { + countdownMax = sDistortionContext.countdown; + depthPhase = 0x3F0; + screenPlanePhase = 0x156; } - angle1Speed = 0.0f; - angle2Speed = 50.0f / countdownMax; + depthPhaseStep = 0.0f; + screenPlanePhaseStep = 50.0f / countdownMax; + rotX = 0.0f; rotY = 0.0f; rotZ = 0.0f; + xScale = 0.01f; yScale = 100.0f; zScale = 0.0f; + speed = 0.4f; - xyScaleFactor = zScaleFactor = ((f32)countdownMax - sQuake2Context.countdown) / (f32)countdownMax; + xyScaleFactor = zScaleFactor = ((f32)countdownMax - sDistortionContext.countdown) / (f32)countdownMax; speedScaleFactor = 0.5f; - } else if (sQuake2Context.type & 0x200) { - if (sQuake2Context.state == QUAKE2_SETUP) { - countdownMax = sQuake2Context.countdown; - angle1 = 0x1FC; - angle2 = 0x156; + } else if (sDistortionContext.type & 0x200) { + if (sDistortionContext.state == DISTORTION_SETUP) { + countdownMax = sDistortionContext.countdown; + depthPhase = 0x1FC; + screenPlanePhase = 0x156; } - angle1Speed = -5.0f; - angle2Speed = 5.0f; + depthPhaseStep = -5.0f; + screenPlanePhaseStep = 5.0f; + rotX = 0.0f; rotY = 0.0f; rotZ = 2.0f; + xScale = 0.3f; yScale = 0.3f; zScale = 0.0f; + speed = 0.1f; - xyScaleFactor = zScaleFactor = ((f32)countdownMax - sQuake2Context.countdown) / (f32)countdownMax; + xyScaleFactor = zScaleFactor = ((f32)countdownMax - sDistortionContext.countdown) / (f32)countdownMax; speedScaleFactor = 1.0f; - } else if (sQuake2Context.type & 0x100) { - if (sQuake2Context.state == QUAKE2_SETUP) { - countdownMax = sQuake2Context.countdown; - angle1 = 0x2710; - angle2 = 0x3E8; + } else if (sDistortionContext.type & 0x100) { + if (sDistortionContext.state == DISTORTION_SETUP) { + countdownMax = sDistortionContext.countdown; + depthPhase = 0x2710; + screenPlanePhase = 0x3E8; } - angle1Speed = 0.0f; - angle2Speed = 150.0f; + depthPhaseStep = 0.0f; + screenPlanePhaseStep = 150.0f; + rotX = 0; rotY = 0; rotZ = 0.2f; + xScale = 0.025f; yScale = 0.02f; zScale = 0.01f; + speed = 1.5f; - if (sQuake2Context.countdown < 5) { - xyScaleFactor = zScaleFactor = ((f32)countdownMax - sQuake2Context.countdown) / (f32)countdownMax; + if (sDistortionContext.countdown < 5) { + xyScaleFactor = zScaleFactor = ((f32)countdownMax - sDistortionContext.countdown) / (f32)countdownMax; } else { xyScaleFactor = zScaleFactor = 0.0f; } speedScaleFactor = 1.0f; - } else if (sQuake2Context.type & 0x80) { - if (sQuake2Context.state == QUAKE2_SETUP) { - countdownMax = sQuake2Context.countdown; - angle1 = 0x4B0; - angle2 = 0x7D0; + } else if (sDistortionContext.type & 0x80) { + if (sDistortionContext.state == DISTORTION_SETUP) { + countdownMax = sDistortionContext.countdown; + depthPhase = 0x4B0; + screenPlanePhase = 0x7D0; } - angle1Speed = 0.0f; - angle2Speed = 150.0f; + depthPhaseStep = 0.0f; + screenPlanePhaseStep = 150.0f; + rotX = 0; rotY = 0; rotZ = 0; + xScale = 0.03f; yScale = 0.02f; zScale = 0.01f; + speed = 1.5f; - xyScaleFactor = zScaleFactor = sQuake2Context.countdown / (f32)countdownMax; + xyScaleFactor = zScaleFactor = sDistortionContext.countdown / (f32)countdownMax; speedScaleFactor = 1.0f; - } else if (sQuake2Context.type & 0x40) { - if (sQuake2Context.state == QUAKE2_SETUP) { - countdownMax = sQuake2Context.countdown; - angle1 = 0x9C4; - angle2 = 0xBB8; + } else if (sDistortionContext.type & 0x40) { + if (sDistortionContext.state == DISTORTION_SETUP) { + countdownMax = sDistortionContext.countdown; + depthPhase = 0x9C4; + screenPlanePhase = 0xBB8; } - angle1Speed = 0.0f; - angle2Speed = 150.0f; + depthPhaseStep = 0.0f; + screenPlanePhaseStep = 150.0f; + rotX = 0; rotY = 0; rotZ = 0; + xScale = 0.03f; yScale = 0.03f; zScale = 0.01f; + speed = 1.3f; - if (sQuake2Context.countdown < 4) { - xyScaleFactor = zScaleFactor = sQuake2Context.countdown / (f32)countdownMax; + if (sDistortionContext.countdown < 4) { + xyScaleFactor = zScaleFactor = sDistortionContext.countdown / (f32)countdownMax; } else { xyScaleFactor = zScaleFactor = 0.0f; } speedScaleFactor = 1.0f; - } else if (sQuake2Context.type & 0x20) { - sQuake2Context.countdown = 2; - if (sQuake2Context.state == QUAKE2_SETUP) { - angle1 = 0x9C4; - angle2 = 0xBB8; + } else if (sDistortionContext.type & 0x20) { + sDistortionContext.countdown = 2; + if (sDistortionContext.state == DISTORTION_SETUP) { + depthPhase = 0x9C4; + screenPlanePhase = 0xBB8; } - angle1 += 0xB1; - angle2 -= 0x2B; - angle1Speed = -107.0f; - angle2Speed = 158.0f; + depthPhase += 0xB1; + screenPlanePhase -= 0x2B; + + depthPhaseStep = -107.0f; + screenPlanePhaseStep = 158.0f; + rotX = 0.2f; rotY = 1.7f; rotZ = -2.9f; + xScale = -0.6f; yScale = -0.7f; zScale = 0.6f; + speed = 0.2f; zScaleFactor = 1.0f; xyScaleFactor = 1.0f; speedScaleFactor = 1.0f; - } else if (sQuake2Context.type & 0x10) { - if (sQuake2Context.state == QUAKE2_SETUP) { - countdownMax = sQuake2Context.countdown; - angle1 = 0x760; - angle2 = 0x1BC; + } else if (sDistortionContext.type & 0x10) { + if (sDistortionContext.state == DISTORTION_SETUP) { + countdownMax = sDistortionContext.countdown; + depthPhase = 0x760; + screenPlanePhase = 0x1BC; } - angle1Speed = 248.0f; - angle2Speed = -90.0f; + depthPhaseStep = 248.0f; + screenPlanePhaseStep = -90.0f; + rotX = 0.0f; rotY = 0.0f; rotZ = 0.0f; + xScale = -0.4f; yScale = 0.4f; zScale = 0.2f; + speed = 0.25f; - countdownRatio = sQuake2Context.countdown / (f32)countdownMax; + countdownRatio = sDistortionContext.countdown / (f32)countdownMax; zScaleFactor = xyScaleFactor = countdownRatio; speedScaleFactor = 1.0f; - } else if (sQuake2Context.type & 8) { - angle1 = 0x3F0; - angle2 = 0x156; - sQuake2Context.countdown = 2; + } else if (sDistortionContext.type & 8) { + depthPhase = 0x3F0; + screenPlanePhase = 0x156; + + sDistortionContext.countdown = 2; player = GET_PLAYER(globalCtx); if (&player->actor != NULL) { Actor_GetWorldPosShapeRot(&playerPosRot, &player->actor); } - angle1Speed = 359.2f; - angle2Speed = -18.5f; + depthPhaseStep = 359.2f; + screenPlanePhaseStep = -18.5f; + rotX = 0.0f; rotY = 0.0f; rotZ = 0.3f; - switch (Quake2_GetFloorQuake(player)) { + + switch (Distortion_GetUnderwaterCurrentSpeed(player)) { case 3: xScale = -0.06f; yScale = 0.1f; @@ -650,17 +683,20 @@ void Quake2_Update(void) { } zScaleFactor = -xyScaleFactor; speedScaleFactor = 1.0f; - } else if (sQuake2Context.type & 4) { - angle1 = 0x3F0; - angle2 = 0x156; - sQuake2Context.countdown = 2; + } else if (sDistortionContext.type & 4) { + depthPhase = 0x3F0; + screenPlanePhase = 0x156; + + sDistortionContext.countdown = 2; player = GET_PLAYER(globalCtx); - angle1Speed = 359.2f; - angle2Speed = -18.5f; + + depthPhaseStep = 359.2f; + screenPlanePhaseStep = -18.5f; + rotX = 0.0f; rotY = 0.0f; rotZ = 0.0f; - switch (Quake2_GetFloorQuake(player)) { + switch (Distortion_GetUnderwaterCurrentSpeed(player)) { case 3: xScale = 0.12f; yScale = 0.12f; @@ -695,18 +731,23 @@ void Quake2_Update(void) { xyScaleFactor = speedScaleFactor = (waterYScaleFactor * 0.15f) + 0.35f + (speedRatio * 0.4f); zScaleFactor = 0.9f - xyScaleFactor; - } else if (sQuake2Context.type & 1) { - angle1 = 0x3F0; - angle2 = 0x156; - sQuake2Context.countdown = 2; - angle1Speed = 0.0f; - angle2Speed = 150.0f; + } else if (sDistortionContext.type & 1) { + // Gives a small mirage-like appearance + depthPhase = 0x3F0; + screenPlanePhase = 0x156; + + sDistortionContext.countdown = 2; + depthPhaseStep = 0.0f; + screenPlanePhaseStep = 150.0f; + rotX = 0.0f; rotY = 0.0f; rotZ = 0.0f; + xScale = -0.01f; yScale = 0.01f; zScale = 0.01f; + speed = 0.6f; speedScaleFactor = 1.0f; zScaleFactor = 1.0f; @@ -715,26 +756,32 @@ void Quake2_Update(void) { return; } - angle1 += DEGF_TO_BINANG(angle1Speed); - angle2 += DEGF_TO_BINANG(angle2Speed); - View_SetQuakeRotation(&sQuake2Context.globalCtx->view, Math_CosS(angle1) * (DEGF_TO_RADF(rotX) * xyScaleFactor), - Math_SinS(angle1) * (DEGF_TO_RADF(rotY) * xyScaleFactor), - Math_SinS(angle2) * (DEGF_TO_RADF(rotZ) * zScaleFactor)); - View_SetQuakeScale(&sQuake2Context.globalCtx->view, (Math_SinS(angle2) * (xScale * xyScaleFactor)) + 1.0f, - (Math_CosS(angle2) * (yScale * xyScaleFactor)) + 1.0f, - (Math_CosS(angle1) * (zScale * zScaleFactor)) + 1.0f); - View_SetQuakeSpeed(&sQuake2Context.globalCtx->view, speed * speedScaleFactor); - sQuake2Context.state = QUAKE2_ACTIVE; - } else if (sQuake2Context.state != QUAKE2_INACTIVE) { - View_ClearQuake(&globalCtx->view); - sQuake2Context.state = QUAKE2_INACTIVE; - sQuake2Context.countdown = 0; + depthPhase += DEGF_TO_BINANG(depthPhaseStep); + screenPlanePhase += DEGF_TO_BINANG(screenPlanePhaseStep); + + View_SetDistortionDirRot(&sDistortionContext.globalCtx->view, + Math_CosS(depthPhase) * (DEGF_TO_RADF(rotX) * xyScaleFactor), + Math_SinS(depthPhase) * (DEGF_TO_RADF(rotY) * xyScaleFactor), + Math_SinS(screenPlanePhase) * (DEGF_TO_RADF(rotZ) * zScaleFactor)); + View_SetDistortionScale(&sDistortionContext.globalCtx->view, + (Math_SinS(screenPlanePhase) * (xScale * xyScaleFactor)) + 1.0f, + (Math_CosS(screenPlanePhase) * (yScale * xyScaleFactor)) + 1.0f, + (Math_CosS(depthPhase) * (zScale * zScaleFactor)) + 1.0f); + View_SetDistortionSpeed(&sDistortionContext.globalCtx->view, speed * speedScaleFactor); + + sDistortionContext.state = DISTORTION_ACTIVE; + + } else if (sDistortionContext.state != DISTORTION_INACTIVE) { + View_ClearDistortion(&globalCtx->view); + + sDistortionContext.state = DISTORTION_INACTIVE; + sDistortionContext.countdown = 0; } - if (sQuake2Context.countdown != 0) { - sQuake2Context.countdown--; - if (sQuake2Context.countdown == 0) { - sQuake2Context.type = 0; + if (sDistortionContext.countdown != 0) { + sDistortionContext.countdown--; + if (sDistortionContext.countdown == 0) { + sDistortionContext.type = 0; } } } diff --git a/src/code/z_view.c b/src/code/z_view.c index da2e3593b..d11a18201 100644 --- a/src/code/z_view.c +++ b/src/code/z_view.c @@ -43,7 +43,7 @@ void View_Init(View* view, GraphicsContext* gfxCtx) { view->zFar = 12800.0f; view->eye.z = -1.0f; - View_InitCameraQuake(view); + View_InitDistortion(view); } void View_SetViewOrientation(View* view, Vec3f* eye, Vec3f* at, Vec3f* up) { @@ -187,87 +187,93 @@ void View_SetScissorForLetterbox(View* view) { CLOSE_DISPS(view->gfxCtx); } -s32 View_SetQuakeRotation(View* view, f32 x, f32 y, f32 z) { - view->quakeRot.x = x; - view->quakeRot.y = y; - view->quakeRot.z = z; +s32 View_SetDistortionDirRot(View* view, f32 dirRotX, f32 dirRotY, f32 dirRotZ) { + view->distortionDirRot.x = dirRotX; + view->distortionDirRot.y = dirRotY; + view->distortionDirRot.z = dirRotZ; return 1; } -s32 View_SetQuakeScale(View* view, f32 x, f32 y, f32 z) { - view->quakeScale.x = x; - view->quakeScale.y = y; - view->quakeScale.z = z; +s32 View_SetDistortionScale(View* view, f32 scaleX, f32 scaleY, f32 scaleZ) { + view->distortionScale.x = scaleX; + view->distortionScale.y = scaleY; + view->distortionScale.z = scaleZ; return 1; } -s32 View_SetQuakeSpeed(View* view, f32 speed) { - view->quakeSpeed = speed; +s32 View_SetDistortionSpeed(View* view, f32 speed) { + view->distortionSpeed = speed; return 1; } -s32 View_InitCameraQuake(View* view) { - view->quakeRot.x = 0.0f; - view->quakeRot.y = 0.0f; - view->quakeRot.z = 0.0f; - view->quakeScale.x = 1.0f; - view->quakeScale.y = 1.0f; - view->quakeScale.z = 1.0f; - view->currQuakeRot = view->quakeRot; - view->currQuakeScale = view->quakeScale; - view->quakeSpeed = 0.0f; +s32 View_InitDistortion(View* view) { + view->distortionDirRot.x = 0.0f; + view->distortionDirRot.y = 0.0f; + view->distortionDirRot.z = 0.0f; + view->distortionScale.x = 1.0f; + view->distortionScale.y = 1.0f; + view->distortionScale.z = 1.0f; + view->curDistortionDirRot = view->distortionDirRot; + view->curDistortionScale = view->distortionScale; + view->distortionSpeed = 0.0f; return 1; } -s32 View_ClearQuake(View* view) { - view->quakeRot.x = 0.0f; - view->quakeRot.y = 0.0f; - view->quakeRot.z = 0.0f; - view->quakeScale.x = 1.0f; - view->quakeScale.y = 1.0f; - view->quakeScale.z = 1.0f; - view->quakeSpeed = 1.0f; +s32 View_ClearDistortion(View* view) { + view->distortionDirRot.x = 0.0f; + view->distortionDirRot.y = 0.0f; + view->distortionDirRot.z = 0.0f; + view->distortionScale.x = 1.0f; + view->distortionScale.y = 1.0f; + view->distortionScale.z = 1.0f; + view->distortionSpeed = 1.0f; return 1; } -s32 View_SetQuake(View* view, Vec3f rot, Vec3f scale, f32 speed) { - view->quakeRot = rot; - view->quakeScale = scale; - view->quakeSpeed = speed; +s32 View_SetDistortion(View* view, Vec3f dirRot, Vec3f scale, f32 speed) { + view->distortionDirRot = dirRot; + view->distortionScale = scale; + view->distortionSpeed = speed; return 1; } -s32 View_StepQuake(View* view, Mtx* matrix) { - MtxF mf; +s32 View_StepDistortion(View* view, Mtx* projectionMtx) { + MtxF projectionMtxF; - if (view->quakeSpeed == 0.0f) { - return 0; - } else if (view->quakeSpeed == 1.0f) { - view->currQuakeRot = view->quakeRot; - view->currQuakeScale = view->quakeScale; - view->quakeSpeed = 0.0f; + if (view->distortionSpeed == 0.0f) { + return false; + } else if (view->distortionSpeed == 1.0f) { + view->curDistortionDirRot = view->distortionDirRot; + view->curDistortionScale = view->distortionScale; + view->distortionSpeed = 0.0f; } else { - view->currQuakeRot.x += ((view->quakeRot.x - view->currQuakeRot.x) * view->quakeSpeed); - view->currQuakeRot.y += ((view->quakeRot.y - view->currQuakeRot.y) * view->quakeSpeed); - view->currQuakeRot.z += ((view->quakeRot.z - view->currQuakeRot.z) * view->quakeSpeed); - - view->currQuakeScale.x += ((view->quakeScale.x - view->currQuakeScale.x) * view->quakeSpeed); - view->currQuakeScale.y += ((view->quakeScale.y - view->currQuakeScale.y) * view->quakeSpeed); - view->currQuakeScale.z += ((view->quakeScale.z - view->currQuakeScale.z) * view->quakeSpeed); + view->curDistortionDirRot.x = + F32_LERPIMP(view->curDistortionDirRot.x, view->distortionDirRot.x, view->distortionSpeed); + view->curDistortionDirRot.y = + F32_LERPIMP(view->curDistortionDirRot.y, view->distortionDirRot.y, view->distortionSpeed); + view->curDistortionDirRot.z = + F32_LERPIMP(view->curDistortionDirRot.z, view->distortionDirRot.z, view->distortionSpeed); + + view->curDistortionScale.x = + F32_LERPIMP(view->curDistortionScale.x, view->distortionScale.x, view->distortionSpeed); + view->curDistortionScale.y = + F32_LERPIMP(view->curDistortionScale.y, view->distortionScale.y, view->distortionSpeed); + view->curDistortionScale.z = + F32_LERPIMP(view->curDistortionScale.z, view->distortionScale.z, view->distortionSpeed); } - Matrix_FromRSPMatrix(matrix, &mf); - Matrix_SetCurrentState(&mf); - Matrix_RotateStateAroundXAxis(view->currQuakeRot.x); - Matrix_InsertYRotation_f(view->currQuakeRot.y, MTXMODE_APPLY); - Matrix_InsertZRotation_f(view->currQuakeRot.z, MTXMODE_APPLY); - Matrix_Scale(view->currQuakeScale.x, view->currQuakeScale.y, view->currQuakeScale.z, MTXMODE_APPLY); - Matrix_InsertZRotation_f(-view->currQuakeRot.z, MTXMODE_APPLY); - Matrix_InsertYRotation_f(-view->currQuakeRot.y, MTXMODE_APPLY); - Matrix_RotateStateAroundXAxis(-view->currQuakeRot.x); - Matrix_ToMtx(matrix); - - return 1; + Matrix_FromRSPMatrix(projectionMtx, &projectionMtxF); + Matrix_SetCurrentState(&projectionMtxF); + Matrix_RotateStateAroundXAxis(view->curDistortionDirRot.x); + Matrix_InsertYRotation_f(view->curDistortionDirRot.y, MTXMODE_APPLY); + Matrix_InsertZRotation_f(view->curDistortionDirRot.z, MTXMODE_APPLY); + Matrix_Scale(view->curDistortionScale.x, view->curDistortionScale.y, view->curDistortionScale.z, MTXMODE_APPLY); + Matrix_InsertZRotation_f(-view->curDistortionDirRot.z, MTXMODE_APPLY); + Matrix_InsertYRotation_f(-view->curDistortionDirRot.y, MTXMODE_APPLY); + Matrix_RotateStateAroundXAxis(-view->curDistortionDirRot.x); + Matrix_ToMtx(projectionMtx); + + return true; } void View_RenderView(View* view, s32 uParm2) { @@ -309,8 +315,8 @@ s32 View_RenderToPerspectiveMatrix(View* view) { guPerspective(projection, &view->normal, view->fovy, aspect, view->zNear, view->zFar, view->scale); view->projection = *projection; - //! @bug: This cast of `projection` is invalid - View_StepQuake(view, (Mtx*)projection); + + View_StepDistortion(view, projection); gSPPerspNormalize(POLY_OPA_DISP++, view->normal); gSPMatrix(POLY_OPA_DISP++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION); |
