return type.name();
}
- public Quat4d getControlPointOrientationQuat(double angle) {
+ public Vector3d getPathLegEndpointVector() {
+ PipeControlPoint a = findPreviousEnd();
+ PipeControlPoint b = findNextEnd();
+
+ if (a == null || b == null) {
+ return getPathLegDirection();
+ }
+
+ Vector3d p1 = a.getWorldPosition();
+ Vector3d p2 = b.getWorldPosition();
+ p2.sub(p1);
+ double l = p2.length();
+ if (l != 0.0) {
+ p2.scale(1.0 / l);
+ return p2;
+ }
+ else {
+ return getPathLegDirection();
+ }
+ }
+ public Vector3d getPathLegDirection() {
if (turnAxis == null) {
- Vector3d dir = getPathLegDirection(Direction.NEXT);
- return getControlPointOrientationQuat(dir, angle);
+ return getPathLegDirection(Direction.NEXT);
} else {
Vector3d dir = getPathLegDirection(Direction.PREVIOUS);
if (dir != null) dir.negate();
+ return dir;
+ }
+ }
+
+ public Quat4d getControlPointOrientationQuat(double angle) {
+ Vector3d dir = getPathLegDirection();
+ if (turnAxis == null) {
+ return getControlPointOrientationQuat(dir, angle);
+ } else {
return getControlPointOrientationQuat(dir, turnAxis, angle);
}
}
}
public Quat4d getControlPointOrientationQuat(double angle, boolean reversed) {
-
- if (turnAxis == null) {
- Vector3d dir = getPathLegDirection(Direction.NEXT);
- return getControlPointOrientationQuat(dir, angle, reversed);
- } else {
- Vector3d dir = getPathLegDirection(Direction.PREVIOUS);
- dir.negate();
- return getControlPointOrientationQuat(dir, angle, reversed);
- }
+ Vector3d dir = getPathLegDirection();
+ return getControlPointOrientationQuat(dir, angle, reversed);
}
-
-
- public static Quat4d getControlPointOrientationQuat(Vector3d dir, double angle) {
+ public Quat4d getControlPointOrientationQuat(Vector3d dir, double angle) {
if (dir == null || dir.lengthSquared() < MathTools.NEAR_ZERO)
return MathTools.getIdentityQuat();
-
Vector3d up = new Vector3d(0.0, 1.0, 0.0);
- double a = up.angle(dir);
+ double a = up.angle(getPathLegEndpointVector());
if (a < 0.1 || (Math.PI - a) < 0.1) {
up.set(1.0, 0.0, 0.0);
}
-
return getControlPointOrientationQuat(dir, up, angle);
}