Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: would like to see modelX(), modelY() functions that exist in Processing #377

Closed
dnassler opened this issue Sep 20, 2014 · 4 comments

Comments

@dnassler
Copy link

I like using the matrix functions: translate, rotate, scale. But sometimes I need to know the coordinates of points drawn from the perspective of the main canvas co-ordinate space. So for example if I have a point A that was drawn using a set of matrix transforms and another point B that was drawn using a different set of matrix transforms, I might want to draw a line from point A to point B. To do that I need to have a common co-ordinate space. The functions modelX(), modelY() in the Processing reference do this, it seems, and it would be nice if p5js had these functions as well. See Processing reference: http://processing.org/reference/modelX_.html

@lmccart
Copy link
Member

lmccart commented Sep 20, 2014

I thought about this more since your post on the forum... this is sort of difficult because p5.js does not keep track of the current matrix as it is transformed. this tradeoff was made to improve performance, so we could take advantage of built-in transform, scale, etc methods in html5 canvas without having to do a lot of matrix multiplication. you can read more of that discussion here: https://github.com/lmccart/p5.js/issues/243

my suggestion for now would be to manually keep track of the matrix as you transform it.
http://stackoverflow.com/questions/21717001/html5-canvas-get-coordinates-after-zoom-and-translate

you could also try wrapping some library like this in:
https://github.com/ardcore/CanvasMemory

but it looks like this one hasn't been updated since 2011 so I don't know. there could be something more recent out there.

@lmccart
Copy link
Member

lmccart commented Nov 21, 2014

thanks for the suggestion and thoughts. I'm going to temporarily close this as it's not likely doable in the near future with canvas renderer, it would just be too slow. we can reopen and revisit this when we begin work on webgl/3d.

@lmccart lmccart closed this as completed Nov 21, 2014
@MAKIO135
Copy link

Is this issue still not doable ? Would love to see these features on p5js

@mkmori
Copy link
Sponsor

mkmori commented Jul 12, 2020

I keep missing modelX/Y/Z() (and screenX/Y/Z), too. I think this closed request is specific to P2D. (In P2D, modelX/Y() and screenX/Y() would give the same, x,y values, right?)

If so, are these limitations specific to canvas/P2D? And so, in WEBGL mode, modelX(), modelY(), modelZ() might be possible? (Or maybe trivial?) Are screenX, screenY, and screenZ (z-buffer depth?) similarly possible or already available in WEBGL mode? (Is some "view" or "projection" matrix readily available?)

If "getMatrix()" (or "getGlMatrix()") were a thing, it might be used with applyMatrix() to reproduce (WebGL) transformations outside of a push()/pop(), right? I read on one of the links below that "getMatrix()" would be problematic...but, again, is that a P2D/canvas-specific problem? Otherwise, is this basically doable? Maybe there is already an easy way to grab the current (3D) transformation matrix, (p5.Matrix.mat4 or something)?

Even with a function like "getMatrix()", I'm not sure how one would get transformed coordinates: If only, in addition to "getMatrix()", applyMatrix() could perhaps be applied to a 3-vector, e.g., pv.set(0,0,0); pv.applyMatrix(); A vector whose x,y,z values could then be read out?

FWIW! Kinda out of my depth, but happy for any hints or advice!

#243 (push()/pop() discussion)
#377 (this issue, modelX(), modelY() feature request)
#1553 (screenX() screenY(), screenZ() feature request)
#1873 (modelX(), modelY() feature request)
#4337 (matrix functions...completed!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants