You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bridge: move out into opts on mapLocation / mapDirection
mapLocation(point?, opts?) and mapDirection(dir?, opts?) no longer take
out as a positional first argument. opts.out accepts the same types as
before (Float32Array | ArrayLike | p5.Vector). When opts.out is absent
a fresh p5.Vector is allocated and returned, giving an ergonomic
non-hot-path call style with no ambiguity.
Internal callers in gizmos.js and picking.js updated: _sl and _wl
scratch buffers are now passed as opts.out, preserving zero-alloc.
_resolveOut(opts) extracted as a shared one-liner inside installMatrix.
**Composite queries** — `out` first, optional overrides in an opts object:
254
254
255
255
```js
256
-
pvMatrix(out, [{ pMatrix, vMatrix }])
257
-
ipvMatrix(out, [{ pMatrix, vMatrix, pvMatrix }])
258
-
mvMatrix(out, [{ mMatrix, vMatrix }])
259
-
pmvMatrix(out, [{ pMatrix, mMatrix, vMatrix }])
260
-
nMatrix(out,[{ mMatrix, vMatrix, mvMatrix }]) // 9-element out
256
+
mat4PV(out, [{ mat4Proj, mat4View }])
257
+
mat4PVInv(out, [{ mat4Proj, mat4View, mat4PV }])
258
+
mat4MV(out, [{ mat4Model, mat4View }])
259
+
mat4PMV(out, [{ mat4Proj, mat4Model, mat4View }])
260
+
mat3Normal(out,[{ mat4Model, mat4View, mat4MV }]) // 9-element out
261
261
mat4Location(out, from, to) // location transform: inv(to) · from
262
262
mat3Direction(out, from, to) // direction transform: to₃ · inv(from₃), 9-element out
263
263
```
264
264
265
265
**Raw matrix math** — forwarded from `@nakednous/tree`, same out-first contract:
266
266
267
267
```js
268
-
mat4Mul(out, A, B) // out = A · B (column-major)
269
-
mat4Invert(out, src) // out = inv(src), null if singular
270
-
mat4MulPoint(out, m, point) // out = m · [x,y,z,1] perspective-divided
271
-
// point: Float32Array | ArrayLike | p5.Vector
268
+
mat4Mul(out, A, B) // out = A · B (column-major)
269
+
mat4Invert(out, src) // out = inv(src), null if singular
270
+
mat4MulPoint(out, m, point) // out = m · [x,y,z,1] perspective-divided
271
+
// point: Float32Array | ArrayLike | p5.Vector
272
272
mat4MulDir(out, m, dx,dy,dz) // out = 3×3 block of m applied to direction
273
273
// no translation, no perspective divide
274
274
```
@@ -284,62 +284,71 @@ const wlm = new Float32Array(16) // e.g. bias · lightPV for shadow mapping
284
284
constpt=newFloat32Array(3)
285
285
286
286
// draw — zero allocations
287
-
eMatrix(e)
288
-
pMatrix(pm)
289
-
pvMatrix(pv)
287
+
mat4Eye(e)
288
+
mat4Proj(pm)
289
+
mat4PV(pv)
290
290
mat4Mul(wlm, biasMatrix, pv)
291
291
mat4MulPoint(pt, wlm, lightPosition)
292
-
viewFrustum({ eMatrix: e, pMatrix: pm })
293
-
mouseHit({ pvMatrix: pv, eMatrix: e })
292
+
viewFrustum({ mat4Eye: e, mat4Proj: pm })
293
+
mouseHit({ mat4PV: pv, mat4Eye: e })
294
294
```
295
295
296
296
## Frustum queries
297
297
298
298
Scalars read directly from the projection matrix — no buffer needed:
299
299
300
300
```js
301
-
lPlane() rPlane() bPlane() tPlane() // side planes
302
-
nPlane() fPlane()// near / far
303
-
fov() hfov()// field of view (radians)
304
-
isOrtho()// true for orthographic
301
+
projLeft() projRight() projBottom() projTop() // side planes
302
+
projNear() projFar() // near / far
303
+
projFov() projHfov() // field of view (radians)
304
+
projIsOrtho() // true for orthographic
305
305
306
-
pixelRatio([worldPos], [{ pMatrix, vMatrix }])
306
+
pixelRatio([worldPos], [{ mat4Proj, mat4View }])
307
307
// world-units-per-pixel at worldPos (defaults to camera position)
308
308
```
309
309
310
310
## Coordinate space conversions
311
311
312
+
`out` is opt-in. When provided via `opts.out` the result is written into it (zero-alloc hot path). When omitted a fresh `p5.Vector` is allocated and returned. Return type matches `opts.out`.
313
+
312
314
```js
313
-
mapLocation(out, point, [opts]) // map a point between spaces
314
-
mapLocation(out, [opts]) // input defaults to p5.Tree.ORIGIN
315
-
mapLocation(out) //defaults to ORIGIN, EYE → WORLD
315
+
mapLocation([point], [opts]) // map a point between spaces
316
+
mapLocation([opts])// input defaults to p5.Tree.ORIGIN
317
+
mapLocation() // ORIGIN, EYE → WORLD → p5.Vector
316
318
317
-
mapDirection(out, vector, [opts]) // map a direction between spaces
318
-
mapDirection(out, [opts]) // input defaults to p5.Tree._k
319
-
mapDirection(out) //defaults to _k, EYE → WORLD
319
+
mapDirection([dir], [opts])// map a direction between spaces
320
+
mapDirection([opts])// input defaults to p5.Tree._k
321
+
mapDirection() // _k, EYE → WORLD → p5.Vector
320
322
```
321
323
322
-
`out` is a 3-element`Float32Array`, `ArrayLike`, or`p5.Vector`.
mat4PV?:/*mat4Proj × mat4View — optional, computed if absent */,
255
+
mat4PVInv?:/* inv(mat4PV) — optional, computed if absent */,
233
256
}
234
-
constvp= [0, height, width, -height]
257
+
constvp= [0, height, width, -height]// signed h = screen y-down
235
258
236
259
mapLocation(out, worldX, worldY, worldZ, WORLD, SCREEN, m, vp, WEBGL)
237
260
```
238
261
239
-
The matrices bag `m` is assembled by the host (p5.tree reads live renderer state into it). All pairs are supported: WORLD↔EYE, WORLD↔SCREEN, WORLD↔NDC, EYE↔SCREEN, SCREEN↔NDC, WORLD↔MATRIX, and their reverses.
262
+
The matrices bag `m` is assembled by the host. All pairs are supported:
263
+
WORLD↔EYE, WORLD↔SCREEN, WORLD↔NDC, EYE↔SCREEN, SCREEN↔NDC, WORLD↔MATRIX, and their reverses.
240
264
241
265
---
242
266
@@ -289,14 +313,14 @@ mat4PV mat4MV
289
313
**Matrix construction from specs** (`form.js`):
290
314
```
291
315
mat4FromBasis — rigid frame from orthonormal basis + translation
292
-
mat4View — view matrix (world→eye) from lookat params
293
-
mat4Eye — eye matrix (eye→world) from lookat params
316
+
mat4View — view matrix (world→eye) from lookat params
317
+
mat4Eye — eye matrix (eye→world) from lookat params
294
318
mat4FromTRS — column-major mat4 from flat TRS scalars
**Pixel ratio:** `pixelRatio(proj, vpH, eyeZ, ndcZMin)` — world-units-per-pixel at a given depth, handles both perspective and orthographic.
314
338
315
-
**Pick matrix:** `mat4Pick(proj, px, py, W, H)` — mutates a projection mat4 in-place so that pixel `(px, py)` maps to the full NDC square. Used by the p5.tree GPU color-ID picking implementation. Convention-independent (perspective and orthographic).
339
+
**Pick matrix:** `mat4Pick(proj, px, py, vp)` — mutates a projection matrix in-place so that the pixel at `(px, py)` maps to the full NDC square, making a 1×1 FBO render contain exactly that pixel. Takes the same signed viewport `vp` as `mapLocation` — the y-convention is preserved automatically.
316
340
317
341
---
318
342
@@ -337,7 +361,7 @@ ORIGIN, i, j, k, _i, _j, _k
337
361
338
362
## Performance contract
339
363
340
-
All hot-path functions follow an **out-first, zero-allocation** contract:
364
+
All functions in this package follow an **out-first, zero-allocation** contract:
341
365
342
366
- `out` is the first parameter — the caller owns the buffer
343
367
- the function writes into `out` and returns it
@@ -346,15 +370,15 @@ All hot-path functions follow an **out-first, zero-allocation** contract:
0 commit comments