use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Roof method flattenQuadTriangle.
private void flattenQuadTriangle(final Node roofPartNode, final double flattenTime) {
final ReadOnlyVector3 normal = (ReadOnlyVector3) roofPartNode.getUserData();
final double angleZ = Util.angleBetween(new Vector3(normal.getX(), normal.getY(), 0).normalizeLocal(), Vector3.NEG_UNIT_Y, Vector3.UNIT_Z);
final Matrix3 m1 = new Matrix3().fromAngles(0, 0, flattenTime * angleZ);
final ReadOnlyVector3 normal2 = m1.applyPost(normal, null);
final double angleX = Util.angleBetween(normal2, Vector3.NEG_UNIT_Y, Vector3.UNIT_X);
final Matrix3 m2 = new Matrix3().fromAngles(flattenTime * angleX, 0, 0);
final Matrix3 matrix = m2.multiplyLocal(m1);
final Boolean isVertical = roofPartPrintVerticalMap.get(roofPartNode);
if (isVertical != null && isVertical) {
new Matrix3().fromAngles(0, -Math.PI / 2.0 * flattenTime, 0).multiply(matrix, matrix);
}
roofPartNode.setRotation(matrix);
ReadOnlyVector3 orgCenter = orgCenters.get(roofPartNode);
if (orgCenter == null) {
orgCenter = Vector3.ZERO;
}
final Vector3 targetPrintCenter = ((UserData) roofPartNode.getChild(0).getUserData()).getPrintCenter();
if (!targetPrintCenter.equals(Vector3.ZERO)) {
roofPartNode.setTranslation(targetPrintCenter.subtract(orgCenter, null).multiplyLocal(flattenTime));
}
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Roof method fits.
@Override
protected boolean fits(final HousePart window) {
for (final Spatial roofPart : roofPartsRoot.getChildren()) {
if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
final Mesh mesh = (Mesh) ((Node) roofPart).getChild(0);
final ArrayList<ReadOnlyVector3> outlinePoints = MeshLib.computeOutline(mesh.getMeshData().getVertexBuffer());
boolean allInside = true;
boolean allOutside = true;
for (int i = 0; i < window.getPoints().size(); i++) {
final Vector3 p = window.getAbsPoint(i);
roofPart.getWorldTransform().applyInverse(p);
if (Util.insidePolygon(p, outlinePoints)) {
allOutside = false;
} else {
allInside = false;
}
}
if (!allInside && !allOutside) {
return false;
}
}
}
return true;
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Roof method drawMesh.
@Override
protected void drawMesh() {
// undo the effect of wall stretch on all walls if roof is moved to new walls
if (previousContainer != container) {
previousContainer = container;
for (final Wall wall : walls) {
wall.setRoof(null);
wall.draw();
}
}
dashPointsCache.clear();
if (wallUpperPoints == null) {
wallUpperPoints = new ArrayList<ReadOnlyVector3>();
} else {
wallUpperPoints.clear();
}
if (container != null) {
initWallUpperPoints((Wall) container, walls, wallUpperPoints, wallNormals);
}
if (!isDrawable()) {
roofPartsRoot.getSceneHints().setCullHint(CullHint.Always);
setEditPointsVisible(false);
return;
}
roofPartsRoot.getSceneHints().setCullHint(CullHint.Inherit);
final ArrayList<Vector3> orgPoints = new ArrayList<Vector3>(points.size());
for (final ReadOnlyVector3 p : points) {
orgPoints.add(p.clone());
}
wallUpperPointsWithoutOverhang = new ArrayList<ReadOnlyVector3>(wallUpperPoints);
drawRoof();
switch(type) {
case TRANSPARENT:
for (final Spatial child : roofPartsRoot.getChildren()) {
((Mesh) ((Node) child).getChild(0)).getSceneHints().setCullHint(CullHint.Always);
((Mesh) ((Node) child).getChild(REAL_MESH_INDEX)).getSceneHints().setCullHint(CullHint.Always);
}
break;
default:
for (final Spatial child : roofPartsRoot.getChildren()) {
((Mesh) ((Node) child).getChild(0)).getSceneHints().setCullHint(CullHint.Inherit);
((Mesh) ((Node) child).getChild(REAL_MESH_INDEX)).getSceneHints().setCullHint(CullHint.Inherit);
}
}
roofPartsRoot.updateWorldBound(true);
drawOutline();
if (Scene.getInstance().areDashedLinesOnRoofShown()) {
drawDashLines();
} else {
for (final Spatial roofPart : roofPartsRoot.getChildren()) {
if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
final Mesh dashLinesMesh = (Mesh) ((Node) roofPart).getChild(5);
dashLinesMesh.setVisible(false);
}
}
}
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Roof method drawHeatFlux.
@Override
public void drawHeatFlux() {
FloatBuffer arrowsVertices = heatFlux.getMeshData().getVertexBuffer();
final Foundation foundation = getTopContainer();
final int cols = (int) Math.max(2, foundation.getAbsPoint(0).distance(foundation.getAbsPoint(2)) / Scene.getInstance().getHeatVectorGridSize());
final int rows = (int) Math.max(2, foundation.getAbsPoint(0).distance(foundation.getAbsPoint(1)) / Scene.getInstance().getHeatVectorGridSize());
arrowsVertices = BufferUtils.createVector3Buffer(rows * cols * 6);
heatFlux.getMeshData().setVertexBuffer(arrowsVertices);
final ReadOnlyVector3 o = foundation.getAbsPoint(0);
final ReadOnlyVector3 u = foundation.getAbsPoint(2).subtract(o, null);
final ReadOnlyVector3 v = foundation.getAbsPoint(1).subtract(o, null);
final Vector3 a = new Vector3();
double g, h;
boolean init = true;
for (int j = 0; j < cols; j++) {
h = j + 0.5;
for (int i = 0; i < rows; i++) {
g = i + 0.5;
a.setX(o.getX() + g * v.getX() / rows + h * u.getX() / cols);
a.setY(o.getY() + g * v.getY() / rows + h * u.getY() / cols);
a.setZ(o.getZ());
if (insideWalls(a.getX(), a.getY(), init)) {
ReadOnlyVector3 b = null;
Node node = null;
Mesh mesh = null;
for (final Spatial child : roofPartsRoot.getChildren()) {
if (child.getSceneHints().getCullHint() != CullHint.Always) {
node = (Node) child;
mesh = (Mesh) node.getChild(REAL_MESH_INDEX);
b = findRoofIntersection(mesh, a);
if (b != null) {
break;
}
}
}
if (b != null) {
final ReadOnlyVector3 normal = (ReadOnlyVector3) node.getUserData();
final double heat = calculateHeatVector(mesh);
drawArrow(b, normal, arrowsVertices, heat);
}
}
if (init) {
init = false;
}
}
heatFlux.getMeshData().updateVertexCount();
heatFlux.updateModelBound();
}
updateHeatFluxVisibility();
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Roof method initWallUpperPoints.
private void initWallUpperPoints(final Wall startWall, final List<Wall> walls, final List<ReadOnlyVector3> wallUpperPoints, final List<ReadOnlyVector3> wallNormals) {
walls.clear();
wallUpperPoints.clear();
wallNormals.clear();
startWall.visitNeighbors(new WallVisitor() {
@Override
public void visit(final Wall currentWall, final Snap prevSnap, final Snap nextSnap) {
if (currentWall.isFirstPointInserted()) {
walls.add(currentWall);
currentWall.setRoof(Roof.this);
final int pointIndex2 = nextSnap != null ? nextSnap.getSnapPointIndexOf(currentWall) + 1 : 1;
final int pointIndex1 = pointIndex2 == 1 ? 3 : 1;
final Vector3 p1 = currentWall.getAbsPoint(pointIndex1);
final Vector3 p2 = currentWall.getAbsPoint(pointIndex2);
final ReadOnlyVector3 normal = currentWall.getNormal();
addPointToPolygon(p1, normal, wallUpperPoints, wallNormals);
addPointToPolygon(p2, normal, wallUpperPoints, wallNormals);
}
}
});
}
Aggregations