Results 1 to 5 of 5

Thread: How can I get the current object position

  1. #1
    Guest

    How can I get the current object position

    Can someone help me,

    I have a problem when I try to get the origin of an object in world space coordinates.

    For example I have a sphere wich moves along Y axis, parallel to it (x = 0, z = 0, Z means UP, Y means DEPTH)

    The projection is perspective :
    gluPerspective(70.0, (float)w / (float) h, 0.08, 4.0);

    Camera position is defined as follows:
    gluLookAt(0.0, -0.2, 0.25, 0.0, 0.3, 0.0, 0.0, 0.0, 1.0);

    I get the sphere's center location using the following code :
    glGetDoublev (GL_MODELVIEW_MATRIX, modelviewMatrix);

    x = modelviewMatrix[12];
    y = modelviewMatrix[13];
    z = modelviewMatrix[14];

    When the sphere's center Y value becomes less then 0, Z value of the sphere's center starts to decrease. Nevertheless the sphere continues to move parallel to the Y axis.

    The problem is why Z value changes ?

    Another point is when I change the position of the camera (Z value) I receive different values for x,y and z, despite the object location is the same.

    Regards!

  2. #2
    Guest

    Re: How can I get the current object position

    [quote]Originally posted by <himchev>:

    x = modelviewMatrix[12];
    y = modelviewMatrix[13];
    z = modelviewMatrix[14];

    When the sphere's center Y value becomes less then 0, Z value of the sphere's center starts to decrease. Nevertheless the sphere continues to move parallel to the Y axis.

    The problem is why Z value changes ?
    /quote]

    Well, I am not sure but I think that you are simply taking wrong elements of modelviewMatrix. Check it out. If that doesn't help, try to use ortographic projection and see if Z keeps changing.

    Another point is when I change the position of the camera (Z value) I receive different values for x,y and z, despite the object location is the same.
    The modelview matrix represent your 'camera' not the object's coordinates (IMHO, of course).

    See ya'

  3. #3
    Guest

    Re: How can I get the current object position

    NOTE : the layout of the previous post has been accidentally screwd up.

  4. #4
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: How can I get the current object position

    The modelview represents the concatenation of both the camera and the object matrices. The translation triplet from the modelview will produce the eyespace coordinate of the object space origin. There is no independent view & model matrix stored by OpenGL, conceptually the view matrix exists on the modelview matrix when the model matrix is identity. If the view matrix were identity then the model matrix would exist on the modelview stack. If you want the model matrix from the modelview you'd have to multiply it by the inverse view matrix.

  5. #5
    Guest

    Re: How can I get the current object position

    Thanks a lot dorbie,

    I think I've got it.
    It's still called 'MODELVIEW' matrix and I should get only the 'MODEL' part from it.
    I've missed out on this.

Similar Threads

  1. finding current position
    By joao flavio in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 09-12-2012, 09:07 PM
  2. current last drawn position to x,y,z
    By Ian Knight in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-01-2002, 01:20 PM
  3. How do I get the My Current Position (coordinates)
    By ca2hill in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-24-2001, 08:04 AM
  4. detect current position
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-19-2000, 04:10 PM
  5. detect current position
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-17-2000, 03:50 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