use of gaiasky.scenegraph.camera.NaturalCamera in project gaiasky by langurmonkey.
the class EventScriptingInterface method landAtObjectLocation.
void landAtObjectLocation(IFocus object, double longitude, double latitude, AtomicBoolean stop) {
if (checkNotNull(object, "object") && checkNum(latitude, -90d, 90d, "latitude") && checkNum(longitude, 0d, 360d, "longitude")) {
stops.add(stop);
ISceneGraph sg = GaiaSky.instance.sceneGraph;
String nameStub = object.getCandidateName() + " [loc]";
if (!sg.containsNode(nameStub)) {
Invisible invisible = new Invisible(nameStub);
EventManager.publish(Event.SCENE_GRAPH_ADD_OBJECT_CMD, invisible, true);
}
Invisible invisible = (Invisible) getObject(nameStub, 5);
if (object instanceof Planet) {
Planet planet = (Planet) object;
NaturalCamera cam = GaiaSky.instance.cameraManager.naturalCamera;
double targetAngle = 35 * MathUtilsd.degRad;
if (planet.viewAngle > targetAngle) {
// Zoom out
while (planet.viewAngle > targetAngle && (stop == null || !stop.get())) {
cam.addForwardForce(-5d);
sleepFrames(1);
}
// STOP
cam.stopMovement();
}
// Go to object
goToObject(object, 20, -1, stop);
// Save speed, set it to 50
double speed = Settings.settings.scene.camera.speed;
em.post(Event.CAMERA_SPEED_CMD, this, 25f / 10f);
// Save turn speed, set it to 50
double turnSpeedBak = Settings.settings.scene.camera.turn;
em.post(Event.TURNING_SPEED_CMD, this, (float) MathUtilsd.lint(50d, Constants.MIN_SLIDER, Constants.MAX_SLIDER, Constants.MIN_TURN_SPEED, Constants.MAX_TURN_SPEED));
// Save rotation speed, set it to 20
double rotationSpeedBak = Settings.settings.scene.camera.rotate;
em.post(Event.ROTATION_SPEED_CMD, this, (float) MathUtilsd.lint(20d, Constants.MIN_SLIDER, Constants.MAX_SLIDER, Constants.MIN_ROT_SPEED, Constants.MAX_ROT_SPEED));
// Save cinematic
boolean cinematic = Settings.settings.scene.camera.cinematic;
Settings.settings.scene.camera.cinematic = true;
// Save crosshair
boolean crosshair = Settings.settings.scene.crosshair.focus;
Settings.settings.scene.crosshair.focus = false;
// Get target position
Vector3b target = aux3b1;
planet.getPositionAboveSurface(longitude, latitude, 50, target);
// Get object position
Vector3b objectPosition = planet.getAbsolutePosition(aux3b2);
// Check intersection with object
boolean intersects = Intersectord.checkIntersectSegmentSphere(cam.pos.tov3d(aux3d3), target.tov3d(aux3d1), objectPosition.tov3d(aux3d2), planet.getRadius());
if (intersects) {
cameraRotate(5d, 5d);
}
while (intersects && (stop == null || !stop.get())) {
sleep(0.1f);
objectPosition = planet.getAbsolutePosition(aux3b2);
intersects = Intersectord.checkIntersectSegmentSphere(cam.pos.tov3d(aux3d3), target.tov3d(aux3d1), objectPosition.tov3d(aux3d2), planet.getRadius());
}
cameraStop();
invisible.ct = planet.ct;
invisible.pos.set(target);
// Go to object
goToObject(nameStub, 20, 0, stop);
// Restore cinematic
Settings.settings.scene.camera.cinematic = cinematic;
// Restore speed
em.post(Event.CAMERA_SPEED_CMD, this, (float) speed);
// Restore turning speed
em.post(Event.TURNING_SPEED_CMD, this, (float) turnSpeedBak);
// Restore rotation speed
em.post(Event.ROTATION_SPEED_CMD, this, (float) rotationSpeedBak);
// Restore crosshair
Settings.settings.scene.crosshair.focus = crosshair;
// Land
landOnObject(object, stop);
}
EventManager.publish(Event.SCENE_GRAPH_REMOVE_OBJECT_CMD, this, invisible, true);
}
}
use of gaiasky.scenegraph.camera.NaturalCamera in project gaiasky by langurmonkey.
the class EventScriptingInterface method landOnObject.
void landOnObject(IFocus object, AtomicBoolean stop) {
if (checkNotNull(object, "object")) {
stops.add(stop);
if (object instanceof Planet) {
NaturalCamera cam = GaiaSky.instance.cameraManager.naturalCamera;
// FOCUS_MODE wait - 2 seconds
float waitTimeSeconds = -1;
/*
* SAVE
*/
// Save speed, set it to 50
double speed = Settings.settings.scene.camera.speed;
em.post(Event.CAMERA_SPEED_CMD, this, 25f / 10f, false);
// Save turn speed, set it to 50
double turnSpeedBak = Settings.settings.scene.camera.turn;
em.post(Event.TURNING_SPEED_CMD, this, (float) MathUtilsd.lint(20d, Constants.MIN_SLIDER, Constants.MAX_SLIDER, Constants.MIN_TURN_SPEED, Constants.MAX_TURN_SPEED), false);
// Save cinematic
boolean cinematic = Settings.settings.scene.camera.cinematic;
Settings.settings.scene.camera.cinematic = true;
/*
* FOCUS
*/
changeFocus(object, cam, waitTimeSeconds);
/* target distance */
double target = 100 * Constants.M_TO_U;
Vector3b camObj = aux3b1;
object.getAbsolutePosition(camObj).add(cam.posinv).nor();
Vector3d dir = cam.direction;
// Add forward movement while distance > target distance
boolean distanceNotMet = (object.getDistToCamera() - object.getRadius()) > target;
boolean viewNotMet = Math.abs(dir.angle(camObj)) < 90;
long prevTime = TimeUtils.millis();
while ((distanceNotMet || viewNotMet) && (stop == null || !stop.get())) {
// dt in ms
long dt = TimeUtils.timeSinceMillis(prevTime);
prevTime = TimeUtils.millis();
if (distanceNotMet)
em.post(Event.CAMERA_FWD, this, 0.1d * dt);
else
cam.stopForwardMovement();
if (viewNotMet) {
if (object.getDistToCamera() - object.getRadius() < object.getRadius() * 5)
// Start turning where we are at n times the radius
em.post(Event.CAMERA_TURN, this, 0d, dt / 500d);
} else {
cam.stopRotateMovement();
}
try {
sleepFrames(1);
} catch (Exception e) {
logger.error(e);
}
// focus.transform.getTranslation(aux);
viewNotMet = Math.abs(dir.angle(camObj)) < 90;
distanceNotMet = (object.getDistToCamera() - object.getRadius()) > target;
}
// STOP
em.post(Event.CAMERA_STOP, this);
// Roll till done
Vector3d up = cam.up;
// aux1 <- camera-object
camObj = object.getAbsolutePosition(aux3b1).sub(cam.pos);
double ang1 = up.angle(camObj);
double ang2 = up.cpy().rotate(cam.direction, 1).angle(camObj);
double rollSign = ang1 < ang2 ? -1d : 1d;
if (ang1 < 170) {
rollAndWait(rollSign * 0.02d, 170d, 50L, cam, camObj, stop);
// STOP
cam.stopMovement();
rollAndWait(rollSign * 0.006d, 176d, 50L, cam, camObj, stop);
// STOP
cam.stopMovement();
rollAndWait(rollSign * 0.003d, 178d, 50L, cam, camObj, stop);
}
/*
* RESTORE
*/
// We can stop now
em.post(Event.CAMERA_STOP, this);
// Restore cinematic
Settings.settings.scene.camera.cinematic = cinematic;
// Restore speed
em.post(Event.CAMERA_SPEED_CMD, this, (float) speed, false);
// Restore turning speed
em.post(Event.TURNING_SPEED_CMD, this, (float) turnSpeedBak, false);
}
}
}
use of gaiasky.scenegraph.camera.NaturalCamera in project gaiasky by langurmonkey.
the class EventScriptingInterface method waitFocus.
@Override
public boolean waitFocus(String name, long timeoutMs) {
long iniTime = TimeUtils.millis();
NaturalCamera cam = GaiaSky.instance.cameraManager.naturalCamera;
while (cam.focus == null || !cam.focus.getName().equalsIgnoreCase(name)) {
sleepFrames(1);
long spent = TimeUtils.millis() - iniTime;
if (timeoutMs > 0 && spent > timeoutMs) {
// Timeout!
return true;
}
}
return false;
}
use of gaiasky.scenegraph.camera.NaturalCamera in project gaiasky by langurmonkey.
the class RecursiveGrid method updateLocalTransform.
private void updateLocalTransform(ICamera camera) {
IFocus focus = camera.getFocus();
localTransform.idt();
Vector3 vroffset = F34.get();
float vrScl = 1f;
if (Settings.settings.runtime.openVr) {
vrScl = 100f;
if (camera.getCurrent() instanceof NaturalCamera) {
((NaturalCamera) camera.getCurrent()).vrOffset.put(vroffset);
vroffset.scl((float) (1f / Constants.M_TO_U));
}
} else {
vroffset.set(0, 0, 0);
}
if (Settings.settings.program.recursiveGrid.origin.isRefSys() || focus == null) {
// Coordinate origin - Sun
if (regime == 1)
localTransform.translate(camera.getInversePos().put(F31.get()));
else
localTransform.translate(camera.getInversePos().put(F31.get()).setLength(vrScl).add(vroffset));
} else {
// Focus object
if (regime == 1)
localTransform.translate(focus.getAbsolutePosition(B31.get()).sub(camera.getPos()).put(F31.get()));
else
localTransform.translate(focus.getAbsolutePosition(B31.get()).sub(camera.getPos()).setLength(vrScl).add(vroffset).put(F31.get()));
}
if (regime == 1)
localTransform.scl((float) (distToCamera * 0.067d * Constants.AU_TO_U / Constants.DISTANCE_SCALE_FACTOR));
else
localTransform.scl((float) (0.067f * vrScl * Constants.AU_TO_U / Constants.DISTANCE_SCALE_FACTOR));
if (coordinateSystem != null)
localTransform.mul(coordinateSystem);
// Must rotate due to orientation of billboard
localTransform.rotate(1, 0, 0, 90);
}
use of gaiasky.scenegraph.camera.NaturalCamera in project gaiasky by langurmonkey.
the class SphericalGrid method render.
/**
* Annotation rendering
*/
@Override
public void render(ExtSpriteBatch spriteBatch, ICamera camera, BitmapFont font, float alpha) {
// Horizon
float stepAngle = 360f / divisionsU;
alpha *= ANNOTATIONS_ALPHA;
font.setColor(labelcolor[0], labelcolor[1], labelcolor[2], labelcolor[3] * alpha);
Vector3 vrOffset = F34.get();
if (Settings.settings.runtime.openVr) {
if (camera.getCurrent() instanceof NaturalCamera) {
((NaturalCamera) camera.getCurrent()).vrOffset.put(vrOffset);
vrOffset.scl((float) (1f / Constants.M_TO_U));
}
} else {
vrOffset.set(0, 0, 0);
}
for (int angle = 0; angle < 360; angle += stepAngle) {
auxf.set(Coordinates.sphericalToCartesian(Math.toRadians(angle), 0f, 1f, auxd).valuesf()).mul(annotTransform).nor();
effectsPos(auxf, camera);
if (auxf.dot(camera.getCamera().direction.nor()) > 0) {
auxf.add(camera.getCamera().position).scl((float) Constants.DISTANCE_SCALE_FACTOR).add(vrOffset);
camera.getCamera().project(auxf);
font.draw(spriteBatch, angle(angle), auxf.x, auxf.y);
}
}
// North-south line
stepAngle = 180f / divisionsV;
for (int angle = -90; angle <= 90; angle += stepAngle) {
if (angle != 0) {
auxf.set(Coordinates.sphericalToCartesian(0, Math.toRadians(angle), 1f, auxd).valuesf()).mul(annotTransform).nor();
effectsPos(auxf, camera);
if (auxf.dot(camera.getCamera().direction.nor()) > 0) {
auxf.add(camera.getCamera().position).scl((float) Constants.DISTANCE_SCALE_FACTOR).add(vrOffset);
camera.getCamera().project(auxf);
font.draw(spriteBatch, angleSign(angle), auxf.x, auxf.y);
}
auxf.set(Coordinates.sphericalToCartesian(0, Math.toRadians(-angle), -1f, auxd).valuesf()).mul(annotTransform).nor();
effectsPos(auxf, camera);
if (auxf.dot(camera.getCamera().direction.nor()) > 0) {
auxf.add(camera.getCamera().position).scl((float) Constants.DISTANCE_SCALE_FACTOR).add(vrOffset);
camera.getCamera().project(auxf);
font.draw(spriteBatch, angleSign(angle), auxf.x, auxf.y);
}
}
}
}
Aggregations