Results 1 to 2 of 2

Thread: Another Mouse Coordinate Question

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2000

    Another Mouse Coordinate Question

    Okay, I'm familiar with detecting which object falls under the mouse cursor, but I need to figure out the actual coordinates of the intersection.

    I want an object to follow the mouse cursor around the screen, so I need to translate screen coordinates into world coordinates, using the first object hit under the cursor as the depth.

    Any suggestions/tutorials out there?

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Feb 2000

    Re: Another Mouse Coordinate Question

    I came up with those equations through trigonometry. I haven't tested them, but there is a high probability they work because we can find the special case(camera is on the xy plane with no rotation whatsoever)(wich I have tested ) throught them.It will make your object move a the same distance from the camera at whatever position your camera is:

    World_Xd = (Xmouse * factor_H *(90 - rotx) * (90 - rotz) / 8100) + (Ymouse * factor_Y *rotz / 90).

    World_Yd = (Ymouse * factor_Y *(90 - roty) * (90 - rotz) / 8100) + (Xmouse * factor_X *rotz / 90).

    World_Zd = (Xmouse * factor_H * rotx / 90) + (Ymouse * factor_Y * roty / 90).

    factor_H = Dist_OC * (fright - fleft) /Window_width

    factor_Y = Dist_OC * (ftop - fbottom) / Window_height.

    World_Id = the displacement in world unit on the I axis.

    Imouse = Mouse displacement in the I coordinates.

    rotI = rotation of the camera from the I axis

    Dist_OC = distance from the camera to the object.

    fright, fleft, fbottom, ftop = values from the frustum.

    if using glProjection :
    ftop = tan(angle) * znear
    fbottom = -top
    fright = top * Window_width / Window_height

    As you can see they are pretty messy equations. There are a bunch of optimizations you can do like changing the division to multiplication.

    the biggest optimisation you can do is to forbid the camera to move. In that case most of the variables have a value.

    And one more thing, if you use an orthographic projecton,

    factor_H = (fright - fleft) /Window_width

    factor_Y = (ftop - fbottom) / Window_height

    It's pretty long to explain where I got the equations so I won't write it.

    [This message has been edited by Gorg (edited 03-13-2000).]

    [This message has been edited by Gorg (edited 03-13-2000).]

Similar Threads

  1. PLZ HELP: convert mouse coordinate(2d) to 3D with using OpenGL
    By xaka in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 06-18-2003, 12:22 AM
  2. Replies: 0
    Last Post: 06-16-2003, 11:42 PM
  3. relationship between mouse position and coordinate and normal
    By ljz in forum OpenGL: Advanced Coding
    Replies: 9
    Last Post: 02-18-2003, 01:54 PM
  4. Need help with getting coordinate using mouse
    By Swift in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 08-11-2002, 04:46 PM
  5. Mouse Coordinate Transformation
    By Nat in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 08-23-2001, 10:36 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