Skip to main content

MouseRotate Class

1 reply [Last post]
Joined: 2008-09-29

How to use right mouse button to rotate a object instead of left mouse button when using the MouseRotate Class.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2010-08-17

Well, this is kinda tricky one, since all Mouse classes are not designed to change the indicator of which button to track down. MouseRotate always binds to LMB, MouseTranslate to RMB. Here's the reason why (j3d_1.5.2 src code fragment):

[code]void doProcess(MouseEvent evt) {
int id;
int dx, dy;

if (((buttonPress)&&((flags & MANUAL_WAKEUP) == 0)) ||
((wakeUp)&&((flags & MANUAL_WAKEUP) != 0))) {
id = evt.getID();
if ((id == MouseEvent.MOUSE_DRAGGED) &&
!evt.isMetaDown() && ! evt.isAltDown()){

What you seek lies around that isMetaDown() call (META_MASK and BUTTON3_MASK values overlap).

1) The best solution would be to inherit the MouseRotate class and redefine this method. It would be something like this:

[code]void doProcess(MouseEvent evt){
MouseEvent newEvt = new MouseEvent(evt.getComponent(),evt.getID(),evt.getWhen(),

But the problem is that this method has this default [i]package[/i] modifier, so outside MouseRotate's package you've no chance to properly extend it. And if you put your class to [i]com.sun.j3d.utils.behaviors.mouse[/i], obviously you get java.lang.SecurityException. If there is a possibility to change sign verifications of the classes, I dunno about it. Maybe somebody does.

2) A different solution (not as beautiful as first one, but also simple) is to create your own MyMouseRotate class (extending MouseBehavior this time) and copypaste the entire code of MouseRotate. After correcting constructors' names the only thing left is to delete the "!" character next to the [i]isMetaDown()[/i] call. Voila.

Good luck.