# Thread: Retrieving Coordinates after rotations

1. ## Retrieving Coordinates after rotations

Hello Guys,

I'm rotating my camera using glRotatef, this work's fine, but my problem is how can I get the new coordinates.

For example I draw a line, after I make a rotation. If I draw a new line, they're coordinates is wrong. But if I rotate the camera to the original angle, the line is in correct position.

How can I make this tranformation?

Thank´s for the moment.

Joe Ramone

2. ## Re: Retrieving Coordinates after rotations

Joe Ramone,

You can use:

GLfloat current_matrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, current_matrix);

at any time to get the current transformation matrix, but it's a bad idea (very slow). I only use it occasionally while debugging and never in stable code. You shouldn't use any of the glGet* calls if you can help it.

For any other purposes it's best to keep track of your transformation matrices yourself. I usually have a singleton matrix object that holds the current matrix.

Hope that helps,
Toby

3. ## Re: Retrieving Coordinates after rotations

Hello guys,

I'm with the same problem, can someone explain how could we solf this ?

Tnks
Best RGDS

Kurt

4. ## Re: Retrieving Coordinates after rotations

I'm if I understand exactly what you mean, but if I understand you right, you want to draw multiple lines, each with different rotations?

Try something like this pseudo-code

Code :
```for each line
{
glPushMatrix();
glRotate(line.angRot, line.xRotAxis, line.yRotAxis, line.zRotAxis);
line.Draw();
glPopMatrix();
}```

5. ## Re: Retrieving Coordinates after rotations

Tnks Deiussum,

but is not exactly this, what we want to do is: draw lines in different planes, you know, I draw one line with XZ plane, than I use glRotate, to have XY or another, so lets imagine that I'm in the origin, then I draw some line, now I change the plane to have another view, I try to draw a line again, the line is displayed but not right, like if I was in the original view.

Any help will be apreciated.

Tnks
Best regards
Kurt

6. ## Re: Retrieving Coordinates after rotations

Ok... let's see if I got this now...

When you mean "change the plane" you mean something like change your point of view?

If that's the case then all you need to do is something like this...

DoTransformationsForPointOfView();
DoLineRotate();
DrawLine();

Typically the DoTransformationsForPointOfView could be done with something such as gluLookAt(); (Most of the time you will probably want a glLoadIdentity(); before the gluLookAt().)

Sorry if this is something you already know and I'm totally missing the problem again...

7. ## Re: Retrieving Coordinates after rotations

Will this just work with gluLookAt ???

I think now you understand my problem, but let explain a little more, lets imagine that I have one "view" that is called "Front View", I call this (I´m using glRotate() to have it working), then I draw some line, it is working, but now I have to draw some line in a diferent view, like "Top View", this is working also (also using glRotate), but when I draw the line, it is not working, the line is not drawn, but if I change the view for the first one, (like the original view) I have the line there, drawn in the wrong way.

Hope I´m clear enough.

Tnks
Best RGDS

Kurt

8. ## Re: Retrieving Coordinates after rotations

No one could figured out what we want to do ? Need we to be more clear in ower question ?

Tnks
Best regards
Kurt

9. ## Re: Retrieving Coordinates after rotations

It sounds like what you need to do is to separate your view and model transformations. Try something like this around your main display function.

glPushMatrix();
DrawScene();
glPopMatrix();

Whenever you change view do this...

DoYourViewTransformations();

The MODELVIEW matrix in OpenGL is exactly that, a combination of the view and model transformations. You generally want the matrix to be setup like so...

Assume M = MODELVIEW matrix, W = model matrix, V = viewmatrix

M = V * W

So you basically do your view transformations first, and then your model/object transformations.

I'm not quite sure what else could be wrong with what you are trying to do. Maybe some code snippets would help.

10. ## Re: Retrieving Coordinates after rotations

Ok, I will post some code here, but not yet, because I have it only at home, and now I'm at work. Anyway tnks for all your help.

RGDS

Kurt

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•