Results 1 to 3 of 3

Thread: Get true location by glGetFloatv(GL_MODELVIEW_MATRIX, mat)?

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2004
    Posts
    15

    Get true location by glGetFloatv(GL_MODELVIEW_MATRIX, mat)?

    There is a point inited with x,y and z.
    Now It has been moved by glTranslatef,glRotatef and some other commends.
    How can i get the true location of this point by glGetFloatv(GL_MODELVIEW_MATRIX, mat)?

  2. #2
    Member Contributor
    Join Date
    Nov 2001
    Posts
    77

    Re: Get true location by glGetFloatv(GL_MODELVIEW_MATRIX, mat)?

    The array mat then holds the current model viewing matrix, so all you have to do is take the vector for the point (x,y,z,1) and multiply it by the matrix you retrieved:

    Code :
     
    ( mat[0][0] mat[1][0] mat[2][0] mat[3][0] )    ( x )
    ( mat[0][1] mat[1][1] mat[2][1] mat[3][1] ) *  ( y )
    ( mat[0][2] mat[1][2] mat[2][2] mat[3][2] )    ( z )
    ( mat[0][3] mat[1][3] mat[2][3] mat[3][3] )    ( 1 )
    That result will yield the transformed point (ie: the actual point in 3D space), just omit the homogenous coordinate (the last entry). If you're not familiar with matrix math, get there! Very important in 3D graphics! ^_~ But, here's the gist: The left matrix tells you how many rows your result will have. The right matrix will tell you how many columns you'll have. In our case, we'll have 4 rows and 1 column (a vector in R^4, or 4 dimensional space). Then, pick a row in the left matrix and a column in the right matrix. This will be the location in our resulting matrix for our final answer. Start from the first entries and multiply them. Move to the next elements and multiply, then add with the previous result. Repeat until you run out. Examples generally help:

    Code :
     
    ( a b ) * ( e f ) = ( a*e + b*g  a*f + b*h )
    ( c d )   ( g h )   ( c*e + d*g  c*f + d*h )
     
    ( a b ) * ( x ) = ( a*x + b*y )
    ( c d )   ( y )   ( c*x + d*y )
    You can find a lot more information on this all over the web. Just look up matrix math. Wow, this got long quick. ^_^

    [This message has been edited by Nychold (edited 02-22-2004).]

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2004
    Posts
    15

    Re: Get true location by glGetFloatv(GL_MODELVIEW_MATRIX, mat)?

    Yes,that is right.

    Thank you very very much.

Similar Threads

  1. Replies: 5
    Last Post: 04-08-2008, 07:41 AM
  2. glGetFloatv(GL_MODELVIEW_MATRIX, mat)?
    By tgtt in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 02-22-2004, 11:34 PM
  3. Replies: 0
    Last Post: 02-20-2004, 09:06 PM
  4. glGetFloatv(GL_MODELVIEW_MATRIX, m)
    By starman in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 06-19-2003, 07:07 AM
  5. Replies: 3
    Last Post: 10-25-2001, 01:20 PM

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