use of com.ardor3d.math.type.ReadOnlyVector3 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.type.ReadOnlyVector3 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.type.ReadOnlyVector3 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.type.ReadOnlyVector3 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.type.ReadOnlyVector3 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);
}
}
Aggregations