use of com.ardor3d.math.type.ReadOnlyVector3 in project energy3d by concord-consortium.
the class Window method drawMesh.
@Override
protected void drawMesh() {
if (points.size() < 4) {
return;
}
mesh.setVisible(container instanceof Roof);
normal = computeNormalAndKeepOnSurface();
final boolean isDrawable = isDrawable();
setHighlight(!isDrawable);
updateEditShapes();
final boolean drawBars = style != NO_MUNTIN_BAR && !Util.isEqual(getAbsPoint(2), getAbsPoint(0)) && !Util.isEqual(getAbsPoint(1), getAbsPoint(0));
final ReadOnlyVector3 meshOffset, barsOffset;
if (!isDrawable) {
meshOffset = new Vector3();
barsOffset = normal.multiply(0.1, null);
} else if (container instanceof Roof) {
if (drawBars) {
meshOffset = normal.multiply(-0.1, null);
barsOffset = new Vector3();
} else {
meshOffset = new Vector3();
barsOffset = null;
}
} else {
meshOffset = normal.multiply(-0.6, null);
if (drawBars) {
barsOffset = normal.multiply(-0.5, null);
} else {
barsOffset = null;
}
}
fillRectangleBuffer(mesh.getMeshData().getVertexBuffer(), meshOffset);
final FloatBuffer normalBuffer = mesh.getMeshData().getNormalBuffer();
for (int i = 0; i < 6; i += 1) {
BufferUtils.setInBuffer(normal.negate(null), normalBuffer, i);
}
fillRectangleBuffer(collisionMesh.getMeshData().getVertexBuffer(), normal.multiply(0.1, null));
mesh.updateModelBound();
collisionMesh.updateModelBound();
CollisionTreeManager.INSTANCE.removeCollisionTree(mesh);
CollisionTreeManager.INSTANCE.removeCollisionTree(collisionMesh);
if (!drawBars) {
bars.getSceneHints().setCullHint(CullHint.Always);
} else {
bars.getSceneHints().setCullHint(CullHint.Inherit);
final double divisionLength = 3.0 + style * 3.0;
FloatBuffer barsVertices = bars.getMeshData().getVertexBuffer();
final int cols = (int) Math.max(2, getAbsPoint(0).distance(getAbsPoint(2)) / divisionLength);
final int rows = (int) Math.max(2, getAbsPoint(0).distance(getAbsPoint(1)) / divisionLength);
if (barsVertices.capacity() < (4 + rows + cols) * 6) {
barsVertices = BufferUtils.createVector3Buffer((4 + rows + cols) * 2);
bars.getMeshData().setVertexBuffer(barsVertices);
} else {
barsVertices.rewind();
barsVertices.limit(barsVertices.capacity());
}
int i = 0;
BufferUtils.setInBuffer(getAbsPoint(0).addLocal(barsOffset), barsVertices, i++);
BufferUtils.setInBuffer(getAbsPoint(1).addLocal(barsOffset), barsVertices, i++);
BufferUtils.setInBuffer(getAbsPoint(1).addLocal(barsOffset), barsVertices, i++);
BufferUtils.setInBuffer(getAbsPoint(3).addLocal(barsOffset), barsVertices, i++);
BufferUtils.setInBuffer(getAbsPoint(3).addLocal(barsOffset), barsVertices, i++);
BufferUtils.setInBuffer(getAbsPoint(2).addLocal(barsOffset), barsVertices, i++);
BufferUtils.setInBuffer(getAbsPoint(2).addLocal(barsOffset), barsVertices, i++);
BufferUtils.setInBuffer(getAbsPoint(0).addLocal(barsOffset), barsVertices, i++);
final ReadOnlyVector3 o = getAbsPoint(0).add(barsOffset, null);
final ReadOnlyVector3 u = getAbsPoint(2).subtract(getAbsPoint(0), null);
final ReadOnlyVector3 v = getAbsPoint(1).subtract(getAbsPoint(0), null);
final Vector3 p = new Vector3();
if (!noVerticalBars) {
for (int col = 1; col < cols; col++) {
u.multiply((double) col / cols, p).addLocal(o);
BufferUtils.setInBuffer(p, barsVertices, i++);
p.addLocal(v);
BufferUtils.setInBuffer(p, barsVertices, i++);
}
}
if (!noHorizontalBars) {
for (int row = 1; row < rows; row++) {
v.multiply((double) row / rows, p).addLocal(o);
BufferUtils.setInBuffer(p, barsVertices, i++);
p.addLocal(u);
BufferUtils.setInBuffer(p, barsVertices, i++);
}
}
barsVertices.limit(i * 3);
bars.getMeshData().updateVertexCount();
bars.updateModelBound();
}
if (hasLeftShutter) {
leftShutter.getSceneHints().setCullHint(CullHint.Inherit);
leftShutterOutline.getSceneHints().setCullHint(CullHint.Inherit);
drawShutter(leftShutter, leftShutterOutline);
} else {
leftShutter.getSceneHints().setCullHint(CullHint.Always);
leftShutterOutline.getSceneHints().setCullHint(CullHint.Always);
}
if (hasRightShutter) {
rightShutter.getSceneHints().setCullHint(CullHint.Inherit);
rightShutterOutline.getSceneHints().setCullHint(CullHint.Inherit);
drawShutter(rightShutter, rightShutterOutline);
} else {
rightShutter.getSceneHints().setCullHint(CullHint.Always);
rightShutterOutline.getSceneHints().setCullHint(CullHint.Always);
}
}
use of com.ardor3d.math.type.ReadOnlyVector3 in project energy3d by concord-consortium.
the class CameraControl method getCurrentExtent.
// the extent that depends on the camera orientation (not a perfect solution)
private static double getCurrentExtent() {
double extent = 10;
final BoundingVolume volume = Scene.getRoot().getWorldBound();
if (volume instanceof BoundingBox) {
final BoundingBox box = (BoundingBox) volume;
final ReadOnlyVector3 cameraDirection = SceneManager.getInstance().getCamera().getDirection();
final Vector3 e1 = box.getExtent(null);
final double extent1 = Math.abs(e1.cross(cameraDirection, null).length());
final Vector3 e2 = new Matrix3().applyRotationZ(Math.PI / 2).applyPost(e1, null);
final double extent2 = Math.abs(e2.cross(cameraDirection, null).length());
extent = 0.45 * (extent1 + extent2);
}
return extent;
}
use of com.ardor3d.math.type.ReadOnlyVector3 in project energy3d by concord-consortium.
the class PrintController method arrangePrintPages.
private void arrangePrintPages(final ArrayList<ArrayList<Spatial>> pages) {
final double ratio = (double) Camera.getCurrentCamera().getWidth() / Camera.getCurrentCamera().getHeight();
cols = (int) Math.round(Math.sqrt(pages.size() + 4) * ratio);
if (cols % 2 == 0) {
cols++;
}
rows = (int) Math.ceil((pages.size() + 4) / cols);
int pageNum = 0;
printCenters.clear();
for (final ArrayList<Spatial> page : pages) {
final Vector3 upperLeftCorner = new Vector3();
double x, z;
final BoundingBox originalHouseBoundingBox = (BoundingBox) Scene.getOriginalHouseRoot().getWorldBound().asType(Type.AABB);
final ReadOnlyVector3 originalHouseCenter = Scene.getOriginalHouseRoot().getWorldBound().getCenter();
final double minXDistance = originalHouseBoundingBox.getXExtent() + pageWidth / 2.0;
final double minYDistance = originalHouseBoundingBox.getZExtent();
do {
x = (pageNum % cols - cols / 2) * (pageWidth + SPACE_BETWEEN_PAGES) + originalHouseCenter.getX();
z = (pageNum / cols) * (pageHeight + SPACE_BETWEEN_PAGES);
upperLeftCorner.setX(x - pageWidth / 2.0);
upperLeftCorner.setZ(z + pageHeight);
pageNum++;
} while (Math.abs(x - originalHouseCenter.getX()) < minXDistance && Math.abs(z - originalHouseCenter.getZ()) < minYDistance);
printCenters.add(upperLeftCorner);
for (final Spatial printSpatial : page) {
((UserData) printSpatial.getUserData()).getPrintCenter().addLocal(upperLeftCorner.multiply(1, 0, 1, null));
}
final Box box = new Box("Page Boundary");
final double y = Scene.getOriginalHouseRoot().getWorldBound().getCenter().getY();
box.setData(upperLeftCorner.add(0, y + 1, 0, null), upperLeftCorner.add(pageWidth, y + 1.2, -pageHeight, null));
box.setModelBound(new BoundingBox());
box.updateModelBound();
pagesRoot.attachChild(box);
final BMText footNote = Annotation.makeNewLabel(1);
final String url = Scene.getURL() != null ? Scene.getURL().getFile().substring(Scene.getURL().getFile().lastIndexOf('/') + 1, Scene.getURL().getFile().length()) + " -" : "";
footNote.setText(url.replaceAll("%20", " ") + " Page " + printCenters.size() + " / " + pages.size() + " - http://energy.concord.org/");
footNote.setFontScale(0.5);
footNote.setAlign(Align.North);
footNote.setTranslation(upperLeftCorner.add(pageWidth / 2.0, 0.0, -pageBottom - spaceBetweenParts / 2.0, null));
pagesRoot.attachChild(footNote);
}
pagesRoot.updateGeometricState(0);
}
use of com.ardor3d.math.type.ReadOnlyVector3 in project energy3d by concord-consortium.
the class NodeWorker method reach.
// If a ray in the direction of the normal of this mesh doesn't hit anything, it is considered as an exterior face of a twin mesh. Otherwise, it is considered as the interior face.
private static void reach(final Mesh mesh, final List<Spatial> collidables) {
final UserData userData = (UserData) mesh.getUserData();
final ReadOnlyVector3 normal = userData.getRotatedNormal() == null ? userData.getNormal() : userData.getRotatedNormal();
final FloatBuffer vertexBuffer = mesh.getMeshData().getVertexBuffer();
vertexBuffer.rewind();
final List<ReadOnlyVector3> vertices = new ArrayList<ReadOnlyVector3>(vertexBuffer.limit() / 3);
while (vertexBuffer.hasRemaining()) {
vertices.add(mesh.localToWorld(new Vector3(vertexBuffer.get(), vertexBuffer.get(), vertexBuffer.get()), null));
}
final Vector3 p = new Vector3();
// use only the center
// for (final ReadOnlyVector3 v : vertices) {
// p.addLocal(v);
// }
// p.multiplyLocal(1.0 / vertices.size());
// check if the centers of the triangles can be reached, if one can, then the entire mesh is considered as an exterior face
boolean reachable = false;
final PickResults pickResults = new PrimitivePickResults();
// assuming triangular meshes
final int n = vertices.size() / 3;
for (int i = 0; i < n; i++) {
// get the center of the triangle
p.zero();
p.addLocal(vertices.get(3 * i));
p.addLocal(vertices.get(3 * i + 1));
p.addLocal(vertices.get(3 * i + 2));
p.multiplyLocal(1.0 / 3.0);
// we must apply the offset transfer as these points come from the vertex buffer that is not affected by the translation definition of the mesh
// p.addLocal(normal.multiply(node.getMeshThickness(), null));
// detect collision
pickResults.clear();
final Ray3 pickRay = new Ray3(p, normal);
for (final Spatial spatial : collidables) {
if (spatial != mesh) {
PickingUtil.findPick(spatial, pickRay, pickResults, false);
if (pickResults.getNumber() != 0) {
break;
}
}
}
if (pickResults.getNumber() == 0) {
reachable = true;
break;
}
}
userData.setReachable(reachable);
}
use of com.ardor3d.math.type.ReadOnlyVector3 in project energy3d by concord-consortium.
the class Wall method addSurroundQuad.
protected void addSurroundQuad(final int i1, final int i2, final ReadOnlyVector3 n, final ReadOnlyVector3 thickness, final FloatBuffer vertexBuffer, final FloatBuffer normalBuffer) {
final ReadOnlyVector3 p1 = getAbsPoint(i1);
final ReadOnlyVector3 p2 = p1.add(thickness, null);
final ReadOnlyVector3 p3 = getAbsPoint(i2);
final ReadOnlyVector3 p4 = p3.add(thickness, null);
vertexBuffer.put(p1.getXf()).put(p1.getYf()).put(p1.getZf());
vertexBuffer.put(p3.getXf()).put(p3.getYf()).put(p3.getZf());
vertexBuffer.put(p4.getXf()).put(p4.getYf()).put(p4.getZf());
vertexBuffer.put(p2.getXf()).put(p2.getYf()).put(p2.getZf());
for (int i = 0; i < 4; i++) {
normalBuffer.put(n.getXf()).put(n.getYf()).put(n.getZf());
}
}
Aggregations