Skip to content

Commit

Permalink
Wind Waker: Fix globals.cameraPosition when demos are enabled
Browse files Browse the repository at this point in the history
Fixes the stars and other kankyo stuff being weird during demos.

Also fix fog on d_wood.
  • Loading branch information
magcius committed Dec 5, 2024
1 parent c609d17 commit 255ff24
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/ZeldaWindWaker/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,6 @@ export class WindWakerRenderer implements Viewer.SceneGfx {
private executeDrawAll(device: GfxDevice, viewerInput: Viewer.ViewerRenderInput): void {
this.time = viewerInput.time;

if (!this.cameraFrozen) {
mat4.getTranslation(this.globals.cameraPosition, viewerInput.camera.worldMatrix);
getMatrixAxisZ(this.globals.cameraFwd, viewerInput.camera.worldMatrix);
vec3.negate(this.globals.cameraFwd, this.globals.cameraFwd);
// Update the "player position" from the camera.
vec3.copy(this.globals.playerPosition, this.globals.cameraPosition);
}

// noclip hack: if only one room is visible, make it the mStayNo
const singleRoomVisibleNo = this.getSingleRoomVisible();
if (singleRoomVisibleNo !== -1)
Expand Down Expand Up @@ -482,14 +474,14 @@ export class WindWakerRenderer implements Viewer.SceneGfx {
let upVec = vec3.set(scratchVec3b, 0, 1, 0);
let roll = 0.0;

if(demoCam.flags & EDemoCamFlags.HasTargetPos) { targetPos = demoCam.targetPosition; }
if(demoCam.flags & EDemoCamFlags.HasEyePos) { viewPos = demoCam.viewPosition; }
if(demoCam.flags & EDemoCamFlags.HasUpVec) { upVec = demoCam.upVector; }
if(demoCam.flags & EDemoCamFlags.HasFovY) { viewerInput.camera.fovY = demoCam.fovY * MathConstants.DEG_TO_RAD; }
if(demoCam.flags & EDemoCamFlags.HasRoll) { roll = demoCam.roll * MathConstants.DEG_TO_RAD; }
if(demoCam.flags & EDemoCamFlags.HasAspect) { debugger; /* Untested. Remove once confirmed working */ }
if(demoCam.flags & EDemoCamFlags.HasNearZ) { viewerInput.camera.near = demoCam.projNear; }
if(demoCam.flags & EDemoCamFlags.HasFarZ) { viewerInput.camera.far = demoCam.projFar; }
if (demoCam.flags & EDemoCamFlags.HasTargetPos) { targetPos = demoCam.targetPosition; }
if (demoCam.flags & EDemoCamFlags.HasEyePos) { viewPos = demoCam.viewPosition; }
if (demoCam.flags & EDemoCamFlags.HasUpVec) { upVec = demoCam.upVector; }
if (demoCam.flags & EDemoCamFlags.HasFovY) { viewerInput.camera.fovY = demoCam.fovY * MathConstants.DEG_TO_RAD; }
if (demoCam.flags & EDemoCamFlags.HasRoll) { roll = demoCam.roll * MathConstants.DEG_TO_RAD; }
if (demoCam.flags & EDemoCamFlags.HasAspect) { debugger; /* Untested. Remove once confirmed working */ }
if (demoCam.flags & EDemoCamFlags.HasNearZ) { viewerInput.camera.near = demoCam.projNear; }
if (demoCam.flags & EDemoCamFlags.HasFarZ) { viewerInput.camera.far = demoCam.projFar; }

mat4.targetTo(viewerInput.camera.worldMatrix, viewPos, targetPos, upVec);
mat4.rotateZ(viewerInput.camera.worldMatrix, viewerInput.camera.worldMatrix, roll);
Expand All @@ -501,6 +493,14 @@ export class WindWakerRenderer implements Viewer.SceneGfx {
this.globals.context.inputManager.isMouseEnabled = true;
}

if (!this.cameraFrozen) {
mat4.getTranslation(this.globals.cameraPosition, viewerInput.camera.worldMatrix);
getMatrixAxisZ(this.globals.cameraFwd, viewerInput.camera.worldMatrix);
vec3.negate(this.globals.cameraFwd, this.globals.cameraFwd);
// Update the "player position" from the camera.
vec3.copy(this.globals.playerPosition, this.globals.cameraPosition);
}

this.globals.camera = viewerInput.camera;

// Not sure exactly where this is ordered...
Expand Down
3 changes: 3 additions & 0 deletions src/ZeldaWindWaker/d_wood.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ class WoodModel {
material.alphaTest.referenceA = kAlphaCutoff;
material.alphaTest.referenceB = kAlphaCutoff;
material.hasDynamicAlphaTest = true;
material.ropInfo.fogType = GX.FogType.PERSP_LIN;
material.ropInfo.fogAdjEnabled = true;
material.hasFogBlock = true;
this.bushMaterial = new GXMaterialHelperGfx(material);

const bushTexture = createTexture(matRegisters, l_Txa_swood_bTEX, 'l_Txa_swood_bTEX');
Expand Down

0 comments on commit 255ff24

Please sign in to comment.