Results 1 to 5 of 5

Thread: mouse coordinates

  1. #1
    Junior Member Newbie
    Join Date
    May 2001
    Posts
    3

    mouse coordinates

    Hello,
    Can somebody tell me how can I obtain a
    glVertex3d from mouse coordinates ?
    Thanks,
    Franco

  2. #2
    Junior Member Newbie
    Join Date
    May 2001
    Posts
    21

    Re: mouse coordinates

    Well, as I understand it you would click with the mouse on the screen, and a vertex should show up in a perspective view. This is not possible unless you use an already defined z-value. Then you could compute the x- and y-value based on the mouse x- and y-values. Which in term would cause the vertices to show up in the same plane in space. If you give me more information about your task, I can help you further.

    Martin

  3. #3
    Senior Member Regular Contributor
    Join Date
    Mar 2001
    Posts
    184

    Re: mouse coordinates

    use gluUnProject to map window-coords to world space...

    gluUnProject(int winx, int winy, int winz, double *model, double *proj, int *view, double *x, double *y, double *z)

    winx and winy would be your mouse coords, model is the modelview matrix, proj is the projection matrix, view is the viewport, x y and z are your resultant world space coords. use the glGetDoublev function to get the matrices and glGetIntegerv to get the viewport. you may want to play around with the winz value. if you call the function twice and use 0 for winz in the first call, then use 1, your resultant points define a ray in your world space which you can then use to select objects (use collision detection with the ray and your objects). good luck

    b

  4. #4
    Junior Member Newbie
    Join Date
    May 2001
    Posts
    3

    Re: mouse coordinates

    ocvan
    Originally posted by coredump:
    use gluUnProject to map window-coords to world space...

    gluUnProject(int winx, int winy, int winz, double *model, double *proj, int *view, double *x, double *y, double *z)

    winx and winy would be your mouse coords, model is the modelview matrix, proj is the projection matrix, view is the viewport, x y and z are your resultant world space coords. use the glGetDoublev function to get the matrices and glGetIntegerv to get the viewport. you may want to play around with the winz value. if you call the function twice and use 0 for winz in the first call, then use 1, your resultant points define a ray in your world space which you can then use to select objects (use collision detection with the ray and your objects). good luck

    b
    This what I do after your answer
    I put this code in OnLButtonDown

    GLdouble model[16];
    double x;
    double y;
    double z;
    GLdouble proj[16];
    GLint view[4];
    glGetDoublev(GL_MODELVIEW_MATRIX, model);
    glGetDoublev(GL_PROJECTION_MATRIX, proj);
    glGetIntegerv(GL_VIEWPORT, view);
    gluUnProject((GLdouble)point.x, (GLdouble)point.y, (GLdouble)0, model, proj, view, &x, &y, &z );
    CString str;
    str.Format("x = %d, y = %d, z = %d", x, y, z);
    AfxMessageBox(str);

    so I have really weird values in x, y, z.

    What I want to do is :
    having a drawble entity let say a cube
    i wish to move it in 3d space with the mouse

    Thanks,
    Franco

  5. #5
    Senior Member Regular Contributor
    Join Date
    Mar 2001
    Posts
    184

    Re: mouse coordinates

    this can be done many different ways. one is to save the last mouse position and each time you get a click, use it with the last to obtain a delta, or change in position. use this delta to translate your geometry.

    // in your mouse handler
    ...
    delta.x = last.x - cur.x;
    delta.y = last.y - cur.y;
    ...

    now use the delta values in translate, or rotate. you may want to scale it (ex. delta * 0.3) just try different values until you acquire the results you need. this works well for x and y translations. if you want a z translation, you will have to come up with a different scheme, perhaps using the right mouse button.

    b

Similar Threads

  1. Replies: 8
    Last Post: 01-22-2016, 04:57 AM
  2. Convert windows mouse coordinates to opengl coordinates
    By throwaway in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-05-2013, 06:44 PM
  3. Mouse coordinates into World coordinates
    By fiodis in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 11-30-2012, 07:24 AM
  4. mouse coordinates
    By nick800 in forum OpenGL: Basic Coding
    Replies: 11
    Last Post: 04-01-2003, 10:53 AM
  5. Converting Mouse Coordinates to 3D Coordinates
    By Infamous in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-18-2002, 08:33 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