use of com.ardor3d.math.type.ReadOnlyVector3 in project energy3d by concord-consortium.
the class Foundation method updateHandle.
private void updateHandle(final Vector3 p, final ReadOnlyVector3 dir) {
final ReadOnlyVector3 step = dir.normalize(null).multiplyLocal(3);
if (step.length() == 0) {
return;
}
final ReadOnlyVector3 center = getCenter();
p.set(center).addLocal(dir).addLocal(step);
final Point2D p2D = new Point2D.Double();
for (final HousePart part : Scene.getInstance().getParts()) {
if (part != this && part instanceof Foundation) {
final ArrayList<Vector3> points = part.getPoints();
final Path2D foundationPoly = new Path2D.Double();
foundationPoly.moveTo(points.get(0).getX(), points.get(0).getY());
foundationPoly.lineTo(points.get(2).getX(), points.get(2).getY());
foundationPoly.lineTo(points.get(3).getX(), points.get(3).getY());
foundationPoly.lineTo(points.get(1).getX(), points.get(1).getY());
foundationPoly.closePath();
p2D.setLocation(p.getX(), p.getY());
if (foundationPoly.contains(p2D)) {
while (foundationPoly.contains(p2D)) {
p.addLocal(step);
p2D.setLocation(p.getX(), p.getY());
}
p.addLocal(step);
}
}
}
}
use of com.ardor3d.math.type.ReadOnlyVector3 in project energy3d by concord-consortium.
the class Foundation method drawGrids.
@Override
public void drawGrids(final double gridSize) {
final ReadOnlyVector3 p0 = getAbsPoint(0);
final ReadOnlyVector3 p1 = getAbsPoint(1);
final ReadOnlyVector3 p2 = getAbsPoint(2);
final ReadOnlyVector3 width = p2.subtract(p0, null);
final ReadOnlyVector3 height = p1.subtract(p0, null);
final ArrayList<ReadOnlyVector3> points = new ArrayList<ReadOnlyVector3>();
final int cols = (int) (width.length() / gridSize);
for (int col = 0; col < cols + 1; col++) {
final ReadOnlyVector3 lineP1 = width.normalize(null).multiplyLocal(col * gridSize).addLocal(p0);
points.add(lineP1);
final ReadOnlyVector3 lineP2 = lineP1.add(height, null);
points.add(lineP2);
}
final int rows = (int) (height.length() / gridSize);
for (int row = 0; row < rows + 1; row++) {
final ReadOnlyVector3 lineP1 = height.normalize(null).multiplyLocal(row * gridSize).addLocal(p0);
points.add(lineP1);
final ReadOnlyVector3 lineP2 = lineP1.add(width, null);
points.add(lineP2);
}
if (points.size() < 2) {
return;
}
final FloatBuffer buf = BufferUtils.createVector3Buffer(points.size());
for (final ReadOnlyVector3 p : points) {
buf.put(p.getXf()).put(p.getYf()).put((float) this.height + 0.1f);
}
gridsMesh.getMeshData().setVertexBuffer(buf);
}
use of com.ardor3d.math.type.ReadOnlyVector3 in project energy3d by concord-consortium.
the class Foundation method rotate.
/**
* If center is null, use the center of this foundation. set update false if this is for rotating the coordinate system of this foundation for easier math
*/
public void rotate(final double angle, ReadOnlyVector3 center, final boolean update) {
final Matrix3 matrix = new Matrix3().fromAngles(0, 0, angle);
if (center == null) {
center = toRelative(getCenter().clone());
}
for (int i = 0; i < points.size(); i++) {
final Vector3 p = getAbsPoint(i);
final Vector3 op = p.subtract(center, null);
matrix.applyPost(op, op);
op.add(center, p);
points.get(i).set(toRelative(p));
}
if (update) {
if (SceneManager.getInstance().getSelectedPart() == this) {
drawAzimuthArrow();
}
clearSelectedMesh();
setRotatedNormalsForImportedMeshes();
updateImportedNodePositionsAfterRotate(matrix);
}
}
use of com.ardor3d.math.type.ReadOnlyVector3 in project energy3d by concord-consortium.
the class HipRoof method setPreviewPoint.
@Override
public void setPreviewPoint(final int x, final int y) {
final Foundation foundation = getTopContainer();
if (foundation != null && foundation.getLockEdit()) {
return;
}
final EditState editState = new EditState();
if (editPointIndex == -1) {
pickContainer(x, y, Wall.class);
recalculateEditPoints = true;
} else if (editPointIndex == 0) {
final ReadOnlyVector3 base = getCenter();
final Vector3 p = Util.closestPoint(base, Vector3.UNIT_Z, x, y);
if (p != null) {
snapToGrid(p, getAbsPoint(editPointIndex), getGridSize());
height = Math.max(0, p.getZ() - base.getZ());
}
} else if (editPointIndex == 1 || editPointIndex == 2) {
final Vector3 hipDirection = container.getAbsPoint(2).subtractLocal(container.getAbsPoint(0)).normalizeLocal();
final Vector3 p = Util.closestPoint(getAbsPoint(0), hipDirection, x, y);
if (p != null) {
// snapToGrid(p, getAbsPoint(editPointIndex), getGridSize(), false);
if (insideWallsPolygon(p)) {
points.get(editPointIndex).set(toRelative(p));
}
}
}
postEdit(editState);
}
use of com.ardor3d.math.type.ReadOnlyVector3 in project energy3d by concord-consortium.
the class HousePart method drawArrow.
protected void drawArrow(final ReadOnlyVector3 o, final ReadOnlyVector3 normal, final FloatBuffer arrowsVertices, final double heat) {
if (this instanceof Wall) {
final Wall wall = (Wall) this;
for (final HousePart x : wall.children) {
if (x instanceof Window || x instanceof Door) {
final Vector3 vo = x.toRelative(o);
double xmin = 2;
double zmin = 2;
double xmax = -2;
double zmax = -2;
for (final Vector3 a : x.points) {
if (a.getX() > xmax) {
xmax = a.getX();
}
if (a.getZ() > zmax) {
zmax = a.getZ();
}
if (a.getX() < xmin) {
xmin = a.getX();
}
if (a.getZ() < zmin) {
zmin = a.getZ();
}
}
if (vo.getX() > xmin && vo.getZ() > zmin && vo.getX() < xmax && vo.getZ() < zmax) {
return;
}
}
}
}
arrowsVertices.put(o.getXf()).put(o.getYf()).put(o.getZf());
final Vector3 p = new Vector3();
normal.multiply(Scene.getInstance().getHeatVectorLength() * Math.abs(heat), p);
final Vector3 p2 = new Vector3();
o.add(p, p2);
arrowsVertices.put(p2.getXf()).put(p2.getYf()).put(p2.getZf());
if (heat < 0) {
p2.set(o);
}
if (heat != 0) {
final float arrowLength = 0.5f;
p.normalizeLocal();
final double sign = Math.signum(heat);
if (this instanceof Roof) {
final float px = (float) (p.getX() * arrowLength * sign);
final float py = (float) (p.getY() * arrowLength * sign);
final float pz = (float) (p.getZ() * arrowLength * sign);
final float yp = -pz;
final float zp = py;
arrowsVertices.put(p2.getXf()).put(p2.getYf()).put(p2.getZf());
arrowsVertices.put(p2.getXf() - px).put(p2.getYf() - py + yp * 0.25f).put(p2.getZf() - pz + zp * 0.25f);
arrowsVertices.put(p2.getXf()).put(p2.getYf()).put(p2.getZf());
arrowsVertices.put(p2.getXf() - px).put(p2.getYf() - py - yp * 0.25f).put(p2.getZf() - pz - zp * 0.25f);
} else if (this instanceof Foundation) {
final float cos = (float) (p.dot(Vector3.UNIT_X) * sign);
final float sin = (float) (p.dot(Vector3.UNIT_Z) * sign);
arrowsVertices.put(p2.getXf()).put(p2.getYf()).put(p2.getZf());
arrowsVertices.put(p2.getXf() - arrowLength * cos).put(p2.getYf() - arrowLength * 0.5f).put(p2.getZf() - arrowLength * sin);
arrowsVertices.put(p2.getXf()).put(p2.getYf()).put(p2.getZf());
arrowsVertices.put(p2.getXf() - arrowLength * cos).put(p2.getYf() + arrowLength * 0.5f).put(p2.getZf() - arrowLength * sin);
} else {
final float cos = (float) (p.dot(Vector3.UNIT_X) * sign);
final float sin = (float) (p.dot(Vector3.UNIT_Y) * sign);
arrowsVertices.put(p2.getXf()).put(p2.getYf()).put(p2.getZf());
arrowsVertices.put(p2.getXf() - arrowLength * cos).put(p2.getYf() - arrowLength * sin).put(p2.getZf() - arrowLength * 0.5f);
arrowsVertices.put(p2.getXf()).put(p2.getYf()).put(p2.getZf());
arrowsVertices.put(p2.getXf() - arrowLength * cos).put(p2.getYf() - arrowLength * sin).put(p2.getZf() + arrowLength * 0.5f);
}
}
}
Aggregations