|
11 | 11 | var Tree = (function (ext) { |
12 | 12 | const INFO = { |
13 | 13 | LIBRARY: 'p5.treegl', |
14 | | - VERSION: '0.10.0', |
| 14 | + VERSION: '0.10.1', |
15 | 15 | HOMEPAGE: 'https://github.com/VisualComputing/p5.treegl' |
16 | 16 | }; |
17 | 17 | Object.freeze(INFO); |
@@ -416,6 +416,15 @@ window.Tree = Tree; |
416 | 416 |
|
417 | 417 | // 2. Space transformations |
418 | 418 |
|
| 419 | + // vertical flip based on (screenX, screenY): |
| 420 | + /* |
| 421 | + beginHUD(); |
| 422 | + translate(screenX, screenY); // move origin to (screenX, screenY) |
| 423 | + scale(1, -1); // Flip vertically |
| 424 | + image(fbo, 0, 0, fboWidth, fboHeight); // draw fbo at the new origin |
| 425 | + endHUD(); |
| 426 | + */ |
| 427 | + |
419 | 428 | p5.prototype.beginHUD = function (...args) { |
420 | 429 | if (this._renderer instanceof p5.RendererGL) { |
421 | 430 | this._renderer.beginHUD(...args); |
@@ -591,7 +600,7 @@ window.Tree = Tree; |
591 | 600 | point = new p5.Vector(0, 0, 0.5), |
592 | 601 | pMatrix, |
593 | 602 | vMatrix, |
594 | | - pvMatrix = this.pvMatrix({ pMatrix: pMatrix, vMatrix: vMatrix }) |
| 603 | + pvMatrix = this.pvMatrix({ pMatrix, vMatrix }) |
595 | 604 | } = {}) { |
596 | 605 | let target = pvMatrix._mult4([point.x, point.y, point.z, 1]); |
597 | 606 | if (target[3] == 0) { |
@@ -1333,24 +1342,35 @@ void main() { |
1333 | 1342 | return [1 / image.width, 1 / image.height]; |
1334 | 1343 | } |
1335 | 1344 |
|
1336 | | - p5.prototype.mousePosition = function () { |
1337 | | - return [this.mouseX * this.pixelDensity(), (this.height - this.mouseY) * this.pixelDensity()]; |
| 1345 | + p5.prototype.mousePosition = function (flip = true) { |
| 1346 | + return [this.pixelDensity() * this.mouseX, this.pixelDensity() * (flip ? this.height - this.mouseY : this.mouseY)]; |
1338 | 1347 | } |
1339 | 1348 |
|
1340 | 1349 | p5.prototype.pointerPosition = function (...args) { |
1341 | 1350 | return this._renderer.pointerPosition(...args); |
1342 | 1351 | } |
1343 | 1352 |
|
1344 | | - p5.RendererGL.prototype.pointerPosition = function (pointerX, pointerY) { |
1345 | | - return [pointerX * this.pixelDensity(), (this.height - pointerY) * this.pixelDensity()]; |
1346 | | - } |
| 1353 | + p5.RendererGL.prototype.pointerPosition = function (...args) { |
| 1354 | + let pointerX, pointerY, flip = true; |
| 1355 | + args.forEach(arg => |
| 1356 | + typeof arg === 'number' |
| 1357 | + ? pointerX === undefined ? pointerX = arg : pointerY = arg |
| 1358 | + : typeof arg === 'boolean' && (flip = arg) |
| 1359 | + ); |
| 1360 | + /* |
| 1361 | + // TODO: if below hack were cleaner mousePosition can be removed |
| 1362 | + pointerX = pointerX ?? window.mouseX; |
| 1363 | + pointerY = pointerY ?? window.mouseY; |
| 1364 | + // */ |
| 1365 | + return [this.pixelDensity() * pointerX, this.pixelDensity() * (flip ? this.height - pointerY : pointerY)]; |
| 1366 | + }; |
1347 | 1367 |
|
1348 | 1368 | p5.prototype.resolution = function (...args) { |
1349 | 1369 | return this._renderer.resolution(...args); |
1350 | 1370 | } |
1351 | 1371 |
|
1352 | 1372 | p5.RendererGL.prototype.resolution = function () { |
1353 | | - return [this.width * this.pixelDensity(), this.height * this.pixelDensity()]; |
| 1373 | + return [this.pixelDensity() * this.width, this.pixelDensity() * this.height]; |
1354 | 1374 | } |
1355 | 1375 |
|
1356 | 1376 | // 4. Utility functions |
@@ -1382,7 +1402,7 @@ void main() { |
1382 | 1402 | * @param {p5.Vector | Array} corner2 box corner2, use it with corner1. |
1383 | 1403 | * @param {p5.Vector | Array} center sphere (or point) center. |
1384 | 1404 | * @param {Number} radius sphere radius. |
1385 | | - * @param {Array} bounds frustum equations 6x4 matrix. |
| 1405 | + * @param {Object} bounds frustum equations 6x4 matrix. |
1386 | 1406 | */ |
1387 | 1407 | p5.RendererGL.prototype.visibility = function ({ |
1388 | 1408 | corner1, |
@@ -1939,7 +1959,9 @@ void main() { |
1939 | 1959 | const l = pMatrix.lPlane(); |
1940 | 1960 | const r = pMatrix.rPlane(); |
1941 | 1961 | // TODO hack: fixes frustum() drawing |
1942 | | - // camera projections should be called as: |
| 1962 | + // i. prioritizes pgs over fbos currently. It should be the other way around. |
| 1963 | + // (test with ball and box visibility) |
| 1964 | + // ii. camera projections should be called as: |
1943 | 1965 | // pg.ortho(lPlane.value(), rPlane.value(), bPlane.value(), tPlane.value(), nPlane.value(), fPlane.value()); |
1944 | 1966 | // pg.frustum(lPlane.value(), rPlane.value(), tPlane.value(), bPlane.value(), nPlane.value(), fPlane.value()); |
1945 | 1967 | const t = pMatrix.isOrtho() ? -pMatrix.tPlane() : pMatrix.tPlane(); |
|
0 commit comments