use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Wall method computeInsideDirectionOfAttachedWalls.
public void computeInsideDirectionOfAttachedWalls(final boolean drawNeighborWalls) {
if (this.thicknessNormal != null) {
return;
}
final ArrayList<Wall> walls;
if (drawNeighborWalls) {
walls = new ArrayList<Wall>();
} else {
walls = null;
}
final double[] side = new double[] { 0.0 };
Wall.clearVisits();
visitNeighbors(new WallVisitor() {
@Override
public void visit(final Wall wall, final Snap prev, final Snap next) {
if (next != null) {
final int indexP2 = next.getSnapPointIndexOf(wall);
final ReadOnlyVector3 p1 = wall.getAbsPoint(indexP2 == 0 ? 2 : 0);
final ReadOnlyVector3 p2 = wall.getAbsPoint(indexP2);
final ReadOnlyVector3 p3 = next.getNeighborOf(wall).getAbsPoint(next.getSnapPointIndexOfNeighborOf(wall) == 0 ? 2 : 0);
final ReadOnlyVector3 p1_p2 = p2.subtract(p1, null).normalizeLocal();
final ReadOnlyVector3 p2_p3 = p3.subtract(p2, null).normalizeLocal();
side[0] += Util.angleBetween(p1_p2, p2_p3, Vector3.UNIT_Z);
}
if (drawNeighborWalls && wall != Wall.this && !walls.contains(wall)) {
walls.add(wall);
}
}
});
Wall.clearVisits();
visitNeighbors(new WallVisitor() {
@Override
public void visit(final Wall wall, final Snap prev, final Snap next) {
if (next != null) {
final int indexP2 = next.getSnapPointIndexOf(wall);
final Vector3 p1 = wall.getAbsPoint(indexP2 == 0 ? 2 : 0);
final Vector3 p2 = wall.getAbsPoint(indexP2);
final Vector3 p1_p2 = p2.subtract(p1, null);
wall.thicknessNormal = p1_p2.cross(Vector3.UNIT_Z, null).normalizeLocal().multiplyLocal(wall.getThickness());
if (side[0] > 0) {
wall.thicknessNormal.negateLocal();
}
} else if (prev != null) {
final int indexP2 = prev.getSnapPointIndexOf(wall);
final Vector3 p2 = wall.getAbsPoint(indexP2);
final Vector3 p3 = wall.getAbsPoint(indexP2 == 0 ? 2 : 0);
final Vector3 p2_p3 = p3.subtract(p2, null);
wall.thicknessNormal = p2_p3.cross(Vector3.UNIT_Z, null).normalizeLocal().multiplyLocal(wall.getThickness());
if (side[0] > 0) {
wall.thicknessNormal.negateLocal();
}
}
}
});
if (drawNeighborWalls) {
for (final HousePart wall : walls) {
wall.draw();
wall.drawChildren();
}
}
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Wall method isAtSamePlaceAsAnotherPart.
public boolean isAtSamePlaceAsAnotherPart() {
final Vector3 p0 = getAbsPoint(0);
final Vector3 p2 = getAbsPoint(2);
for (final HousePart part : container.getChildren()) {
if (part != this && part instanceof Wall && part.isDrawCompleted()) {
final Vector3 q0 = part.getAbsPoint(0);
final Vector3 q2 = part.getAbsPoint(2);
if ((p0.equals(q0) && p2.equals(q2)) || (p2.equals(q0) && p0.equals(q2))) {
return true;
}
}
}
return false;
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Window method setPreviewPoint.
@Override
public void setPreviewPoint(final int x, final int y) {
final Foundation foundation = getTopContainer();
if (foundation != null && foundation.getLockEdit()) {
return;
}
int index = editPointIndex;
if (index == -1) {
if (isFirstPointInserted()) {
index = 3;
} else {
index = 0;
}
}
final PickedHousePart pick = pickContainer(x, y, new Class[] { Wall.class, Roof.class });
Vector3 p = points.get(index);
if (pick != null && !(pick.getUserData().getHousePart() instanceof Roof && isNormalHorizontal(pick))) {
p.set(pick.getPoint());
snapToGrid(p, getAbsPoint(index), getGridSize(), false);
p = toRelative(p);
if (container instanceof Wall) {
toAbsolute(p);
p = enforceContraints(p);
}
} else {
return;
}
final ArrayList<Vector3> orgPoints = new ArrayList<Vector3>(points.size());
for (final Vector3 v : points) {
orgPoints.add(v.clone());
}
points.get(index).set(p);
if (container instanceof Roof) {
computeNormalAndKeepOnSurface();
}
if (!isFirstPointInserted()) {
points.get(1).set(p);
if (container instanceof Roof) {
normal = (ReadOnlyVector3) ((Roof) container).getRoofPartsRoot().getChild(pick.getUserData().getEditPointIndex()).getUserData();
}
} else if (container instanceof Wall) {
if (index == 0 || index == 3) {
points.get(1).set(points.get(0).getX(), 0, points.get(3).getZ());
points.get(2).set(points.get(3).getX(), 0, points.get(0).getZ());
} else {
points.get(0).set(points.get(1).getX(), 0, points.get(2).getZ());
points.get(3).set(points.get(2).getX(), 0, points.get(1).getZ());
}
} else {
final boolean isFlat = MeshLib.isSameDirection(Vector3.UNIT_Z, normal);
final ReadOnlyVector3 u = isFlat ? Vector3.UNIT_X : Vector3.UNIT_Z.cross(normal, null);
final ReadOnlyVector3 v = isFlat ? Vector3.UNIT_Y : normal.cross(u, null);
if (index == 0 || index == 3) {
final Vector3 p0 = getAbsPoint(0);
final Vector3 p3 = getAbsPoint(3);
points.get(1).set(toRelative(Util.closestPoint(p0, v, p3, u)));
points.get(2).set(toRelative(Util.closestPoint(p0, u, p3, v)));
} else {
final Vector3 p1 = getAbsPoint(1);
final Vector3 p2 = getAbsPoint(2);
points.get(0).set(toRelative(Util.closestPoint(p1, v, p2, u)));
points.get(3).set(toRelative(Util.closestPoint(p1, u, p2, v)));
}
}
if (isFirstPointInserted()) {
if (container instanceof Wall && !((Wall) container).fits(this)) {
for (int i = 0; i < points.size(); i++) {
points.get(i).set(orgPoints.get(i));
}
return;
}
}
if (container != null) {
draw();
setEditPointsVisible(true);
container.draw();
}
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Window method drawMesh.
@Override
protected void drawMesh() {
if (points.size() < 4) {
return;
}
mesh.setVisible(container instanceof Roof);
normal = computeNormalAndKeepOnSurface();
final boolean isDrawable = isDrawable();
setHighlight(!isDrawable);
updateEditShapes();
final boolean drawBars = style != NO_MUNTIN_BAR && !Util.isEqual(getAbsPoint(2), getAbsPoint(0)) && !Util.isEqual(getAbsPoint(1), getAbsPoint(0));
final ReadOnlyVector3 meshOffset, barsOffset;
if (!isDrawable) {
meshOffset = new Vector3();
barsOffset = normal.multiply(0.1, null);
} else if (container instanceof Roof) {
if (drawBars) {
meshOffset = normal.multiply(-0.1, null);
barsOffset = new Vector3();
} else {
meshOffset = new Vector3();
barsOffset = null;
}
} else {
meshOffset = normal.multiply(-0.6, null);
if (drawBars) {
barsOffset = normal.multiply(-0.5, null);
} else {
barsOffset = null;
}
}
fillRectangleBuffer(mesh.getMeshData().getVertexBuffer(), meshOffset);
final FloatBuffer normalBuffer = mesh.getMeshData().getNormalBuffer();
for (int i = 0; i < 6; i += 1) {
BufferUtils.setInBuffer(normal.negate(null), normalBuffer, i);
}
fillRectangleBuffer(collisionMesh.getMeshData().getVertexBuffer(), normal.multiply(0.1, null));
mesh.updateModelBound();
collisionMesh.updateModelBound();
CollisionTreeManager.INSTANCE.removeCollisionTree(mesh);
CollisionTreeManager.INSTANCE.removeCollisionTree(collisionMesh);
if (!drawBars) {
bars.getSceneHints().setCullHint(CullHint.Always);
} else {
bars.getSceneHints().setCullHint(CullHint.Inherit);
final double divisionLength = 3.0 + style * 3.0;
FloatBuffer barsVertices = bars.getMeshData().getVertexBuffer();
final int cols = (int) Math.max(2, getAbsPoint(0).distance(getAbsPoint(2)) / divisionLength);
final int rows = (int) Math.max(2, getAbsPoint(0).distance(getAbsPoint(1)) / divisionLength);
if (barsVertices.capacity() < (4 + rows + cols) * 6) {
barsVertices = BufferUtils.createVector3Buffer((4 + rows + cols) * 2);
bars.getMeshData().setVertexBuffer(barsVertices);
} else {
barsVertices.rewind();
barsVertices.limit(barsVertices.capacity());
}
int i = 0;
BufferUtils.setInBuffer(getAbsPoint(0).addLocal(barsOffset), barsVertices, i++);
BufferUtils.setInBuffer(getAbsPoint(1).addLocal(barsOffset), barsVertices, i++);
BufferUtils.setInBuffer(getAbsPoint(1).addLocal(barsOffset), barsVertices, i++);
BufferUtils.setInBuffer(getAbsPoint(3).addLocal(barsOffset), barsVertices, i++);
BufferUtils.setInBuffer(getAbsPoint(3).addLocal(barsOffset), barsVertices, i++);
BufferUtils.setInBuffer(getAbsPoint(2).addLocal(barsOffset), barsVertices, i++);
BufferUtils.setInBuffer(getAbsPoint(2).addLocal(barsOffset), barsVertices, i++);
BufferUtils.setInBuffer(getAbsPoint(0).addLocal(barsOffset), barsVertices, i++);
final ReadOnlyVector3 o = getAbsPoint(0).add(barsOffset, null);
final ReadOnlyVector3 u = getAbsPoint(2).subtract(getAbsPoint(0), null);
final ReadOnlyVector3 v = getAbsPoint(1).subtract(getAbsPoint(0), null);
final Vector3 p = new Vector3();
if (!noVerticalBars) {
for (int col = 1; col < cols; col++) {
u.multiply((double) col / cols, p).addLocal(o);
BufferUtils.setInBuffer(p, barsVertices, i++);
p.addLocal(v);
BufferUtils.setInBuffer(p, barsVertices, i++);
}
}
if (!noHorizontalBars) {
for (int row = 1; row < rows; row++) {
v.multiply((double) row / rows, p).addLocal(o);
BufferUtils.setInBuffer(p, barsVertices, i++);
p.addLocal(u);
BufferUtils.setInBuffer(p, barsVertices, i++);
}
}
barsVertices.limit(i * 3);
bars.getMeshData().updateVertexCount();
bars.updateModelBound();
}
if (hasLeftShutter) {
leftShutter.getSceneHints().setCullHint(CullHint.Inherit);
leftShutterOutline.getSceneHints().setCullHint(CullHint.Inherit);
drawShutter(leftShutter, leftShutterOutline);
} else {
leftShutter.getSceneHints().setCullHint(CullHint.Always);
leftShutterOutline.getSceneHints().setCullHint(CullHint.Always);
}
if (hasRightShutter) {
rightShutter.getSceneHints().setCullHint(CullHint.Inherit);
rightShutterOutline.getSceneHints().setCullHint(CullHint.Inherit);
drawShutter(rightShutter, rightShutterOutline);
} else {
rightShutter.getSceneHints().setCullHint(CullHint.Always);
rightShutterOutline.getSceneHints().setCullHint(CullHint.Always);
}
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Window method moveTo.
public void moveTo(final HousePart target) {
final double w1 = target.getAbsPoint(0).distance(target.getAbsPoint(2));
final double h1 = target.getAbsPoint(0).distance(target.getAbsPoint(1));
final double w2 = container.getAbsPoint(0).distance(container.getAbsPoint(2));
final double h2 = container.getAbsPoint(0).distance(container.getAbsPoint(1));
final double ratioW = w2 / w1;
final double ratioH = h2 / h1;
final Vector3 v0 = points.get(0);
final Vector3 v1 = points.get(1);
v1.setX(v0.getX() + (v1.getX() - v0.getX()) * ratioW);
v1.setY(v0.getY() + (v1.getY() - v0.getY()) * ratioW);
v1.setZ(v0.getZ() + (v1.getZ() - v0.getZ()) * ratioH);
final Vector3 v2 = points.get(2);
v2.setX(v0.getX() + (v2.getX() - v0.getX()) * ratioW);
v2.setY(v0.getY() + (v2.getY() - v0.getY()) * ratioW);
v2.setZ(v0.getZ() + (v2.getZ() - v0.getZ()) * ratioH);
final Vector3 v3 = points.get(3);
v3.setX(v0.getX() + (v3.getX() - v0.getX()) * ratioW);
v3.setY(v0.getY() + (v3.getY() - v0.getY()) * ratioW);
v3.setZ(v0.getZ() + (v3.getZ() - v0.getZ()) * ratioH);
setContainer(target);
}
Aggregations