MouseTranslate behavior not working

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

MouseTranslate behavior not working

runiter
I used to be able to use MouseTranslate to move the scene by dragging mouse while holding right-click but it no longer works. When I looked inside the code I noticed the problem is this code:

https://github.com/hharrison/java3d-utils/blob/master/src/com/sun/j3d/utils/behaviors/mouse/MouseTranslate.java#L231

Looks like in addition to dragging mouse, the Meta key needs to be pressed too?
Is there any way to translate the scene by just dragging mouse without pressing Meta key?
Saeid Nourian, Ph.D. Eng. | Graphing Calculator 3D
Reply | Threaded
Open this post in threaded view
|

Re: MouseTranslate behavior not working

gouessej
Administrator
Hello

Does it have something to do with the version of Java?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: MouseTranslate behavior not working

runiter
At first it seemed like it was due to Java version because it used to work, but after looking at Java3D code it seemed like it was intentional.

Anyways I fixed it by changing its code to this:

import java.awt.AWTEvent;
import java.awt.event.MouseEvent;
import java.util.Iterator;
import org.jogamp.java3d.TransformGroup;
import org.jogamp.java3d.WakeupCriterion;
import org.jogamp.java3d.WakeupOnAWTEvent;
import org.jogamp.java3d.WakeupOnBehaviorPost;
import org.jogamp.java3d.utils.behaviors.mouse.MouseBehavior;
import org.jogamp.java3d.utils.behaviors.mouse.MouseBehaviorCallback;
import org.jogamp.vecmath.Vector3d;

public class MouseTranslate extends MouseBehavior {
        double x_factor = 0.02D;
        double y_factor = 0.02D;
        Vector3d translation = new Vector3d();
        private MouseBehaviorCallback callback = null;

        public MouseTranslate(TransformGroup transformGroup) {
                super(transformGroup);
        }

        public void initialize() {
                super.initialize();
                if ((this.flags & 2) == 2) {
                        this.invert = true;
                        this.x_factor *= -1.0D;
                        this.y_factor *= -1.0D;
                }

        }

        public void setFactor(double factor) {
                this.x_factor = this.y_factor = factor;
        }

        public void processStimulus(Iterator<WakeupCriterion> criteria) {
                while(criteria.hasNext()) {
                        WakeupCriterion wakeup = criteria.next();
                        MouseEvent evt;
                        if (wakeup instanceof WakeupOnAWTEvent) {
                                AWTEvent[] events = ((WakeupOnAWTEvent)wakeup).getAWTEvent();
                                if (events.length > 0) {
                                        evt = (MouseEvent)events[events.length - 1];
                                        this.doProcess(evt);
                                }
                        } else if (wakeup instanceof WakeupOnBehaviorPost) {
                                while(true) {
                                        synchronized(this.mouseq) {
                                                if (this.mouseq.isEmpty()) {
                                                        break;
                                                }

                                                for(evt = (MouseEvent)this.mouseq.remove(0); evt.getID() == 506 && !this.mouseq.isEmpty() && ((MouseEvent)this.mouseq.get(0)).getID() == 506; evt = (MouseEvent)this.mouseq.remove(0)) {
                                                }
                                        }

                                        this.doProcess(evt);
                                }
                        }
                }

                this.wakeupOn(this.mouseCriterion);
        }

        public void processMouseEvent(MouseEvent evt) {
                if (evt.getButton() == 3) {
                        super.processMouseEvent(evt);
                }
        }

        void doProcess(MouseEvent evt) {
                this.processMouseEvent(evt);
                if (this.buttonPress && (this.flags & 1) == 0 || this.wakeUp && (this.flags & 1) != 0) {
                        int id = evt.getID();
                        if (id == 506 && !evt.isAltDown()) {
                                this.x = evt.getX();
                                this.y = evt.getY();
                                int dx = this.x - this.x_last;
                                int dy = this.y - this.y_last;
                                if (!this.reset && Math.abs(dy) < 50 && Math.abs(dx) < 50) {
                                        this.transformGroup.getTransform(this.currXform);
                                        this.translation.x = (double)dx * this.x_factor;
                                        this.translation.y = (double)(-dy) * this.y_factor;
                                        this.transformX.set(this.translation);
                                        if (this.invert) {
                                                this.currXform.mul(this.currXform, this.transformX);
                                        } else {
                                                this.currXform.mul(this.transformX, this.currXform);
                                        }

                                        this.transformGroup.setTransform(this.currXform);
                                        if (this.callback != null) {
                                                this.callback.transformChanged(1, this.currXform);
                                        }
                                } else {
                                        this.reset = false;
                                }

                                this.x_last = this.x;
                                this.y_last = this.y;
                        } else if (id == 501) {
                                this.x_last = evt.getX();
                                this.y_last = evt.getY();
                        }
                }

        }

        public void setupCallback(MouseBehaviorCallback callback) {
                this.callback = callback;
        }
}
Saeid Nourian, Ph.D. Eng. | Graphing Calculator 3D
Reply | Threaded
Open this post in threaded view
|

Re: MouseTranslate behavior not working

unixnerd
Sorry to bump this after 18 months. Which key did you find to be the Meta key? On Windows 10 I can't get this to translate at all. Tried Ctrl, Alt, etc...........
Reply | Threaded
Open this post in threaded view
|

Re: MouseTranslate behavior not working

runiter
In Windows, Meta key is the "Windows" key (the key on your keyboard with Windows icon).
Saeid Nourian, Ph.D. Eng. | Graphing Calculator 3D