Package com.ardor3d.math

Examples of com.ardor3d.math.Matrix3


        final ReadOnlyVector3 camLeft = _camera.getLeft();
        final ReadOnlyVector3 camUp = _camera.getUp();
        final ReadOnlyVector3 camDir = _camera.getDirection();
        final ReadOnlyVector3 camLoc = _camera.getLocation();

        final Matrix3 rotation = Matrix3.fetchTempInstance();
        rotation.fromAxes(camLeft, camUp, camDir);

        setRotation(rotation);
        setTranslation(camLoc);

        Matrix3.releaseTempInstance(rotation);
View Full Code Here


        _orient.setValue(2, 1, xzp.getZ() * -_look.getY());
        _orient.setValue(2, 2, xzp.getZ() * cosp);

        // The billboard must be oriented to face the camera before it is
        // transformed into the world.
        final Matrix3 mat = Matrix3.fetchTempInstance().set(_worldTransform.getMatrix()).multiplyLocal(_orient);
        _worldTransform.setRotation(mat);
        Matrix3.releaseTempInstance(mat);
    }
View Full Code Here

        final Camera camera = Camera.getCurrentCamera();
        // Compute the additional rotation required for the billboard to face
        // the camera. To do this, the camera must be inverse-transformed into
        // the model space of the billboard.
        _look.set(camera.getLocation()).subtractLocal(_worldTransform.getTranslation());
        final Matrix3 worldMatrix = Matrix3.fetchTempInstance().set(_worldTransform.getMatrix());
        worldMatrix.applyPost(_look, _left); // coopt left for our own purposes.
        final ReadOnlyVector3 scale = _worldTransform.getScale();
        _left.divideLocal(scale);

        // squared length of the camera projection in the xz-plane
        final double lengthSquared = _left.getX() * _left.getX() + _left.getZ() * _left.getZ();
        if (lengthSquared < MathUtils.EPSILON) {
            // camera on the billboard axis, rotation not defined
            return;
        }

        // unitize the projection
        final double invLength = 1.0 / Math.sqrt(lengthSquared);
        if (axis.getY() == 1) {
            _left.setX(_left.getX() * invLength);
            _left.setY(0.0);
            _left.setZ(_left.getZ() * invLength);

            // compute the local orientation matrix for the billboard
            _orient.setValue(0, 0, _left.getZ());
            _orient.setValue(0, 1, 0);
            _orient.setValue(0, 2, _left.getX());
            _orient.setValue(1, 0, 0);
            _orient.setValue(1, 1, 1);
            _orient.setValue(1, 2, 0);
            _orient.setValue(2, 0, -_left.getX());
            _orient.setValue(2, 1, 0);
            _orient.setValue(2, 2, _left.getZ());
        } else if (axis.getZ() == 1) {
            _left.setX(_left.getX() * invLength);
            _left.setY(_left.getY() * invLength);
            _left.setZ(0.0);

            // compute the local orientation matrix for the billboard
            _orient.setValue(0, 0, _left.getY());
            _orient.setValue(0, 1, _left.getX());
            _orient.setValue(0, 2, 0);
            _orient.setValue(1, 0, -_left.getY());
            _orient.setValue(1, 1, _left.getX());
            _orient.setValue(1, 2, 0);
            _orient.setValue(2, 0, 0);
            _orient.setValue(2, 1, 0);
            _orient.setValue(2, 2, 1);
        }

        // The billboard must be oriented to face the camera before it is
        // transformed into the world.
        worldMatrix.multiplyLocal(_orient);
        _worldTransform.setRotation(worldMatrix);
        Matrix3.releaseTempInstance(worldMatrix);
    }
View Full Code Here

    }

    @Override
    public void write(final OutputCapsule capsule) throws IOException {
        super.write(capsule);
        capsule.write(_orient, "orient", new Matrix3());
        capsule.write(_look, "look", new Vector3(Vector3.ZERO));
        capsule.write(_left, "left", new Vector3(Vector3.ZERO));
        capsule.write(_alignment, "alignment", BillboardAlignment.ScreenAligned);
    }
View Full Code Here

    }

    @Override
    public void read(final InputCapsule capsule) throws IOException {
        super.read(capsule);
        _orient.set((Matrix3) capsule.readSavable("orient", new Matrix3(Matrix3.IDENTITY)));
        _look.set((Vector3) capsule.readSavable("look", new Vector3(Vector3.ZERO)));
        _left.set((Vector3) capsule.readSavable("left", new Vector3(Vector3.ZERO)));
        _alignment = capsule.readEnum("alignment", BillboardAlignment.class, BillboardAlignment.ScreenAligned);
    }
View Full Code Here

            renderer.setOrtho();

            // hold onto our old translation
            final ReadOnlyVector3 wTrans = getWorldTranslation();
            final double x = wTrans.getX(), y = wTrans.getY(), z = wTrans.getZ();
            final Matrix3 rot = Matrix3.fetchTempInstance().set(getWorldRotation());

            // set our new translation so that we are drawn in the bottom left corner of the texture.
            double newX = 0, newY = 0;
            if (width > dispWidth && x < 0) {
                newX = x;
View Full Code Here

    public MovePlanarWidget withDefaultHandle(final double radius, final double height, final ReadOnlyColorRGBA color) {
        final Cylinder handle = new Cylinder("handle", 2, 16, radius, height, true);
        handle.setDefaultColor(color);
        switch (_plane) {
            case XZ:
                handle.setRotation(new Matrix3().fromAngleNormalAxis(MathUtils.HALF_PI, Vector3.UNIT_X));
                break;
            case YZ:
                handle.setRotation(new Matrix3().fromAngleNormalAxis(MathUtils.HALF_PI, Vector3.UNIT_Y));
                break;
            default:
                // do nothing
                break;
        }
View Full Code Here

        _root.attachChild(_box);

        // set it to rotate:
        _box.addController(new SpatialController<Spatial>() {
            private final Vector3 _axis = new Vector3(1, 1, 0.5f).normalizeLocal();
            private final Matrix3 _rotate = new Matrix3();
            private double _angle = 0;

            public void update(final double time, final Spatial caller) {
                // update our rotation
                _angle = _angle + (timer.getTimePerFrame() * 25);
                if (_angle > 180) {
                    _angle = -180;
                }

                _rotate.fromAngleNormalAxis(_angle * MathUtils.DEG_TO_RAD, _axis);
                _box.setRotation(_rotate);
            }
        });

        // Add our awt based image loader.
View Full Code Here

        _root.attachChild(_box);

        // set it to rotate:
        _box.addController(new SpatialController<Spatial>() {
            private final Vector3 _axis = new Vector3(1, 1, 0.5f).normalizeLocal();
            private final Matrix3 _rotate = new Matrix3();
            private double _angle = 0;

            public void update(final double time, final Spatial caller) {
                // update our rotation
                _angle = _angle + (_timer.getTimePerFrame() * 25);
                if (_angle > 180) {
                    _angle = -180;
                }

                _rotate.fromAngleNormalAxis(_angle * MathUtils.DEG_TO_RAD, _axis);
                _box.setRotation(_rotate);
            }
        });

        // Add our awt based image loader.
View Full Code Here

        _root.attachChild(_box);

        // set it to rotate:
        _box.addController(new SpatialController<Box>() {
            private final Vector3 _axis = new Vector3(1, 1, 0.5f).normalizeLocal();
            private final Matrix3 _rotate = new Matrix3();
            private double _angle = 0;

            public void update(final double time, final Box caller) {
                // update our rotation
                _angle = _angle + (_timer.getTimePerFrame() * 25);
                if (_angle > 180) {
                    _angle = -180;
                }

                _rotate.fromAngleNormalAxis(_angle * MathUtils.DEG_TO_RAD, _axis);
                _box.setRotation(_rotate);
            }
        });

        // Add our awt based image loader.
View Full Code Here

TOP

Related Classes of com.ardor3d.math.Matrix3

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.