1 // ******************************************************************************
2 //
3 // Title: Force Field X.
4 // Description: Force Field X - Software for Molecular Biophysics.
5 // Copyright: Copyright (c) Michael J. Schnieders 2001-2025.
6 //
7 // This file is part of Force Field X.
8 //
9 // Force Field X is free software; you can redistribute it and/or modify it
10 // under the terms of the GNU General Public License version 3 as published by
11 // the Free Software Foundation.
12 //
13 // Force Field X is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 // details.
17 //
18 // You should have received a copy of the GNU General Public License along with
19 // Force Field X; if not, write to the Free Software Foundation, Inc., 59 Temple
20 // Place, Suite 330, Boston, MA 02111-1307 USA
21 //
22 // Linking this library statically or dynamically with other modules is making a
23 // combined work based on this library. Thus, the terms and conditions of the
24 // GNU General Public License cover the whole combination.
25 //
26 // As a special exception, the copyright holders of this library give you
27 // permission to link this library with independent modules to produce an
28 // executable, regardless of the license terms of these independent modules, and
29 // to copy and distribute the resulting executable under terms of your choice,
30 // provided that you also meet, for each linked independent module, the terms
31 // and conditions of the license of that module. An independent module is a
32 // module which is not derived from or based on this library. If you modify this
33 // library, you may extend this exception to your version of the library, but
34 // you are not obligated to do so. If you do not wish to do so, delete this
35 // exception statement from your version.
36 //
37 // ******************************************************************************
38 package ffx.ui.behaviors;
39
40 import org.jogamp.java3d.Canvas3D;
41 import org.jogamp.java3d.Transform3D;
42 import org.jogamp.java3d.utils.behaviors.vp.OrbitBehavior;
43 import org.jogamp.vecmath.Matrix3d;
44 import org.jogamp.vecmath.Vector3d;
45
46 /**
47 * The GlobalBehavior class allows mouse control over camera position, adding a few functions to the
48 * OrbitBehavior class.
49 *
50 * @author Michael J. Schnieders
51 */
52 public class GlobalBehavior extends OrbitBehavior {
53
54 private Transform3D trans3D = new Transform3D();
55 private Matrix3d homeQuat = new Matrix3d();
56 private Vector3d homeTrans = new Vector3d(0.0, 0.0, 2.0);
57 private Vector3d trans = new Vector3d();
58 private MouseBehaviorCallback navigation = null;
59 private boolean first = false;
60
61 /** Constructor for GlobalBehavior. */
62 public GlobalBehavior() {
63 super();
64 }
65
66 /**
67 * Constructor for GlobalBehavior.
68 *
69 * @param canvas a {@link org.jogamp.java3d.Canvas3D} object.
70 */
71 public GlobalBehavior(Canvas3D canvas) {
72 super(canvas, OrbitBehavior.MOUSE_MOTION_LISTENER);
73 trans3D.setTranslation(homeTrans);
74 setHomeTransform(trans3D);
75 setReverseRotate(true);
76 setReverseTranslate(true);
77 setRotFactors(2.0, 2.0);
78 setProportionalZoom(true);
79 setEnable(false);
80 homeQuat.setIdentity();
81 }
82
83 /**
84 * centerView
85 *
86 * @param resetRotation a boolean.
87 * @param resetTranslation a boolean.
88 */
89 public void centerView(boolean resetRotation, boolean resetTranslation) {
90 if (!resetRotation && !resetTranslation) {
91 return;
92 }
93 vp.getViewPlatformTransform().getTransform(trans3D);
94 trans3D.get(trans);
95 if (resetRotation) {
96 trans3D.set(homeQuat);
97 trans3D.setTranslation(homeTrans);
98 }
99 if (resetTranslation) {
100 trans3D.setTranslation(homeTrans);
101 }
102 setHomeTransform(trans3D);
103 goHome();
104 if (resetRotation) {
105 navigation.transformChanged(MouseBehaviorCallback.ORBIT, trans3D);
106 }
107 }
108
109 /** integrateTransforms */
110 public void integrateTransforms() {
111 // The "first" flag allows the mouse motion to be reset
112 // (ie. dx = x - x_last where x_last is wrong initially)
113 if (first) {
114 vp.getViewPlatformTransform().getTransform(trans3D);
115 }
116 super.integrateTransforms();
117 if (first) {
118 first = false;
119 vp.getViewPlatformTransform().setTransform(trans3D);
120 }
121 vp.getViewPlatformTransform().getTransform(trans3D);
122 navigation.transformChanged(MouseBehaviorCallback.ORBIT, trans3D);
123 }
124
125 /** {@inheritDoc} */
126 public void setEnable(boolean b) {
127 super.setEnable(b);
128 if (b) {
129 first = true;
130 }
131 }
132
133 /**
134 * setUpCallback
135 *
136 * @param m a {@link ffx.ui.behaviors.MouseBehaviorCallback} object.
137 */
138 public void setUpCallback(MouseBehaviorCallback m) {
139 navigation = m;
140 }
141 }