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=bd581ac2c3b2d7639865c8ac9d66f02701a0360a;hb=53d55c24c779745f188bdb18d32f71d20acb61b2;hp=c45316e8c10dfc68d7e9d064e4cf85bedf4ff47a;hpb=f36217aeeb09c0c46f99886ee99772156ce9cfe6;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 c45316e8..bd581ac2 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 @@ -47,9 +47,9 @@ 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 TranslateGizmo gizmo = new TranslateGizmo(); @@ -65,8 +65,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; @@ -113,13 +113,13 @@ public class RotateAction extends vtkSwtAction{ 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); } public void attach() { @@ -251,31 +251,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 +303,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 +340,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 +354,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 +550,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) { @@ -623,39 +623,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; + } }