use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Wall method drawMesh.
@Override
protected void drawMesh() {
final boolean drawable = isDrawable();
final CullHint drawableSolidWall = drawable && type == SOLID_WALL ? CullHint.Inherit : CullHint.Always;
mesh.getSceneHints().setCullHint(drawableSolidWall);
outlineMesh.getSceneHints().setCullHint(drawableSolidWall);
final CullHint drawableSolidNoneFrozenWall = drawable && type == SOLID_WALL ? CullHint.Inherit : CullHint.Always;
backMesh.getSceneHints().setCullHint(drawableSolidNoneFrozenWall);
surroundMesh.getSceneHints().setCullHint(drawableSolidNoneFrozenWall);
windowsSurroundMesh.getSceneHints().setCullHint(drawableSolidNoneFrozenWall);
if (!drawable) {
return;
}
computeNormalAndXYTransform();
wallAndWindowsPoints = computeWallAndWindowPolygon(false);
stretchToRoof(wallAndWindowsPoints.get(0));
switch(type) {
case EMPTY:
outlineMesh.getSceneHints().setCullHint(CullHint.Always);
columns.getSceneHints().setCullHint(CullHint.Always);
rails.getSceneHints().setCullHint(CullHint.Always);
steelFrame.getSceneHints().setCullHint(CullHint.Always);
break;
case VERTICAL_EDGES_ONLY:
outlineMesh.getSceneHints().setCullHint(CullHint.Always);
columns.getSceneHints().setCullHint(CullHint.Inherit);
rails.getSceneHints().setCullHint(CullHint.Always);
steelFrame.getSceneHints().setCullHint(CullHint.Always);
drawVerticalEdges(columnRadius);
break;
case COLUMNS_ONLY:
outlineMesh.getSceneHints().setCullHint(CullHint.Always);
columns.getSceneHints().setCullHint(CullHint.Inherit);
rails.getSceneHints().setCullHint(CullHint.Always);
steelFrame.getSceneHints().setCullHint(CullHint.Always);
drawColumns(10);
break;
case RAILS_ONLY:
outlineMesh.getSceneHints().setCullHint(CullHint.Always);
columns.getSceneHints().setCullHint(CullHint.Always);
rails.getSceneHints().setCullHint(CullHint.Inherit);
steelFrame.getSceneHints().setCullHint(CullHint.Always);
drawRails(1, false);
break;
case COLUMNS_RAILS:
outlineMesh.getSceneHints().setCullHint(CullHint.Always);
columns.getSceneHints().setCullHint(CullHint.Inherit);
rails.getSceneHints().setCullHint(CullHint.Inherit);
steelFrame.getSceneHints().setCullHint(CullHint.Always);
drawColumns(10);
drawRails(1, false);
break;
case FENCE:
outlineMesh.getSceneHints().setCullHint(CullHint.Always);
columns.getSceneHints().setCullHint(CullHint.Always);
rails.getSceneHints().setCullHint(CullHint.Inherit);
steelFrame.getSceneHints().setCullHint(CullHint.Always);
drawRails(1, true);
break;
case STEEL_FRAME:
outlineMesh.getSceneHints().setCullHint(CullHint.Always);
columns.getSceneHints().setCullHint(CullHint.Inherit);
rails.getSceneHints().setCullHint(CullHint.Always);
steelFrame.getSceneHints().setCullHint(CullHint.Inherit);
drawVerticalEdges(1);
drawSteelFrame(0.25, 10);
break;
default:
outlineMesh.getSceneHints().setCullHint(drawable && !hideOutline ? CullHint.Inherit : CullHint.Always);
columns.getSceneHints().setCullHint(CullHint.Always);
rails.getSceneHints().setCullHint(CullHint.Always);
steelFrame.getSceneHints().setCullHint(CullHint.Always);
if (Scene.getInstance().isDrawThickness() && isShortWall) {
final Vector3 dir = getAbsPoint(2).subtract(getAbsPoint(0), null).normalizeLocal();
if (neighbors[0] != null && neighbors[0].getNeighborOf(this).isFirstPointInserted()) {
if (isPerpendicularToNeighbor(0)) {
reduceBackMeshWidth(wallAndWindowsPoints.get(0), dir, 0);
}
}
if (neighbors[1] != null && neighbors[1].getNeighborOf(this).isFirstPointInserted()) {
dir.normalizeLocal().negateLocal();
if (isPerpendicularToNeighbor(1)) {
reduceBackMeshWidth(wallAndWindowsPoints.get(0), dir, 1);
}
}
}
drawOutline(wallAndWindowsPoints);
if (isDrawBackMesh()) {
drawBackMesh(computeWallAndWindowPolygon(true));
} else {
backMesh.getSceneHints().setCullHint(CullHint.Always);
}
drawSurroundMesh(thicknessNormal);
drawWindowsSurroundMesh(thicknessNormal);
}
drawPolygon(wallAndWindowsPoints, mesh, true, true, true);
drawPolygon(wallAndWindowsPoints, invisibleMesh, false, false, false);
CollisionTreeManager.INSTANCE.removeCollisionTree(mesh);
CollisionTreeManager.INSTANCE.removeCollisionTree(invisibleMesh);
root.updateWorldBound(true);
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Wall method fits.
@Override
public boolean fits(final HousePart window) {
if (wallAndWindowsPoints != null) {
final List<Vector3> hole = computeWindowHole(window, Vector3.ZERO);
applyXYTransform(hole);
final double minDistanceToRoof = 0.1 * getGridSize();
final ArrayList<Vector3> polygon = new ArrayList<Vector3>(wallAndWindowsPoints.get(0).size());
for (int i = 0; i < wallAndWindowsPoints.get(0).size(); i++) {
final Vector3 p = wallAndWindowsPoints.get(0).get(i).clone();
if (i == 0 || i > 2) {
p.subtractLocal(0, 0, minDistanceToRoof);
}
polygon.add(p);
}
applyXYTransform(polygon);
for (final Vector3 p : hole) {
if (!Util.insidePolygon(p, polygon)) {
return false;
}
}
}
return true;
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Wall method stretchToRoof.
private void stretchToRoof(final List<Vector3> polygon) {
if (!extendToRoofEnabled || roof == null || roof.isSingleFlatMesh()) {
return;
}
final ReadOnlyVector3 o = polygon.get(0).clone();
final Vector3 dir = polygon.get(3).subtract(o, null);
dir.setZ(0);
final double length = dir.length();
dir.normalizeLocal();
final int[] upper = { 0, 3 };
for (final int i : upper) {
final Vector3 tp = polygon.get(i);
final double z = findRoofIntersection(tp);
tp.set(tp.getX(), tp.getY(), z);
}
Vector3 direction = null;
Vector3 previousStretchPoint = polygon.get(3);
for (double d = length - STRETCH_ROOF_STEP; d > STRETCH_ROOF_STEP; d -= STRETCH_ROOF_STEP) {
final Vector3 p = dir.multiply(d, null).addLocal(o);
final double findRoofIntersection = findRoofIntersection(p);
final Vector3 currentStretchPoint = new Vector3(p.getX(), p.getY(), findRoofIntersection);
final Vector3 currentDirection = currentStretchPoint.subtract(previousStretchPoint, null).normalizeLocal();
if (direction == null) {
direction = currentDirection;
} else if (direction.dot(currentDirection) < 1.0 - MathUtils.ZERO_TOLERANCE) {
direction = null;
polygon.add(previousStretchPoint);
polygon.add(currentStretchPoint);
}
previousStretchPoint = currentStretchPoint;
}
if (!polygon.get(polygon.size() - 1).equals(previousStretchPoint)) {
polygon.add(previousStretchPoint);
}
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Wall method drawHeatFlux.
@Override
public void drawHeatFlux() {
if (type != SOLID_WALL) {
return;
}
double zmax = -Double.MAX_VALUE;
final List<Vector3> wallPolygonPoints = getWallPolygonPoints();
for (final Vector3 a : wallPolygonPoints) {
if (a.getZ() > zmax) {
zmax = a.getZ();
}
}
final Path2D.Double path = new Path2D.Double();
path.moveTo(0, 0);
final Vector3 v1 = new Vector3();
final Vector3 v2 = new Vector3();
wallPolygonPoints.get(1).subtract(wallPolygonPoints.get(0), v1);
wallPolygonPoints.get(2).subtract(wallPolygonPoints.get(0), v2);
if (Util.isZero(v1.getX()) && Util.isZero(v2.getX())) {
path.moveTo(v1.getY(), v1.getZ());
path.lineTo(v2.getY(), v2.getZ());
for (int i = 3; i < wallPolygonPoints.size(); i++) {
wallPolygonPoints.get(i).subtract(wallPolygonPoints.get(0), v2);
path.lineTo(v2.getY(), v2.getZ());
}
} else {
// always use the Y plane unless it is a X plane as above
path.moveTo(v1.getX(), v1.getZ());
path.lineTo(v2.getX(), v2.getZ());
for (int i = 3; i < wallPolygonPoints.size(); i++) {
wallPolygonPoints.get(i).subtract(wallPolygonPoints.get(0), v2);
path.lineTo(v2.getX(), v2.getZ());
}
}
path.lineTo(0, 0);
path.closePath();
heatFlux.getSceneHints().setCullHint(CullHint.Inherit);
FloatBuffer arrowsVertices = heatFlux.getMeshData().getVertexBuffer();
final int cols = (int) Math.max(2, getAbsPoint(0).distance(getAbsPoint(2)) / Scene.getInstance().getHeatVectorGridSize());
final int rows = (int) Math.max(2, zmax / Scene.getInstance().getHeatVectorGridSize());
arrowsVertices = BufferUtils.createVector3Buffer(rows * cols * 6);
heatFlux.getMeshData().setVertexBuffer(arrowsVertices);
final double heat = calculateHeatVector();
if (heat != 0) {
final ReadOnlyVector3 o = getAbsPoint(0);
final ReadOnlyVector3 u = getAbsPoint(2).subtract(o, null);
final ReadOnlyVector3 v = getAbsPoint(1).subtract(o, null);
final ReadOnlyVector3 normal = getNormal();
final Vector3 a = new Vector3();
double g, h;
for (int j = 0; j < cols; j++) {
h = j + 0.5;
for (int i = 0; i < rows - 1; 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() + g * zmax / rows);
a.subtract(wallPolygonPoints.get(0), v1);
if (Util.isZero(v1.getX())) {
if (!path.contains(v1.getY(), v1.getZ())) {
break;
}
} else {
if (!path.contains(v1.getX(), v1.getZ())) {
break;
}
}
drawArrow(a, normal, arrowsVertices, heat);
}
}
heatFlux.getMeshData().updateVertexCount();
heatFlux.updateModelBound();
}
updateHeatFluxVisibility();
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Wall method drawVerticalEdges.
private void drawVerticalEdges(final double size) {
columns.setDefaultColor(getColor());
final FloatBuffer vertexBuffer = columns.getMeshData().getVertexBuffer();
final FloatBuffer normalBuffer = columns.getMeshData().getNormalBuffer();
vertexBuffer.rewind();
normalBuffer.rewind();
vertexBuffer.limit(vertexBuffer.capacity());
normalBuffer.limit(normalBuffer.capacity());
final ReadOnlyVector3 o = getAbsPoint(0);
final ReadOnlyVector3 u = getAbsPoint(2).subtract(o, null);
final Vector3 dir = new Vector3(u).normalizeLocal().multiplyLocal(size);
Util.addPointToQuad(normal, o, getAbsPoint(1), dir, vertexBuffer, normalBuffer);
Util.addPointToQuad(normal, getAbsPoint(2), getAbsPoint(3), dir, vertexBuffer, normalBuffer);
vertexBuffer.limit(vertexBuffer.position());
normalBuffer.limit(normalBuffer.position());
columns.getMeshData().updateVertexCount();
columns.updateModelBound();
}
Aggregations