Archived

This topic is now archived and is closed to further replies.

Bennettovia

Mouse Interpretation

Recommended Posts

What I need to do is process a mouse click, figure out where that click occured in my GL space, and plot a point there. This is for a modelling tool and that plotted point would be the anchor of a line, or the anchor of a polygon etc. I''m not trying to select or pick anything. Just figure out where I clicked in GL space so that I can plot a point. I obviously have the windows location of where I clicked. Any help would own, since I''m severely frustrated, and if the solution is simple I''m going to kick myself in the head.

Share this post


Link to post
Share on other sites
this should be in the graphics theory forum

you''re gonna need some information about your camera.
1. position in space (in GL_PROJECTION-mode)
2. orientation as normalized vector
3. the *up*-vector
3. optionally the right vector, but it can be determined by cross producing up an orientation vector.
4. the near plane of your view frustum

now, scalar-multiply the orientation-vector with the distance to the near plane. then add the mouse x (relative to the midpoint of your monitor & divided by the half of your x resolution) and the y (also relative ...). now you have the vector pointing from the camera''s origin to the mouse pointer - you''ll have to scale it to be in your view frustum. at last, transform the vector by the projection matrix, and you have the coordinate (at the end of the vector*).

*vector --- actually it''s a ray, since a vector doesn''t have a origin. so, you have to translate the camera''s position stored in the last column of the projection matrix by that vector.

Share this post


Link to post
Share on other sites
quote:
Original post by 666_1337
this should be in the graphics theory forum


I posted here because I didn''t know if there were GL specific commands I could make use of. Thanks for your help though

Share this post


Link to post
Share on other sites
quote:
Original post by Bennettovia
I posted here because I didn''t know if there were GL specific commands I could make use of. Thanks for your help though

hmmm... well... there is a command you could use which is opengl-specific: glGetFloatv with GL_PROJECTION_MATRIX as argument :D

Share this post


Link to post
Share on other sites
quote:
Original post by 666_1337
[quote]Original post by Bennettovia
I posted here because I didn't know if there were GL specific commands I could make use of. Thanks for your help though

hmmm... well... there is a command you could use which is opengl-specific: glGetFloatv with GL_PROJECTION_MATRIX as argument :D

Although I haven't programmed this bit (I was sleeping) I was just going to base my coordinate translator on your above psuedo algorithm

The thing is, I'd want all the mouse clicks processed in a fixed XY plane. Essentially my window is split into four, XY, XZ, YZ and view. so any point placed in window XY would have a Z of 0.0 until it was moved in another window.....

[edited by - Bennettovia on May 4, 2003 6:05:50 PM]

Share this post


Link to post
Share on other sites
a cad program, i see

so you are surely looking down the z axis for one of your *windows*, the y axis on another and the x axis on the last one.

then you might have something like

  
struct GLCanvas //or maybe it''s class. doesn''t care this time

{
int width, height, xpos, ypos;
GLint _xleft, _xright, ... //parameters to glOrtho

...
};

with xpos beeing the x distance to the left side of your main window. ypos the distance to the top, width and height are that what they are named. now if you catch a click on p(x, y) you have to do the following:
1. divide your mouseposition_x through your viewport coordinates and store the result
2. find the difference from _xleft and _xright
3. multiply the result of 1. with that one of 2.
4. add _xleft to the result of 3.
5. do the same thing with y

now you''ve got the point (x, y, 0) if it was the xy plane. else, simply interpret it as (x, 0, z) or (0, y, z)

Share this post


Link to post
Share on other sites