MCPcopy
hub / github.com/bbycroft/llm-viz / genModelViewMatrices

Function genModelViewMatrices

src/llm/Camera.ts:69–99  ·  view source on GitHub ↗
(state: IProgramState, layout: IModelLayout, modelOffset: Vec3 = Vec3.zero)

Source from the content-addressed store, hash-verified

67}
68
69export function genModelViewMatrices(state: IProgramState, layout: IModelLayout, modelOffset: Vec3 = Vec3.zero) {
70 let { camera } = state;
71
72 let bb = new BoundingBox3d();
73 for (let c of layout.cubes) {
74 let tl = new Vec3(c.x, c.y, c.z).add(modelOffset);
75 let br = new Vec3(c.x + c.dx, c.y + c.dy, c.z + c.dz).add(modelOffset);
76 bb.addInPlace(tl);
77 bb.addInPlace(br);
78 }
79 let localDist = bb.size().len();
80
81 let { lookAt, camPos } = cameraToMatrixView(camera);
82 let dist = 200 * camera.angle.z;
83
84 // let persp = Mat4f.fromPersp(40, state.render.size.x / state.render.size.y, dist / 100, localDist + Math.max(dist * 2, 100000));
85 let persp = Mat4f.fromPersp(40, state.render.size.x / state.render.size.y, 100, 10000000);
86 let viewMtx = persp.mul(lookAt);
87 let modelMtx = new Mat4f();
88 modelMtx[0] = 1.0;
89 modelMtx[5] = 0.0;
90 modelMtx[6] = -1.0;
91 modelMtx[9] = -1.0;
92 modelMtx[10] = 0.0;
93
94 state.camera.modelMtx = modelMtx;
95 state.camera.viewMtx = viewMtx;
96 state.camera.camPos = camPos;
97 state.camera.camPosModel = modelMtx.invert().mulVec3Affine(camPos);
98 state.camera.lookAtMtx = lookAt;
99}
100
101export function camScaleToScreen(state: IProgramState, modelPt: Vec3) {
102 let camDist = state.camera.camPosModel.dist(modelPt);

Callers 1

runProgramFunction · 0.90

Calls 9

addInPlaceMethod · 0.95
sizeMethod · 0.95
invertMethod · 0.95
cameraToMatrixViewFunction · 0.85
fromPerspMethod · 0.80
mulVec3AffineMethod · 0.80
addMethod · 0.45
lenMethod · 0.45
mulMethod · 0.45

Tested by

no test coverage detected