Skip to main content

Get mouse position

2 replies [Last post]
Kaito-Hacker
Offline
Joined: 2011-03-23
Points: 0

How to get the mouse location in the canvas in point3d form?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sal
Offline
Joined: 2005-07-06
Points: 0

Hello Kaito,
you have to create a behavior which listen to mouseclicking (this.wakeon(new WakeuponAWTEvent(MouseEvent.MouseClicked) has to be written in initialization and processstimulus methods). Then you have to do some casts so that you got a mouseevent. At
the end you only need to use a method provided by the MouseEvent. I think it s something like e.getLocation... or something else. This methods returns a Point with x and y coordinates. Those coordinates you can use to create the Point3f or Point3d. The z coordinate has to set manually. (Choose some value e. g. 0 or 1). You can only determine the x and y coordinate by clicking. But not the z coordinate. Therefore the perspective does not give any chance.
Hope it might help you!
Good luck

Kaito-Hacker
Offline
Joined: 2011-03-23
Points: 0

Thanks for you comment.
If I have an object, let's said a box, rotated using mouse mouseratote class, can the method you provided still works if I want to pick the point inside that box, the point it should have before the rotation?