use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class HousePart method getAbsCenter.
public Vector3 getAbsCenter() {
double x = 0, y = 0, z = 0;
final int n = points.size();
for (int i = 0; i < n; i++) {
final Vector3 v = getAbsPoint(i);
x += v.getX();
y += v.getY();
z += v.getZ();
}
final double invert = 1.0 / n;
return new Vector3(x * invert, y * invert, z * invert);
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class HousePart method flatten.
public void flatten(final double flattenTime) {
if (isPrintable()) {
if (isPrintVertical) {
root.setRotation(new Matrix3().fromAngles(0, -Math.PI / 2.0 * flattenTime, 0).multiply(root.getRotation(), null));
}
final Vector3 targetCenter = new Vector3(((UserData) mesh.getUserData()).getPrintCenter());
root.setTranslation(targetCenter.subtractLocal(flattenCenter).multiplyLocal(flattenTime));
root.updateGeometricState(0);
}
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class HousePart method toRelative.
public Vector3 toRelative(final ReadOnlyVector3 p) {
final HousePart container = getContainerRelative();
if (container == null) {
return p.clone();
}
final Vector3 p0 = container.getAbsPoint(0);
final Vector3 p1 = container.getAbsPoint(1);
final Vector3 p2 = container.getAbsPoint(2);
final Vector2 p_2d = new Vector2(p.getX(), p.getY());
final Vector2 p0_2d = new Vector2(p0.getX(), p0.getY());
final double uScale = Util.projectPointOnLineScale(p_2d, p0_2d, new Vector2(p2.getX(), p2.getY()));
final double vScale;
final boolean relativeToHorizontal = getContainerRelative().isHorizontal();
if (relativeToHorizontal) {
vScale = Util.projectPointOnLineScale(p_2d, p0_2d, new Vector2(p1.getX(), p1.getY()));
return new Vector3(uScale, vScale, p.getZ());
} else {
vScale = Util.projectPointOnLineScale(new Vector2(0, p.getZ()), new Vector2(0, p0.getZ()), new Vector2(0, p1.getZ()));
return new Vector3(uScale, 0.0, vScale);
}
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class HousePart method updateEditShapes.
public void updateEditShapes() {
final Vector3 p = Vector3.fetchTempInstance();
try {
for (int i = 0; i < points.size(); i++) {
getAbsPoint(i, p);
if (!Double.isFinite(p.getZ())) {
p.setZ(1000);
}
getEditPointShape(i).setTranslation(p);
}
for (int i = 0; i < pointsRoot.getNumberOfChildren(); i++) {
final Camera camera = SceneManager.getInstance().getCamera();
if (camera != null && camera.getProjectionMode() != ProjectionMode.Parallel) {
final double distance = camera.getLocation().distance(getEditPointShape(i).getTranslation());
getEditPointShape(i).setScale(distance > 0.1 ? distance / 10 : 0.01);
} else {
getEditPointShape(i).setScale(camera.getFrustumTop() / 4);
}
}
} finally {
Vector3.releaseTempInstance(p);
}
// /* remove remaining edit shapes */
// for (int i = points.size(); i < pointsRoot.getNumberOfChildren(); i++) {
// pointsRoot.detachChildAt(points.size());
// }
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class HousePart method toAbsolute.
protected Vector3 toAbsolute(final ReadOnlyVector3 p, final Vector3 result) {
final HousePart container = getContainerRelative();
if (container == null) {
return result == null ? new Vector3(p) : result.set(p);
}
final Vector3 u = Vector3.fetchTempInstance();
final Vector3 v = Vector3.fetchTempInstance();
final Vector3 p0 = Vector3.fetchTempInstance();
Vector3 pointOnSpace;
try {
container.getAbsPoint(0, p0);
container.getAbsPoint(2, u).subtract(p0, u);
if (Util.isZero(u.length())) {
u.set(MathUtils.ZERO_TOLERANCE, 0, 0);
}
container.getAbsPoint(1, v).subtract(p0, v);
final boolean relativeToHorizontal = getContainerRelative().isHorizontal();
if (Util.isZero(v.length())) {
v.set(0, relativeToHorizontal ? MathUtils.ZERO_TOLERANCE : 0, relativeToHorizontal ? 0 : MathUtils.ZERO_TOLERANCE);
}
pointOnSpace = p0.add(u.multiply(p.getX(), u), u).add(v.multiply((relativeToHorizontal) ? p.getY() : p.getZ(), v), result);
if (relativeToHorizontal) {
pointOnSpace.setZ(pointOnSpace.getZ() + p.getZ());
}
} finally {
Vector3.releaseTempInstance(u);
Vector3.releaseTempInstance(v);
Vector3.releaseTempInstance(p0);
}
/* do not round the result, otherwise neighboring walls won't have exact same edit points */
return pointOnSpace;
}
Aggregations