X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d.vtk%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fvtk%2Fswt%2FTranslateAction.java;h=47a3ea3b7a82cf0faec732e13c8d9739a5270229;hb=53d55c24c779745f188bdb18d32f71d20acb61b2;hp=83c434bb6ee15bdcada1aee42e3019e62e8e8d42;hpb=f36217aeeb09c0c46f99886ee99772156ce9cfe6;p=simantics%2F3d.git diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/TranslateAction.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/TranslateAction.java index 83c434bb..47a3ea3b 100644 --- a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/TranslateAction.java +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/TranslateAction.java @@ -40,12 +40,12 @@ import vtk.vtkProp; public class TranslateAction extends vtkSwtAction{ public static final int X = 0; - public static final int Y = 1; - public static final int Z = 2; - public static final int XY = 3; - public static final int XZ = 4; - public static final int YZ = 5; - public static final int P = 6; + public static final int Y = 1; + public static final int Z = 2; + public static final int XY = 3; + public static final int XZ = 4; + public static final int YZ = 5; + public static final int P = 6; private VTKNodeMap nodeMap; //private TranslateGizmo gizmo = new TranslateGizmo(); @@ -77,7 +77,7 @@ public class TranslateAction extends vtkSwtAction{ this.nodeMap = nodeMap; activeCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_HAND); - dragCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_SIZEALL); + dragCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_SIZEALL); } public void attach() { @@ -226,31 +226,31 @@ public class TranslateAction 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.Render(); @@ -333,9 +333,9 @@ public class TranslateAction extends vtkSwtAction{ } @Override - public boolean mouseWheelMoved(MouseWheelEvent e) { - return getDefaultAction().mouseWheelMoved(e); - } + public boolean mouseWheelMoved(MouseWheelEvent e) { + return getDefaultAction().mouseWheelMoved(e); + } protected void setPos(Vector3d pos) { node.setPosition(pos); @@ -345,31 +345,31 @@ public class TranslateAction extends vtkSwtAction{ node.setWorldPosition(pos); } - private double istep = 10.0; - private int decimals = 2; + private double istep = 10.0; + private int decimals = 2; protected Vector3d constaints(Vector3d p, boolean step) { if(!step) return p; switch (index) { case X: - p.x = Math.round(istep * p.x) / istep; - BigDecimal bx = new BigDecimal(p.x); - bx.setScale(decimals, BigDecimal.ROUND_HALF_UP); - p.x = bx.doubleValue(); + p.x = Math.round(istep * p.x) / istep; + BigDecimal bx = new BigDecimal(p.x); + bx.setScale(decimals, BigDecimal.ROUND_HALF_UP); + p.x = bx.doubleValue(); break; case Y: - p.y = Math.round(istep * p.y) / istep; - BigDecimal by = new BigDecimal(p.y); - by.setScale(decimals, BigDecimal.ROUND_HALF_UP); - p.y = by.doubleValue(); + p.y = Math.round(istep * p.y) / istep; + BigDecimal by = new BigDecimal(p.y); + by.setScale(decimals, BigDecimal.ROUND_HALF_UP); + p.y = by.doubleValue(); break; - + case Z: - p.z = Math.round(istep * p.z) / istep; - BigDecimal bz = new BigDecimal(p.z); - bz.setScale(decimals, BigDecimal.ROUND_HALF_UP); - p.z = bz.doubleValue(); + p.z = Math.round(istep * p.z) / istep; + BigDecimal bz = new BigDecimal(p.z); + bz.setScale(decimals, BigDecimal.ROUND_HALF_UP); + p.z = bz.doubleValue(); break; } return p; @@ -401,85 +401,85 @@ public class TranslateAction extends vtkSwtAction{ } normal.normalize(); double s[] = new double[1]; - Vector3d r = new Vector3d(); - if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) { - r.sub(p); - translate.x = r.x; - translate.y = r.y; - translate.z = r.z; - } - break; + Vector3d r = new Vector3d(); + if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) { + r.sub(p); + translate.x = r.x; + translate.y = r.y; + translate.z = r.z; + } + break; - case X : - dir = new Vector3d(1.0,0.0,0.0); - if(!worldCoord) - MathTools.rotate(q, dir, dir); - Vector3d i1 = new Vector3d(); - Vector3d i2 = new Vector3d(); - s = new double[2]; - MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,s); - translate.x = s[0]; - - break; - case Y : - dir = new Vector3d(0.0,1.0,0.0); - if(!worldCoord) - MathTools.rotate(q, dir, dir); - i1 = new Vector3d(); - i2 = new Vector3d(); - s = new double[2]; - MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,s); - translate.y = s[0]; - break; - case Z : - dir = new Vector3d(0.0,0.0,1.0); - if(!worldCoord) - MathTools.rotate(q, dir, dir); - i1 = new Vector3d(); - i2 = new Vector3d(); - s = new double[2]; - MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,s); - translate.z = s[0]; - break; - case XY : - normal = new Vector3d(0.0,0.0,1.0); - if(!worldCoord) - MathTools.rotate(q, normal, normal); - r = new Vector3d(); - if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) { - r.sub(p); - translate.x = r.x; - translate.y = r.y; - } - break; - case XZ : - normal = new Vector3d(0.0,1.0,0.0); - if(!worldCoord) - MathTools.rotate(q, normal, normal); - r = new Vector3d(); - if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) { - r.sub(p); - translate.x = r.x; - translate.z = r.z; - } - break; - case YZ : - normal = new Vector3d(1.0,0.0,0.0); - if(!worldCoord) - MathTools.rotate(q, normal, normal); - r = new Vector3d(); - if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) { - r.sub(p); - translate.y = r.y; - translate.z = r.z; - } - break; - default : - - return null; - } - translate.sub(offset); - return translate; + case X : + dir = new Vector3d(1.0,0.0,0.0); + if(!worldCoord) + MathTools.rotate(q, dir, dir); + Vector3d i1 = new Vector3d(); + Vector3d i2 = new Vector3d(); + s = new double[2]; + MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,s); + translate.x = s[0]; + + break; + case Y : + dir = new Vector3d(0.0,1.0,0.0); + if(!worldCoord) + MathTools.rotate(q, dir, dir); + i1 = new Vector3d(); + i2 = new Vector3d(); + s = new double[2]; + MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,s); + translate.y = s[0]; + break; + case Z : + dir = new Vector3d(0.0,0.0,1.0); + if(!worldCoord) + MathTools.rotate(q, dir, dir); + i1 = new Vector3d(); + i2 = new Vector3d(); + s = new double[2]; + MathTools.intersectStraightStraight( p, dir,ray.pos, ray.dir, i2, i1,s); + translate.z = s[0]; + break; + case XY : + normal = new Vector3d(0.0,0.0,1.0); + if(!worldCoord) + MathTools.rotate(q, normal, normal); + r = new Vector3d(); + if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) { + r.sub(p); + translate.x = r.x; + translate.y = r.y; + } + break; + case XZ : + normal = new Vector3d(0.0,1.0,0.0); + if(!worldCoord) + MathTools.rotate(q, normal, normal); + r = new Vector3d(); + if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) { + r.sub(p); + translate.x = r.x; + translate.z = r.z; + } + break; + case YZ : + normal = new Vector3d(1.0,0.0,0.0); + if(!worldCoord) + MathTools.rotate(q, normal, normal); + r = new Vector3d(); + if (MathTools.intersectStraightPlane(ray.pos, ray.dir, p, normal, r)) { + r.sub(p); + translate.y = r.y; + translate.z = r.z; + } + break; + default : + + return null; + } + translate.sub(offset); + return translate; } }