# getting the current coordinates?

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).

gluUnProject may help.

i think, the below details may help you.

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

glutMouseFunc(mouse);

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

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

glutPassiveMotionFunc(mouse);

thanks
santosh

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.

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.

Well, I’ve been trying to figure it out, and I can’t seem to. In short, I have this:

However, if I rotate everything but the plane, I get this:

or, even worse, this:

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

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.

Nope, far from it. I’m trying to draw a perpendicular line from a moving object to a plane, OK?

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?