Advertisement
MysteriousWolf

OrbitTool

Apr 2nd, 2018
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.20 KB | None | 0 0
  1. public void rotate(double angleDiff, Axis axis) {
  2.     Vec3d vec3d = SpaceTransforms.rotateOnPlaneBy(angleDiff, c.getAngle());
  3.  
  4.     switch (axis) {
  5.     case X:
  6.         addRotate(this, new Rotate(0, Rotate.X_AXIS), relativeRotate(vec3d.x, Rotate.X_AXIS));
  7.         break;
  8.     case Y:
  9.         addRotate(this, new Rotate(0, Rotate.Y_AXIS), relativeRotate(vec3d.y, Rotate.Y_AXIS));
  10.         break;
  11.     case Z:
  12.         addRotate(this, new Rotate(0, Rotate.Z_AXIS), relativeRotate(vec3d.z, Rotate.Z_AXIS));
  13.         break;
  14.     }
  15.     //TransformUtil.cleanupTransform(this);
  16. }
  17.  
  18. private void addRotate(Node node, Rotate rotate, double angle) {
  19.     Affine affine = node.getTransforms().isEmpty() ? new Affine() : new Affine(node.getTransforms().get(0));
  20.     double A11 = affine.getMxx(), A12 = affine.getMxy(), A13 = affine.getMxz();
  21.     double A21 = affine.getMyx(), A22 = affine.getMyy(), A23 = affine.getMyz();
  22.     double A31 = affine.getMzx(), A32 = affine.getMzy(), A33 = affine.getMzz();
  23.     // rotations over local axis
  24.     Rotate newRotateX = new Rotate(angle, new Point3D(A11, A21, A31));
  25.     Rotate newRotateY = new Rotate(angle, new Point3D(A12, A22, A32));
  26.     Rotate newRotateZ = new Rotate(angle, new Point3D(A13, A23, A33));
  27.     // apply rotation
  28.     affine.prepend(rotate.getAxis() == Rotate.X_AXIS ?
  29.             newRotateX :
  30.             rotate.getAxis() == Rotate.Y_AXIS ? newRotateY : newRotateZ);
  31.     node.getTransforms().setAll(affine);
  32. }
  33.  
  34. private double relativeRotate(double rotate, Point3D axis) {
  35.     Vec3d oa = TransformUtil.getAngle(this);
  36.     Vec3d ca = TransformUtil.getAngle(c);
  37.     System.out.println("x: " + oa.x + ", y: " + oa.y + ", z: " + oa.z);
  38.     /*if (axis == Rotate.X_AXIS) {
  39.         return changeSign(rotate, Math.abs(oa.x - ca.x));
  40.     } else if (axis == Rotate.Y_AXIS) {
  41.         return changeSign(rotate, Math.abs(oa.y - ca.y));
  42.     } else if (axis == Rotate.Z_AXIS) {
  43.         return changeSign(rotate, Math.abs(oa.z - ca.z));
  44.     } else*/
  45.     return rotate;
  46. }
  47.  
  48.  
  49. TransformUtil.java ...
  50. public static Vec3d getAngle(Node n) {
  51.         Transform T = n.getLocalToSceneTransform();
  52.         double roll = Math.atan2(-T.getMyx(), T.getMxx());
  53.         double pitch = Math.atan2(-T.getMzy(), T.getMzz());
  54.         double yaw = Math.atan2(T.getMzx(), Math.sqrt(T.getMzy() * T.getMzy() + T.getMzz() * T.getMzz()));
  55.         return new Vec3d(roll, pitch, yaw);
  56. }
  57. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement