Example usage for com.badlogic.gdx.math Quaternion setEulerAngles

List of usage examples for com.badlogic.gdx.math Quaternion setEulerAngles

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Quaternion setEulerAngles.

Prototype

public Quaternion setEulerAngles(float yaw, float pitch, float roll) 

Source Link

Document

Sets the quaternion to the given euler angles in degrees.

Usage

From source file:com.mbrlabs.mundus.ui.modules.inspector.TransformWidget.java

License:Apache License

private void setupListeners() {
    final ProjectContext projectContext = projectManager.current();

    // position//w  ww  .  java 2 s . com
    posX.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            GameObject go = projectContext.currScene.currentSelection;
            if (go == null)
                return;
            TranslateCommand command = new TranslateCommand(go);
            Vector3 pos = go.getLocalPosition(tempV3);
            command.setBefore(pos);
            go.setLocalPosition(posX.getFloat(), pos.y, pos.z);
            command.setAfter(go.getLocalPosition(tempV3));
            history.add(command);
        }
    });
    posY.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            GameObject go = projectContext.currScene.currentSelection;
            if (go == null)
                return;
            TranslateCommand command = new TranslateCommand(go);
            Vector3 pos = go.getLocalPosition(tempV3);
            command.setBefore(pos);
            go.setLocalPosition(pos.x, posY.getFloat(), pos.z);
            command.setAfter(go.getLocalPosition(tempV3));
            history.add(command);
        }
    });
    posZ.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            GameObject go = projectContext.currScene.currentSelection;
            if (go == null)
                return;
            TranslateCommand command = new TranslateCommand(go);
            Vector3 pos = go.getLocalPosition(tempV3);
            command.setBefore(pos);
            go.setLocalPosition(pos.x, pos.y, posZ.getFloat());
            command.setAfter(go.getLocalPosition(tempV3));
            history.add(command);
        }
    });

    // rotation
    rotX.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            GameObject go = projectContext.currScene.currentSelection;
            if (go == null)
                return;
            Quaternion rot = go.getLocalRotation(tempQuat);
            RotateCommand rotateCommand = new RotateCommand(go);
            rotateCommand.setBefore(rot);
            rot.setEulerAngles(rot.getYaw(), rotX.getFloat(), rot.getRoll());
            go.setLocalRotation(rot.x, rot.y, rot.z, rot.w);
            rotateCommand.setAfter(go.getLocalRotation(tempQuat));
            history.add(rotateCommand);
        }
    });
    rotY.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            GameObject go = projectContext.currScene.currentSelection;
            if (go == null)
                return;
            Quaternion rot = go.getLocalRotation(tempQuat);
            RotateCommand rotateCommand = new RotateCommand(go);
            rotateCommand.setBefore(rot);
            rot.setEulerAngles(rotY.getFloat(), rot.getPitch(), rot.getRoll());
            go.setLocalRotation(rot.x, rot.y, rot.z, rot.w);
            rotateCommand.setAfter(go.getLocalRotation(tempQuat));
            history.add(rotateCommand);
        }
    });
    rotZ.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            GameObject go = projectContext.currScene.currentSelection;
            if (go == null)
                return;
            Quaternion rot = go.getLocalRotation(tempQuat);
            RotateCommand rotateCommand = new RotateCommand(go);
            rotateCommand.setBefore(rot);
            rot.setEulerAngles(rot.getYaw(), rot.getPitch(), rotZ.getFloat());
            go.setLocalRotation(rot.x, rot.y, rot.z, rot.w);
            rotateCommand.setAfter(go.getLocalRotation(tempQuat));
            history.add(rotateCommand);
        }
    });

    // scale
    scaleX.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            GameObject go = projectContext.currScene.currentSelection;
            if (go != null && scaleX.getFloat() > 0f) {
                ScaleCommand command = new ScaleCommand(go);
                Vector3 scl = go.getLocalScale(tempV3);
                command.setBefore(scl);
                go.setLocalScale(scaleX.getFloat(), scl.y, scl.z);
                command.setAfter(go.getLocalScale(tempV3));
                history.add(command);
            }
        }
    });
    scaleY.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            GameObject go = projectContext.currScene.currentSelection;
            if (go != null && scaleY.getFloat() > 0f) {
                ScaleCommand command = new ScaleCommand(go);
                Vector3 scl = go.getLocalScale(tempV3);
                command.setBefore(scl);
                go.setLocalScale(scl.x, scaleY.getFloat(), scl.z);
                command.setAfter(go.getLocalScale(tempV3));
                history.add(command);
            }
        }
    });
    scaleZ.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            GameObject go = projectContext.currScene.currentSelection;
            if (go != null && scaleZ.getFloat() > 0f) {
                ScaleCommand command = new ScaleCommand(go);
                Vector3 scl = go.getLocalScale(tempV3);
                command.setBefore(scl);
                go.setLocalScale(scl.x, scl.y, scaleZ.getFloat());
                command.setAfter(go.getLocalScale(tempV3));
                history.add(command);
            }
        }
    });

}