Examples of Quaternion


Examples of com.jme.math.Quaternion

            cellSetup.setName(importedModel.getWonderlandName());
           
           
            BoundingVolume modelBounds = importedModel.getModelBG().getWorldBound();
            float scale = scaleBounds(modelBounds);
            modelBounds = modelBounds.transform(new Quaternion(), Vector3f.ZERO,
                                                new Vector3f(scale, scale, scale));
           
            cellSetup.setBoundingVolumeHint(new BoundingVolumeHint(false, modelBounds));
            deployedModel.setModelBounds(modelBounds);
View Full Code Here

Examples of com.jme.math.Quaternion

        // Convert to radians
        x = (float) Math.toRadians(x);
        y = (float) Math.toRadians(y);
        z = (float) Math.toRadians(z);

        Quaternion newRotation = new Quaternion(new float[]{x, y, z});
        if (movableComponent != null) {
            CellTransform cellTransform = selectedCell.getLocalTransform();
            cellTransform.setRotation(newRotation);
            movableComponent.localMoveRequest(cellTransform);
        }
View Full Code Here

Examples of com.jme.math.Quaternion

        }

        // 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.
        setLocalChanges(true);
View Full Code Here

Examples of com.jme.math.Quaternion

        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));
View Full Code Here

Examples of com.jme.math.Quaternion

        }

        // 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);
                        ClientContextJME.getWorldManager().addToUpdateList(rootNode);
                    }
                };
View Full Code Here

Examples of com.jme.math.Quaternion

            }

            // 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);

            // Rotate the object along the defined axis and angle.
            Quaternion q = new Quaternion().fromAngleAxis((float)angle, axis);
            fireRotationChanged(q);
        }
View Full Code Here

Examples of com.jme.math.Quaternion

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

Examples of com.jme.math.Quaternion

         * @inheritDoc()
         */
        public void rotationPerformed(Quaternion rotation) {
            // Move the cell via the moveable comopnent
            CellTransform transform = cell.getLocalTransform();
            Quaternion newRotation = rotationOnPress.mult(rotation);
            transform.setRotation(newRotation);
            movableComp.localMoveRequest(transform);
        }
View Full Code Here

Examples of com.jme.math.Quaternion

        // Create a red arrow in the +x direction. We arrow we get back is
        // pointed in the +y direction, so we rotate around the -z axis to
        // orient the arrow properly.
        xEntity = new Entity("Entity X");
        xNode = createArrow("Arrow X", extent + LENGTH_OFFSET, THICKNESS, ColorRGBA.red);
        Quaternion xRotation = new Quaternion().fromAngleAxis((float)Math.PI / 2, new Vector3f(0, 0, -1));
        xNode.setLocalRotation(xRotation);
        xNode.setLocalScale(new Vector3f(1.0f, LENGTH_SCALE, 1.0f));
        xNode.setRenderState(zbuf);
        addSubEntity(xEntity, xNode);
        xListener = addDragListener(xEntity, xNode, TranslateAxis.X_AXIS);

        // Create a green arrow in the +y direction. We arrow we get back is
        // pointed in the +y direction.
        yEntity = new Entity("Entity Y");
        yNode = createArrow("Arrow Y", extent + LENGTH_OFFSET, THICKNESS, ColorRGBA.green);
        yNode.setLocalScale(new Vector3f(1.0f, LENGTH_SCALE, 1.0f));
        yNode.setRenderState(zbuf);
        addSubEntity(yEntity, yNode);
        yListener = addDragListener(yEntity, yNode, TranslateAxis.Y_AXIS);

        // Create a red arrow in the +z direction. We arrow we get back is
        // pointed in the +y direction, so we rotate around the +x axis to
        // orient the arrow properly.
        zEntity = new Entity("Entity Z");
        zNode = createArrow("Arrow Z", extent + LENGTH_OFFSET, THICKNESS, ColorRGBA.blue);
        Quaternion zRotation = new Quaternion().fromAngleAxis((float)Math.PI / 2, new Vector3f(1, 0, 0));
        zNode.setLocalRotation(zRotation);
        zNode.setRenderState(zbuf);
        zNode.setLocalScale(new Vector3f(1.0f, LENGTH_SCALE, 1.0f));
        addSubEntity(zEntity, zNode);
        zListener = addDragListener(zEntity, zNode, TranslateAxis.Z_AXIS);
View Full Code Here

Examples of com.jme.math.Quaternion

        // Create a sub-node to hold the second arrow. We must rotate it 180
        // degrees (about the +y axis since arrows by default point up). We
        // also must translate it down. Attach the second arrow to this node.
        Node subNode2 = new Node();
        Quaternion q = new Quaternion().fromAngleAxis((float)Math.PI, new Vector3f(0, 0, 1));
        subNode2.setLocalRotation(q);
        subNode2.setLocalTranslation(0, -length / 2, 0);
        subNode2.attachChild(a2);

        // Attach the first arrow and the subnode to the main node
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.