Getting x1 and y1 after glrotate

Started by
7 comments, last by Kitasia 18 years, 7 months ago
Does anyone know how to get the object's coordinates after glrotate? Thanks in advance.
Advertisement
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.
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.




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).
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.
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.
Quote:Original post by mikeman
It'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.

As your leader, I encourage you from time to time, and always in a respectful manner, to question my logic. If you're unconvinced that a particular plan of action I've decided is the wisest, tell me so, but allow me to convince you and I promise you right here and now, no subject will ever be taboo. Except, of course, the subject that was just under discussion. The price you pay for bringing up either my Chinese or American heritage as a negative is - I collect your f***ing head.


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.
HA HA!!! Finally got it! I'm not quite sure but I did somehow. Thanks again all!

This topic is closed to new replies.

Advertisement