Search in sources :

Example 11 with NaturalCamera

use of gaiasky.scenegraph.camera.NaturalCamera in project gaiasky by langurmonkey.

the class EventScriptingInterface method cameraTransition.

@Override
public void cameraTransition(double[] camPos, double[] camDir, double[] camUp, double seconds, boolean sync) {
    NaturalCamera cam = GaiaSky.instance.cameraManager.naturalCamera;
    // Put in focus mode
    em.post(Event.CAMERA_MODE_CMD, this, CameraMode.FREE_MODE);
    // Set up final actions
    String name = "cameraTransition" + (cTransSeq++);
    Runnable end = null;
    if (!sync)
        end = () -> unparkRunnable(name);
    // Create and park runnable
    CameraTransitionRunnable r = new CameraTransitionRunnable(cam, camPos, camDir, camUp, seconds, end);
    parkRunnable(name, r);
    if (sync) {
        // Wait on lock
        synchronized (r.lock) {
            try {
                r.lock.wait();
            } catch (InterruptedException e) {
                logger.error(e);
            }
        }
        // Remove and return
        unparkRunnable(name);
    }
}
Also used : NaturalCamera(gaiasky.scenegraph.camera.NaturalCamera)

Example 12 with NaturalCamera

use of gaiasky.scenegraph.camera.NaturalCamera in project gaiasky by langurmonkey.

the class EventScriptingInterface method goToObject.

void goToObject(IFocus object, double viewAngle, float waitTimeSeconds, AtomicBoolean stop) {
    if (checkNotNull(object, "object") && checkNum(viewAngle, -Double.MAX_VALUE, Double.MAX_VALUE, "viewAngle")) {
        stops.add(stop);
        NaturalCamera cam = GaiaSky.instance.cameraManager.naturalCamera;
        changeFocus(object, cam, waitTimeSeconds);
        /* target angle */
        double target = Math.toRadians(viewAngle);
        if (target < 0)
            target = Math.toRadians(20d);
        long prevTime = TimeUtils.millis();
        if (object.getViewAngleApparent() < target) {
            // Add forward movement while distance > target distance
            while (object.getViewAngleApparent() < target && (stop == null || !stop.get())) {
                // dt in ms
                long dt = TimeUtils.timeSinceMillis(prevTime);
                prevTime = TimeUtils.millis();
                em.post(Event.CAMERA_FWD, this, (double) dt);
                try {
                    sleep(0.1f);
                } catch (Exception e) {
                    logger.error(e);
                }
            }
        } else {
            // Add backward movement while distance > target distance
            while (object.getViewAngleApparent() > target && (stop == null || !stop.get())) {
                // dt in ms
                long dt = TimeUtils.timeSinceMillis(prevTime);
                prevTime = TimeUtils.millis();
                em.post(Event.CAMERA_FWD, this, (double) -dt);
                try {
                    sleep(0.1f);
                } catch (Exception e) {
                    logger.error(e);
                }
            }
        }
        // We can stop now
        em.post(Event.CAMERA_STOP, this);
    }
}
Also used : NaturalCamera(gaiasky.scenegraph.camera.NaturalCamera) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

NaturalCamera (gaiasky.scenegraph.camera.NaturalCamera)12 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)3 IFocus (gaiasky.scenegraph.IFocus)3 SceneGraphNode (gaiasky.scenegraph.SceneGraphNode)3 Vector3 (com.badlogic.gdx.math.Vector3)2 Actor (com.badlogic.gdx.scenes.scene2d.Actor)2 ChangeEvent (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)2 Array (com.badlogic.gdx.utils.Array)2 OwnLabel (gaiasky.util.scene2d.OwnLabel)2 OwnTextField (gaiasky.util.scene2d.OwnTextField)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Keys (com.badlogic.gdx.Input.Keys)1 Vector2 (com.badlogic.gdx.math.Vector2)1 Action (com.badlogic.gdx.scenes.scene2d.Action)1 Type (com.badlogic.gdx.scenes.scene2d.InputEvent.Type)1 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)1 Stage (com.badlogic.gdx.scenes.scene2d.Stage)1 com.badlogic.gdx.scenes.scene2d.ui (com.badlogic.gdx.scenes.scene2d.ui)1 Cell (com.badlogic.gdx.scenes.scene2d.ui.Cell)1 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)1