Skip to content

Commit

Permalink
Hackily set up new ortho view and proj matrices within d_a_title
Browse files Browse the repository at this point in the history
  • Loading branch information
themikelester committed Dec 27, 2024
1 parent fa4b417 commit 2234e9e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Common/JSYSTEM/J2Dv1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
24 changes: 24 additions & 0 deletions src/ZeldaWindWaker/d_a.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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];
Expand All @@ -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) {
Expand Down

0 comments on commit 2234e9e

Please sign in to comment.