PVector zAxis = new PVector();
PVector up = new PVector();
PVector objToCamera = new PVector();
PVector objectToCameraProjection = new PVector();
PVector lookAt = new PVector(0, 0, 1);
float angle;
public void rotateToCamera(PGraphics _buffer, PVector objectPosition, PVector cameraPosition)
{
_buffer.pushMatrix();
objectToCameraProjection.x = cameraPosition.x - objectPosition.x;
objectToCameraProjection.y = 0;
objectToCameraProjection.z = cameraPosition.z - objectPosition.z;
objectToCameraProjection.normalize();
up = lookAt.cross(objectToCameraProjection);
angle = PVector.dot(lookAt, objectToCameraProjection);
if ((angle < 0.9999f) && (angle > -0.9999f)) {
// _buffer.rotate(angle, up.x, up.y, up.z);
_buffer.rotate(parent.acos(angle) * 180 / parent.PI, up.x, up.y, up.z);
}
objToCamera.x = cameraPosition.x - objectPosition.x;
objToCamera.y = cameraPosition.y - objectPosition.y;
objToCamera.z = cameraPosition.z - objectPosition.z;
objToCamera.normalize();
angle = PVector.dot(objectToCameraProjection, objToCamera);
// parent.println(parent.acos(angle) * 180 / parent.PI);
if ((angle < 2f) && (angle > -2f)) {
if (objToCamera.y < 0) {
_buffer.rotate(parent.acos(angle) * 180 / parent.PI, 1, 0, 0);
} else {
_buffer.rotate(parent.acos(angle) * 180 / parent.PI, -1, 0, 0);
}
}
}
public void updateController() {
for (Controller controller : deck_controllers) {
if (controller.getClass().getSimpleName().equalsIgnoreCase("Slider")) {
if (parameters.containsKey(controller.getLabel())) {
Parameter p = (Parameter) parameters.get(controller.getLabel());
if (controller.getValue() != p.getFloat()) {
controller.setValue(p.getInt());
} else {
PApplet.println("not changed");
}
}
}
}
for (Flight flight : flights.values()) {
JSONArray flightID = root.optJSONArray(flight.flightId);
if (flightID != null) {
try {
// Get the "planeLat, planeLong" value from the
// flightID
DateTime now = new DateTime();
float planeLat = (float) flightID.optDouble(1);
float planeLong = (float) flightID.getDouble(2);
String planeOrigin = (String) flightID.optString(11);
String planeDestination = (String) flightID.optString(12);
TimeLocation timeLocation = new TimeLocation(
new Location(planeLat, planeLong), now);
flight.addTimeLocation(timeLocation);
flight.setOrigin(planeOrigin);
flight.setDestination(planeDestination);
// Print the coordinates
// println("Lat: " + planeLat + " Long: " +
// planeLong);
// println(planeLat);
println(planeOrigin + " " + planeDestination );
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}