use of com.ardor3d.math.type.ReadOnlyTransform in project energy3d by concord-consortium.
the class SolarPanel method checkContainerIntersection.
public boolean checkContainerIntersection() {
final double z0 = container.getAbsCenter().getZ() + container.height + surround.getZExtent() * 2;
final FloatBuffer buf = mesh.getMeshData().getVertexBuffer();
final ReadOnlyTransform trans = mesh.getWorldTransform();
final Vector3 v1 = new Vector3();
final Vector3 v2 = new Vector3();
BufferUtils.populateFromBuffer(v1, buf, 0);
BufferUtils.populateFromBuffer(v2, buf, 1);
final Vector3 p1 = trans.applyForward(v1).add(trans.applyForward(v2), null).multiplyLocal(0.5);
if (p1.getZ() < z0) {
return true;
}
BufferUtils.populateFromBuffer(v1, buf, 1);
BufferUtils.populateFromBuffer(v2, buf, 2);
final Vector3 p2 = trans.applyForward(v1).add(trans.applyForward(v2), null).multiplyLocal(0.5);
if (p2.getZ() < z0) {
return true;
}
BufferUtils.populateFromBuffer(v1, buf, 2);
BufferUtils.populateFromBuffer(v2, buf, 4);
final Vector3 p3 = trans.applyForward(v1).add(trans.applyForward(v2), null).multiplyLocal(0.5);
if (p3.getZ() < z0) {
return true;
}
BufferUtils.populateFromBuffer(v1, buf, 4);
BufferUtils.populateFromBuffer(v2, buf, 0);
final Vector3 p4 = trans.applyForward(v1).add(trans.applyForward(v2), null).multiplyLocal(0.5);
if (p4.getZ() < z0) {
return true;
}
return false;
}
use of com.ardor3d.math.type.ReadOnlyTransform in project energy3d by concord-consortium.
the class Rack method updateEditShapes.
@Override
public void updateEditShapes() {
final FloatBuffer buf = mesh.getMeshData().getVertexBuffer();
final ReadOnlyTransform trans = mesh.getWorldTransform();
final Vector3 v1 = new Vector3();
final Vector3 v2 = new Vector3();
BufferUtils.populateFromBuffer(v1, buf, 0);
BufferUtils.populateFromBuffer(v2, buf, 1);
final Vector3 p1 = trans.applyForward(v1).add(trans.applyForward(v2), null).multiplyLocal(0.5);
BufferUtils.populateFromBuffer(v1, buf, 1);
BufferUtils.populateFromBuffer(v2, buf, 2);
final Vector3 p2 = trans.applyForward(v1).add(trans.applyForward(v2), null).multiplyLocal(0.5);
BufferUtils.populateFromBuffer(v1, buf, 2);
BufferUtils.populateFromBuffer(v2, buf, 4);
final Vector3 p3 = trans.applyForward(v1).add(trans.applyForward(v2), null).multiplyLocal(0.5);
BufferUtils.populateFromBuffer(v1, buf, 4);
BufferUtils.populateFromBuffer(v2, buf, 0);
final Vector3 p4 = trans.applyForward(v1).add(trans.applyForward(v2), null).multiplyLocal(0.5);
if (!monolithic) {
// the rack may be filled with individual solar panels whose center may overlap with the handles when zooming out, so shift them out
final Vector3 d31 = p3.subtract(p1, null).normalizeLocal();
final Vector3 d42 = p4.subtract(p2, null).normalizeLocal();
p1.subtractLocal(d31.multiply(2.5, null));
p3.addLocal(d31.multiply(2.5, null));
p2.subtractLocal(d42.multiply(2.5, null));
p4.addLocal(d42.multiply(2.5, null));
}
int i = 1;
getEditPointShape(i++).setTranslation(p1);
getEditPointShape(i++).setTranslation(p2);
getEditPointShape(i++).setTranslation(p3);
getEditPointShape(i++).setTranslation(p4);
final ReadOnlyColorRGBA c = Scene.getInstance().isGroundImageLightColored() ? ColorRGBA.DARK_GRAY : (lockEdit ? disabledColor : ColorRGBA.WHITE);
for (i = 1; i < 5; i++) {
getEditPointShape(i).setDefaultColor(c);
}
super.updateEditShapes();
getEditPointShape(0).setTranslation(p1.addLocal(p3).multiplyLocal(0.5).addLocal(0, 0, (monolithic ? 0.15 : 1)));
}
use of com.ardor3d.math.type.ReadOnlyTransform in project energy3d by concord-consortium.
the class Rack method checkContainerIntersection.
public boolean checkContainerIntersection() {
final double z0 = (container instanceof Floor ? container.getAbsCenter().getZ() : container.getAbsCenter().getZ() + container.height) + surround.getZExtent() * 2;
final FloatBuffer buf = mesh.getMeshData().getVertexBuffer();
final ReadOnlyTransform trans = mesh.getWorldTransform();
final Vector3 v1 = new Vector3();
final Vector3 v2 = new Vector3();
BufferUtils.populateFromBuffer(v1, buf, 0);
BufferUtils.populateFromBuffer(v2, buf, 1);
final Vector3 p1 = trans.applyForward(v1).add(trans.applyForward(v2), null).multiplyLocal(0.5);
if (p1.getZ() < z0) {
return true;
}
BufferUtils.populateFromBuffer(v1, buf, 1);
BufferUtils.populateFromBuffer(v2, buf, 2);
final Vector3 p2 = trans.applyForward(v1).add(trans.applyForward(v2), null).multiplyLocal(0.5);
if (p2.getZ() < z0) {
return true;
}
BufferUtils.populateFromBuffer(v1, buf, 2);
BufferUtils.populateFromBuffer(v2, buf, 4);
final Vector3 p3 = trans.applyForward(v1).add(trans.applyForward(v2), null).multiplyLocal(0.5);
if (p3.getZ() < z0) {
return true;
}
BufferUtils.populateFromBuffer(v1, buf, 4);
BufferUtils.populateFromBuffer(v2, buf, 0);
final Vector3 p4 = trans.applyForward(v1).add(trans.applyForward(v2), null).multiplyLocal(0.5);
if (p4.getZ() < z0) {
return true;
}
return false;
}
use of com.ardor3d.math.type.ReadOnlyTransform in project energy3d by concord-consortium.
the class Rack method drawSolarPanelOutlines.
// solar panels would vanish in the single heat map texture without drawing these lines
private void drawSolarPanelOutlines() {
final FloatBuffer vertexBuffer = mesh.getMeshData().getVertexBuffer();
// do not use WorldTransform
final ReadOnlyTransform trans = mesh.getTransform();
// (0, 0)
final Vector3 p0 = trans.applyForward(new Vector3(vertexBuffer.get(3), vertexBuffer.get(4), vertexBuffer.get(5)));
// (1, 0)
final Vector3 p1 = trans.applyForward(new Vector3(vertexBuffer.get(6), vertexBuffer.get(7), vertexBuffer.get(8)));
// (0, 1)
final Vector3 p2 = trans.applyForward(new Vector3(vertexBuffer.get(0), vertexBuffer.get(1), vertexBuffer.get(2)));
final boolean portrait = !sampleSolarPanel.isRotated();
double a = portrait ? sampleSolarPanel.getPanelWidth() : sampleSolarPanel.getPanelHeight();
double b = portrait ? sampleSolarPanel.getPanelHeight() : sampleSolarPanel.getPanelWidth();
final int nw = (int) Math.round(rackWidth / a);
final int nh = (int) Math.round(rackHeight / b);
a /= Scene.getInstance().getAnnotationScale();
b /= Scene.getInstance().getAnnotationScale();
final int bufferSize = (nw + nh - 2) * 6;
FloatBuffer vertices = solarPanelOutlines.getMeshData().getVertexBuffer();
if (vertices.capacity() != bufferSize) {
vertices = BufferUtils.createFloatBuffer(bufferSize);
solarPanelOutlines.getMeshData().setVertexBuffer(vertices);
} else {
vertices.rewind();
vertices.limit(vertices.capacity());
}
final Vector3 u = p1.subtract(p0, null).normalizeLocal().multiplyLocal(b);
final Vector3 v = p2.subtract(p0, null).normalizeLocal().multiplyLocal(a);
Vector3 p, q;
for (int i = 1; i < nw; i++) {
q = v.multiply(i, null);
p = p0.add(q, null);
vertices.put(p.getXf()).put(p.getYf()).put(p.getZf());
p = p1.add(q, null);
vertices.put(p.getXf()).put(p.getYf()).put(p.getZf());
}
for (int i = 1; i < nh; i++) {
q = u.multiply(i, null);
p = p0.add(q, null);
vertices.put(p.getXf()).put(p.getYf()).put(p.getZf());
p = p2.add(q, null);
vertices.put(p.getXf()).put(p.getYf()).put(p.getZf());
}
solarPanelOutlines.updateModelBound();
solarPanelOutlines.setVisible(true);
}
use of com.ardor3d.math.type.ReadOnlyTransform in project energy3d by concord-consortium.
the class Rack method drawSunBeam.
@Override
public void drawSunBeam() {
if (Heliodon.getInstance().isNightTime() || !drawSunBeam) {
sunBeam.setVisible(false);
normalVector.setVisible(false);
sunAngle.setVisible(false);
return;
}
final Vector3 o = getAbsPoint(0);
final Vector3 sunLocation = Heliodon.getInstance().computeSunLocation(Heliodon.getInstance().getCalendar()).normalizeLocal();
final FloatBuffer beamsVertices = sunBeam.getMeshData().getVertexBuffer();
beamsVertices.rewind();
// draw sun vector
Vector3 r = o.clone();
r.addLocal(sunLocation.multiply(10000, null));
beamsVertices.put(o.getXf()).put(o.getYf()).put(o.getZf());
beamsVertices.put(r.getXf()).put(r.getYf()).put(r.getZf());
sunBeam.updateModelBound();
sunBeam.setVisible(true);
if (bloomRenderPass == null) {
bloomRenderPass = new BloomRenderPass(SceneManager.getInstance().getCamera(), 10);
bloomRenderPass.setBlurIntensityMultiplier(0.5f);
bloomRenderPass.setNrBlurPasses(2);
SceneManager.getInstance().getPassManager().add(bloomRenderPass);
}
if (!bloomRenderPass.contains(sunBeam)) {
bloomRenderPass.add(sunBeam);
}
final FloatBuffer normalVertices = normalVector.getMeshData().getVertexBuffer();
normalVertices.rewind();
// draw normal vector
r = o.clone();
r.addLocal(normal.multiply(normalVectorLength, null));
normalVertices.put(o.getXf()).put(o.getYf()).put(o.getZf());
normalVertices.put(r.getXf()).put(r.getYf()).put(r.getZf());
// draw arrows of the normal vector
final double arrowLength = 0.75;
final double arrowAngle = Math.toRadians(20);
final Matrix3 matrix = new Matrix3();
final FloatBuffer buf = mesh.getMeshData().getVertexBuffer();
final ReadOnlyTransform trans = mesh.getWorldTransform();
final Vector3 v1 = new Vector3();
final Vector3 v2 = new Vector3();
BufferUtils.populateFromBuffer(v1, buf, 1);
BufferUtils.populateFromBuffer(v2, buf, 2);
Vector3 a = trans.applyForward(v1).subtract(trans.applyForward(v2), null).normalizeLocal();
a = a.crossLocal(normal);
Vector3 s = normal.clone();
s = matrix.fromAngleNormalAxis(arrowAngle, a).applyPost(s, null).multiplyLocal(arrowLength);
s = r.subtract(s, null);
normalVertices.put(r.getXf()).put(r.getYf()).put(r.getZf());
normalVertices.put(s.getXf()).put(s.getYf()).put(s.getZf());
s = normal.clone();
s = matrix.fromAngleNormalAxis(-arrowAngle, a).applyPost(s, null).multiplyLocal(arrowLength);
s = r.subtract(s, null);
normalVertices.put(r.getXf()).put(r.getYf()).put(r.getZf());
normalVertices.put(s.getXf()).put(s.getYf()).put(s.getZf());
// draw the angle between the sun beam and the normal vector
normal.cross(sunLocation, a);
sunAngle.setRange(o, o.add(sunLocation, null), o.add(normal, null), a);
sunAngle.setVisible(true);
normalVector.updateModelBound();
normalVector.setVisible(true);
}
Aggregations