X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d.vtk%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fvtk%2Fswt%2FRotateAction.java;h=f9ea1877b154b13653963026501138a7b1a712be;hb=refs%2Fchanges%2F10%2F3510%2F2;hp=1b2d791432a7c4c8037e03cc669694b51380abd1;hpb=84132a1d750c45f9161afbd58b78572964e50d26;p=simantics%2F3d.git diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/RotateAction.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/RotateAction.java index 1b2d7914..f9ea1877 100644 --- a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/RotateAction.java +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/RotateAction.java @@ -21,20 +21,26 @@ import javax.vecmath.Quat4d; import javax.vecmath.Vector3d; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; import org.simantics.g3d.math.EulerTools; import org.simantics.g3d.math.EulerTools.Order; import org.simantics.g3d.math.MathTools; import org.simantics.g3d.math.Ray; import org.simantics.g3d.preferences.PreferenceConstants; import org.simantics.g3d.scenegraph.IG3DNode; +import org.simantics.g3d.scenegraph.base.INode; import org.simantics.g3d.scenegraph.structural.IStructuralNode; +import org.simantics.g3d.toolbar.ToolComposite; import org.simantics.g3d.vtk.Activator; import org.simantics.g3d.vtk.common.VTKNodeMap; import org.simantics.g3d.vtk.gizmo.RotateAxisGizmo; import org.simantics.g3d.vtk.utils.vtkUtil; -import org.simantics.utils.threads.AWTThread; import org.simantics.utils.threads.ThreadUtils; import vtk.vtkProp; @@ -47,11 +53,11 @@ import vtk.vtkProp; public class RotateAction extends vtkSwtAction{ public static final int X = 0; - public static final int Y = 1; - public static final int Z = 2; - public static final int P = 3; + public static final int Y = 1; + public static final int Z = 2; + public static final int P = 3; - private VTKNodeMap nodeMap; + private VTKNodeMap nodeMap; //private TranslateGizmo gizmo = new TranslateGizmo(); private RotateAxisGizmo gizmo = new RotateAxisGizmo(); private IG3DNode node; @@ -65,8 +71,8 @@ public class RotateAction extends vtkSwtAction{ int stepMethod = 1; Order order = Order.YXZ; - private int steps; - private double angles[]; + private int steps; + private double angles[]; int index = P; boolean valid = false; @@ -77,6 +83,9 @@ public class RotateAction extends vtkSwtAction{ //AxisAngle4d rotation = new AxisAngle4d(); Quat4d worldOrientation = new Quat4d(); + protected ToolComposite toolComposite; + protected Combo axisCombo; + public void setNode(IG3DNode node) { this.node = node; if ((node instanceof IStructuralNode) && ((IStructuralNode)node).isPartOfInstantiatedModel() && !((IStructuralNode)node).isInstantiatedModelRoot()) { @@ -105,27 +114,58 @@ public class RotateAction extends vtkSwtAction{ return node; } - public RotateAction(InteractiveVtkComposite panel, VTKNodeMap nodeMap) { + public RotateAction(InteractiveVtkComposite panel, VTKNodeMap nodeMap, ToolComposite toolComposite) { super(panel); setImageDescriptor(Activator.imageDescriptorFromPlugin("com.famfamfam.silk", "icons/arrow_rotate_clockwise.png")); setText("Rotate"); this.nodeMap = nodeMap; - + this.toolComposite = toolComposite; steps = 36; - angles = new double[steps+1]; - for (int i = 0; i < angles.length; i++) { - angles[i] = - Math.PI + (Math.PI * i * 2.0 / steps); - } - - activeCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_HAND); - dragCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_CROSS); + angles = new double[steps+1]; + for (int i = 0; i < angles.length; i++) { + angles[i] = - Math.PI + (Math.PI * i * 2.0 / steps); + } + + activeCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_HAND); + dragCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_CROSS); } + protected void createTools(ToolComposite toolComposite) { + Label label = new Label(toolComposite, SWT.READ_ONLY); + label.setText("Rotate axis:"); + axisCombo = new Combo(toolComposite, SWT.READ_ONLY); + axisCombo.add("X"); + axisCombo.add("Y"); + axisCombo.add("Z"); + axisCombo.add("Camera"); + axisCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + Combo c = (Combo)e.getSource(); + index = c.getSelectionIndex(); + updateLock(); + panel.getComponent().setFocus(); + } + }); + axisCombo.select(index); + + Button close = new Button(toolComposite, SWT.PUSH); + close.setText("Close"); + close.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + panel.useDefaultAction(); + }; + }); + toolComposite.relayout(); + } + public void attach() { if (node == null) return; - + if (toolComposite != null) { + createTools(toolComposite); + } super.attach(); ThreadUtils.asyncExec(panel.getThreadQueue(), new Runnable() { public void run() { @@ -139,9 +179,12 @@ public class RotateAction extends vtkSwtAction{ } public void deattach() { - + if (toolComposite != null) { + toolComposite.clear(); + axisCombo = null; + } node = null; - nodeMap.commit(); + nodeMap.commit("Rotate"); deattachUI(); super.deattach(); panel.refresh(); @@ -184,11 +227,19 @@ public class RotateAction extends vtkSwtAction{ if (e.getKeyCode() == KeyEvent.VK_G) { worldCoord = !worldCoord; } - gizmo.setType(index); - panel.refresh(); + + updateLock(); + return true; } + private void updateLock() { + gizmo.setType(index); + if (axisCombo != null) + axisCombo.select(index); + panel.refresh(); + } + @Override public boolean keyReleased(KeyEvent e) { return false; @@ -227,7 +278,7 @@ public class RotateAction extends vtkSwtAction{ private void update() { Vector3d nodePos = node.getWorldPosition(); - System.out.println(nodePos); +// System.out.println(nodePos); gizmo.setPosition(nodePos); if (worldCoord) { gizmo.setRotation(new AxisAngle4d()); @@ -251,31 +302,31 @@ public class RotateAction extends vtkSwtAction{ if (panel.getRenderer().GetActiveCamera().GetParallelProjection() == 0) { double distance = p.length(); p.negate(); - double fov = panel.getRenderer().GetActiveCamera().GetViewAngle(); - float s = (float) (Math.sin(fov) * distance * 0.1); + double fov = panel.getRenderer().GetActiveCamera().GetViewAngle(); + float s = (float) (Math.sin(fov) * distance * 0.1); - Vector3d scale = new Vector3d(1., 1., 1.); - + Vector3d scale = new Vector3d(1., 1., 1.); + // if (p.x > 0.f) // scale.x = -1.; // if (p.y > 0.f) // scale.y = -1.; // if (p.z > 0.f) // scale.z = -1.; - scale.scale(s); - gizmo.setScale(scale); + scale.scale(s); + gizmo.setScale(scale); } else { Vector3d scale = new Vector3d(1.f, 1.f, 1.f); - double s = panel.getRenderer().GetActiveCamera().GetParallelScale() / 5.; + double s = panel.getRenderer().GetActiveCamera().GetParallelScale() / 5.; // if (p.x > 0.f) // scale.x = -1.; // if (p.y > 0.f) // scale.y = -1.; // if (p.z > 0.f) // scale.z = -1.; - scale.scale(s); - gizmo.setScale(scale); + scale.scale(s); + gizmo.setScale(scale); } panel.refresh(); @@ -303,9 +354,9 @@ public class RotateAction extends vtkSwtAction{ valid = true; if ((e.getModifiers() & MouseEvent.CTRL_MASK) > 0) { useStep = true; - } else { - useStep = false; - } + } else { + useStep = false; + } worldOrientation = node.getWorldOrientation(); doChanges(true, e.getX(), e.getY()); @@ -340,9 +391,9 @@ public class RotateAction extends vtkSwtAction{ if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) > 0 && valid) { if ((e.getModifiers() & MouseEvent.CTRL_MASK) > 0) { useStep = true; - } else { - useStep = false; - } + } else { + useStep = false; + } doChanges(false, e.getX(), e.getY()); //nodeMap.modified(node); @@ -354,188 +405,188 @@ public class RotateAction extends vtkSwtAction{ return true; } - Vector3d axis = null; + Vector3d axis = null; @Override public boolean keyTyped(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_LEFT) { - inputType = InputType.KEY; - axis = new Vector3d(0.0,1.0,0.0); - } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { - inputType = InputType.KEY; - axis = new Vector3d(0.0,-1.0,0.0); - } else if (e.getKeyCode() ==KeyEvent.VK_UP) { - inputType = InputType.KEY; - axis = new Vector3d(1.0,0.0,0.0); - } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { - inputType = InputType.KEY; - axis = new Vector3d(-1.0,0.0,0.0); - } - return true; + if (e.getKeyCode() == KeyEvent.VK_LEFT) { + inputType = InputType.KEY; + axis = new Vector3d(0.0,1.0,0.0); + } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { + inputType = InputType.KEY; + axis = new Vector3d(0.0,-1.0,0.0); + } else if (e.getKeyCode() ==KeyEvent.VK_UP) { + inputType = InputType.KEY; + axis = new Vector3d(1.0,0.0,0.0); + } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { + inputType = InputType.KEY; + axis = new Vector3d(-1.0,0.0,0.0); + } + return true; } - public void doChanges(boolean pressed, int x, int y) { - Ray ray = vtkUtil.createMouseRay(panel.getRenderer(),x, y); - Vector3d p = node.getWorldPosition(); - - if (pressed) { - Vector3d axis = getRotationAxis(); - if (axis != null) { - if (!worldCoord) { - MathTools.rotate(parentWorldOrientation, axis, axis); - } + public void doChanges(boolean pressed, int x, int y) { + Ray ray = vtkUtil.createMouseRay(panel.getRenderer(),x, y); + Vector3d p = node.getWorldPosition(); + + if (pressed) { + Vector3d axis = getRotationAxis(); + if (axis != null) { + if (!worldCoord) { + MathTools.rotate(parentWorldOrientation, axis, axis); + } - - double s[] = new double[2]; - Vector3d i2 = new Vector3d(); - - boolean intersect = MathTools.intersectStraightPlane(ray.pos, ray.dir, p, axis, i2, s); - double dot = Math.abs(ray.dir.dot(axis)); - if (intersect && dot > 0.4) - inputType = InputType.INTERSECT; - else - inputType = InputType.NONINTERSECT; - - - if (inputType == InputType.INTERSECT) { - // picking ray and plane defined by gizmo's center point and - // rotation axis can intersect - // vector from center point to intersection point - i2.sub(p); - // creating vectors i and j that are lying on the plane and - // are perpendicular - // vectors are used to calculate polar coordinate for - // intersection point - j.set(i2); - i.cross(j, axis); - System.out.println("I,J " + i + " " + j); - double angleI = i2.angle(i); - double angleJ = i2.angle(j); - prevAngle = Math.atan2(Math.cos(angleJ), Math.cos(angleI)); - } else { - // picking ray and plane defined by gizmo's center point and - // rotation axis are parallel, - // so we'll use cross product of rotation axis and picking - // ray to detect amount of rotation - i.cross(ray.dir, axis); - MathTools.intersectStraightStraight(ray.pos, ray.dir, p, i, new Vector3d(), new Vector3d(), s); - prevS = s[1]; - } - } - - - } + + double s[] = new double[2]; + Vector3d i2 = new Vector3d(); + + boolean intersect = MathTools.intersectStraightPlane(ray.pos, ray.dir, p, axis, i2, s); + double dot = Math.abs(ray.dir.dot(axis)); + if (intersect && dot > 0.4) + inputType = InputType.INTERSECT; + else + inputType = InputType.NONINTERSECT; + + + if (inputType == InputType.INTERSECT) { + // picking ray and plane defined by gizmo's center point and + // rotation axis can intersect + // vector from center point to intersection point + i2.sub(p); + // creating vectors i and j that are lying on the plane and + // are perpendicular + // vectors are used to calculate polar coordinate for + // intersection point + j.set(i2); + i.cross(j, axis); +// System.out.println("I,J " + i + " " + j); + double angleI = i2.angle(i); + double angleJ = i2.angle(j); + prevAngle = Math.atan2(Math.cos(angleJ), Math.cos(angleI)); + } else { + // picking ray and plane defined by gizmo's center point and + // rotation axis are parallel, + // so we'll use cross product of rotation axis and picking + // ray to detect amount of rotation + i.cross(ray.dir, axis); + MathTools.intersectStraightStraight(ray.pos, ray.dir, p, i, new Vector3d(), new Vector3d(), s); + prevS = s[1]; + } + } + + + } - if (inputType != InputType.KEY) - axis = getRotationAxis(); - if (axis == null) { - return; - } - Vector3d taxis = null; - if (!worldCoord) { - taxis = new Vector3d(axis); - MathTools.rotate(parentWorldOrientation, axis, axis); - } - System.out.println(inputType); - if (inputType == InputType.INTERSECT) { + if (inputType != InputType.KEY) + axis = getRotationAxis(); + if (axis == null) { + return; + } + Vector3d taxis = null; + if (!worldCoord) { + taxis = new Vector3d(axis); + MathTools.rotate(parentWorldOrientation, axis, axis); + } +// System.out.println(inputType); + if (inputType == InputType.INTERSECT) { - double s[] = new double[2]; - Vector3d i2 = new Vector3d(); - MathTools.intersectStraightPlane(ray.pos, ray.dir, p, axis, i2, s); - i2.sub(p); - double angleI = i2.angle(i); - double angleJ = i2.angle(j); - double angle = Math.atan2(Math.cos(angleJ), Math.cos(angleI)); - System.out.println("Angle " + angle + " i " + angleI + " j " + angleJ + " prev " + prevAngle); - if(!worldCoord) - axis = taxis; - if (useStep) { + double s[] = new double[2]; + Vector3d i2 = new Vector3d(); + MathTools.intersectStraightPlane(ray.pos, ray.dir, p, axis, i2, s); + i2.sub(p); + double angleI = i2.angle(i); + double angleJ = i2.angle(j); + double angle = Math.atan2(Math.cos(angleJ), Math.cos(angleI)); +// System.out.println("Angle " + angle + " i " + angleI + " j " + angleJ + " prev " + prevAngle); + if(!worldCoord) + axis = taxis; + if (useStep) { - //setOrientation(MathTools.getQuat(rotation)); - AxisAngle4d rot = new AxisAngle4d(axis,angle-prevAngle); - Quat4d qrot = new Quat4d(); - MathTools.getQuat(rot, qrot); - //prevAngle = angle; - qrot.mulInverse(worldOrientation); - - - if (stepMethod == 0) { - rot.set(qrot); - rot.angle = roundAngle(rot.angle); - //qrot.set(rot); - MathTools.getQuat(rot,qrot); - setOrientation(qrot); - } else if (stepMethod == 1){ - - //Vector3d euler = MathTools.getEuler(qrot); - Vector3d euler = EulerTools.getEulerFromQuat(order, qrot); - euler.x = roundAngle(euler.x); - euler.y = roundAngle(euler.y); - euler.z = roundAngle(euler.z); - //Quat4d q = MathTools.getQuat(euler); - Quat4d q = EulerTools.getQuatFromEuler(order, euler); - setOrientation(q); - System.out.println(" (" + MathTools.radToDeg(euler.x) + " " + MathTools.radToDeg(euler.y) + " " + MathTools.radToDeg(euler.z) + ") " + qrot + " "+ q); - } else { - setOrientation(qrot); - } - - } else { - if (worldCoord) { - //G3DTools.multiplyOrientation(mo.getG3DNode(graph).getWorldOrientation(), new AxisAngle4d(axis,angle-prevAngle)); - AxisAngle4d aa = MathTools.getAxisAngle(node.getWorldOrientation()); - AxisAngle4d rot = new AxisAngle4d(axis,angle-prevAngle); - MathTools.multiplyOrientation(aa, rot); - setWorldOrientation(MathTools.getQuat(rot)); - } else { - AxisAngle4d aa = MathTools.getAxisAngle(node.getOrientation()); - AxisAngle4d rot = new AxisAngle4d(axis,angle-prevAngle); - MathTools.multiplyOrientation(aa, rot); - setOrientation(MathTools.getQuat(rot)); - //G3DTools.multiplyOrientation(mo.getG3DNode(graph).getLocalOrientation(), new AxisAngle4d(axis,angle-prevAngle)); - } - prevAngle = angle; - } - - } else if (inputType == InputType.NONINTERSECT){ + //setOrientation(MathTools.getQuat(rotation)); + AxisAngle4d rot = new AxisAngle4d(axis,angle-prevAngle); + Quat4d qrot = new Quat4d(); + MathTools.getQuat(rot, qrot); + //prevAngle = angle; + qrot.mulInverse(worldOrientation); + + + if (stepMethod == 0) { + rot.set(qrot); + rot.angle = roundAngle(rot.angle); + //qrot.set(rot); + MathTools.getQuat(rot,qrot); + setOrientation(qrot); + } else if (stepMethod == 1){ + + //Vector3d euler = MathTools.getEuler(qrot); + Vector3d euler = EulerTools.getEulerFromQuat(order, qrot); + euler.x = roundAngle(euler.x); + euler.y = roundAngle(euler.y); + euler.z = roundAngle(euler.z); + //Quat4d q = MathTools.getQuat(euler); + Quat4d q = EulerTools.getQuatFromEuler(order, euler); + setOrientation(q); +// System.out.println(" (" + MathTools.radToDeg(euler.x) + " " + MathTools.radToDeg(euler.y) + " " + MathTools.radToDeg(euler.z) + ") " + qrot + " "+ q); + } else { + setOrientation(qrot); + } + + } else { + if (worldCoord) { + //G3DTools.multiplyOrientation(mo.getG3DNode(graph).getWorldOrientation(), new AxisAngle4d(axis,angle-prevAngle)); + AxisAngle4d aa = MathTools.getAxisAngle(node.getWorldOrientation()); + AxisAngle4d rot = new AxisAngle4d(axis,angle-prevAngle); + MathTools.multiplyOrientation(aa, rot); + setWorldOrientation(MathTools.getQuat(rot)); + } else { + AxisAngle4d aa = MathTools.getAxisAngle(node.getOrientation()); + AxisAngle4d rot = new AxisAngle4d(axis,angle-prevAngle); + MathTools.multiplyOrientation(aa, rot); + setOrientation(MathTools.getQuat(rot)); + //G3DTools.multiplyOrientation(mo.getG3DNode(graph).getLocalOrientation(), new AxisAngle4d(axis,angle-prevAngle)); + } + prevAngle = angle; + } + + } else if (inputType == InputType.NONINTERSECT){ - double s[] = new double[2]; - MathTools.intersectStraightStraight(ray.pos, ray.dir, p, i, new Vector3d(), new Vector3d(), s); - if(!worldCoord) - axis = taxis; - if (useStep) { - //setOrientation(MathTools.getQuat(rotation)); - AxisAngle4d rot = new AxisAngle4d(axis,s[1] - prevS); - - Quat4d qrot = new Quat4d(); - //qrot.set(rot); - MathTools.getQuat(rot, qrot); - //prevAngle = angle; - qrot.mulInverse(worldOrientation); - - - if (stepMethod == 0) { - rot.set(qrot); - rot.angle = roundAngle(rot.angle); - //qrot.set(rot); - MathTools.getQuat(rot,qrot); - setOrientation(qrot); - } else if (stepMethod == 1){ - - //Vector3d euler = MathTools.getEuler(qrot); - Vector3d euler = EulerTools.getEulerFromQuat(order, qrot); - euler.x = roundAngle(euler.x); - euler.y = roundAngle(euler.y); - euler.z = roundAngle(euler.z); - //Quat4d q = MathTools.getQuat(euler); - Quat4d q = EulerTools.getQuatFromEuler(order, euler); - setOrientation(q); - System.out.println(" (" + MathTools.radToDeg(euler.x) + " " + MathTools.radToDeg(euler.y) + " " + MathTools.radToDeg(euler.z) + ") " + qrot + " "+ q); - } else { - setOrientation(qrot); - } - prevS = s[1]; - + double s[] = new double[2]; + MathTools.intersectStraightStraight(ray.pos, ray.dir, p, i, new Vector3d(), new Vector3d(), s); + if(!worldCoord) + axis = taxis; + if (useStep) { + //setOrientation(MathTools.getQuat(rotation)); + AxisAngle4d rot = new AxisAngle4d(axis,s[1] - prevS); + + Quat4d qrot = new Quat4d(); + //qrot.set(rot); + MathTools.getQuat(rot, qrot); + //prevAngle = angle; + qrot.mulInverse(worldOrientation); + + + if (stepMethod == 0) { + rot.set(qrot); + rot.angle = roundAngle(rot.angle); + //qrot.set(rot); + MathTools.getQuat(rot,qrot); + setOrientation(qrot); + } else if (stepMethod == 1){ + + //Vector3d euler = MathTools.getEuler(qrot); + Vector3d euler = EulerTools.getEulerFromQuat(order, qrot); + euler.x = roundAngle(euler.x); + euler.y = roundAngle(euler.y); + euler.z = roundAngle(euler.z); + //Quat4d q = MathTools.getQuat(euler); + Quat4d q = EulerTools.getQuatFromEuler(order, euler); + setOrientation(q); +// System.out.println(" (" + MathTools.radToDeg(euler.x) + " " + MathTools.radToDeg(euler.y) + " " + MathTools.radToDeg(euler.z) + ") " + qrot + " "+ q); + } else { + setOrientation(qrot); + } + prevS = s[1]; + // G3DTools.setOrientation(mo.getG3DNode(graph).getLocalOrientation(), rotations.get(mo)); // G3DTools.multiplyOrientation(mo.getG3DNode(graph).getWorldOrientation(), new AxisAngle4d(axis,s[1] - prevS)); // AxisAngle4d aa = G3DTools.getOrientation(mo.getG3DNode(graph).getLocalOrientation()); @@ -550,55 +601,55 @@ public class RotateAction extends vtkSwtAction{ // Vector3d e = MathTools.getEuler(G3DTools.getOrientation(mo.getG3DNode(graph).getLocalOrientation())); // e.scale(180.0/Math.PI); // text += G3DTools.getOrientation(mo.getG3DNode(graph).getLocalOrientation()) + " " + e + " "; - - - } else { - if (worldCoord) { - AxisAngle4d aa = MathTools.getAxisAngle(node.getWorldOrientation()); - AxisAngle4d rot = new AxisAngle4d(axis,s[1] - prevS); - MathTools.multiplyOrientation(aa, rot); - setWorldOrientation(MathTools.getQuat(rot)); - //G3DTools.multiplyOrientation(mo.getG3DNode(graph).getWorldOrientation(), new AxisAngle4d(axis,s[1] - prevS)); - } else { - AxisAngle4d aa = MathTools.getAxisAngle(node.getOrientation()); - AxisAngle4d rot = new AxisAngle4d(axis,s[1] - prevS); - MathTools.multiplyOrientation(aa, rot); - setOrientation(MathTools.getQuat(rot)); - //G3DTools.multiplyOrientation(mo.getG3DNode(graph).getLocalOrientation(), new AxisAngle4d(axis,s[1] - prevS)); - } - //text += G3DTools.getOrientation(mo.getG3DNode(graph).getLocalOrientation()) + " " + MathTools.getEuler(G3DTools.getOrientation(mo.getG3DNode(graph).getLocalOrientation())) + " "; - prevS = s[1]; - - } - - } else { - if (worldCoord) { - AxisAngle4d aa = MathTools.getAxisAngle(node.getWorldOrientation()); - AxisAngle4d rot = new AxisAngle4d(axis,Math.PI * 0.5); - MathTools.multiplyOrientation(aa, rot); - setWorldOrientation(MathTools.getQuat(rot)); - //G3DTools.multiplyOrientation(mo.getG3DNode(graph).getWorldOrientation(), new AxisAngle4d(axis,Math.PI * 0.5)); - } else { - AxisAngle4d aa = MathTools.getAxisAngle(node.getOrientation()); - AxisAngle4d rot = new AxisAngle4d(axis,Math.PI * 0.5); - MathTools.multiplyOrientation(aa, rot); - setOrientation(MathTools.getQuat(rot)); - //G3DTools.multiplyOrientation(mo.getG3DNode(graph).getLocalOrientation(), new AxisAngle4d(axis,Math.PI * 0.5)); - } - // text += G3DTools.getOrientation(mo.getG3DNode(graph).getLocalOrientation()) + " " + MathTools.getEuler(G3DTools.getOrientation(mo.getG3DNode(graph).getLocalOrientation())) + " "; - - } - //setInfoText(text); - - } - - protected void setOrientation(Quat4d q) { - node.setOrientation(q); - } - - protected void setWorldOrientation(Quat4d q) { - node.setWorldOrientation(q); - } + + + } else { + if (worldCoord) { + AxisAngle4d aa = MathTools.getAxisAngle(node.getWorldOrientation()); + AxisAngle4d rot = new AxisAngle4d(axis,s[1] - prevS); + MathTools.multiplyOrientation(aa, rot); + setWorldOrientation(MathTools.getQuat(rot)); + //G3DTools.multiplyOrientation(mo.getG3DNode(graph).getWorldOrientation(), new AxisAngle4d(axis,s[1] - prevS)); + } else { + AxisAngle4d aa = MathTools.getAxisAngle(node.getOrientation()); + AxisAngle4d rot = new AxisAngle4d(axis,s[1] - prevS); + MathTools.multiplyOrientation(aa, rot); + setOrientation(MathTools.getQuat(rot)); + //G3DTools.multiplyOrientation(mo.getG3DNode(graph).getLocalOrientation(), new AxisAngle4d(axis,s[1] - prevS)); + } + //text += G3DTools.getOrientation(mo.getG3DNode(graph).getLocalOrientation()) + " " + MathTools.getEuler(G3DTools.getOrientation(mo.getG3DNode(graph).getLocalOrientation())) + " "; + prevS = s[1]; + + } + + } else { + if (worldCoord) { + AxisAngle4d aa = MathTools.getAxisAngle(node.getWorldOrientation()); + AxisAngle4d rot = new AxisAngle4d(axis,Math.PI * 0.5); + MathTools.multiplyOrientation(aa, rot); + setWorldOrientation(MathTools.getQuat(rot)); + //G3DTools.multiplyOrientation(mo.getG3DNode(graph).getWorldOrientation(), new AxisAngle4d(axis,Math.PI * 0.5)); + } else { + AxisAngle4d aa = MathTools.getAxisAngle(node.getOrientation()); + AxisAngle4d rot = new AxisAngle4d(axis,Math.PI * 0.5); + MathTools.multiplyOrientation(aa, rot); + setOrientation(MathTools.getQuat(rot)); + //G3DTools.multiplyOrientation(mo.getG3DNode(graph).getLocalOrientation(), new AxisAngle4d(axis,Math.PI * 0.5)); + } + // text += G3DTools.getOrientation(mo.getG3DNode(graph).getLocalOrientation()) + " " + MathTools.getEuler(G3DTools.getOrientation(mo.getG3DNode(graph).getLocalOrientation())) + " "; + + } + //setInfoText(text); + + } + + protected void setOrientation(Quat4d q) { + node.setOrientation(q); + } + + protected void setWorldOrientation(Quat4d q) { + node.setWorldOrientation(q); + } @Override public boolean mouseMoved(MouseEvent e) { @@ -614,8 +665,7 @@ public class RotateAction extends vtkSwtAction{ case Z: return new Vector3d(0.0, 0.0, 1.0); case P: - Vector3d axis = new Vector3d(panel.getRenderer().GetActiveCamera() - .GetDirectionOfProjection()); + Vector3d axis = new Vector3d(panel.getRenderer().GetActiveCamera().GetDirectionOfProjection()); axis.normalize(); return axis; default: @@ -623,39 +673,39 @@ public class RotateAction extends vtkSwtAction{ } } - private double prevS = 0.0; - - private Vector3d i = new Vector3d(); - private Vector3d j = new Vector3d(); - private double prevAngle = 0; + private double prevS = 0.0; + + private Vector3d i = new Vector3d(); + private Vector3d j = new Vector3d(); + private double prevAngle = 0; - enum InputType{INTERSECT,NONINTERSECT,KEY,NONE}; - InputType inputType; - private boolean useStep = false; - - - - private double roundAngle(double angle) { - while (angle < - Math.PI) - angle += Math.PI*2.0; - while (angle > Math.PI) - angle -= Math.PI*2.0; - - - int index = 0; - while (angle > angles[index]) - index++; - if (index == 0) { - angle = angles[0]; - } else { - double d = angle - angles[index - 1]; - double d2 = angles[index] - angle; - if (d < d2) - angle = angles[index - 1]; - else - angle = angles[index]; - } - return angle; - } + enum InputType{INTERSECT,NONINTERSECT,KEY,NONE}; + InputType inputType; + private boolean useStep = false; + + + + private double roundAngle(double angle) { + while (angle < - Math.PI) + angle += Math.PI*2.0; + while (angle > Math.PI) + angle -= Math.PI*2.0; + + + int index = 0; + while (angle > angles[index]) + index++; + if (index == 0) { + angle = angles[0]; + } else { + double d = angle - angles[index - 1]; + double d2 = angles[index] - angle; + if (d < d2) + angle = angles[index - 1]; + else + angle = angles[index]; + } + return angle; + } }