Java Code Examples for com.jme3.scene.Node#setLocalRotation()

The following examples show how to use com.jme3.scene.Node#setLocalRotation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractTransformControl.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@JmeThread
public void setCollisionPlane(@NotNull final CollisionResult collisionResult) {

    final EditorTransformSupport editorControl = getEditorControl();
    final Transform transform = editorControl.getTransformCenter();

    if (transform == null) {
        LOGGER.warning(this, "not found transform center for the " + editorControl);
        return;
    }

    detectPickedAxis(editorControl, collisionResult);

    // set the collision Plane location and rotation
    final Node collisionPlane = getCollisionPlane();
    collisionPlane.setLocalTranslation(transform.getTranslation());
    collisionPlane.setLocalRotation(Quaternion.IDENTITY);
}
 
Example 2
Source File: EditorLightNode.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Update position and rotation of a model.
 */
@JmeThread
public void updateModel() {

    final Node model = getModel();
    if (model == null) return;

    final LocalObjects local = LocalObjects.get();
    final Vector3f positionOnCamera = local.nextVector();
    positionOnCamera.set(getLocalTranslation())
            .subtractLocal(camera.getLocation())
            .normalizeLocal()
            .multLocal(camera.getFrustumNear() + 0.4f)
            .addLocal(camera.getLocation());

    model.setLocalTranslation(positionOnCamera);
    model.setLocalRotation(getLocalRotation());
}
 
Example 3
Source File: SelectionIndicator.java    From Lemur with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void setupIndicator() {
    indicator = new Node("Indicator");
    indicator.setQueueBucket(Bucket.Translucent);
    root.attachChild(indicator);
    
    // Just in case the root node has been moved
    indicator.setLocalTranslation(root.getLocalTranslation().negate());
    indicator.setLocalRotation(root.getLocalRotation().inverse());
    
    // Setup the indicator material
    this.material = GuiGlobals.getInstance().createMaterial(color, false).getMaterial();
    material.getAdditionalRenderState().setWireframe(true);
    material.getAdditionalRenderState().setDepthFunc(TestFunction.Always);
    
    // Find all of the geometry children of our spatial
    spatial.depthFirstTraversal( new SceneGraphVisitorAdapter() {
            @Override
            public void visit( Geometry geom ) {
                // Make a copy of it
                Geometry copy = cloneGeometry(geom);
                indicator.attachChild(copy);
            }
        });        
}
 
Example 4
Source File: EditorTransformSupport.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@JmeThread
public void prepareToMove(@NotNull final Node parent, @NotNull final Node child,
                          @NotNull final Transform transform, @NotNull final Camera camera) {
    parent.setLocalTranslation(Vector3f.ZERO);
    parent.setLocalRotation(Quaternion.IDENTITY);
    child.setLocalTranslation(transform.getTranslation());
    child.setLocalRotation(transform.getRotation());
}
 
Example 5
Source File: EditorTransformSupport.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@JmeThread
public void prepareToMove(@NotNull final Node parent, @NotNull final Node child,
                          @NotNull final Transform transform, @NotNull final Camera camera) {
    parent.setLocalRotation(camera.getRotation());
    parent.setLocalTranslation(transform.getTranslation());
    child.setLocalTranslation(Vector3f.ZERO);
    child.setLocalRotation(Quaternion.IDENTITY);
}
 
Example 6
Source File: EditorTransformSupport.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Prepare nodes to move.
 *
 * @param parent    the parent node.
 * @param child     the child node.
 * @param transform the base transform.
 * @param camera    the camera.
 */
@JmeThread
public void prepareToMove(@NotNull final Node parent, @NotNull final Node child,
                          @NotNull final Transform transform, @NotNull final Camera camera) {
    parent.setLocalTranslation(transform.getTranslation());
    parent.setLocalRotation(transform.getRotation());
    child.setLocalTranslation(Vector3f.ZERO);
    child.setLocalRotation(Quaternion.IDENTITY);
}
 
Example 7
Source File: EditorAudioNode.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Synchronize this node with audio node.
 */
@JmeThread
public void sync() {

    final AudioNode audioNode = getAudioNode();
    if (audioNode == null) return;

    final LocalObjects local = LocalObjects.get();
    final Quaternion rotation = local.nextRotation();
    rotation.lookAt(audioNode.getDirection(), camera.getUp(local.nextVector()));

    final Node editedNode = getEditedNode();
    editedNode.setLocalRotation(rotation);
    editedNode.setLocalTranslation(audioNode.getLocalTranslation());
}
 
Example 8
Source File: EditorAudioNode.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Update position and rotation of a model.
 */
@JmeThread
public void updateModel() {

    final AudioNode audioNode = getAudioNode();
    final Node model = getModel();
    if (model == null || audioNode == null) return;

    final Node parent = audioNode.getParent();

    if (parent != null) {
        setLocalTranslation(parent.getWorldTranslation());
        setLocalRotation(parent.getWorldRotation());
        setLocalScale(parent.getWorldScale());
    }

    final Node editedNode = getEditedNode();
    final LocalObjects local = LocalObjects.get();
    final Vector3f positionOnCamera = local.nextVector();
    positionOnCamera.set(editedNode.getWorldTranslation()).subtractLocal(camera.getLocation());
    positionOnCamera.normalizeLocal();
    positionOnCamera.multLocal(camera.getFrustumNear() + 0.4f);
    positionOnCamera.addLocal(camera.getLocation());

    model.setLocalTranslation(positionOnCamera);
    model.setLocalRotation(editedNode.getLocalRotation());
}
 
Example 9
Source File: EditorPresentableNode.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Synchronize this node with presented object.
 */
@JmeThread
public void sync() {

    final ScenePresentable object = getObject();

    final Node editedNode = getEditedNode();
    editedNode.setLocalRotation(object.getRotation());
    editedNode.setLocalTranslation(object.getLocation());
    editedNode.setLocalScale(object.getScale());
}
 
Example 10
Source File: EditorTransformSupport.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
@Override
@JmeThread
public void prepareToRotate(@NotNull final Node parent, @NotNull final Node child,
                            @NotNull final Transform transform, @NotNull final Camera camera) {
    parent.setLocalRotation(Quaternion.IDENTITY);
    child.setLocalRotation(transform.getRotation());
}
 
Example 11
Source File: EditorTransformSupport.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
@Override
@JmeThread
public void prepareToRotate(@NotNull final Node parent, @NotNull final Node child,
                            @NotNull final Transform transform, @NotNull final Camera camera) {
    parent.setLocalRotation(Quaternion.IDENTITY);
    child.setLocalRotation(transform.getRotation());
}
 
Example 12
Source File: MoveToolControl.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
@Override
@JmeThread
public void setCollisionPlane(@NotNull final CollisionResult collisionResult) {

    final EditorTransformSupport editorControl = getEditorControl();
    final Transform transform = editorControl.getTransformCenter();

    if (transform == null) {
        LOGGER.warning(this, "not found transform center for the " + editorControl);
        return;
    }

    final LocalObjects local = LocalObjects.get();
    final Camera camera = editorControl.getCamera();
    final Vector3f direction = camera.getDirection(local.nextVector());

    detectPickedAxis(editorControl, collisionResult);

    final Node parentNode = getParentNode();
    final Node childNode = getChildNode();

    final PickedAxis pickedAxis = editorControl.getPickedAxis();
    final TransformationMode transformationMode = editorControl.getTransformationMode();
    transformationMode.prepareToMove(parentNode, childNode, transform, camera);

    final Quaternion rotation = parentNode.getLocalRotation();

    // select an angle between 0 and 90 degrees (from 0 to 1.57 in radians) (for collisionPlane)
    final Vector3f angleVectorX = rotation.mult(Vector3f.UNIT_X, local.nextVector());
    final Vector3f angleVectorY = rotation.mult(Vector3f.UNIT_Y, local.nextVector());
    final Vector3f angleVectorZ = rotation.mult(Vector3f.UNIT_Z, local.nextVector());

    float angleX = direction.angleBetween(angleVectorX);
    float angleY = direction.angleBetween(angleVectorY);
    float angleZ = direction.angleBetween(angleVectorZ);

    if (angleX > 1.57) {
        angleX = direction.angleBetween(angleVectorX.negateLocal());
    }

    if (angleY > 1.57) {
        angleY = direction.angleBetween(angleVectorY.negateLocal());
    }

    if (angleZ > 1.57) {
        angleZ = direction.angleBetween(angleVectorZ.negateLocal());
    }

    // select the less angle for collisionPlane
    float lessAngle = angleX;

    if (lessAngle > angleY) lessAngle = angleY;
    if (lessAngle > angleZ) lessAngle = angleZ;

    // set the collision Plane location and rotation
    final Node collisionPlane = getCollisionPlane();
    collisionPlane.setLocalTranslation(parentNode.getLocalTranslation());
    collisionPlane.setLocalRotation(rotation); //equals to angleZ

    final Quaternion planeRotation = collisionPlane.getLocalRotation();
    final Quaternion tempRotation = local.nextRotation();

    // rotate the plane for constraints
    if (lessAngle == angleX) {

        if (pickedAxis == PickedAxis.X && angleY > angleZ) {
            planeRotation.multLocal(tempRotation.fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_Z));
        } else if (pickedAxis == PickedAxis.X && angleY < angleZ) {
            planeRotation.multLocal(tempRotation.fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_X));
            planeRotation.multLocal(tempRotation.fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_Z));
        } else if (pickedAxis == PickedAxis.Y) {
            planeRotation.multLocal(tempRotation.fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_Y));
        } else if (pickedAxis == PickedAxis.Z) {
            planeRotation.multLocal(tempRotation.fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_Y));
            planeRotation.multLocal(tempRotation.fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_Z));
        }

    } else if (lessAngle == angleY) {

        if (pickedAxis == PickedAxis.X) {
            planeRotation.multLocal(tempRotation.fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_X));
            planeRotation.multLocal(tempRotation.fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_Z));
        } else if (pickedAxis == PickedAxis.Y && angleX < angleZ) {
            planeRotation.multLocal(tempRotation.fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_Y));
        } else if (pickedAxis == PickedAxis.Z) {
            planeRotation.multLocal(tempRotation.fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_X));
        }

    } else if (lessAngle == angleZ) {

        if (pickedAxis == PickedAxis.X) {
            planeRotation.multLocal(tempRotation.fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_Z));
        } else if (pickedAxis == PickedAxis.Z && angleY < angleX) {
            planeRotation.multLocal(tempRotation.fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_X));
        } else if (pickedAxis == PickedAxis.Z && angleY > angleX) {
            planeRotation.multLocal(tempRotation.fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_Y));
            planeRotation.multLocal(tempRotation.fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_Z));
        }
    }
}
 
Example 13
Source File: RotationToolControl.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
@Override
@JmeThread
public void processTransform() {

    final LocalObjects local = LocalObjects.get();
    final EditorTransformSupport editorControl = getEditorControl();
    final InputManager inputManager = EditorUtil.getInputManager();
    final Camera camera = editorControl.getCamera();

    final Transform transform = notNull(editorControl.getTransformCenter());

    // cursor position and selected position vectors
    final Vector2f cursorPos = inputManager.getCursorPosition();
    final Vector3f transformOnScreen = camera.getScreenCoordinates(transform.getTranslation());
    final Vector2f selectedCoords = local.nextVector(transformOnScreen.getX(), transformOnScreen.getY());

    //set new deltaVector if it's not set
    if (Float.isNaN(editorControl.getTransformDeltaX())) {
        editorControl.setTransformDeltaX(selectedCoords.getX() - cursorPos.getX());
        editorControl.setTransformDeltaY(selectedCoords.getY() - cursorPos.getY());
    }

    // Picked vector
    final TransformationMode transformationMode = editorControl.getTransformationMode();
    final Vector3f pickedVector = transformationMode.getPickedVector(transform, editorControl.getPickedAxis(), camera);
    final Vector3f deltaVector = local.nextVector(editorControl.getTransformDeltaX(), editorControl.getTransformDeltaY(), 0F);

    // rotate according to angle
    final Vector2f cursorDirection = selectedCoords.subtractLocal(cursorPos).normalizeLocal();
    float angle = cursorDirection.angleBetween(local.nextVector(deltaVector.getX(), deltaVector.getY()));
    angle = FastMath.RAD_TO_DEG * angle * FastMath.DEG_TO_RAD;

    final Node parentNode = getParentNode();
    final Node childNode = getChildNode();

    transformationMode.prepareToRotate(parentNode, childNode, transform, camera);

    final Quaternion rotation = parentNode.getLocalRotation();
    final Vector3f axisToRotate = rotation.mult(pickedVector, local.nextVector());

    float angleCheck = axisToRotate.angleBetween(camera.getDirection(local.nextVector()));

    if (angleCheck > FastMath.HALF_PI) {
        angle = -angle;
    }

    final Quaternion difference = local.nextRotation().fromAngleAxis(angle, pickedVector);
    final Quaternion newRotation = rotation.mult(difference, local.nextRotation());

    parentNode.setLocalRotation(newRotation);

    final Spatial toTransform = notNull(editorControl.getToTransform());
    toTransform.setLocalRotation(childNode.getWorldRotation());

    editorControl.notifyTransformed(toTransform);
}
 
Example 14
Source File: EditorTransformSupport.java    From jmonkeybuilder with Apache License 2.0 3 votes vote down vote up
/**
 * Prepare nodes to rotate.
 *
 * @param parent    the parent node.
 * @param child     the child node.
 * @param transform the base transform.
 * @param camera    the camera.
 */
@JmeThread
public void prepareToRotate(@NotNull final Node parent, @NotNull final Node child,
                            @NotNull final Transform transform, @NotNull final Camera camera) {
    parent.setLocalRotation(transform.getRotation());
    child.setLocalRotation(Quaternion.IDENTITY);
}