Jump to content
  • Advertisement
Sign in to follow this  
Kitasia

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.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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: Position
glMatrixMode(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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!