PDA

View Full Version : getting the current coordinates?



egasimus
04-24-2009, 05:41 PM
Is there a way to get some sort of current X, Y, Z coordinates after applying transformations? What I'm trying to do is draw a bunch of objects, translated and rotated and all, and then draw perpendicular lines from them to a plane (which has it center at one point, but rotates freely).

dletozeun
04-25-2009, 06:09 AM
gluUnProject (http://www.opengl.org/sdk/docs/man/xhtml/gluUnProject.xml) may help.

SANTOS_GL
04-26-2009, 04:48 AM
i think, the below details may help you.

void mouse ( int button, int state, int x, int y )
{
DirectionX = x;
DirectionY = y;
}

And in your main, add:

glutMouseFunc(mouse);

This only works when the user press the button of the mouse.

void mouse (int x, int y )
{
DirectionX = x;
DirectionY = y;
}

And in your main, add:

glutPassiveMotionFunc(mouse);

thanks
santosh

egasimus
04-26-2009, 11:36 AM
No, what I'm trying to do has nothing to do with the mouse. I'll look into gluUnProject, though.

EDIT: Looked into it, isn't there a way to do what I want without going through window coordinates? Maybe something with getting the modelview matrix. I'll try that.

dletozeun
04-26-2009, 11:48 AM
In this case, could you be more specific on what transformations you want to undo? You can also retrieve modelview and projection matrices and invert them with your own matrix class tools, all is possible.

egasimus
04-26-2009, 08:25 PM
Well, I've been trying to figure it out, and I can't seem to. In short, I have this:
http://img6.imageshack.us/img6/6319/screenshot3a.th.png (http://img6.imageshack.us/my.php?image=screenshot3a.png)
However, if I rotate everything but the plane, I get this:
http://img401.imageshack.us/img401/4089/screenshot4x.th.png (http://img401.imageshack.us/my.php?image=screenshot4x.png)
or, even worse, this:
http://img5.imageshack.us/img5/8513/screenshot5q.th.png (http://img5.imageshack.us/my.php?image=screenshot5q.png)

...while I'm trying to get them all to look like the first one, with the lines connecting the objects and the plane.

dletozeun
04-27-2009, 05:29 AM
I think you need something like glPush/glPop (see man pages for more information).

With this functions you can apply a transformation to a particular object, taking care to save the matrix state calling glPush. Then to go back to the previous matrix state, just call glPop.

egasimus
05-06-2009, 09:59 AM
Nope, far from it. I'm trying to draw a perpendicular line from a moving object to a plane, OK?

Salbris
07-06-2009, 04:02 PM
There's obviously some math involved it what your trying to do.

But the question is do you have some variables in your code representing the vectors that make up your plane? Or is it some simple plane like the x,z plane? You need to know the vectors such that the normal to your plane is the vector along which all your lines will run:

http://en.wikipedia.org/wiki/File:Normal_vectors2.svg

Does that help?