# Getting x1 and y1 after glrotate

This topic is 4831 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Does anyone know how to get the object's coordinates after glrotate? Thanks in advance.

##### Share on other sites
You can use the glGet*() family of functions with either GL_MODELVIEW_MATRIX or GL_PROJECTION_MATRIX to get the matrix and multiply the matrix yourself manually, depending on which transformed coordinate set you want.

##### Share on other sites
I'm still a bit lost. So I can do this

glTranslatef(Obj.x1,Obj.y1,0)
glRotatef(90,0,0,1)
glTranslatef(-Obj.x1,-Obj.y1,0)

then use

glGetFloatv(GL_MODELVIEW_MATRIX, matrix)

but I'm not sure where to go from there.

##### Share on other sites
Quote:
 but I'm not sure where to go from there.
Google 'matrix vector multiplication'. The code will depend on matrix majorness and vector convention. In OpenGL, you have:
[0 2][x] = [0*x+2*y][1 3][y]   [1*x+3*y]
Note that the numbers are array indices, not values. Of course you're working with 4x4 matrices, but you can just extrapolate from the above. You'll also need to load your 2d point into a homogenous 4d vector, which will simply be (x, y, 0, 1).

##### Share on other sites
Augh I'm still having trouble with this! I should've stayed in math my 12th grade year. Ah I'm sure I'll figure out something with the info given. Thx.

##### Share on other sites
If you want a quick solution, there's a dirty trick I used sometimes when I was bored to do the math:

...float pos[]={3.24,5.12,8.457,1};//w=0: Vector, w=1: PositionglMatrixMode(GL_MODELVIEW);glPushMatrix();//Manipulate matrix here...glLightfv(GL_LIGHT0,GL_POSITION,pos);glGetLightfv(GL_LIGHT0,GL_POSITION,pos);glPopMatrix();...

I supply the coordinates as a (dummy) light position, GL automatically transforms it with the current MV matrix and stores it, and then I retrieve the new coords with glGetLight. It's an awful hack though, so better work with your math, it's very simple.

##### Share on other sites
Quote:
 Original post by mikemanIt's an awful hack though, so better work with your math, it's very simple.

it may be a hack, but i like it. very creative.

##### Share on other sites

These functions have some strange effects. Just to make sure we're on the same page, this is what it does right? I can't have the right collision detection if I don't get this right.

##### Share on other sites
HA HA!!! Finally got it! I'm not quite sure but I did somehow. Thanks again all!

1. 1
2. 2
Rutin
19
3. 3
4. 4
khawk
15
5. 5

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633743
• Total Posts
3013644
×