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);
}
}
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);
}
}
Aggregations