#### Archived

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

# Mouse Interpretation

This topic is 5706 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
Look at gluProject/gluUnProject...

##### Share on other sites
this should be in the graphics theory forum

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 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 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 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 on other sites

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 on other sites
...and...
there are several open-source cad programs...
why don''t dont you take a look at them? they have much more than only "finding a point"

##### Share on other sites
thats a really good idea. I completely forgot about open source cad and I was tottaly stuck in the open source map editor mindset...

##### Share on other sites
Oh my gosh, I''m such an idiot. Thank you so much for pointing out the obviousness to me.

Argh, I could kick myself in the head now.....

1. 1
2. 2
Rutin
20
3. 3
khawk
16
4. 4
A4L
14
5. 5

• 11
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633756
• Total Posts
3013707
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!