From b7208362ee58f55bfb91727f4ad979ef0c77dc46 Mon Sep 17 00:00:00 2001 From: Mike Lester Date: Sun, 5 Jan 2025 11:56:39 -0700 Subject: [PATCH] Wind Waker: Fix demos incorrectly computing root rotation A simple degrees vs radians mixup. This fixes Link's rotation in the Title demo (the only current demo which has a root rotation). --- src/Common/JSYSTEM/JStudio.ts | 10 +++++----- src/ZeldaWindWaker/Main.ts | 2 +- src/ZeldaWindWaker/d_demo.ts | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Common/JSYSTEM/JStudio.ts b/src/Common/JSYSTEM/JStudio.ts index b6ec3c08a..27a0fbfbc 100644 --- a/src/Common/JSYSTEM/JStudio.ts +++ b/src/Common/JSYSTEM/JStudio.ts @@ -5,7 +5,7 @@ import ArrayBufferSlice from "../../ArrayBufferSlice"; import { align, assert, nArray, readString } from "../../util.js"; import { JSystemFileReaderHelper } from "./J3D/J3DLoader.js"; import { GfxColor } from "../../gfx/platform/GfxPlatform"; -import { clamp } from "../../MathHelpers.js"; +import { clamp, MathConstants } from "../../MathHelpers.js"; import { Endianness } from "../../endian.js"; const scratchVec3a = vec3.create(); @@ -1901,17 +1901,17 @@ export class TControl { public isTransformEnabled() { return !!this.transformOrigin; } public getTransformOnSet() { return this.transformOnSetMtx; } public getTransformOnGet() { return this.transformOnGetMtx; } - public transformSetOrigin(originPos: vec3, rotY: number) { + public transformSetOrigin(originPos: vec3, rotYDeg: number) { this.transformOrigin = originPos; - this.transformRotY = rotY; + this.transformRotY = rotYDeg; // The "OnGet" matrix transforms from world space into demo space - mat4.fromYRotation(this.transformOnGetMtx, -rotY); + mat4.fromYRotation(this.transformOnGetMtx, -rotYDeg * MathConstants.DEG_TO_RAD); mat4.translate(this.transformOnGetMtx, this.transformOnGetMtx, vec3.negate(scratchVec3a, originPos)); // The "OnSet" matrix is the inverse mat4.fromTranslation(this.transformOnSetMtx, originPos); - mat4.rotateY(this.transformOnSetMtx, this.transformOnSetMtx, rotY); + mat4.rotateY(this.transformOnSetMtx, this.transformOnSetMtx, rotYDeg * MathConstants.DEG_TO_RAD); } public setControlObject(obj: TBlockObject) { diff --git a/src/ZeldaWindWaker/Main.ts b/src/ZeldaWindWaker/Main.ts index 46cb16541..dfe62a99a 100644 --- a/src/ZeldaWindWaker/Main.ts +++ b/src/ZeldaWindWaker/Main.ts @@ -967,7 +967,7 @@ class DemoDesc extends SceneDesc implements Viewer.SceneDesc { demoData = globals.modelCache.resCtrl.getStageResByName(ResType.Stb, "Stage", this.stbFilename); if (demoData !== null) { - globals.scnPlay.demo.create(this.id, demoData, this.offsetPos, this.rotY / 180.0 * Math.PI, this.startFrame); + globals.scnPlay.demo.create(this.id, demoData, this.offsetPos, this.rotY, this.startFrame); globals.camera.setTrimHeight(this.id != 'title' ? CameraTrimHeight.Cinematic : CameraTrimHeight.Default) globals.camera.snapToCinematic(); } else { diff --git a/src/ZeldaWindWaker/d_demo.ts b/src/ZeldaWindWaker/d_demo.ts index 0976f1636..81a8ce949 100644 --- a/src/ZeldaWindWaker/d_demo.ts +++ b/src/ZeldaWindWaker/d_demo.ts @@ -436,7 +436,7 @@ export class dDemo_manager_c { public getMode() { return this.mode; } public getSystem() { return this.system; } - public create(name: string, data: ArrayBufferSlice, originPos?: vec3, rotY?: number, startFrame?: number): boolean { + public create(name: string, data: ArrayBufferSlice, originPos?: vec3, rotYDeg?: number, startFrame?: number): boolean { this.name = name; this.parser = new TParse(this.control); @@ -447,7 +447,7 @@ export class dDemo_manager_c { this.control.forward(startFrame || 0); if (originPos) { - this.control.transformSetOrigin(originPos, rotY || 0); + this.control.transformSetOrigin(originPos, rotYDeg || 0); } this.frame = startFrame || 0;