View Full Version : mouse click event for 3D coordinates in java

vamsee kanth
11-08-2004, 07:31 AM
when i use mouse click event in java i can catch the x coordinate and the y coordinate of the point clicked by using event.getX() and event.getY(). But when similarly i use event.getZ(),it is giving error.

i desperately need the Z coordinate also to be read as iam working on OPENGL and java and developing a graphics tool for which this Z coordinate is very very important.

please somebody help me how to go about it or any other way by which i can read all the three coordinates X,Y,Z of a mouse click action.

is there separate mouse click action in openGL and if so will it catch the 3D coordinates???
plz help!!!!

code in this regard will be highly helpful.

please do the needful.
hoping a quick response...........


11-11-2004, 05:38 AM
Of course not, the screen is 2 dimensional so there is no Z coordinate no matter how much you want it.

If you click in a window, where is the Z coordinate ?, you cannot know unless there is something you click on with a known distance, and in that case it is OpenGL and not Java that can help you out.

You can use OpenGL selection mode to get a hit from a mouse click and this will give you a depth value for the hit that can be converted to a Z value if you want.

gluProject/gluUnProject can be used to convert 2D to 3D and the other way around, but there you are back with the depth problem, you do not know how far away the Z value is.