Package com.jme.math

Examples of com.jme.math.Vector3f


            return;
        }

        // Fetch the current transform from the movable component
        CellTransform cellTransform = selectedCell.getLocalTransform();
        final Vector3f translation = cellTransform.getTranslation(null);
        Quaternion rotation = cellTransform.getRotation(null);
        final Vector3f scale = cellTransform.getScaling(null);
        final float[] angles = rotation.toAngles(new float[3]);

        // Says that we are changing the values of the spinners
        // programmatically. This prevents the values from being sent
        // back to the Cell via the movable component.
View Full Code Here


        // Draw an arrow that mimics the light position --direction still under
        //construction.
        TextLabel2D label = new TextLabel2D(name,
                                            Color.black, Color.white, 1.0f, true, Font.getFont("SANS_SERIF"));
       
        Vector3f direction = directionalLight.getDirection();
        Vector3f position = lightNode.getLocalTranslation();
        Vector3f labelPosition = new Vector3f(position.x, position.y + 3, position.z);
       
        Arrow arrow = new Arrow("Arrow", 3, 0.5f);
        Node rotatedOnX = new Node("Rotated For Arrow");
        rotatedOnX.setLocalRotation(new Quaternion().fromAngleAxis(90*FastMath.DEG_TO_RAD, new Vector3f(1, 0, 0)));
        rotatedOnX.attachChild(arrow);
        rotatedOnX.setLocalTranslation(position);
//        arrow.setLocalTranslation(position);
        label.setLocalTranslation(labelPosition);
        arrow.lookAt(direction, new Vector3f(0,1,0));
        rootNode.attachChild(label);
        rootNode.attachChild(rotatedOnX);
        // Fetch the world translation for the root node of the cell and set
        // the translation for this entity root node
        rootNode.setLocalTranslation(transform.getTranslation(null));
View Full Code Here

            outerRadius = innerRadius + RADIUS_WIDTH;
        }

        // Fetch the world translation for the root node of the cell and set
        // the translation and rotation for this entity root node
        Vector3f translation = sceneRoot.getWorldTranslation();
        Quaternion rotation = sceneRoot.getWorldRotation();
        rootNode.setLocalTranslation(translation);
        rootNode.setLocalRotation(rotation);

        float[] angles = new float[3];
        rotation.toAngles(angles);
       
        // Create a tube to rotate about the X axis. The tube is drawn in the
        // X-Z plane, so we must rotate 90 degrees about the +z axis so that the
        // axis of rotation is about +x axis.
        xEntity = new Entity("Tube X");
        xNode = createTube("Tube X", outerRadius, innerRadius, THICKNESS, ColorRGBA.red);
        Quaternion xQ = new Quaternion().fromAngleAxis(1.5707f, new Vector3f(0, 0, 1));
        xNode.setLocalRotation(xQ);
        xNode.setLocalScale(new Vector3f(currentScale, 1.0f, currentScale));
        xNode.setRenderState(zbuf);
        addSubEntity(xEntity, xNode);
        xListener = addRotateListener(xEntity, xNode, RotateAxis.X_AXIS);

        // Create a tube to rotate about the Y axis. The tube is drawn in the
        // X-Z plane already.
        yEntity = new Entity("Tube Y");
        yNode = createTube("Tube Y", outerRadius, innerRadius, THICKNESS, ColorRGBA.green);
        yNode.setLocalScale(new Vector3f(currentScale, 1.0f, currentScale));
        yNode.setRenderState(zbuf);
        addSubEntity(yEntity, yNode);
        yListener = addRotateListener(yEntity, yNode, RotateAxis.Y_AXIS);

        // Create a tube to rotate about the Z axis. The tube is drawn in the
        // X-Z plane, so we must rotate 90 degrees about the +x axis so that the
        // axis of rotation is about +z axis.
        zEntity = new Entity("Tube Z");
        zNode = createTube("Tube Z", outerRadius, innerRadius, THICKNESS, ColorRGBA.blue);
        Quaternion zQ = new Quaternion().fromAngleAxis(1.5707f, new Vector3f(1, 0, 0));
        zNode.setLocalRotation(zQ);
        zNode.setLocalScale(new Vector3f(currentScale, 1.0f, currentScale));
        zNode.setRenderState(zbuf);
        addSubEntity(zEntity, zNode);
        zListener = addRotateListener(zEntity, zNode, RotateAxis.Z_AXIS);
       
        // Listen for changes to the cell's translation and apply the same
        // update to the root node of the affordances
        sceneRoot.addGeometricUpdateListener(updateListener = new GeometricUpdateListener() {
            public void geometricDataChanged(final Spatial spatial) {
                // We need to perform this work inside a proper updater, to
                // make sure we are MT thread safe
                RenderUpdater u = new RenderUpdater() {
                    public void update(Object obj) {
                        // For the rotate affordance we need to move it whenever
                        // the cell is moved, but also need to rotate it when
                        // the cell rotation changes too. We also need to
                        // account for any changes to the size of the cell's
                        // scene graph, so we reset the size here to take care
                        // of that.
                        Vector3f translation = spatial.getWorldTranslation();
                        rootNode.setLocalTranslation(translation);

                        Quaternion rotation = spatial.getLocalRotation();
                        rootNode.setLocalRotation(rotation);
                        setSizeInternal(currentScale);
View Full Code Here

        }

        // In order to set the size of the arrows, we just set the scaling. Note
        // that we set the scaling along the (x, z) axis since disks are drawn
        // in the x-z plane
        xNode.setLocalScale(new Vector3f(scale, 1.0f, scale));
        yNode.setLocalScale(new Vector3f(scale, 1.0f, scale));
        zNode.setLocalScale(new Vector3f(scale, 1.0f, scale));
        ClientContextJME.getWorldManager().addToUpdateList(xNode);
        ClientContextJME.getWorldManager().addToUpdateList(yNode);
        ClientContextJME.getWorldManager().addToUpdateList(zNode);
    }
View Full Code Here

            }

            // Get the vector of the drag motion from the initial starting
            // point in world coordinates.
            MouseDraggedEvent3D dragEvent = (MouseDraggedEvent3D) event;
            Vector3f dragWorld = dragEvent.getDragVectorWorld(dragStartWorld,
                    dragStartScreen, new Vector3f());

            // Figure out what the vector is of the current drag location in
            // world coodinates. This gives a vector from the center of the
            // affordance. We just take the vector (from the center) of the
            // start of the drag and add the bit we dragged the mouse.
            Vector3f dragEndVectorWorld = dragStartVectorWorld.add(dragWorld);

            // Formulate the two vectors in three dimensions, which is just
            // the normalized start and end vectors
            Vector3f v1 = dragStartVectorWorld.normalize();
            Vector3f v2 = dragEndVectorWorld.normalize();
           
            // We also figure out the axis normal and the axis of rotation
            Vector3f normal = null, axis = null;
            switch (direction) {
                case X_AXIS:
                    normal = new Vector3f(1, 0, 0);
                    axis = new Vector3f(1, 0, 0);
                    break;

                case Y_AXIS:
                    normal = new Vector3f(0, 1, 0);
                    axis = new Vector3f(0, 1, 0);
                    break;

                case Z_AXIS:
                    normal = new Vector3f(0, 0, 1);
                    axis = new Vector3f(0, 0, 1);
                    break;

                default:
                    // This should never happen, so just return
                    return;
            }

            // We need to rotate the normal about the rotation already applied
            // to the Cell. This will make sure that the direction of rotation
            // comes out properly.
            Quaternion rotation = rootNode.getLocalRotation();
            float angles[] = new float[3];
            rotation.toAngles(angles);
            normal = rotation.mult(normal);
           
            // Compute the signed angle between v1 and v2. We do this with the
            // following formula: angle = atan2(normal dot (v1 cross v2), v1 dot v2)
            float dotProduct = v1.dot(v2);
            Vector3f crossProduct = v1.cross(v2);
            double angle = Math.atan2(normal.dot(crossProduct), dotProduct);
           
            // Update the rotation label, make sure we do this in an AWT Event
            // Thread
            updateRotationLabel(angle, awtMouseEvent);
View Full Code Here

    private ScheduledExecutorService exec=null;
    private ScheduledExecutorService exec_cellStatus = null;
    private JDialog dialog=null;

    public CoverScreenListener(final Vector3f goalPos,final CoverScreenData csd) {
        Vector3f fromLoc = ClientContextJME.getViewManager()
                .getPrimaryViewCell().getWorldTransform().getTranslation(null);
        Vector3f toLoc = goalPos;
        if(Math.abs((fromLoc.x)-(toLoc.x))<=150 &&
                Math.abs((fromLoc.y)-(toLoc.y))<=150 &&
                Math.abs((fromLoc.z)-(toLoc.z))<=150) {
            //Cover Screen not needed
        } else {
View Full Code Here

* @author morrisford
*/
public class QuaternionInterpolator implements PropertyInterpolator {

    public Quaternion interpolate(Object from, Object to, float timelinePosition) {
        Vector3f fromAxis = new Vector3f();
        Vector3f toAxis = new Vector3f();
        Quaternion newQuat = new Quaternion();

        float fromAngle = ((Quaternion)from).toAngleAxis(fromAxis);
        float toAngle = ((Quaternion)to).toAngleAxis(toAxis);

        newQuat.fromAngleAxis(fromAngle + (toAngle - fromAngle) * timelinePosition,
                new Vector3f(fromAxis.x + (toAxis.x - fromAxis.x) * timelinePosition,
                fromAxis.y + (toAxis.y - fromAxis.y) * timelinePosition,
                fromAxis.z + (toAxis.z - fromAxis.z) * timelinePosition));
        return newQuat;
    }
View Full Code Here

            // TODO: someday: We can get away with this only because we currently don't
            // support secondary rotations. When we finally do support secondary
            // rotations we'll need to modify the sync protocol to send the entire
            // transform.
            CellTransform userTransformCell = win.getUserTransformCell();
            Vector3f userTranslation = userTransformCell.getTranslation(null);
            AppXrw.logger.info("userTranslation = " + userTranslation);

            // Send basic window attributes
            encode(syncBuf, 0, win.getWid());
            encode(syncBuf, 4, win.getOffsetX());
View Full Code Here

    // This gimble locks, but good enough for now...
    public static Matrix3f calcRotationMatrix(float x, float y, float z) {
        Matrix3f m3f = new Matrix3f();
        m3f.loadIdentity();
        m3f.fromAngleAxis(x, new Vector3f(1f, 0f, 0f));
        Matrix3f rotY = new Matrix3f();
        rotY.loadIdentity();
        rotY.fromAngleAxis(y, new Vector3f(0f, 1f, 0f));
        Matrix3f rotZ = new Matrix3f();
        rotZ.loadIdentity();
        rotZ.fromAngleAxis(z, new Vector3f(0f, 0f, 1f));

        m3f.multLocal(rotY);
        m3f.multLocal(rotZ);

        return m3f;
View Full Code Here

    void loadCancelled(ImportedModel model) {
        if (editingRow >= 0 && imports.contains(model)) {
            // Restore Position of model
            final ImportedModel imp = model; //imports.get(editingRow);
            final Node tg = imp.getRootBG();
            final Vector3f rot = imp.getOrientation();
            RenderUpdater renderUpdater = new RenderUpdater() {

                public void update(Object arg0) {
                    tg.setLocalRotation(
                            calcRotationMatrix(rot.x, rot.y, rot.z));
View Full Code Here

TOP

Related Classes of com.jme.math.Vector3f

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.