From 363fe6533ccf577f6c8ffda409657a29ccaf1c29 Mon Sep 17 00:00:00 2001
From: lm <pixhawk@student.ethz.ch>
Date: Mon, 3 Jan 2011 08:58:42 +0100
Subject: [PATCH] Added position interpolation

---
 images/earth.html | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/images/earth.html b/images/earth.html
index 0ab8487..b345e27 100644
--- a/images/earth.html
+++ b/images/earth.html
@@ -18,6 +18,7 @@ var followEnabled = false;
 
 var lastLat = 0;
 var lastLon = 0;
+var lastAlt = 0;
 var currLat = 47.3769;
 var currLon = 8.549444;
 var currAlt = 470;
@@ -210,8 +211,11 @@ function setAircraftPositionAttitude(id, lat, lon, alt, roll, pitch, yaw)
 {
 	if (id == currAircraft)
 	{
-		lastLat = currLat;
-		lastLon = lastLon;
+		if (lastLat == 0)
+		{
+			lastLat = currLat;
+			lastLon = lastLon;
+		}
 		currLat = lat;
 		currLon = lon;
 		currAlt = alt;
@@ -262,12 +266,17 @@ function setCurrentAircraft(id)
 function updateFollowAircraft()
 {
 	currView = ge.getView().copyAsLookAt(ge.ALTITUDE_ABSOLUTE);
-	currView.setLatitude(currLat);
-	currView.setLongitude(currLon);
-	currView.setAltitude(currAlt);
+	// Interpolate
+	currView.setLatitude(lastLat*0.7+currLat*0.3);
+	currView.setLongitude(lastLon*0.7+currLon*0.3);
+	currView.setAltitude(lastAlt*0.7+currAlt*0.3);
+	// Set new states
+	lastLat = lastLat*0.7+currLat*0.3;
+	lastLon = lastLon*0.7+currLon*0.3;
+	lastAlt = lastAlt*0.7+currAlt*0.3;
 	currView.setRange(currViewRange);
 	currView.setTilt(currFollowTilt);
-	currFollowHeading = 0.9*currFollowHeading+0.1*((Math.atan2(lastLat-currLat, lastLon-currLon)/M_PI)+1.0)*360.0;
+	currFollowHeading = 0;// 0.9*currFollowHeading+0.1*((Math.atan2(lastLat-currLat, lastLon-currLon)/M_PI)+1.0)*360.0;
 	currView.setHeading(currFollowHeading-0.0);
 	ge.getView().setAbstractView(currView);
 }