use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Wall method reduceBackMeshWidth.
private void reduceBackMeshWidth(final List<Vector3> polygon, final ReadOnlyVector3 wallDir, final int neighbor) {
final Snap snap = neighbors[neighbor];
final int neighborPointIndex = snap.getSnapPointIndexOfNeighborOf(this);
final Wall otherWall = snap.getNeighborOf(this);
final Vector3 otherWallDir = otherWall.getAbsPoint(neighborPointIndex == 0 ? 2 : 0).subtract(otherWall.getAbsPoint(neighborPointIndex), null).normalizeLocal();
final double angle = Math.max(0.1, otherWallDir.smallestAngleBetween(wallDir));
final double angle360;
if (wallDir.dot(otherWall.getThicknessNormal().normalize(null)) < 0) {
angle360 = Math.PI + angle;
} else {
angle360 = angle;
}
final boolean reverse = angle360 >= Math.PI;
final double length = wallThickness * Math.tan((Math.PI - angle) / 2) * (reverse ? -1 : 1);
final Vector3 v = wallDir.normalize(null).multiplyLocal(length);
final Vector3 p1 = polygon.get(neighbor == 0 ? 1 : 2);
final Vector3 p2 = polygon.get(neighbor == 0 ? 0 : 3);
// now reduce the actual wall points
p1.set(p1.getX() + v.getX(), p1.getY() + v.getY(), p1.getZ());
p2.set(p2.getX() + v.getX(), p2.getY() + v.getY(), p2.getZ());
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Wall method drawSteelFrame.
private void drawSteelFrame(final double size, final int n) {
steelFrame.setDefaultColor(getColor());
final FloatBuffer vertexBuffer = steelFrame.getMeshData().getVertexBuffer();
final FloatBuffer normalBuffer = steelFrame.getMeshData().getNormalBuffer();
vertexBuffer.rewind();
normalBuffer.rewind();
vertexBuffer.limit(vertexBuffer.capacity());
normalBuffer.limit(normalBuffer.capacity());
final ReadOnlyVector3 p0 = getAbsPoint(0);
final ReadOnlyVector3 p1 = getAbsPoint(1);
final ReadOnlyVector3 p2 = getAbsPoint(2);
final ReadOnlyVector3 p3 = getAbsPoint(3);
final Vector3 d10 = p1.subtract(p0, null);
final Vector3 d32 = p3.subtract(p2, null);
d10.setZ(d10.getZ() / n);
d32.setZ(d32.getZ() / n);
final Vector3 dir = d10.normalize(null).multiplyLocal(size);
for (int i = 0; i < n; i++) {
final Vector3 a = p0.add(d10.multiply(1, 1, i, null), null);
final Vector3 b = p2.add(d32.multiply(1, 1, i, null), null);
Util.addPointToQuad(normal, a, b, dir, vertexBuffer, normalBuffer);
final Vector3 c = p2.add(d32.multiply(1, 1, i + 1, null), null);
Util.addPointToQuad(normal, a, c, dir, vertexBuffer, normalBuffer);
final Vector3 d = p0.add(d10.multiply(1, 1, i + 1, null), null);
Util.addPointToQuad(normal, b, d, dir, vertexBuffer, normalBuffer);
}
vertexBuffer.limit(vertexBuffer.position());
normalBuffer.limit(normalBuffer.position());
steelFrame.getMeshData().updateVertexCount();
steelFrame.updateModelBound();
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Wall method drawBackMesh.
private void drawBackMesh(final List<List<Vector3>> polygon) {
final Vector3 dir = getAbsPoint(2).subtract(getAbsPoint(0), null).normalizeLocal();
if (neighbors[0] != null && neighbors[0].getNeighborOf(this).isFirstPointInserted() && !(Scene.getInstance().isDrawThickness() && isShortWall && isPerpendicularToNeighbor(0))) {
reduceBackMeshWidth(polygon.get(0), dir, 0);
}
if (neighbors[1] != null && neighbors[1].getNeighborOf(this).isFirstPointInserted() && !(Scene.getInstance().isDrawThickness() && isShortWall && isPerpendicularToNeighbor(1))) {
dir.normalizeLocal().negateLocal();
reduceBackMeshWidth(polygon.get(0), dir, 1);
}
enforceGablePointsRangeAndRemoveDuplicatedGablePoints(polygon.get(0));
stretchToRoof(polygon.get(0));
/* lower the z of back wall to ensure it doesn't stick up through the roof */
if (roof != null) {
for (final Vector3 p : polygon.get(0)) {
p.setZ(p.getZ() - 0.3);
}
}
drawPolygon(polygon, backMesh, true, true, false);
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Wall method getThicknessNormal.
public Vector3 getThicknessNormal() {
if (thicknessNormal != null) {
return thicknessNormal;
}
computeNormalAndXYTransform();
final Vector3 n = normal.clone();
final Snap neighbor;
final int whichNeighbor;
if (editPointIndex == 0 || editPointIndex == 1) {
/*
* if edit point has snapped to a new wall then use the angle with new wall to determine inside direction of this wall otherwise use the angle with the other wall attached to none moving corner of the this wall
*/
if (neighbors[0] == null) {
whichNeighbor = 1;
} else {
whichNeighbor = 0;
}
} else {
if (neighbors[1] == null) {
whichNeighbor = 0;
} else {
whichNeighbor = 1;
}
}
neighbor = neighbors[whichNeighbor];
if (neighbor != null && neighbor.getNeighborOf(this).getPoints().size() >= 4) {
final HousePart other = neighbor.getNeighborOf(this);
final int otherPointIndex = neighbor.getSnapPointIndexOfNeighborOf(this);
final Vector3 otherWallDir = other.getAbsPoint(otherPointIndex == 0 ? 2 : 0).subtract(other.getAbsPoint(otherPointIndex), null).normalizeLocal();
if (n.dot(otherWallDir) < 0) {
n.negateLocal();
}
} else {
final ReadOnlyVector3 camera = SceneManager.getInstance().getCamera().getDirection();
if (camera.dot(n) < 0) {
n.negateLocal();
}
}
n.multiplyLocal(wallThickness);
thicknessNormal = n;
return thicknessNormal;
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Wall method drawWindowsSurroundMesh.
private void drawWindowsSurroundMesh(final Vector3 thickness) {
int numOfWindows = 0;
for (final HousePart child : children) {
if (child instanceof Window) {
numOfWindows++;
}
}
final int bufferSize = numOfWindows == 0 ? 1 : (numOfWindows * 4 * 4 * 3);
FloatBuffer vertexBuffer = windowsSurroundMesh.getMeshData().getVertexBuffer();
FloatBuffer normalBuffer = windowsSurroundMesh.getMeshData().getNormalBuffer();
if (vertexBuffer.capacity() != bufferSize) {
vertexBuffer = BufferUtils.createFloatBuffer(bufferSize);
normalBuffer = BufferUtils.createFloatBuffer(bufferSize);
windowsSurroundMesh.getMeshData().setVertexBuffer(vertexBuffer);
windowsSurroundMesh.getMeshData().setNormalBuffer(normalBuffer);
} else {
vertexBuffer.rewind();
normalBuffer.rewind();
vertexBuffer.limit(vertexBuffer.capacity());
normalBuffer.limit(vertexBuffer.capacity());
}
final int[] order1 = new int[] { 0, 1, 3, 2, 0 };
final int[] order2 = new int[] { 2, 3, 1, 0, 2 };
final Vector3 sideNormal = thickness.cross(0, 0, 1, null).normalizeLocal();
final Vector3 n = new Vector3();
final Vector3 p = new Vector3();
final Vector3 wallDirection = getAbsPoint(2).subtract(getAbsPoint(0), null);
for (final HousePart child : children) {
if (child instanceof Window && includeWindow(child)) {
int[] order = order1;
final Vector3 windowDirection = child.getAbsPoint(2).subtract(child.getAbsPoint(0), null);
if (windowDirection.dot(wallDirection) < 0) {
order = order2;
}
for (int index = 0; index < order.length - 1; index++) {
int i = order[index];
p.set(child.getAbsPoint(i));
vertexBuffer.put(p.getXf()).put(p.getYf()).put(p.getZf());
p.set(child.getAbsPoint(i)).addLocal(thickness);
vertexBuffer.put(p.getXf()).put(p.getYf()).put(p.getZf());
i = order[index + 1];
p.set(child.getAbsPoint(i)).addLocal(thickness);
vertexBuffer.put(p.getXf()).put(p.getYf()).put(p.getZf());
p.set(child.getAbsPoint(i));
vertexBuffer.put(p.getXf()).put(p.getYf()).put(p.getZf());
if (index == 1 || index == 3) {
int z = 1;
if (index == 1) {
z = -z;
}
final boolean reversedThickness = getAbsPoint(1).subtract(getAbsPoint(0), null).normalizeLocal().crossLocal(wallDirection.normalize(null)).dot(thicknessNormal.normalize(null)) >= 0;
if (!reversedThickness) {
z = -z;
}
for (int j = 0; j < 4; j++) {
normalBuffer.put(0).put(0).put(z);
}
} else if (index == 0 || index == 2) {
n.set(sideNormal);
if (index == 2) {
n.negateLocal();
}
for (int j = 0; j < 4; j++) {
normalBuffer.put(n.getXf()).put(n.getYf()).put(n.getZf());
}
}
}
}
}
windowsSurroundMesh.getMeshData().updateVertexCount();
windowsSurroundMesh.updateModelBound();
}
Aggregations