diff --git a/include/functions.h b/include/functions.h index 016a87e09e..136376368f 100644 --- a/include/functions.h +++ b/include/functions.h @@ -944,7 +944,7 @@ u32 SurfaceType_GetEcho(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) u32 SurfaceType_IsHookshotSurface(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); s32 SurfaceType_IsIgnoredByEntities(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); s32 SurfaceType_IsIgnoredByProjectiles(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); -s32 SurfaceType_IsConveyor(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); +s32 SurfaceType_GetConveyorType(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); s32 func_800C9DDC(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); u32 SurfaceType_GetConveyorSpeed(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); u32 SurfaceType_GetConveyorDirection(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId); @@ -2150,14 +2150,14 @@ void Quake_Init(void); s16 Quake_Add(Camera* camera, u32 callbackIdx); u32 Quake_RemoveFromIdx(s16 idx); s16 Quake_Calc(Camera* camera, QuakeCamCalc* camData); -void Quake2_Init(GlobalContext* globalCtx); -void Quake2_SetCountdown(s16 countdown); -s16 Quake2_GetCountdown(void); -s16 Quake2_GetType(void); -void Quake2_SetType(s32 type); -void Quake2_ClearType(s32 type); -s32 Quake2_GetFloorQuake(Player* player); -void Quake2_Update(void); +void Distortion_Init(GlobalContext* globalCtx); +void Distortion_SetCountdown(s16 countdown); +s16 Distortion_GetCountdown(void); +s16 Distortion_GetType(void); +void Distortion_SetType(s32 type); +void Distortion_ClearType(s32 type); +s32 Distortion_GetUnderwaterCurrentSpeed(Player* player); +void Distortion_Update(void); s32 Quake_NumActiveQuakes(void); Gfx* Gfx_SetFog(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 n, s32 f); Gfx* Gfx_SetFogWithSync(Gfx* gfx, s32 r, s32 g, s32 b, s32 a, s32 n, s32 f); @@ -2581,13 +2581,13 @@ void View_GetViewport(View* view, Viewport* viewport); void View_WriteScissor(Gfx** gfx, s32 ulx, s32 uly, s32 lrx, s32 lry); void View_SyncAndWriteScissor(View* view, Gfx** gfx); void View_SetScissorForLetterbox(View* view); -s32 View_SetQuakeRotation(View* view, f32 x, f32 y, f32 z); -s32 View_SetQuakeScale(View* view, f32 x, f32 y, f32 z); -s32 View_SetQuakeSpeed(View* view, f32 speed); -s32 View_InitCameraQuake(View* view); -s32 View_ClearQuake(View* view); -s32 View_SetQuake(View* view, Vec3f rot, Vec3f scale, f32 speed); -s32 View_StepQuake(View* view, Mtx* matrix); +s32 View_SetDistortionDirRot(View* view, f32 dirRotX, f32 dirRotY, f32 dirRotZ); +s32 View_SetDistortionScale(View* view, f32 scaleX, f32 scaleY, f32 scaleZ); +s32 View_SetDistortionSpeed(View* view, f32 speed); +s32 View_InitDistortion(View* view); +s32 View_ClearDistortion(View* view); +s32 View_SetDistortion(View* view, Vec3f dirRot, Vec3f scale, f32 speed); +s32 View_StepDistortion(View* view, Mtx* projectionMtx); void View_RenderView(View* view, s32 uParm2); s32 View_RenderToPerspectiveMatrix(View* view); s32 View_RenderToOrthographicMatrix(View* view); diff --git a/include/z64.h b/include/z64.h index cb41a82496..be20942a38 100644 --- a/include/z64.h +++ b/include/z64.h @@ -494,13 +494,12 @@ typedef struct { /* 0x0E0 */ Mtx unkE0; /* 0x120 */ Mtx* projectionPtr; /* 0x124 */ Mtx* viewingPtr; - /* 0x128 */ Vec3f quakeRot; - /* 0x134 */ Vec3f quakeScale; - /* 0x140 */ f32 quakeSpeed; - /* 0x144 */ Vec3f currQuakeRot; - /* 0x150 */ Vec3f currQuakeScale; + /* 0x128 */ Vec3f distortionDirRot; + /* 0x134 */ Vec3f distortionScale; + /* 0x140 */ f32 distortionSpeed; + /* 0x144 */ Vec3f curDistortionDirRot; + /* 0x150 */ Vec3f curDistortionScale; /* 0x15C */ u16 normal; - /* 0x15E */ UNK_TYPE1 pad15E[0x2]; /* 0x160 */ u32 flags; // bit 3: Render to an orthographic perspective /* 0x164 */ UNK_TYPE4 unk164; } View; // size = 0x168 @@ -1124,13 +1123,13 @@ typedef struct { /* 0x4 */ s32 type; // bitfield, highest set bit determines type /* 0x8 */ s16 countdown; /* 0xA */ s16 state; -} Quake2Context; // size = 0xC +} DistortionContext; // size = 0xC typedef enum { - QUAKE2_INACTIVE, - QUAKE2_ACTIVE, - QUAKE2_SETUP, -} Quake2State; + /* 0 */ DISTORTION_INACTIVE, + /* 1 */ DISTORTION_ACTIVE, + /* 2 */ DISTORTION_SETUP, +} DistortionState; typedef struct { /* 0x000 */ u8 controllers; // bit 0 is set if controller 1 is plugged in, etc. @@ -1310,7 +1309,7 @@ struct GlobalContext { /* 0x187B0 */ MtxF viewProjectionMtxF; /* 0x187F0 */ Vec3f unk_187F0; /* 0x187FC */ MtxF billboardMtxF; - /* 0x1883C */ Mtx* unk_1883C; + /* 0x1883C */ Mtx* billboardMtx; /* 0x18840 */ u32 gameplayFrames; /* 0x18844 */ u8 unk_18844; /* 0x18845 */ u8 unk_18845; diff --git a/include/z64bgcheck.h b/include/z64bgcheck.h index 6ca0b66d54..55429a4338 100644 --- a/include/z64bgcheck.h +++ b/include/z64bgcheck.h @@ -56,6 +56,11 @@ struct DynaPolyActor; // CollisionContext flags #define BGCHECK_FLAG_REVERSE_CONVEYOR_FLOW 1 +typedef enum { + /* 0 */ CONVEYOR_WATER, + /* 1 */ CONVEYOR_FLOOR +} ConveyorType; + typedef struct { /* 0x0 */ Vec3s pos; } BgVertex; // size = 0x6 diff --git a/src/code/z_bgcheck.c b/src/code/z_bgcheck.c index 850d5234b7..7fa1b755bc 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 e699ff0862..d38746bf46 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 da2e3593b3..d11a18201d 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->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->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->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); + 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 1; + 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); diff --git a/tools/actorfixer.py b/tools/actorfixer.py index 384821a55e..990d672511 100755 --- a/tools/actorfixer.py +++ b/tools/actorfixer.py @@ -344,7 +344,7 @@ animdict = { "func_800C9CEC": "SurfaceType_IsHookshotSurface", "func_800C9D14": "SurfaceType_IsIgnoredByEntities", "func_800C9D50": "SurfaceType_IsIgnoredByProjectiles", - "func_800C9D8C": "SurfaceType_IsConveyor", + "func_800C9D8C": "SurfaceType_GetConveyorType", "func_800C9E18": "SurfaceType_GetConveyorSpeed", "func_800C9E40": "SurfaceType_GetConveyorDirection", "func_800C9E88": "SurfaceType_IsWallDamage", diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index 15ac9dc2a5..6a2ea013a2 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -1075,7 +1075,7 @@ 0x800C9CEC:("SurfaceType_IsHookshotSurface",), 0x800C9D14:("SurfaceType_IsIgnoredByEntities",), 0x800C9D50:("SurfaceType_IsIgnoredByProjectiles",), - 0x800C9D8C:("SurfaceType_IsConveyor",), + 0x800C9D8C:("SurfaceType_GetConveyorType",), 0x800C9DDC:("func_800C9DDC",), 0x800C9E18:("SurfaceType_GetConveyorSpeed",), 0x800C9E40:("SurfaceType_GetConveyorDirection",), @@ -2302,14 +2302,14 @@ 0x8012AA9C:("Quake_Add",), 0x8012AAC0:("Quake_RemoveFromIdx",), 0x8012AB08:("Quake_Calc",), - 0x8012AE68:("Quake2_Init",), - 0x8012AEAC:("Quake2_SetCountdown",), - 0x8012AED4:("Quake2_GetCountdown",), - 0x8012AEE4:("Quake2_GetType",), - 0x8012AEF4:("Quake2_SetType",), - 0x8012AF18:("Quake2_ClearType",), - 0x8012AF38:("Quake2_GetFloorQuake",), - 0x8012AF9C:("Quake2_Update",), + 0x8012AE68:("Distortion_Init",), + 0x8012AEAC:("Distortion_SetCountdown",), + 0x8012AED4:("Distortion_GetCountdown",), + 0x8012AEE4:("Distortion_GetType",), + 0x8012AEF4:("Distortion_SetType",), + 0x8012AF18:("Distortion_ClearType",), + 0x8012AF38:("Distortion_GetUnderwaterCurrentSpeed",), + 0x8012AF9C:("Distortion_Update",), 0x8012BBE8:("Quake_NumActiveQuakes",), 0x8012BC50:("Gfx_SetFog",), 0x8012BD8C:("Gfx_SetFogWithSync",), @@ -2734,13 +2734,13 @@ 0x8013F1D8:("View_WriteScissor",), 0x8013F28C:("View_SyncAndWriteScissor",), 0x8013F2F8:("View_SetScissorForLetterbox",), - 0x8013F3F8:("View_SetQuakeRotation",), - 0x8013F420:("View_SetQuakeScale",), - 0x8013F448:("View_SetQuakeSpeed",), - 0x8013F45C:("View_InitCameraQuake",), - 0x8013F4C0:("View_ClearQuake",), - 0x8013F4F4:("View_SetQuake",), - 0x8013F54C:("View_StepQuake",), + 0x8013F3F8:("View_SetDistortionDirRot",), + 0x8013F420:("View_SetDistortionScale",), + 0x8013F448:("View_SetDistortionSpeed",), + 0x8013F45C:("View_InitDistortion",), + 0x8013F4C0:("View_ClearDistortion",), + 0x8013F4F4:("View_SetDistortion",), + 0x8013F54C:("View_StepDistortion",), 0x8013F6FC:("View_RenderView",), 0x8013F748:("View_RenderToPerspectiveMatrix",), 0x8013FA1C:("View_RenderToOrthographicMatrix",), diff --git a/tools/disasm/variables.txt b/tools/disasm/variables.txt index 976967bb48..aedb3d7195 100644 --- a/tools/disasm/variables.txt +++ b/tools/disasm/variables.txt @@ -4075,7 +4075,7 @@ 0x801F59F4:("D_801F59F4","UNK_TYPE1","",0x1), 0x801F59F8:("D_801F59F8","UNK_TYPE1","",0x1), 0x801F5A00:("sQuakeRequest","QuakeRequest","[4]",0x90), - 0x801F5A90:("sQuake2Context","Quake2Context","",0xc), + 0x801F5A90:("sDistortionContext","DistortionContext","",0xc), 0x801F5AA0:("sMatAnimStep","s32","",0x4), 0x801F5AA4:("sMatAnimFlags","u32","",0x4), 0x801F5AA8:("sMatAnimAlphaRatio","f32","",0x4), diff --git a/tools/sizes/code_functions.csv b/tools/sizes/code_functions.csv index 22244cad78..3ce371c04d 100644 --- a/tools/sizes/code_functions.csv +++ b/tools/sizes/code_functions.csv @@ -589,7 +589,7 @@ asm/non_matchings/code/z_bgcheck/SurfaceType_GetEcho.s,SurfaceType_GetEcho,0x800 asm/non_matchings/code/z_bgcheck/SurfaceType_IsHookshotSurface.s,SurfaceType_IsHookshotSurface,0x800C9CEC,0xA asm/non_matchings/code/z_bgcheck/SurfaceType_IsIgnoredByEntities.s,SurfaceType_IsIgnoredByEntities,0x800C9D14,0xF asm/non_matchings/code/z_bgcheck/SurfaceType_IsIgnoredByProjectiles.s,SurfaceType_IsIgnoredByProjectiles,0x800C9D50,0xF -asm/non_matchings/code/z_bgcheck/SurfaceType_IsConveyor.s,SurfaceType_IsConveyor,0x800C9D8C,0x14 +asm/non_matchings/code/z_bgcheck/SurfaceType_GetConveyorType.s,SurfaceType_GetConveyorType,0x800C9D8C,0x14 asm/non_matchings/code/z_bgcheck/func_800C9DDC.s,func_800C9DDC,0x800C9DDC,0xF asm/non_matchings/code/z_bgcheck/SurfaceType_GetConveyorSpeed.s,SurfaceType_GetConveyorSpeed,0x800C9E18,0xA asm/non_matchings/code/z_bgcheck/SurfaceType_GetConveyorDirection.s,SurfaceType_GetConveyorDirection,0x800C9E40,0x12 @@ -1816,14 +1816,14 @@ asm/non_matchings/code/z_quake/Quake_Init.s,Quake_Init,0x8012AA48,0x15 asm/non_matchings/code/z_quake/Quake_Add.s,Quake_Add,0x8012AA9C,0x9 asm/non_matchings/code/z_quake/Quake_RemoveFromIdx.s,Quake_RemoveFromIdx,0x8012AAC0,0x12 asm/non_matchings/code/z_quake/Quake_Calc.s,Quake_Calc,0x8012AB08,0xD8 -asm/non_matchings/code/z_quake/Quake2_Init.s,Quake2_Init,0x8012AE68,0x11 -asm/non_matchings/code/z_quake/Quake2_SetCountdown.s,Quake2_SetCountdown,0x8012AEAC,0xA -asm/non_matchings/code/z_quake/Quake2_GetCountdown.s,Quake2_GetCountdown,0x8012AED4,0x4 -asm/non_matchings/code/z_quake/Quake2_GetType.s,Quake2_GetType,0x8012AEE4,0x4 -asm/non_matchings/code/z_quake/Quake2_SetType.s,Quake2_SetType,0x8012AEF4,0x9 -asm/non_matchings/code/z_quake/Quake2_ClearType.s,Quake2_ClearType,0x8012AF18,0x8 -asm/non_matchings/code/z_quake/Quake2_GetFloorQuake.s,Quake2_GetFloorQuake,0x8012AF38,0x19 -asm/non_matchings/code/z_quake/Quake2_Update.s,Quake2_Update,0x8012AF9C,0x313 +asm/non_matchings/code/z_quake/Distortion_Init.s,Distortion_Init,0x8012AE68,0x11 +asm/non_matchings/code/z_quake/Distortion_SetCountdown.s,Distortion_SetCountdown,0x8012AEAC,0xA +asm/non_matchings/code/z_quake/Distortion_GetCountdown.s,Distortion_GetCountdown,0x8012AED4,0x4 +asm/non_matchings/code/z_quake/Distortion_GetType.s,Distortion_GetType,0x8012AEE4,0x4 +asm/non_matchings/code/z_quake/Distortion_SetType.s,Distortion_SetType,0x8012AEF4,0x9 +asm/non_matchings/code/z_quake/Distortion_ClearType.s,Distortion_ClearType,0x8012AF18,0x8 +asm/non_matchings/code/z_quake/Distortion_GetUnderwaterCurrentSpeed.s,Distortion_GetUnderwaterCurrentSpeed,0x8012AF38,0x19 +asm/non_matchings/code/z_quake/Distortion_Update.s,Distortion_Update,0x8012AF9C,0x313 asm/non_matchings/code/z_quake/Quake_NumActiveQuakes.s,Quake_NumActiveQuakes,0x8012BBE8,0x1A asm/non_matchings/code/z_rcp/Gfx_SetFog.s,Gfx_SetFog,0x8012BC50,0x4F asm/non_matchings/code/z_rcp/Gfx_SetFogWithSync.s,Gfx_SetFogWithSync,0x8012BD8C,0x5F @@ -2248,13 +2248,13 @@ asm/non_matchings/code/z_view/View_GetViewport.s,View_GetViewport,0x8013F1B0,0xA asm/non_matchings/code/z_view/View_WriteScissor.s,View_WriteScissor,0x8013F1D8,0x2D asm/non_matchings/code/z_view/View_SyncAndWriteScissor.s,View_SyncAndWriteScissor,0x8013F28C,0x1B asm/non_matchings/code/z_view/View_SetScissorForLetterbox.s,View_SetScissorForLetterbox,0x8013F2F8,0x40 -asm/non_matchings/code/z_view/View_SetQuakeRotation.s,View_SetQuakeRotation,0x8013F3F8,0xA -asm/non_matchings/code/z_view/View_SetQuakeScale.s,View_SetQuakeScale,0x8013F420,0xA -asm/non_matchings/code/z_view/View_SetQuakeSpeed.s,View_SetQuakeSpeed,0x8013F448,0x5 -asm/non_matchings/code/z_view/View_InitCameraQuake.s,View_InitCameraQuake,0x8013F45C,0x19 -asm/non_matchings/code/z_view/View_ClearQuake.s,View_ClearQuake,0x8013F4C0,0xD -asm/non_matchings/code/z_view/View_SetQuake.s,View_SetQuake,0x8013F4F4,0x16 -asm/non_matchings/code/z_view/View_StepQuake.s,View_StepQuake,0x8013F54C,0x6C +asm/non_matchings/code/z_view/View_SetDistortionDirRot.s,View_SetDistortionDirRot,0x8013F3F8,0xA +asm/non_matchings/code/z_view/View_SetDistortionScale.s,View_SetDistortionScale,0x8013F420,0xA +asm/non_matchings/code/z_view/View_SetDistortionSpeed.s,View_SetDistortionSpeed,0x8013F448,0x5 +asm/non_matchings/code/z_view/View_InitDistortion.s,View_InitDistortion,0x8013F45C,0x19 +asm/non_matchings/code/z_view/View_ClearDistortion.s,View_ClearDistortion,0x8013F4C0,0xD +asm/non_matchings/code/z_view/View_SetDistortion.s,View_SetDistortion,0x8013F4F4,0x16 +asm/non_matchings/code/z_view/View_StepDistortion.s,View_StepDistortion,0x8013F54C,0x6C asm/non_matchings/code/z_view/View_RenderView.s,View_RenderView,0x8013F6FC,0x13 asm/non_matchings/code/z_view/View_RenderToPerspectiveMatrix.s,View_RenderToPerspectiveMatrix,0x8013F748,0xB5 asm/non_matchings/code/z_view/View_RenderToOrthographicMatrix.s,View_RenderToOrthographicMatrix,0x8013FA1C,0x6B