Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void rotate(double angleDiff, Axis axis) {
- Vec3d vec3d = SpaceTransforms.rotateOnPlaneBy(angleDiff, c.getAngle());
- switch (axis) {
- case X:
- addRotate(this, new Rotate(0, Rotate.X_AXIS), relativeRotate(vec3d.x, Rotate.X_AXIS));
- break;
- case Y:
- addRotate(this, new Rotate(0, Rotate.Y_AXIS), relativeRotate(vec3d.y, Rotate.Y_AXIS));
- break;
- case Z:
- addRotate(this, new Rotate(0, Rotate.Z_AXIS), relativeRotate(vec3d.z, Rotate.Z_AXIS));
- break;
- }
- //TransformUtil.cleanupTransform(this);
- }
- private void addRotate(Node node, Rotate rotate, double angle) {
- Affine affine = node.getTransforms().isEmpty() ? new Affine() : new Affine(node.getTransforms().get(0));
- double A11 = affine.getMxx(), A12 = affine.getMxy(), A13 = affine.getMxz();
- double A21 = affine.getMyx(), A22 = affine.getMyy(), A23 = affine.getMyz();
- double A31 = affine.getMzx(), A32 = affine.getMzy(), A33 = affine.getMzz();
- // rotations over local axis
- Rotate newRotateX = new Rotate(angle, new Point3D(A11, A21, A31));
- Rotate newRotateY = new Rotate(angle, new Point3D(A12, A22, A32));
- Rotate newRotateZ = new Rotate(angle, new Point3D(A13, A23, A33));
- // apply rotation
- affine.prepend(rotate.getAxis() == Rotate.X_AXIS ?
- newRotateX :
- rotate.getAxis() == Rotate.Y_AXIS ? newRotateY : newRotateZ);
- node.getTransforms().setAll(affine);
- }
- private double relativeRotate(double rotate, Point3D axis) {
- Vec3d oa = TransformUtil.getAngle(this);
- Vec3d ca = TransformUtil.getAngle(c);
- System.out.println("x: " + oa.x + ", y: " + oa.y + ", z: " + oa.z);
- /*if (axis == Rotate.X_AXIS) {
- return changeSign(rotate, Math.abs(oa.x - ca.x));
- } else if (axis == Rotate.Y_AXIS) {
- return changeSign(rotate, Math.abs(oa.y - ca.y));
- } else if (axis == Rotate.Z_AXIS) {
- return changeSign(rotate, Math.abs(oa.z - ca.z));
- } else*/
- return rotate;
- }
- TransformUtil.java ...
- public static Vec3d getAngle(Node n) {
- Transform T = n.getLocalToSceneTransform();
- double roll = Math.atan2(-T.getMyx(), T.getMxx());
- double pitch = Math.atan2(-T.getMzy(), T.getMzz());
- double yaw = Math.atan2(T.getMzx(), Math.sqrt(T.getMzy() * T.getMzy() + T.getMzz() * T.getMzz()));
- return new Vec3d(roll, pitch, yaw);
- }
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement