From 2234e9ed6ebe57f4c190808c9063cd69da4fcb16 Mon Sep 17 00:00:00 2001 From: Mike Lester Date: Fri, 27 Dec 2024 13:23:34 -0700 Subject: [PATCH] Hackily set up new ortho view and proj matrices within d_a_title --- src/Common/JSYSTEM/J2Dv1.ts | 2 +- src/ZeldaWindWaker/d_a.ts | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Common/JSYSTEM/J2Dv1.ts b/src/Common/JSYSTEM/J2Dv1.ts index d92f5023f..cd64e17dd 100644 --- a/src/Common/JSYSTEM/J2Dv1.ts +++ b/src/Common/JSYSTEM/J2Dv1.ts @@ -57,7 +57,7 @@ enum J2DUVBinding { // TODO: Move and reorganize export class J2DGrafContext { - private sceneParams = new SceneParams(); + public sceneParams = new SceneParams(); public aspectRatio: number; constructor(device: GfxDevice, x: number, y: number, w: number, h: number, far: number, near: number) { diff --git a/src/ZeldaWindWaker/d_a.ts b/src/ZeldaWindWaker/d_a.ts index ce7e3db49..8b90c9a58 100644 --- a/src/ZeldaWindWaker/d_a.ts +++ b/src/ZeldaWindWaker/d_a.ts @@ -38,6 +38,7 @@ import { fopAc_ac_c, fopAcIt_JudgeByID, fopAcM_create, fopAcM_prm_class } from " import { dProcName_e } from "./d_procname.js"; import { TextureMapping } from "../TextureHolder.js"; import { calcANK1JointAnimationTransform } from "../Common/JSYSTEM/J3D/J3DGraphAnimator.js"; +import { J2DGrafContext } from "../Common/JSYSTEM/J2Dv1.js"; // Framework'd actors @@ -5788,6 +5789,22 @@ class d_a_title extends fopAc_ac_c { } public override draw(globals: dGlobals, renderInstManager: GfxRenderInstManager, viewerInput: ViewerRenderInput): void { + let oldViewMtx = globals.camera.viewFromWorldMatrix; + let oldProjMtx = globals.camera.clipFromViewMatrix; + + // From mDoGph_Painter(). Set up new view and ortho proj matrices. + // TODO: This should be set by the Opa2D draw list + const adjustedWidth = 480 * viewerInput.backbufferWidth / viewerInput.backbufferHeight; + mat4.fromTranslation(scratchMat4a, [adjustedWidth * 0.5, 240, 1000]); + mDoMtx_ZrotM(scratchMat4a, -0x8000); + globals.camera.viewFromWorldMatrix = scratchMat4a; + const orthoCtx = new J2DGrafContext(globals.sceneContext.device, -9.0, -21.0, adjustedWidth + 10, 503.0, 100000.0, -100000.0); + globals.camera.clipFromViewMatrix = orthoCtx.sceneParams.u_Projection; + mat4.mul(globals.camera.clipFromWorldMatrix, globals.camera.clipFromViewMatrix, globals.camera.viewFromWorldMatrix); + globals.camera.frustum.updateClipFrustum(globals.camera.clipFromWorldMatrix, globals.camera.clipSpaceNearZ); + const template = renderInstManager.pushTemplate(); + orthoCtx.setOnRenderInst(template); + // TODO: This should be a global immediate light set by the Opa2D draw list const light = this.modelShip.getGXLightReference(0); light.Position = [-35000.0, 0.0, -30000.0]; @@ -5799,6 +5816,13 @@ class d_a_title extends fopAc_ac_c { this.bpkShip.entry(this.modelShip); mDoExt_modelUpdateDL(globals, this.modelShip, renderInstManager, viewerInput, globals.dlst.ui); } + + // TODO: This should be set by the Opa2D draw list + globals.camera.viewFromWorldMatrix = oldViewMtx; + globals.camera.clipFromViewMatrix = oldProjMtx; + mat4.mul(globals.camera.clipFromWorldMatrix, globals.camera.clipFromViewMatrix, globals.camera.viewFromWorldMatrix); + globals.camera.frustum.updateClipFrustum(globals.camera.clipFromWorldMatrix, globals.camera.clipSpaceNearZ); + renderInstManager.popTemplate(); } private proc_init2D(globals: dGlobals) {