use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Heliodon method drawSunRegion.
private void drawSunRegion() {
final FloatBuffer buf = sunRegion.getMeshData().getVertexBuffer();
buf.limit(buf.capacity());
buf.rewind();
final double declinationStep = 2.0 * TILT_ANGLE / DECLINATION_DIVISIONS;
final double hourStep = MathUtils.TWO_PI / HOUR_DIVISIONS;
int limit = 0;
for (double declinationAngle = -TILT_ANGLE; declinationAngle < TILT_ANGLE - declinationStep / 2.0; declinationAngle += declinationStep) {
for (double hourAngle = -Math.PI; hourAngle < Math.PI - hourStep / 2.0; hourAngle += hourStep) {
double hourAngle2 = hourAngle + hourStep;
double declinationAngle2 = declinationAngle + declinationStep;
if (hourAngle2 > Math.PI) {
hourAngle2 = Math.PI;
}
if (declinationAngle2 > TILT_ANGLE) {
declinationAngle2 = TILT_ANGLE;
}
final Vector3 v1 = computeSunLocation(hourAngle, declinationAngle, latitude);
final Vector3 v2 = computeSunLocation(hourAngle2, declinationAngle, latitude);
final Vector3 v3 = computeSunLocation(hourAngle2, declinationAngle2, latitude);
final Vector3 v4 = computeSunLocation(hourAngle, declinationAngle2, latitude);
if (v1.getZ() >= 0 || v2.getZ() >= 0 || v3.getZ() >= 0 || v4.getZ() >= 0) {
buf.put(v1.getXf()).put(v1.getYf()).put(v1.getZf()).put(v2.getXf()).put(v2.getYf()).put(v2.getZf()).put(v3.getXf()).put(v3.getYf()).put(v3.getZf()).put(v4.getXf()).put(v4.getYf()).put(v4.getZf());
limit += 12;
}
}
}
buf.limit(limit);
sunRegion.getMeshData().updateVertexCount();
sunRegion.updateModelBound();
sunRegion.updateGeometricState(0);
dirtySunRegion = false;
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Heliodon method drawSun.
public void drawSun() {
final Vector3 sunLocation = computeSunLocation(hourAngle, declinationAngle, latitude);
setSunLocation(sunLocation);
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class SizeAnnotation method draw.
@Override
public void draw() {
final double C = 1.0;
final Vector3 v = new Vector3();
final Vector3 offset = new Vector3();
if (front && !drawInside)
offset.set(faceDirection).normalizeLocal().multiplyLocal(C).addLocal(0, 0, 0.05);
else {
offset.set(to).subtractLocal(from).normalizeLocal().crossLocal(faceDirection).multiplyLocal(C);
if (autoFlipOffset) {
v.set(from).subtractLocal(center).normalizeLocal();
if (v.dot(offset) < 0)
offset.negateLocal();
}
}
if (drawInside)
offset.negateLocal();
final ReadOnlyVector3 dir = to.subtract(from, null).normalizeLocal();
final int scale = upsideDownText ? -1 : 1;
final Vector3 xdir = dir.multiply(scale, null);
final Vector3 ydir = faceDirection.normalize(null);
final Vector3 zdir = ydir.cross(xdir, null).normalizeLocal();
zdir.cross(ydir, xdir);
if (zdir.dot(Vector3.UNIT_Z) < 0) {
zdir.negateLocal();
xdir.negateLocal();
}
final Matrix3 matrix = new Matrix3().fromAxes(xdir, ydir, zdir);
label.setRotation(matrix);
FloatBuffer vertexBuffer = mesh.getMeshData().getVertexBuffer();
vertexBuffer.rewind();
// main line
final Vector3 newFrom = new Vector3(from).addLocal(offset);
final Vector3 newTo = new Vector3(to).addLocal(offset);
final Vector3 middle = new Vector3(newFrom).addLocal(newTo).multiplyLocal(0.5);
final Vector3 body = new Vector3(to).subtractLocal(from).multiplyLocal(0.5);
label.setTranslation(middle);
final DecimalFormat df = new DecimalFormat("#.##");
double length = to.subtract(from, null).length() * Scene.getInstance().getAnnotationScale();
switch(Scene.getInstance().getUnit()) {
case InternationalSystemOfUnits:
label.setText(df.format(length) + " m");
break;
case USCustomaryUnits:
label.setText(df.format(length * 3.28084) + " ft");
break;
}
label.setAlign(align);
label.updateWorldTransform(true);
label.updateWorldBound(true);
vertexBuffer.put(newFrom.getXf()).put(newFrom.getYf()).put(newFrom.getZf());
final double bankSpace = label.getWidth() * 0.70;
final double blankSpaceFactor = Math.max(0, body.length() - bankSpace) / body.length();
v.set(body).multiplyLocal(blankSpaceFactor).addLocal(newFrom);
vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
v.set(body).multiplyLocal(-blankSpaceFactor).addLocal(newTo);
vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
vertexBuffer.put(newTo.getXf()).put(newTo.getYf()).put(newTo.getZf());
offset.multiplyLocal(0.5);
// from End
v.set(from);
vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
v.set(newFrom).addLocal(offset);
vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
// to End
v.set(to);
vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
v.set(newTo).addLocal(offset);
vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
// arrow
offset.multiplyLocal(0.5);
body.set(to).subtractLocal(from).normalizeLocal().multiplyLocal(0.5);
mesh.updateModelBound();
vertexBuffer = arrows.getMeshData().getVertexBuffer();
vertexBuffer.rewind();
// arrow from
v.set(newFrom);
vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
v.addLocal(offset).addLocal(body);
vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
v.set(newFrom).subtractLocal(offset).addLocal(body);
vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
// arrow to
body.negateLocal();
v.set(newTo);
vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
v.addLocal(offset).addLocal(body);
vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
v.set(newTo).subtractLocal(offset).addLocal(body);
vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
arrows.updateModelBound();
updateWorldTransform(true);
updateWorldBound(true);
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Rack method findRotationMatrix.
private Matrix3 findRotationMatrix(final ReadOnlyVector3 v1, final ReadOnlyVector3 v2) {
final double angle = v1.smallestAngleBetween(v2);
final Vector3 axis = v1.cross(v2, null).normalizeLocal();
final Matrix3 matrix = new Matrix3().fromAngleAxis(angle, axis);
return matrix;
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Rack method outOfBound.
private boolean outOfBound() {
drawMesh();
if (container instanceof Foundation) {
final Foundation foundation = (Foundation) container;
final int n = Math.round(mesh.getMeshData().getVertexBuffer().limit() / 3);
for (int i = 0; i < n; i++) {
final Vector3 a = getVertex(i);
if (a.getZ() < foundation.getHeight() * 1.1) {
// left a 10% margin above the foundation
return true;
}
if (!foundation.containsPoint(a.getX(), a.getY())) {
return true;
}
}
} else if (container instanceof Roof) {
final Roof roof = (Roof) container;
final int n = Math.round(mesh.getMeshData().getVertexBuffer().limit() / 3);
boolean init = true;
for (int i = 0; i < n; i++) {
final Vector3 a = getVertex(i);
if (!roof.insideWalls(a.getX(), a.getY(), init)) {
return true;
}
if (init) {
init = false;
}
}
}
return false;
}
Aggregations