Results 1 to 9 of 9

Thread: getting the current coordinates?

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2009
    Posts
    7

    getting the current coordinates?

    Is there a way to get some sort of current X, Y, Z coordinates after applying transformations? What I'm trying to do is draw a bunch of objects, translated and rotated and all, and then draw perpendicular lines from them to a plane (which has it center at one point, but rotates freely).

  2. #2
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: getting the current coordinates?

    gluUnProject may help.

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2009
    Posts
    18

    Re: getting the current coordinates?

    i think, the below details may help you.

    void mouse ( int button, int state, int x, int y )
    {
    DirectionX = x;
    DirectionY = y;
    }

    And in your main, add:

    glutMouseFunc(mouse);

    This only works when the user press the button of the mouse.

    void mouse (int x, int y )
    {
    DirectionX = x;
    DirectionY = y;
    }

    And in your main, add:

    glutPassiveMotionFunc(mouse);

    thanks
    santosh

  4. #4
    Junior Member Newbie
    Join Date
    Apr 2009
    Posts
    7

    Re: getting the current coordinates?

    No, what I'm trying to do has nothing to do with the mouse. I'll look into gluUnProject, though.

    EDIT: Looked into it, isn't there a way to do what I want without going through window coordinates? Maybe something with getting the modelview matrix. I'll try that.

  5. #5
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: getting the current coordinates?

    In this case, could you be more specific on what transformations you want to undo? You can also retrieve modelview and projection matrices and invert them with your own matrix class tools, all is possible.

  6. #6
    Junior Member Newbie
    Join Date
    Apr 2009
    Posts
    7

    Re: getting the current coordinates?

    Well, I've been trying to figure it out, and I can't seem to. In short, I have this:

    However, if I rotate everything but the plane, I get this:

    or, even worse, this:


    ...while I'm trying to get them all to look like the first one, with the lines connecting the objects and the plane.

  7. #7
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: getting the current coordinates?

    I think you need something like glPush/glPop (see man pages for more information).

    With this functions you can apply a transformation to a particular object, taking care to save the matrix state calling glPush. Then to go back to the previous matrix state, just call glPop.

  8. #8
    Junior Member Newbie
    Join Date
    Apr 2009
    Posts
    7

    Re: getting the current coordinates?

    Nope, far from it. I'm trying to draw a perpendicular line from a moving object to a plane, OK?

  9. #9
    Junior Member Newbie
    Join Date
    Jul 2009
    Posts
    14

    Re: getting the current coordinates?

    There's obviously some math involved it what your trying to do.

    But the question is do you have some variables in your code representing the vectors that make up your plane? Or is it some simple plane like the x,z plane? You need to know the vectors such that the normal to your plane is the vector along which all your lines will run:

    http://en.wikipedia.org/wiki/File:Normal_vectors2.svg

    Does that help?

Similar Threads

  1. Texture Coordinates and Depth Buffer to obtain world coordinates
    By snkhan42 in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 04-27-2018, 11:52 AM
  2. Replies: 4
    Last Post: 06-08-2016, 07:01 PM
  3. Convert windows mouse coordinates to opengl coordinates
    By throwaway in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-05-2013, 06:44 PM
  4. Replies: 2
    Last Post: 06-02-2012, 08:10 AM
  5. 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

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