Search in sources :

Example 6 with ReadOnlyTransform

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;
}
Also used : ReadOnlyTransform(com.ardor3d.math.type.ReadOnlyTransform) FloatBuffer(java.nio.FloatBuffer) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 7 with ReadOnlyTransform

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)));
}
Also used : ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) ReadOnlyTransform(com.ardor3d.math.type.ReadOnlyTransform) FloatBuffer(java.nio.FloatBuffer) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 8 with ReadOnlyTransform

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;
}
Also used : ReadOnlyTransform(com.ardor3d.math.type.ReadOnlyTransform) FloatBuffer(java.nio.FloatBuffer) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 9 with ReadOnlyTransform

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);
}
Also used : ReadOnlyTransform(com.ardor3d.math.type.ReadOnlyTransform) FloatBuffer(java.nio.FloatBuffer) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 10 with ReadOnlyTransform

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);
}
Also used : ReadOnlyTransform(com.ardor3d.math.type.ReadOnlyTransform) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) FloatBuffer(java.nio.FloatBuffer) BloomRenderPass(com.ardor3d.extension.effect.bloom.BloomRenderPass) Matrix3(com.ardor3d.math.Matrix3)

Aggregations

Vector3 (com.ardor3d.math.Vector3)12 ReadOnlyTransform (com.ardor3d.math.type.ReadOnlyTransform)12 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)12 FloatBuffer (java.nio.FloatBuffer)10 CullHint (com.ardor3d.scenegraph.hint.CullHint)8 Matrix3 (com.ardor3d.math.Matrix3)3 ReadOnlyColorRGBA (com.ardor3d.math.type.ReadOnlyColorRGBA)3 BloomRenderPass (com.ardor3d.extension.effect.bloom.BloomRenderPass)2 ColladaImporter (com.ardor3d.extension.model.collada.jdom.ColladaImporter)1 ColladaStorage (com.ardor3d.extension.model.collada.jdom.data.ColladaStorage)1 Canvas (com.ardor3d.framework.Canvas)1 MouseState (com.ardor3d.input.MouseState)1 InputTrigger (com.ardor3d.input.logical.InputTrigger)1 KeyPressedCondition (com.ardor3d.input.logical.KeyPressedCondition)1 MouseButtonPressedCondition (com.ardor3d.input.logical.MouseButtonPressedCondition)1 MouseButtonReleasedCondition (com.ardor3d.input.logical.MouseButtonReleasedCondition)1 MouseMovedCondition (com.ardor3d.input.logical.MouseMovedCondition)1 TriggerAction (com.ardor3d.input.logical.TriggerAction)1 TwoInputStates (com.ardor3d.input.logical.TwoInputStates)1 IntersectionRecord (com.ardor3d.intersection.IntersectionRecord)1