]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Rotation angle fully in context of the path leg delta 95/3895/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Thu, 20 Feb 2020 16:31:32 +0000 (18:31 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Thu, 20 Feb 2020 16:31:53 +0000 (18:31 +0200)
gitlab #81

Change-Id: I4f03b62450af42e5680f9e689e6f2fd699184007

org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java

index 72ef4e687a0f378d24400f94ff79405585c61179..9e9beb9c37711e63012c006b4221839de8cfb819 100644 (file)
@@ -584,11 +584,16 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
 
                final P3DRootNode root = getRoot();
                Vector3d up = root != null ? new Vector3d(root.getUpVector()) : new Vector3d(0.0, 1.0, 0.0);
-               double a = up.angle(getPathLegEndpointVector());
+               final Vector3d legDir = getPathLegEndpointVector();
+               double a = up.angle(legDir);
                if (a < 0.1 || (Math.PI - a) < 0.1) {
                        // Rotate components
                        up.set(up.getY(), up.getZ(), up.getX());
                }
+               
+               // Project up vector into a normal of the leg direction before applying to 'dir'
+               MathTools.mad(up, legDir, -legDir.dot(up)/legDir.lengthSquared());
+               up.normalize();
 
                return getControlPointOrientationQuat(dir, up, angle);
        }