use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Roof method computeArea.
@Override
protected void computeArea() {
this.area = 0;
if (container == null) {
return;
}
if (areaByPartWithOverhang == null) {
areaByPartWithOverhang = new HashMap<Mesh, Double>();
} else {
areaByPartWithOverhang.clear();
}
if (areaByPartWithoutOverhang == null) {
areaByPartWithoutOverhang = new HashMap<Mesh, Double>();
} else {
areaByPartWithoutOverhang.clear();
}
for (final Spatial roofPart : roofPartsRoot.getChildren()) {
if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
final Node roofPartNode = (Node) roofPart;
final Mesh roofPartMesh = (Mesh) roofPartNode.getChild(REAL_MESH_INDEX);
areaByPartWithOverhang.put(roofPartMesh, Util.computeArea(roofPartMesh));
final FloatBuffer vertexBuffer = roofPartMesh.getMeshData().getVertexBuffer();
final Vector3 p = new Vector3();
if (overhangLength <= OVERHANG_MIN) {
final double a = Util.computeArea(roofPartMesh);
areaByPartWithoutOverhang.put(roofPartMesh, a);
area += a;
} else {
final List<ReadOnlyVector3> result = computeDashPoints(roofPartMesh);
if (result.isEmpty()) {
vertexBuffer.rewind();
p.set(vertexBuffer.get(), vertexBuffer.get(), vertexBuffer.get());
final double a;
if (Util.insidePolygon(p, wallUpperPointsWithoutOverhang)) {
a = Util.computeArea(roofPartMesh);
} else {
a = 0;
}
areaByPartWithoutOverhang.put(roofPartMesh, a);
area += a;
} else {
// if (roofPartsRoot.getNumberOfChildren() > 1) {
double highPointZ = Double.NEGATIVE_INFINITY;
vertexBuffer.rewind();
while (vertexBuffer.hasRemaining()) {
p.set(vertexBuffer.get(), vertexBuffer.get(), vertexBuffer.get());
if (p.getZ() > highPointZ) {
highPointZ = p.getZ();
}
}
final List<ReadOnlyVector3> highPoints = new ArrayList<ReadOnlyVector3>();
vertexBuffer.rewind();
while (vertexBuffer.hasRemaining()) {
p.set(vertexBuffer.get(), vertexBuffer.get(), vertexBuffer.get());
if (p.getZ() >= highPointZ - MathUtils.ZERO_TOLERANCE && Util.insidePolygon(p, wallUpperPointsWithoutOverhang)) {
highPoints.add(new Vector3(p));
}
}
if (highPoints.size() == 1) {
result.add(highPoints.get(0));
} else {
final ReadOnlyVector3 lastPoint = result.get(result.size() - 1);
while (!highPoints.isEmpty()) {
double shortestDistance = Double.MAX_VALUE;
ReadOnlyVector3 nearestPoint = null;
for (final ReadOnlyVector3 hp : highPoints) {
final double distance = hp.distance(lastPoint);
if (distance < shortestDistance) {
shortestDistance = distance;
nearestPoint = hp;
}
}
result.add(nearestPoint);
highPoints.remove(nearestPoint);
}
}
result.add(result.get(0));
final double annotationScale = Scene.getInstance().getAnnotationScale();
final double a = Util.area3D_Polygon(result, (ReadOnlyVector3) roofPart.getUserData()) * annotationScale * annotationScale;
areaByPartWithoutOverhang.put(roofPartMesh, a);
this.area += a;
}
}
}
}
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Sensor method setPreviewPoint.
@Override
public void setPreviewPoint(final int x, final int y) {
final PickedHousePart picked = pickContainer(x, y, new Class<?>[] { Roof.class, Wall.class, Foundation.class });
if (picked != null && picked.getUserData() != null) {
// when the user data is null, it picks the land
final Vector3 p = picked.getPoint().clone();
snapToGrid(p, getAbsPoint(0), getGridSize(), false);
points.get(0).set(toRelative(p));
}
if (container != null) {
draw();
setEditPointsVisible(true);
setHighlight(!isDrawable());
}
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Sensor method drawMesh.
@Override
protected void drawMesh() {
if (container == null) {
return;
}
if (container instanceof Roof) {
final PickResults pickResults = new PrimitivePickResults();
final Ray3 ray = new Ray3(getAbsPoint(0).addLocal(0, 0, 1000), Vector3.NEG_UNIT_Z);
PickingUtil.findPick(container.getRoot(), ray, pickResults, false);
if (pickResults.getNumber() != 0) {
final PickData pickData = pickResults.getPickData(0);
final Vector3 p = pickData.getIntersectionRecord().getIntersectionPoint(0);
points.get(0).setZ(p.getZ());
final UserData userData = (UserData) ((Spatial) pickData.getTarget()).getUserData();
final int roofPartIndex = userData.getEditPointIndex();
normal = (ReadOnlyVector3) ((Roof) container).getRoofPartsRoot().getChild(roofPartIndex).getUserData();
}
} else {
normal = container.getNormal();
}
updateEditShapes();
final double annotationScale = Scene.getInstance().getAnnotationScale();
// last arg sets close to zero so the sensor doesn't cast shadow
surround.setData(Vector3.ZERO, WIDTH / 2.0 / annotationScale, HEIGHT / 2.0 / annotationScale, 0.02);
surround.updateModelBound();
final FloatBuffer boxVertexBuffer = surround.getMeshData().getVertexBuffer();
final FloatBuffer vertexBuffer = mesh.getMeshData().getVertexBuffer();
final FloatBuffer textureBuffer = mesh.getMeshData().getTextureBuffer(0);
final FloatBuffer outlineBuffer = outlineMesh.getMeshData().getVertexBuffer();
vertexBuffer.rewind();
outlineBuffer.rewind();
textureBuffer.rewind();
int i = 8 * 3;
vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
textureBuffer.put(1).put(0);
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
i += 3;
vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
textureBuffer.put(0).put(0);
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
i += 3;
vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
textureBuffer.put(0).put(1);
textureBuffer.put(0).put(1);
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
i += 3;
vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
textureBuffer.put(1).put(1);
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
i = 8 * 3;
vertexBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
textureBuffer.put(1).put(0);
outlineBuffer.put(boxVertexBuffer.get(i)).put(boxVertexBuffer.get(i + 1)).put(boxVertexBuffer.get(i + 2));
mesh.updateModelBound();
outlineMesh.updateModelBound();
mesh.setTranslation(getAbsPoint(0));
if (normal != null) {
// FIXME: Sometimes normal is null
if (Util.isEqual(normal, Vector3.UNIT_Z)) {
mesh.setRotation(new Matrix3());
} else {
mesh.setRotation(new Matrix3().lookAt(normal, Vector3.UNIT_Z));
}
}
surround.setTranslation(mesh.getTranslation());
surround.setRotation(mesh.getRotation());
outlineMesh.setTranslation(mesh.getTranslation());
outlineMesh.setRotation(mesh.getRotation());
final ReadOnlyVector3 translation = mesh.getTranslation();
label.setText("" + getId());
if (normal != null) {
final double labelOffset = 1.0;
label.setTranslation(translation.getX() + labelOffset * normal.getX(), translation.getY() + labelOffset * normal.getY(), translation.getZ() + labelOffset * normal.getZ());
}
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Sensor method move.
@Override
public void move(final Vector3 v, final double steplength) {
if (lockEdit) {
return;
}
v.normalizeLocal().multiplyLocal(steplength);
final Vector3 p = getAbsPoint(0).addLocal(v);
points.get(0).set(toRelative(p));
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Wall method applyXYTransform.
public void applyXYTransform(final List<Vector3> hole) {
if (toXY == null) {
computeNormalAndXYTransform();
}
for (final Vector3 p : hole) {
final Point point = new ArdorVector3Point(p);
toXY.transform(point);
p.set(point.getX(), point.getY(), point.getZ());
}
}
Aggregations