133 lines
4.0 KiB
Java
133 lines
4.0 KiB
Java
//This file is part of SECONDO.
|
|
|
|
//Copyright (C) 2004, University in Hagen, Department of Computer Science,
|
|
//Database Systems for New Applications.
|
|
|
|
//SECONDO is free software; you can redistribute it and/or modify
|
|
//it under the terms of the GNU General Public License as published by
|
|
//the Free Software Foundation; either version 2 of the License, or
|
|
//(at your option) any later version.
|
|
|
|
//SECONDO is distributed in the hope that it will be useful,
|
|
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
//GNU General Public License for more details.
|
|
|
|
//You should have received a copy of the GNU General Public License
|
|
//along with SECONDO; if not, write to the Free Software
|
|
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
package viewer.spatial3D;
|
|
|
|
import tools.Reporter;
|
|
|
|
import com.sun.j3d.utils.picking.*;
|
|
import com.sun.j3d.utils.picking.behaviors.*;
|
|
import com.sun.j3d.utils.behaviors.mouse.*;
|
|
import java.util.Vector;
|
|
|
|
import java.awt.*;
|
|
import java.awt.event.*;
|
|
import java.util.*;
|
|
import javax.media.j3d.*;
|
|
import javax.vecmath.*;
|
|
|
|
/**
|
|
* A mouse behavior that allows user to pick and rotate, rotate and zoom
|
|
* scene graph objects.
|
|
*/
|
|
|
|
public class CustomPickRotate extends PickMouseBehavior implements MouseBehaviorCallback {
|
|
|
|
MouseRotate drag;
|
|
private PickingCallback callback = null;
|
|
private TransformGroup currentTG;
|
|
private Transform3D currTrans = new Transform3D();
|
|
private Matrix3f rotation = new Matrix3f(1, 0, 0, 0, 1, 0, 0, 0, 1);
|
|
|
|
/**
|
|
* Creates a pick/rotate behavior that waits for user
|
|
* mouse events for the scene graph.
|
|
*
|
|
* @param root
|
|
* Root of your scene graph.
|
|
* @param canvas
|
|
* Java 3D drawing canvas.
|
|
* @param bounds
|
|
* Bounds of your scene.
|
|
**/
|
|
|
|
public CustomPickRotate( BranchGroup root, Canvas3D canvas, Bounds bounds) {
|
|
super(canvas, root, bounds);
|
|
drag = new MouseRotate(MouseBehavior.MANUAL_WAKEUP);
|
|
drag.setTransformGroup(currGrp);
|
|
currGrp.addChild(drag);
|
|
drag.setSchedulingBounds(bounds);
|
|
this.setSchedulingBounds(bounds);
|
|
}
|
|
|
|
/**
|
|
* Update the scene to manipulate any nodes. This is not meant to be called
|
|
* by users. Behavior automatically calls this. You can call this only if
|
|
* you know what you are doing.
|
|
*
|
|
* @param xpos
|
|
* Current mouse X pos.
|
|
* @param ypos
|
|
* Current mouse Y pos.
|
|
**/
|
|
public void updateScene(int xpos, int ypos) {
|
|
TransformGroup tg = null;
|
|
if (!mevent.isControlDown() && !mevent.isMetaDown() && !mevent.isAltDown()){
|
|
pickCanvas.setShapeLocation(xpos, ypos);
|
|
PickResult pr = pickCanvas.pickClosest();
|
|
if ((pr != null) &&
|
|
((tg = (TransformGroup)pr.getNode(PickResult.TRANSFORM_GROUP))
|
|
!= null) &&
|
|
(tg.getCapability(TransformGroup.ALLOW_TRANSFORM_READ)) &&
|
|
(tg.getCapability(TransformGroup.ALLOW_TRANSFORM_WRITE))){
|
|
drag.setTransformGroup(tg);
|
|
drag.wakeup();
|
|
currentTG = tg;
|
|
} else if (callback!=null)
|
|
callback.transformChanged( PickingCallback.NO_PICK, null );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Callback method from MouseTranslate This is used when the Picking
|
|
* callback is enabled
|
|
*/
|
|
public void transformChanged(int type, Transform3D transform) {
|
|
callback.transformChanged( PickingCallback.ROTATE, currentTG );
|
|
}
|
|
|
|
/**
|
|
* Register the class @param callback to be called each time the picked
|
|
* object moves
|
|
*/
|
|
public void setupCallback(PickingCallback callback) {
|
|
this.callback = callback;
|
|
if (callback==null)
|
|
drag.setupCallback( null );
|
|
else
|
|
drag.setupCallback( this );
|
|
}
|
|
|
|
public void setFactor(double factor) {
|
|
drag.setFactor(factor);
|
|
}
|
|
|
|
/**
|
|
* getRotation
|
|
* passes the rotation has been carried out
|
|
*/
|
|
public Matrix3f getRotation() {
|
|
if (currentTG != null) {
|
|
currentTG.getTransform(currTrans);
|
|
currTrans.get(rotation);
|
|
}
|
|
return rotation;
|
|
}
|
|
|
|
} |