|
Author |
Topic: getting absolute x and y coordinates (Read 2609 times) |
|
Frederik De Bleser Guest
|
getting absolute x and y coordinates
« on: Apr 15th, 2003, 5:24pm » |
|
Hi, I've been using processing for programming l-systems. An example can be found here: http://users.pandora.be/frederik/lsys/ I'm currently optimizing the algorithm so I can keep zooming in. That requires that I know the absolute coordinates of the transformation matrix. Right now, I've been doing some reverse assembly to find out the variables (m03 for x, m13 for y). I wonder if it would be possible to make this public? You can view the source code to see what I mean. Kind regards, Frederik De Bleser Processing addict
|
|
|
|
fry
|
Re: getting absolute x and y coordinates
« Reply #1 on: Apr 15th, 2003, 7:17pm » |
|
at a quick glance, i think that objectX/Y/Z or screenX/Y/Z would give you the coordinates you want: (from revisions.txt) Code:- get the on-screen locations of an xyz point using: float sx = screenX(x, y, z); float sy = screenY(x, y, z); float sz = screenZ(x, y, z); - get the object-space coordinates (how the object is affected by translate and rotate etc) using: float ox = objectX(x, y, z); float oy = objectY(x, y, z); float oz = objectZ(x, y, z); |
| in most cases, m03 and m13 will only give you the translation for x and y, not the scale or other transformations.
|
|
|
|
fdb
|
Re: getting absolute x and y coordinates
« Reply #2 on: Apr 16th, 2003, 4:36pm » |
|
Thanks! And is their a way to get the full transformation matrix for later retrieval? I know of push and pop, but I need to save the transformation matrix in my own queue for a breadth-first tree traversal. There might be another solution where I traverse the list at level 0 in normal order, pushing matrices where I need them later, and then traversing the list in reverse order, popping those stacks, but I don't know if that approach would work. (If you know any other way of doing this without self-storing the trans matrix, please let me know) Frederik
|
|
|
|
fry
|
Re: getting absolute x and y coordinates
« Reply #3 on: Apr 16th, 2003, 11:51pm » |
|
if you're not using push/pop, or want to store the matrices, the thing to do would be to copy the 16 values of mNN (N going from 0..3) and stuff em in an array of floats. then, to use that matrix later, just unpack it and set the mNN values again. though make sure you don't mix this with push/pop otherwise the graphics engine will get pretty confused. another function that may be of interest is apply(), which takes 16 floats and multiples the matrix you supply by the current mNN. note that this isn't the same as assigning them, but rather concatenates that transformation.
|
|
|
|
fdb
|
Re: getting absolute x and y coordinates
« Reply #4 on: Apr 18th, 2003, 3:34am » |
|
Thanks. Is this something that will be changed in the future, or can I trust that those variables stay the same? Also, could you explain what all the m's do? Just a bunch of numbers is rather vague... Frederik
|
|
|
|
fry
|
Re: getting absolute x and y coordinates
« Reply #5 on: May 6th, 2003, 1:16am » |
|
on Apr 18th, 2003, 3:34am, fdb wrote:Thanks. Is this something that will be changed in the future, or can I trust that those variables stay the same |
| i think these will stay the same for a long time. maybe we'll have a function for getting them instead. it's not so optimal to say g.m00 and all that, but maybe it's fine. Quote:Also, could you explain what all the m's do Just a bunch of numbers is rather vague... |
| they're the "transformation matrix", which is a 4x4 set of numbers that get multiplied against an xyz coordinate to produce a two-dimensional on-screen coordinate. anyone have a good tutorial on the basics of matrix math
|
« Last Edit: May 6th, 2003, 1:16am by fry » |
|
|
|
|
fdb
|
Re: getting absolute x and y coordinates
« Reply #7 on: May 23rd, 2003, 11:54pm » |
|
thanks. excellent article. actually, i already found what i was looking for when programming for the Graphics2D api (but that one contains a 3x2 matrix, of course). however, the purpose still remained rather vague until i read the article.
|
|
|
|
|