Skip to content

Commit

Permalink
Wind Waker: Fix demos incorrectly computing root rotation
Browse files Browse the repository at this point in the history
A simple degrees vs radians mixup. This fixes Link's rotation in the Title demo (the only current demo which has a root rotation).
  • Loading branch information
themikelester committed Jan 5, 2025
1 parent e51b903 commit b720836
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/Common/JSYSTEM/JStudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/ZeldaWindWaker/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/ZeldaWindWaker/d_demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand Down

0 comments on commit b720836

Please sign in to comment.