Search in sources :

Example 36 with Matrix3

use of com.ardor3d.math.Matrix3 in project energy3d by concord-consortium.

the class Floor method flatten.

@Override
public void flatten(final double flattenTime) {
    root.setRotation((new Matrix3().fromAngles(flattenTime * Math.PI / 2, 0, 0)));
    root.updateWorldTransform(true);
    super.flatten(flattenTime);
}
Also used : Matrix3(com.ardor3d.math.Matrix3)

Example 37 with Matrix3

use of com.ardor3d.math.Matrix3 in project energy3d by concord-consortium.

the class FresnelReflector method drawMesh.

@Override
protected void drawMesh() {
    if (container == null) {
        return;
    }
    getEditPointShape(0).setDefaultColor(ColorRGBA.ORANGE);
    final double absoluteAzimuth = Math.toRadians(relativeAzimuth + getTopContainer().getAzimuth());
    baseZ = container instanceof Foundation ? container.getHeight() : container.getPoints().get(0).getZ();
    points.get(0).setZ(baseZ + baseHeight);
    final Vector3 center = getAbsPoint(0);
    final double annotationScale = Scene.getInstance().getAnnotationScale();
    reflector.setData(new Vector3(), 0.5 * moduleWidth / annotationScale, 0.5 * length / annotationScale, 0.15);
    reflector.updateModelBound();
    final FloatBuffer boxVertexBuffer = reflector.getMeshData().getVertexBuffer();
    final FloatBuffer vertexBuffer = mesh.getMeshData().getVertexBuffer();
    final FloatBuffer textureBuffer = mesh.getMeshData().getTextureBuffer(0);
    FloatBuffer outlineBuffer = outlines.getMeshData().getVertexBuffer();
    vertexBuffer.rewind();
    textureBuffer.rewind();
    final int nModules = Math.max(1, getNumberOfModules());
    final int outlineBufferSize = 24 + nModules * 6;
    if (outlineBuffer.capacity() < outlineBufferSize) {
        outlineBuffer = BufferUtils.createFloatBuffer(outlineBufferSize);
        outlines.getMeshData().setVertexBuffer(outlineBuffer);
    } else {
        outlineBuffer.rewind();
        outlineBuffer.limit(outlineBufferSize);
    }
    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();
    modulesRoot.detachAllChildren();
    if (nModules > 1) {
        // (0, 0)
        final Vector3 p0 = new Vector3(vertexBuffer.get(3), vertexBuffer.get(4), vertexBuffer.get(5));
        // (1, 0)
        final Vector3 p1 = new Vector3(vertexBuffer.get(6), vertexBuffer.get(7), vertexBuffer.get(8));
        // (0, 1)
        final Vector3 p2 = new Vector3(vertexBuffer.get(0), vertexBuffer.get(1), vertexBuffer.get(2));
        final Vector3 pd = p1.subtract(p0, null).normalizeLocal();
        final Vector3 pm = p2.add(p0, null).multiplyLocal(0.5);
        final Vector3 pn = p2.subtract(p0, null).multiplyLocal(0.5);
        for (double u = moduleLength; u < length; u += moduleLength) {
            // outline buffer will be rotated later
            final Vector3 p = pd.multiply(u / annotationScale, null).addLocal(pm);
            final Vector3 q = p.add(pn, null);
            outlineBuffer.put(q.getXf()).put(q.getYf()).put(q.getZf());
            p.subtractLocal(pn);
            outlineBuffer.put(p.getXf()).put(p.getYf()).put(p.getZf());
        }
        final Vector3 qd = new Matrix3().applyRotationZ(-absoluteAzimuth).applyPost(pd, null);
        for (double u = moduleLength; u < length; u += moduleLength) {
            addPole(qd.multiply((u - 0.5 * length) / annotationScale, null).addLocal(center), baseHeight, baseZ);
        }
    } else {
        addPole(center, baseHeight, baseZ);
    }
    outlines.updateModelBound();
    modulesRoot.getSceneHints().setCullHint(CullHint.Inherit);
    Matrix3 rotation;
    if (absorber != null) {
        final Vector3 absorberCenter = absorber.getSolarReceiverCenter();
        final Vector3 sunDirection = Heliodon.getInstance().computeSunLocation(Heliodon.getInstance().getCalendar()).normalizeLocal();
        // by default, the rotation axis is in the north-south direction, so az = 0 maps to (0, 1, 0)
        final Vector3 rotationAxis = new Vector3(Math.sin(absoluteAzimuth), Math.cos(absoluteAzimuth), 0);
        final double axisSunDot = sunDirection.dot(rotationAxis);
        // avoid singularity when the direction of the sun is perpendicular to the axis of the reflector
        sunDirection.subtractLocal(rotationAxis.multiply(Util.isZero(axisSunDot) ? 0.001 : axisSunDot, null)).normalizeLocal();
        // how much the reflected light should shift in the direction of the absorber tube?
        final double shift = sunDirection.getZ() < MathUtils.ZERO_TOLERANCE ? 0 : (center.getZ() - absorberCenter.getZ()) * (sunDirection.getY() * rotationAxis.getY() + sunDirection.getX() * rotationAxis.getX()) / sunDirection.getZ();
        absorberCenter.setY(absorberCenter.getY() + shift * rotationAxis.getY());
        absorberCenter.setX(absorberCenter.getX() + shift * rotationAxis.getX());
        final Vector3 reflectorToAbsorberDirection = absorberCenter.subtractLocal(center).normalizeLocal();
        final double axisRefDot = reflectorToAbsorberDirection.dot(rotationAxis);
        reflectorToAbsorberDirection.subtractLocal(rotationAxis.multiply(Util.isZero(axisRefDot) ? 0.001 : axisRefDot, null)).normalizeLocal();
        normal = reflectorToAbsorberDirection.add(sunDirection, null).multiplyLocal(0.5).normalizeLocal();
        if (Util.isEqual(normal, Vector3.UNIT_Z)) {
            normal = new Vector3(-0.001, 0, 1).normalizeLocal();
        }
        rotation = new Matrix3().lookAt(normal, rotationAxis);
    } else {
        // exactly 90 degrees will cause the reflector to disappear
        setNormal(Math.PI / 2 * 0.9999, Math.toRadians(relativeAzimuth));
        if (Util.isEqual(normal, Vector3.UNIT_Z)) {
            normal = new Vector3(-0.001, 0, 1).normalizeLocal();
        }
        rotation = new Matrix3().lookAt(normal, normal.getX() > 0 ? Vector3.UNIT_Z : Vector3.NEG_UNIT_Z);
    }
    mesh.setRotation(rotation);
    mesh.setTranslation(center);
    reflector.setRotation(mesh.getRotation());
    reflector.setTranslation(mesh.getTranslation());
    outlines.setRotation(mesh.getRotation());
    outlines.setTranslation(mesh.getTranslation());
    mesh.updateModelBound();
    reflector.updateModelBound();
    outlines.updateModelBound();
    if (beamsVisible) {
        drawSunBeam();
    }
    updateLabel();
    CollisionTreeManager.INSTANCE.removeCollisionTree(mesh);
    CollisionTreeManager.INSTANCE.removeCollisionTree(reflector);
    root.updateGeometricState(0);
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) FloatBuffer(java.nio.FloatBuffer) CullHint(com.ardor3d.scenegraph.hint.CullHint) Matrix3(com.ardor3d.math.Matrix3)

Example 38 with Matrix3

use of com.ardor3d.math.Matrix3 in project energy3d by concord-consortium.

the class FresnelReflector method setNormal.

private void setNormal(final double angle, final double azimuth) {
    final Foundation foundation = getTopContainer();
    Vector3 v = foundation.getAbsPoint(0);
    // x direction
    final Vector3 vx = foundation.getAbsPoint(2).subtractLocal(v);
    // y direction
    final Vector3 vy = foundation.getAbsPoint(1).subtractLocal(v);
    if (Util.isZero(azimuth)) {
        v = new Matrix3().fromAngleAxis(angle, vx).applyPost(vy, null);
    } else {
        final Matrix3 m = new Matrix3().applyRotationZ(-azimuth);
        final Vector3 v1 = m.applyPost(vx, null);
        final Vector3 v2 = m.applyPost(vy, null);
        v = new Matrix3().fromAngleAxis(angle, v1).applyPost(v2, null);
    }
    if (v.getZ() < 0) {
        v.negateLocal();
    }
    normal = v.normalizeLocal();
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Matrix3(com.ardor3d.math.Matrix3)

Aggregations

Matrix3 (com.ardor3d.math.Matrix3)38 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)31 Vector3 (com.ardor3d.math.Vector3)30 FloatBuffer (java.nio.FloatBuffer)12 CullHint (com.ardor3d.scenegraph.hint.CullHint)10 BloomRenderPass (com.ardor3d.extension.effect.bloom.BloomRenderPass)6 Node (com.ardor3d.scenegraph.Node)5 Spatial (com.ardor3d.scenegraph.Spatial)5 Mesh (com.ardor3d.scenegraph.Mesh)4 BoundingBox (com.ardor3d.bounding.BoundingBox)3 ColladaImporter (com.ardor3d.extension.model.collada.jdom.ColladaImporter)3 ColladaStorage (com.ardor3d.extension.model.collada.jdom.data.ColladaStorage)3 ReadOnlyTransform (com.ardor3d.math.type.ReadOnlyTransform)3 DirectionalLight (com.ardor3d.light.DirectionalLight)2 BlendState (com.ardor3d.renderer.state.BlendState)2 LightState (com.ardor3d.renderer.state.LightState)2 BillboardNode (com.ardor3d.scenegraph.extension.BillboardNode)2 CameraNode (com.ardor3d.scenegraph.extension.CameraNode)2 Quad (com.ardor3d.scenegraph.shape.Quad)2 ResourceSource (com.ardor3d.util.resource.ResourceSource)2