Search in sources :

Example 6 with Matrix3

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

the class HousePart method flatten.

public void flatten(final double flattenTime) {
    if (isPrintable()) {
        if (isPrintVertical) {
            root.setRotation(new Matrix3().fromAngles(0, -Math.PI / 2.0 * flattenTime, 0).multiply(root.getRotation(), null));
        }
        final Vector3 targetCenter = new Vector3(((UserData) mesh.getUserData()).getPrintCenter());
        root.setTranslation(targetCenter.subtractLocal(flattenCenter).multiplyLocal(flattenTime));
        root.updateGeometricState(0);
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Matrix3(com.ardor3d.math.Matrix3)

Example 7 with Matrix3

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

the class Human method init.

@Override
protected void init() {
    super.init();
    final double h;
    final double w;
    switch(humanType) {
        case JANE:
            w = 2.5;
            h = 8;
            break;
        case JENI:
            w = 3;
            h = 9;
            break;
        case JILL:
            w = 3;
            h = 8;
            break;
        case JACK:
            w = 2.8;
            h = 9;
            break;
        case JOHN:
            w = 4;
            h = 10;
            break;
        case JOSE:
            w = 8;
            h = 8;
            break;
        default:
            w = 2.5;
            h = 8;
    }
    mesh = new Quad("Human Quad", w, h);
    mesh.setModelBound(new BoundingBox());
    mesh.updateModelBound();
    mesh.setRotation(new Matrix3().fromAngles(Math.PI / 2, 0, 0));
    // stand on the ground by default
    translate(w, h, feetHeight);
    mesh.setUserData(new UserData(this, 0, true));
    final BlendState bs = new BlendState();
    bs.setEnabled(true);
    bs.setBlendEnabled(false);
    bs.setTestEnabled(true);
    bs.setTestFunction(TestFunction.GreaterThan);
    bs.setReference(0.7f);
    mesh.setRenderState(bs);
    mesh.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
    billboard = new BillboardNode("Billboard");
    billboard.setAlignment(BillboardAlignment.AxialZ);
    billboard.attachChild(mesh);
    root.attachChild(billboard);
    updateTextureAndColor();
}
Also used : Quad(com.ardor3d.scenegraph.shape.Quad) BoundingBox(com.ardor3d.bounding.BoundingBox) BillboardNode(com.ardor3d.scenegraph.extension.BillboardNode) BlendState(com.ardor3d.renderer.state.BlendState) Matrix3(com.ardor3d.math.Matrix3)

Example 8 with Matrix3

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

the class SceneManager method createCompass.

private Node createCompass() throws IOException {
    final ResourceSource source = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_MODEL, "compass.dae");
    final ColladaImporter colladaImporter = new ColladaImporter();
    // Load the collada scene
    Logger.getLogger(ColladaAnimUtils.class.getName()).setLevel(Level.SEVERE);
    Logger.getLogger(ColladaMaterialUtils.class.getName()).setLevel(Level.SEVERE);
    final ColladaStorage storage = colladaImporter.load(source);
    final Node compass = storage.getScene();
    BMText txt;
    final double Z = 0.1;
    txt = new BMText("N", "N", FontManager.getInstance().getAnnotationFont(), Align.South);
    txt.setTextColor(ColorRGBA.BLACK);
    txt.setAutoRotate(false);
    txt.setTranslation(2, 0.0, Z);
    txt.setRotation(new Matrix3().fromAngles(0.0, MathUtils.HALF_PI, -MathUtils.HALF_PI));
    compass.attachChild(txt);
    txt = new BMText("S", "S", FontManager.getInstance().getAnnotationFont(), Align.South);
    txt.setTextColor(ColorRGBA.BLACK);
    txt.setAutoRotate(false);
    txt.setTranslation(-2, -0.0, Z);
    txt.setRotation(new Matrix3().fromAngles(0.0, -MathUtils.HALF_PI, MathUtils.HALF_PI));
    compass.attachChild(txt);
    txt = new BMText("W", "W", FontManager.getInstance().getAnnotationFont(), Align.South);
    txt.setAutoRotate(false);
    txt.setTranslation(-0.0, 2, Z);
    txt.setRotation(new Matrix3().fromAngles(-MathUtils.HALF_PI, 0.0, 0.0));
    compass.attachChild(txt);
    txt = new BMText("E", "E", FontManager.getInstance().getAnnotationFont(), Align.South);
    txt.setAutoRotate(false);
    txt.setTranslation(-0.0, -2, Z);
    txt.setRotation(new Matrix3().fromAngles(MathUtils.HALF_PI, MathUtils.PI, 0.0));
    compass.attachChild(txt);
    final DirectionalLight light = new DirectionalLight();
    light.setDirection(new Vector3(0, 0, -1));
    light.setEnabled(true);
    final LightState lightState = new LightState();
    lightState.attach(light);
    compass.setRenderState(lightState);
    compass.getSceneHints().setLightCombineMode(LightCombineMode.Replace);
    compass.updateWorldRenderStates(true);
    final Node compassNode = new Node();
    compassNode.setRotation(new Matrix3().fromAngles(-MathUtils.HALF_PI, 0.0, 0.0));
    compassNode.attachChild(compass);
    System.out.println("done");
    compass.addController(new SpatialController<Spatial>() {

        @Override
        public void update(final double time, final Spatial caller) {
            final Vector3 direction = getCamera().getDirection().normalize(null);
            direction.setZ(0);
            direction.normalizeLocal();
            double angle = -direction.smallestAngleBetween(Vector3.UNIT_Y);
            if (direction.dot(Vector3.UNIT_X) > 0) {
                angle = -angle;
            }
            angle -= MathUtils.HALF_PI;
            compass.setRotation(new Matrix3().fromAngles(0.0, 0.0, angle - 0.3));
        }
    });
    return compassNode;
}
Also used : LightState(com.ardor3d.renderer.state.LightState) ColladaImporter(com.ardor3d.extension.model.collada.jdom.ColladaImporter) Node(com.ardor3d.scenegraph.Node) CameraNode(com.ardor3d.scenegraph.extension.CameraNode) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Matrix3(com.ardor3d.math.Matrix3) ResourceSource(com.ardor3d.util.resource.ResourceSource) Spatial(com.ardor3d.scenegraph.Spatial) DirectionalLight(com.ardor3d.light.DirectionalLight) ColladaStorage(com.ardor3d.extension.model.collada.jdom.data.ColladaStorage) BMText(com.ardor3d.ui.text.BMText)

Example 9 with Matrix3

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

the class AngleAnnotation method draw.

@Override
public void draw() {
    final ReadOnlyVector3 a = new Vector3().set(p2).subtractLocal(mainPoint).normalizeLocal();
    final ReadOnlyVector3 b = new Vector3().set(p3).subtractLocal(mainPoint).normalizeLocal();
    final ReadOnlyVector3 axis = n.cross(Vector3.UNIT_Z, null).normalizeLocal();
    final Matrix3 toFlat = new Matrix3().fromAngleAxis(Util.angleBetween(n, Vector3.UNIT_Z, n.cross(Vector3.UNIT_Z, null).normalizeLocal()), axis);
    final ReadOnlyVector3 aFlat = toFlat.applyPost(a, null);
    final ReadOnlyVector3 bFlat = toFlat.applyPost(b, null);
    double start, angle;
    if (Util.angleBetween(aFlat, bFlat, Vector3.UNIT_Z) >= 0) {
        start = Util.angleBetween(Vector3.UNIT_X, aFlat, Vector3.UNIT_Z);
        angle = Util.angleBetween(aFlat, bFlat, Vector3.UNIT_Z);
    } else {
        start = Util.angleBetween(Vector3.UNIT_X, bFlat, Vector3.UNIT_Z);
        angle = Util.angleBetween(bFlat, aFlat, Vector3.UNIT_Z);
    }
    double end = start + angle;
    final long angleDegrees = Math.round(Math.toDegrees(end - start));
    final double radius = customRadius > 0 ? customRadius : (end == start ? 0.0 : 3.0 / Math.sqrt(end - start));
    if (angleDegrees == 90) {
        final ReadOnlyVector3[] p = new ReadOnlyVector3[3];
        p[0] = a.normalize(null).multiplyLocal(2.0);
        p[1] = a.normalize(null).addLocal(b.normalize(null)).multiplyLocal(2.0);
        p[2] = b.normalize(null).multiplyLocal(2.0);
        final FloatBuffer buf = mesh.getMeshData().getVertexBuffer();
        buf.rewind();
        buf.limit(9);
        mesh.getMeshData().updateVertexCount();
        buf.rewind();
        for (final ReadOnlyVector3 v : p) {
            buf.put(v.getXf()).put(v.getYf()).put(v.getZf());
        }
        mesh.setRotation(new Matrix3());
        detachChild(label);
    } else {
        boolean special = false;
        if ("A".equals(customText) && Util.isEqual(start, Math.PI / 2)) {
            // special case for azimuth
            angle = angle - Math.PI * 2;
            if (Util.isEqual(Math.abs(angle), 2 * Math.PI)) {
                angle = 0;
            }
            end = start + angle;
            label.setText("A=" + (angleDegrees == 0 ? 0 : (360 - angleDegrees)) + "\u00B0");
            special = true;
        } else {
            label.setText((customText != null ? customText + "=" : "") + angleDegrees + "\u00B0");
        }
        ((Arc) mesh).set(radius, start, end);
        mesh.setRotation(toFlat.invertLocal());
        final double start360 = start < 0 ? MathUtils.TWO_PI + start : start;
        final double angle360 = angle < 0 ? MathUtils.TWO_PI + angle : angle;
        final double end360 = start360 + angle360;
        final Matrix3 rotMatrix = toFlat.multiplyLocal(new Matrix3().fromAngles(-Math.PI / 2, 0, (special ? Math.PI / 2 : -Math.PI / 2) + (start360 + end360) / 2));
        label.setRotation(rotMatrix);
        final Vector3 trans = new Vector3(0, 0, radius / 1.7);
        label.setTranslation(rotMatrix.applyPost(trans, trans));
        attachChild(label);
    }
    mesh.updateModelBound();
    this.setTranslation(mainPoint);
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) FloatBuffer(java.nio.FloatBuffer) Matrix3(com.ardor3d.math.Matrix3)

Example 10 with Matrix3

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