| 
					
				 | 
			
			
				@@ -16,13 +16,12 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package org.ros.android.views.map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import android.graphics.Point; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import android.opengl.GLSurfaceView; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import android.opengl.GLU; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.ros.message.geometry_msgs.Point; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.ros.message.geometry_msgs.Pose; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import org.ros.message.geometry_msgs.Quaternion; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.ros.message.nav_msgs.OccupancyGrid; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.ros.message.nav_msgs.Path; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.ros.rosjava_geometry.Geometry; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import javax.microedition.khronos.egl.EGLConfig; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import javax.microedition.khronos.opengles.GL10; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -34,25 +33,13 @@ import javax.microedition.khronos.opengles.GL10; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 class MapRenderer implements GLSurfaceView.Renderer { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * Most the user can zoom in (distance of the camera from origin) in the map 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * centric view. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * Most the user can zoom in. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  private static final float MIN_ZOOM_MAP_CENTRIC_MODE = -70; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  private static final float MIN_ZOOM_SCALE_FACTOR = 0.01f; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * Most the user can zoom out (distance of the camera from origin) in the map 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * centric view. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * Most the user can zoom out. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  private static final float MAX_ZOOM_MAP_CENTRIC_MODE = -400; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * Most the user can zoom in (distance of the camera from origin) in the robot 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * centric view. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  private static final float MIN_ZOOM_ROBOT_CENTRIC_MODE = -100; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * Most the user can zoom out (distance of the camera from origin) in the 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * robot centric view. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  private static final float MAX_ZOOM_ROBOT_CENTRIC_MODE = -400; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  private static final float MAX_ZOOM_SCALE_FACTOR = 1.0f; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    * Instance of the helper class that draws the map, robot, etc. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    */ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -61,20 +48,19 @@ class MapRenderer implements GLSurfaceView.Renderer { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    * Real world (x,y) coordinates of the camera. The depth (z-axis) is based on 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    * {@link #zoom}. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  private Point cameraLocation = new Point(0, 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  private Point cameraPoint = new Point(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * The max x and y coordinates of the map in meters. In the current 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * Implementation the assumption is that the 0,0 cell of the map is at the 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * origin of the coordinates system. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   *  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * TODO: This is not a necessary assumption and should not be required. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * The minimal x and y coordinates of the map in meters. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  private Point topLeftMapPoint = new Point(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * The maximal x and y coordinates of the map in meters. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  private Point maxCoords = new Point(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  private Point bottomRightMapPoint = new Point(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * The distance of the OpenGL camera from the origin. By default it will 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * zoomed in all the way. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * The current zoom factor used to scale the world. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  private float zoom = MIN_ZOOM_MAP_CENTRIC_MODE; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  private float scalingFactor = 0.1f; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    * True when the map is supposed to be in the robot centric mode and false 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    * when the map is supposed to be in the map centric mode. 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -84,42 +70,34 @@ class MapRenderer implements GLSurfaceView.Renderer { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    * True when the camera should follow the robot in the map centric mode, false 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    * otherwise. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  private boolean centerOnRobot = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  private boolean centerOnRobot = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * Robot's x coordinate in the real world. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * The Robot pose. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  private float robotX; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * Robot's y coordinate in the real world. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  private float robotY; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * Robot's orientation (in radians) coordinate in the real world. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  private float robotTheta; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  private Pose robotPose; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    * True when the icon for the user to specify a goal must be shown, false 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    * otherwise. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   private boolean showUserGoal; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * True is the regions should be shown, false otherwise. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  private boolean showRegion; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  private int viewportHalfWidth; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  private android.graphics.Point viewport; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  public void onSurfaceChanged(GL10 gl, int w, int h) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    gl.glViewport(0, 0, w, h); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  public void onSurfaceChanged(GL10 gl, int width, int height) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    gl.glViewport(0, 0, width, height); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     gl.glMatrixMode(GL10.GL_PROJECTION); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     gl.glLoadIdentity(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // The aspect ratio is currently set to 1. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    GLU.gluPerspective(gl, 60.0f, 1f, 1f, 450.0f); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    viewportHalfWidth = w / 2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    gl.glOrthof(-width / 2, -height / 2, width / 2, height / 2, -10.0f, 10.0f); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    viewport = new android.graphics.Point(width, height); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     gl.glMatrixMode(GL10.GL_MODELVIEW); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     gl.glLoadIdentity(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    gl.glEnable(GL10.GL_BLEND); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     gl.glHint(GL10.GL_POLYGON_SMOOTH_HINT, GL10.GL_NICEST); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    gl.glDisable(GL10.GL_LIGHTING); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    gl.glDisable(GL10.GL_DEPTH_TEST); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    gl.glEnable(GL10.GL_COLOR_MATERIAL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   @Override 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -129,96 +107,67 @@ class MapRenderer implements GLSurfaceView.Renderer { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   public void onDrawFrame(GL10 gl) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    gl.glClearColor(0, 0, 0.0f, 0.0f); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     gl.glLoadIdentity(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // If the map view is supposed to be robot centric then move the 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // camera to the x,y coordinate of the robot and rotate it so it aligns with 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // the robot's orientation. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (robotCentricMode) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      gl.glRotatef(robotTheta - 90, 0, 0, -1f); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      gl.glTranslatef(robotX - getCenterCoordinates(), robotY - getCenterCoordinates(), zoom); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      gl.glRotatef(0, 0, 0, -1f); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      gl.glTranslatef(cameraLocation.x, cameraLocation.y, zoom); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // We need to negate cameraLocation.x because at this point, in the OpenGL 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // coordinate system, x is pointing left. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    gl.glScalef(scalingFactor, scalingFactor, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    gl.glRotatef(90, 0, 0, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    gl.glTranslatef((float) -cameraPoint.x, (float) -cameraPoint.y, (float) -cameraPoint.z); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     map.drawMap(gl); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     map.drawPath(gl); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     map.drawCurrentGoal(gl); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (showRegion) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      map.drawRegion(gl); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    map.drawRobot(gl, zoom / MIN_ZOOM_MAP_CENTRIC_MODE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    map.drawRobot(gl, 1.0f / scalingFactor); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if (showUserGoal) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      map.drawUserGoal(gl, zoom / MIN_ZOOM_MAP_CENTRIC_MODE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      map.drawUserGoal(gl, 1.0f / scalingFactor); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   public void updateMap(OccupancyGrid newMap) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     map.updateMap(newMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    maxCoords.x = (int) -newMap.info.width; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    maxCoords.y = (int) -newMap.info.height; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    topLeftMapPoint.x = (float) newMap.info.origin.position.x; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    topLeftMapPoint.y = (float) newMap.info.origin.position.y; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    bottomRightMapPoint.x = (float) topLeftMapPoint.x + newMap.info.width * newMap.info.resolution; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    bottomRightMapPoint.y = (float) topLeftMapPoint.y + newMap.info.height * newMap.info.resolution; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  public void updatePath(Path path, float res) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    map.updatePath(path, res); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  public void updatePath(Path path) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    map.updatePath(path); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * Draw the region selection box based on the specified pixel coordinates. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  public void drawRegion(int x1, int y1, int x2, int y2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    showRegion = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    map.updateRegion(getWorldCoordinate(x1, y1), getWorldCoordinate(x2, y2)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  public void moveCamera(android.graphics.Point point) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // Point is the relative movement in pixels on the viewport. We need to 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // scale this by width end height of the viewport. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    cameraPoint.x += (float) point.y / viewport.y / scalingFactor; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    cameraPoint.y += (float) point.x / viewport.x / scalingFactor; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    disableCenterOnRobot(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  public void moveCamera(Point point) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // Since the movement can be relative and need not be based on the real 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // world coordinates, the change in coordinates is divided by 3 to maintain 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // a descent panning pace. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    cameraLocation.x += point.x / 3; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    cameraLocation.y -= point.y / 3; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // Bounds checking to prevent the user from panning too much. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (cameraLocation.x > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      cameraLocation.x = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } else if (cameraLocation.x < maxCoords.x) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      cameraLocation.x = maxCoords.x; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (cameraLocation.y > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      cameraLocation.y = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } else if (cameraLocation.y < maxCoords.y) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      cameraLocation.y = maxCoords.y; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  public void zoomCamera(float zoomLevel) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    scalingFactor *= zoomLevel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (scalingFactor < MIN_ZOOM_SCALE_FACTOR) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      scalingFactor = MIN_ZOOM_SCALE_FACTOR; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } else if (scalingFactor > MAX_ZOOM_SCALE_FACTOR) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      scalingFactor = MAX_ZOOM_SCALE_FACTOR; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // Disabling the centerOnRobot when the user moves the map is similar to the 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // navigation app in android. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    centerOnRobot = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  public void zoomCamera(float zoomLevel) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // Diving by 3 to maintain a steady pace for zooming in/out. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    zoom += zoomLevel / 3f; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (robotCentricMode) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      if (zoom < MAX_ZOOM_ROBOT_CENTRIC_MODE) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        zoom = MAX_ZOOM_ROBOT_CENTRIC_MODE; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      } else if (zoom > MIN_ZOOM_ROBOT_CENTRIC_MODE) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        zoom = MIN_ZOOM_ROBOT_CENTRIC_MODE; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      if (zoom < MAX_ZOOM_MAP_CENTRIC_MODE) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        zoom = MAX_ZOOM_MAP_CENTRIC_MODE; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      } else if (zoom > MIN_ZOOM_MAP_CENTRIC_MODE) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        zoom = MIN_ZOOM_MAP_CENTRIC_MODE; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  public void enableCenterOnRobot() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    centerOnRobot = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    centerOnRobot(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  public void hideRegion() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    showRegion = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  public void disableCenterOnRobot() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    centerOnRobot = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  public void enableCenterOnRobot() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    centerOnRobot = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    centerCamera(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  public boolean centerOnRobotEnabled() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return centerOnRobot; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  public void toggleCenterOnRobot() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    centerOnRobot = !centerOnRobot; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   public void userGoalVisible(boolean visibility) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -234,13 +183,30 @@ class MapRenderer implements GLSurfaceView.Renderer { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    *          Coordinate of the view in pixels. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    * @return Real world coordinate. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  public Point getWorldCoordinate(float x, float y) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    Point realCoord = new Point(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    float multiplier = (float) (Math.tan(30 * Math.PI / 180f) * (-zoom)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    float onePixelToMeter = multiplier / viewportHalfWidth; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    realCoord.x = cameraLocation.x - (int) ((viewportHalfWidth - x) * onePixelToMeter); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    realCoord.y = cameraLocation.y - (int) ((viewportHalfWidth - y) * onePixelToMeter); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    return realCoord; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  public Point toOpenGLCoordinates(android.graphics.Point screenPoint) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    Point worldCoordinate = new Point(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    worldCoordinate.x = 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        (0.5 - (double) screenPoint.y / viewport.y) / (0.5 * scalingFactor) + cameraPoint.x; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    worldCoordinate.y = 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        (0.5 - (double) screenPoint.x / viewport.x) / (0.5 * scalingFactor) + cameraPoint.y; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    worldCoordinate.z = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return worldCoordinate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * Returns the pose in the OpenGL world that corresponds to a screen 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * coordinate and an orientation. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   *  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * @param goalScreenPoint 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   *          the point on the screen 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * @param orientation 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   *          the orientation of the pose on the screen 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  public Pose toOpenGLPose(android.graphics.Point goalScreenPoint, float orientation) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    Pose goal = new Pose(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    goal.position = toOpenGLCoordinates(goalScreenPoint); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    goal.orientation = Geometry.axisAngleToQuaternion(0, 0, -1, Math.PI + orientation); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return goal; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -248,18 +214,12 @@ class MapRenderer implements GLSurfaceView.Renderer { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    *  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    * @param pose 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    *          Robot's pose in real world coordinate. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * @param res 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   *          The resolution of the current map in meters/cell. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  public void updateRobotPose(Pose pose, float res) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    map.updateRobotPose(pose, res); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    robotX = (float) (-pose.position.x); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    robotY = (float) (-pose.position.y); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    robotTheta = calculateHeading(pose.orientation); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // If the camera is supposed to be centered on the robot then move the 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // camera to the same coordinates as the robot. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  public void updateRobotPose(Pose pose) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    robotPose = pose; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    map.updateRobotPose(pose); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     if (centerOnRobot) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      centerCamera(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      centerOnRobot(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -272,66 +232,19 @@ class MapRenderer implements GLSurfaceView.Renderer { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   public void setViewMode(boolean isRobotCentricMode) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     robotCentricMode = isRobotCentricMode; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (robotCentricMode) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      if (zoom < MAX_ZOOM_ROBOT_CENTRIC_MODE) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        zoom = MAX_ZOOM_ROBOT_CENTRIC_MODE; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      } else if (zoom > MIN_ZOOM_ROBOT_CENTRIC_MODE) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        zoom = MIN_ZOOM_ROBOT_CENTRIC_MODE; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  public void updateCurrentGoalPose(Pose goalPose, float res) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    map.updateCurrentGoalPose(goalPose, res); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  public void updateUserGoalLocation(Point goalScreenPoint) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    map.updateUserGoalLocation(getWorldCoordinate(goalScreenPoint.x, goalScreenPoint.y)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  public void updateUserGoalOrientation(float theta) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    map.updateUserGoalOrientation(theta); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * Updates the coordinates of the map. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   *  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * @param x 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   *          The real world x coordinate for the camera. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * @param y 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   *          The real world y coordinate for the camera. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  public void moveCamera(float x, float y) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    cameraLocation.x = (int) x; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    cameraLocation.y = (int) y; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * Returns the heading (in degree) from the quaternion passed to it. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  private float calculateHeading(Quaternion orientation) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    double w = orientation.w; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    double x = orientation.x; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    double y = orientation.z; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    double z = orientation.y; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    return (float) Math.toDegrees(Math.atan2(2 * y * w - 2 * x * z, x * x - y * y - z * z + w * w)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  public void updateCurrentGoalPose(Pose goalPose) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    map.updateCurrentGoalPose(goalPose); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * Returns the real world coordinates that matches the center of the viewport. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  private float getCenterCoordinates() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    float multiplier = (float) (Math.tan(Math.toRadians(30)) * (-zoom)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    float oneMeterToPixel = viewportHalfWidth / multiplier; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    return oneMeterToPixel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  public void centerOnRobot() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (robotPose != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      cameraPoint = robotPose.position; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * Sets the camera coordinates to that of the robot's. Hence the camera starts 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   * to follow the robot. Though the camera orientation is not changed. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-   */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  private void centerCamera() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    cameraLocation.x = (int) robotX; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    cameraLocation.y = (int) robotY; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  public void updateUserGoal(Pose goal) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    map.updateUserGoal(goal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |