use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Floor method setPreviewPoint.
@Override
public void setPreviewPoint(final int x, final int y) {
final Foundation foundation = getTopContainer();
if (foundation != null && foundation.getLockEdit()) {
return;
}
pickContainer(x, y, Wall.class);
if (container != null) {
final ReadOnlyVector3 base = getCenter();
final Vector3 p = Util.closestPoint(base, Vector3.UNIT_Z, x, y);
if (p == null) {
return;
}
snapToGrid(p, base, getGridSize());
final double zMin = container.getAbsPoint(0).getZ() + 0.5;
final double zmax = container.getAbsPoint(1).getZ();
height = Math.min(zmax, Math.max(zMin, p.getZ()));
}
draw();
setEditPointsVisible(container != null);
final Foundation f = getTopContainer();
if (f != null) {
f.draw();
// need to redraw the walls when the floor is part of a balcony
f.drawChildren();
}
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Floor method drawAnnotations.
@Override
public void drawAnnotations() {
if (container == null) {
return;
}
int annotCounter = 0;
for (int i = 0; i < wallUpperPoints.size(); i++) {
PolygonPoint p = wallUpperPoints.get(i);
final Vector3 a = new Vector3(p.getX(), p.getY(), p.getZ());
p = wallUpperPoints.get((i + 1) % wallUpperPoints.size());
final Vector3 b = new Vector3(p.getX(), p.getY(), p.getZ());
final SizeAnnotation sizeAnnot = fetchSizeAnnot(annotCounter++);
sizeAnnot.setRange(a, b, getCenter(), getNormal(), original == null, Align.Center, true, false, Scene.isDrawAnnotationsInside());
sizeAnnot.setLineWidth(original == null ? 1f : 2f);
}
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Foundation method moveAllWithinPolygon.
public void moveAllWithinPolygon(final Vector3 direction) {
if (foundationPolygon == null || !foundationPolygon.isVisible()) {
return;
}
final Path2D.Double path = new Path2D.Double();
final int n = foundationPolygon.points.size();
Vector3 v = foundationPolygon.getAbsPoint(0);
path.moveTo(v.getX(), v.getY());
for (int i = 1; i < n / 2; i++) {
// use only the first half of the vertices from the polygon
v = foundationPolygon.getAbsPoint(i);
path.lineTo(v.getX(), v.getY());
}
path.closePath();
final List<HousePart> selectedParts = new ArrayList<HousePart>();
for (final HousePart child : children) {
final Vector3 center = child.getAbsCenter();
if (path.contains(center.getX(), center.getY())) {
selectedParts.add(child);
}
}
// final RemoveMultiplePartsCommand c = new RemoveMultiplePartsCommand(selectedParts);
double steplength = 0;
for (final HousePart part : selectedParts) {
if (part instanceof SolarCollector) {
if (steplength == 0) {
steplength = part.getGridSize();
}
((SolarCollector) part).move(direction, steplength);
part.draw();
}
}
foundationPolygon.move(direction, steplength);
foundationPolygon.draw();
// SceneManager.getInstance().getUndoManager().addEdit(c);
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Foundation method drawSideMesh.
private void drawSideMesh() {
final FloatBuffer vertexBuffer0 = sideMesh[0].getMeshData().getVertexBuffer();
final FloatBuffer vertexBuffer1 = sideMesh[1].getMeshData().getVertexBuffer();
final FloatBuffer vertexBuffer2 = sideMesh[2].getMeshData().getVertexBuffer();
final FloatBuffer vertexBuffer3 = sideMesh[3].getMeshData().getVertexBuffer();
vertexBuffer0.rewind();
vertexBuffer1.rewind();
vertexBuffer2.rewind();
vertexBuffer3.rewind();
final Vector3 p0 = getAbsPoint(0);
final Vector3 p1 = getAbsPoint(1);
final Vector3 p2 = getAbsPoint(2);
final Vector3 p3 = getAbsPoint(3);
vertexBuffer0.put(p0.getXf()).put(p0.getYf()).put((float) height);
vertexBuffer0.put(p0.getXf()).put(p0.getYf()).put(0f);
vertexBuffer0.put(p2.getXf()).put(p2.getYf()).put(0f);
vertexBuffer0.put(p2.getXf()).put(p2.getYf()).put(0f);
vertexBuffer0.put(p2.getXf()).put(p2.getYf()).put((float) height);
vertexBuffer0.put(p0.getXf()).put(p0.getYf()).put((float) height);
vertexBuffer1.put(p2.getXf()).put(p2.getYf()).put((float) height);
vertexBuffer1.put(p2.getXf()).put(p2.getYf()).put(0f);
vertexBuffer1.put(p3.getXf()).put(p3.getYf()).put(0f);
vertexBuffer1.put(p3.getXf()).put(p3.getYf()).put(0f);
vertexBuffer1.put(p3.getXf()).put(p3.getYf()).put((float) height);
vertexBuffer1.put(p2.getXf()).put(p2.getYf()).put((float) height);
vertexBuffer2.put(p3.getXf()).put(p3.getYf()).put((float) height);
vertexBuffer2.put(p3.getXf()).put(p3.getYf()).put(0f);
vertexBuffer2.put(p1.getXf()).put(p1.getYf()).put(0f);
vertexBuffer2.put(p1.getXf()).put(p1.getYf()).put(0f);
vertexBuffer2.put(p1.getXf()).put(p1.getYf()).put((float) height);
vertexBuffer2.put(p3.getXf()).put(p3.getYf()).put((float) height);
vertexBuffer3.put(p1.getXf()).put(p1.getYf()).put((float) height);
vertexBuffer3.put(p1.getXf()).put(p1.getYf()).put(0f);
vertexBuffer3.put(p0.getXf()).put(p0.getYf()).put(0f);
vertexBuffer3.put(p0.getXf()).put(p0.getYf()).put(0f);
vertexBuffer3.put(p0.getXf()).put(p0.getYf()).put((float) height);
vertexBuffer3.put(p1.getXf()).put(p1.getYf()).put((float) height);
final FloatBuffer normalBuffer0 = sideMesh[0].getMeshData().getNormalBuffer();
final FloatBuffer normalBuffer1 = sideMesh[1].getMeshData().getNormalBuffer();
final FloatBuffer normalBuffer2 = sideMesh[2].getMeshData().getNormalBuffer();
final FloatBuffer normalBuffer3 = sideMesh[3].getMeshData().getNormalBuffer();
normalBuffer0.rewind();
normalBuffer1.rewind();
normalBuffer2.rewind();
normalBuffer3.rewind();
final ReadOnlyVector3 n1 = p0.subtract(p1, null).normalizeLocal();
final ReadOnlyVector3 n2 = p2.subtract(p0, null).normalizeLocal();
ReadOnlyVector3 normal = n1;
((UserData) sideMesh[0].getUserData()).setNormal(normal);
for (int i = 0; i < 6; i++) {
normalBuffer0.put(normal.getXf()).put(normal.getYf()).put(normal.getZf());
}
normal = n2;
((UserData) sideMesh[1].getUserData()).setNormal(normal);
for (int i = 0; i < 6; i++) {
normalBuffer1.put(normal.getXf()).put(normal.getYf()).put(normal.getZf());
}
normal = n1.negate(null);
((UserData) sideMesh[2].getUserData()).setNormal(normal);
for (int i = 0; i < 6; i++) {
normalBuffer2.put(normal.getXf()).put(normal.getYf()).put(normal.getZf());
}
normal = n2.negate(null);
((UserData) sideMesh[3].getUserData()).setNormal(normal);
for (int i = 0; i < 6; i++) {
normalBuffer3.put(normal.getXf()).put(normal.getYf()).put(normal.getZf());
}
for (int i = 0; i < 4; i++) {
sideMesh[i].updateModelBound();
CollisionTreeManager.INSTANCE.removeCollisionTree(sideMesh[i]);
}
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Foundation method addCircularHeliostatArrays.
public int addCircularHeliostatArrays(final HeliostatCircularFieldLayout layout) {
EnergyPanel.getInstance().updateRadiationHeatMap();
final Class<?>[] clazz = new Class[] { Mirror.class };
final AddArrayCommand command = new AddArrayCommand(removeChildrenOfClass(clazz), this, clazz);
final double a = 0.5 * Math.min(getAbsPoint(0).distance(getAbsPoint(2)), getAbsPoint(0).distance(getAbsPoint(1)));
final Vector3 center = getAbsCenter();
final double w = (layout.getApertureWidth() + layout.getAzimuthalSpacing()) / Scene.getInstance().getAnnotationScale();
final double h = (layout.getApertureHeight() + layout.getRadialSpacing()) / Scene.getInstance().getAnnotationScale();
final double rows = a / h;
final int nrows = (int) (rows > 2 ? rows - 2 : rows);
final double roadHalfWidth = 0.5 * layout.getAxisRoadWidth() / Scene.getInstance().getAnnotationScale();
switch(layout.getType()) {
case EQUAL_AZIMUTHAL_SPACING:
for (int r = nrows - 1; r >= 0; r--) {
double b = a * (1.0 - r / rows);
b += b * b * layout.getRadialSpacingIncrement();
if (b > a) {
break;
}
final double roadAngle = Math.toDegrees(Math.atan(roadHalfWidth / b));
final int n = (int) (2 * Math.PI * b / w);
for (int i = 0; i < n; i++) {
final double theta = i * 2.0 * Math.PI / n;
final double az = Math.toDegrees(theta);
if (az >= layout.getStartAngle() && az < layout.getEndAngle()) {
if (!Util.isZero(roadAngle) && nearAxes(az, roadAngle)) {
continue;
}
final Vector3 p = new Vector3(center.getX() + b * Math.cos(theta), center.getY() + b * Math.sin(theta), 0);
addMirror(p, layout.getBaseHeight(), layout.getApertureWidth(), layout.getApertureHeight(), az);
}
}
}
break;
case // http://www.powerfromthesun.net/Book/chapter10/chapter10.html#10.1.3%20%20%20Field%20Layout
RADIAL_STAGGER:
final double rmin = a * (1.0 - (nrows - 5) / rows);
final int n = (int) (rmin / layout.getApertureWidth() * Scene.getInstance().getAnnotationScale());
for (int i = 0; i < n; i++) {
double theta = i * 2.0 * Math.PI / n;
double az = Math.toDegrees(theta);
if (az >= layout.getStartAngle() && az < layout.getEndAngle()) {
for (int j = 0; j < nrows; j++) {
final double r = a * (1.0 - j / rows);
final Vector3 p = new Vector3(center.getX() + r * Math.cos(theta), center.getY() + r * Math.sin(theta), 0);
addMirror(p, layout.getBaseHeight(), layout.getApertureWidth(), layout.getApertureHeight(), az);
}
}
theta = (i + 0.5) * 2.0 * Math.PI / n;
az = Math.toDegrees(theta);
if (az >= layout.getStartAngle() && az < layout.getEndAngle()) {
for (int j = 0; j < nrows; j++) {
final double r = a * (1.0 - j / rows) - 0.5 * h;
final Vector3 p = new Vector3(center.getX() + r * Math.cos(theta), center.getY() + r * Math.sin(theta), 0);
addMirror(p, layout.getBaseHeight(), layout.getApertureWidth(), layout.getApertureHeight(), az);
}
}
}
break;
}
SceneManager.getInstance().getUndoManager().addEdit(command);
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
EnergyPanel.getInstance().updateProperties();
}
});
return countParts(Mirror.class);
}
Aggregations