Results 1 to 7 of 7

Thread: Calculating Positions based upon glRotatef

  1. #1
    Guest

    Calculating Positions based upon glRotatef

    i have the following code:
    Code :
    { 
     DoTranslateRotate();
     glBegin(GL_POINTS);
     glVertex3f(x,y,z);
     glEnd();
     UndoTranslateRotate();
    }
     
     
    void DoTranslateRotate()
    {
    	//Perform XYZ Translation
    	glTranslatef(COrigin.x,COrigin.y,COrigin.z);
     
    	//Perform XYZ rotations
    	glRotatef(COrigin.xAngle, 1.0f,0.0f,0.0f);
    	glRotatef(COrigin.yAngle, 0.0f,1.0f,0.0f);
    	glRotatef(COrigin.zAngle, 0.0f,0.0f,1.0f);
     
     
    }	
     
    void UnDoTranslateRotate()
    {
    	//Undo XYZ rotations
    	glRotatef(-COrigin.zAngle, 0.0f,0.0f,1.0f);
    	glRotatef(-COrigin.yAngle, 0.0f,1.0f,0.0f);
    	glRotatef(-COrigin.xAngle, 1.0f,0.0f,0.0f);
       //Undo XYZ Translation
    	glTranslatef(-COrigin.x,-COrigin.y,-COrigin.z);
    }
    i want to know where the point (x,y,z) will be drawn, and i do know the Data in COrigin

    is there some way i can use the OGL matrix and just multiply the matrix by my {X Y Z} values to obtain the new X, Y, Z that the point will appear at (relative to the world)

    say if i had the point (1,0,0) and i rotated my y - axis 180 degrees, the point is now at (-1,0,0) correct? given the XYZ, and the rotations i want to find the new XYZ location.

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Nov 2002
    Location
    Latvia
    Posts
    626

    Re: Calculating Positions based upon glRotatef

    When you call glrotatef(alpha,x,y,z) you give angle alpha, & amount to rotate on x,y&z axis. So everything else is pure math (sin,cos)
    But you can use modelview matrix, as 1st row will include all x coord trans, y all y trans and so on (or maybe not, I forgot that as I had a lot of work to be done at uni) take a look at matrix multiplication defs.

  3. #3
    Guest

    Re: Calculating Positions based upon glRotatef

    im using the perspective matrix so that wont work exactly. i need openGLs calculation

    unless a better way of figuring it out can be done

    what im trying to do is to see if a user has clicked on a square which can be viewed from any angle. so this is affected by the matrix that openGL is using.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,502

    Re: Calculating Positions based upon glRotatef

    See gluUnproject and/or gluProject.

    [This message has been edited by DFrey (edited 01-08-2003).]

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Calculating Positions based upon glRotatef

    You do understand the order in which you call the translate and rotate has a big effect on the location of the object.

    Also the the last command before drawing the object is the one effecting the object first.

    In the order you have it:

    glRotate
    glTranslate

    Draw_object();

    What happens is the object is translated from its origin to some location, then rotate about the openGL's axis of 0,0,0.

    So if say you translate the object 5 units out on the X axis and then rotate 20 degrees. The object will be moved along the openGL origin in a 20 degree arc along the axis of rotation with a radius 5 units.

    Now if you do the following:

    glTranslate
    glRotate

    Draw_object()

    The object is rotated on the openGL 0,0,0 axis and then moved out to the location.


    Code :
    { 
     DoTranslateRotate();
     glBegin(GL_POINTS);
     glVertex3f(x,y,z);
     glEnd();
     UndoTranslateRotate();
    }
     
     
    void DoTranslateRotate()
    {
    	//Perform XYZ Translation
    	glTranslatef(COrigin.x,COrigin.y,COrigin.z);
     
    	//Perform XYZ rotations
    	glRotatef(COrigin.xAngle, 1.0f,0.0f,0.0f);
    	glRotatef(COrigin.yAngle, 0.0f,1.0f,0.0f);
    	glRotatef(COrigin.zAngle, 0.0f,0.0f,1.0f);
     
     
    }	
     
    void UnDoTranslateRotate()
    {
    	//Undo XYZ rotations
    	glRotatef(-COrigin.zAngle, 0.0f,0.0f,1.0f);
    	glRotatef(-COrigin.yAngle, 0.0f,1.0f,0.0f);
    	glRotatef(-COrigin.xAngle, 1.0f,0.0f,0.0f);
       //Undo XYZ Translation
    	glTranslatef(-COrigin.x,-COrigin.y,-COrigin.z);
    }
    i want to know where the point (x,y,z) will be drawn, and i do know the Data in COrigin

    is there some way i can use the OGL matrix and just multiply the matrix by my {X Y Z} values to obtain the new X, Y, Z that the point will appear at (relative to the world)

    say if i had the point (1,0,0) and i rotated my y - axis 180 degrees, the point is now at (-1,0,0) correct? given the XYZ, and the rotations i want to find the new XYZ location.[/B]<HR></BLOCKQUOTE>



    [This message has been edited by nexusone (edited 01-09-2003).]

  6. #6
    Guest

    Re: Calculating Positions based upon glRotatef

    Yeah, i get all that.

    but i need the X,Y position in terms of pixels from the top left of the window given the 3d co-ord for my model.

    my model code works fine, it draws it textures, but i cant obtain the xy position of a given xyz position after it has been drawn and rotated and viewport transformed.

  7. #7
    Senior Member Frequent Contributor
    Join Date
    Dec 2002
    Location
    Espoo, Finland
    Posts
    599

    Re: Calculating Positions based upon glRotatef

    Like DFrey said, use gluProject. It does exactly what you need. For more advanced picking try gluPickMatrix and glRenderMode(GL_SELECT).

    -Ilkka

Similar Threads

  1. Not able to draw at certain x positions
    By fizzlesticks in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 02-11-2012, 11:57 PM
  2. GL_LINES on different positions
    By Thomas Alton in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-22-2011, 01:17 PM
  3. positions
    By arthas in forum OpenGL: General
    Replies: 1
    Last Post: 03-15-2008, 05:24 AM
  4. Replace two glRotatef() with one glRotatef()?
    By tgtt in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 02-24-2004, 02:33 PM
  5. Please help me- light positions
    By alok47 in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 07-20-2001, 03:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean