The boat is now viewable in top down view (60 degrees for isometric) and the race is playable #story[1261]
parent
18a689b110
commit
7bad0e53ff
@ -0,0 +1,91 @@
|
|||||||
|
package visualiser.utils;
|
||||||
|
|
||||||
|
import shared.model.GPSCoordinate;
|
||||||
|
import visualiser.model.GraphCoordinate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by fwy13 on 7/09/17.
|
||||||
|
*/
|
||||||
|
public class GPSConverter {
|
||||||
|
double longRight;
|
||||||
|
double longLeft;
|
||||||
|
double latBottom;
|
||||||
|
double latTop;
|
||||||
|
int paneWidth;
|
||||||
|
int paneHeight;
|
||||||
|
|
||||||
|
public GPSConverter(double latTop, double longLeft, double latBottom, double longRight, double paneWidth, double paneHeight){
|
||||||
|
this.longRight = longRight;
|
||||||
|
this.longLeft = longLeft;
|
||||||
|
this.latBottom = latBottom;
|
||||||
|
this.latTop = latTop;
|
||||||
|
this.paneWidth = (int)paneWidth;
|
||||||
|
this.paneHeight = (int)paneHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts GPS coordinates to coordinates for container.
|
||||||
|
* It is assumed that the provided GPSCoordinate will always be within the GPSCoordinate boundaries of the RaceMap.
|
||||||
|
*
|
||||||
|
* @param lat GPS latitude
|
||||||
|
* @param lon GPS longitude
|
||||||
|
* @return GraphCoordinate (pair of doubles)
|
||||||
|
* @see GraphCoordinate
|
||||||
|
*/
|
||||||
|
private GraphCoordinate convertGPS(double lat, double lon) {
|
||||||
|
|
||||||
|
//Calculate the width/height, in gps coordinates, of the map.
|
||||||
|
double longWidth = longRight - longLeft;
|
||||||
|
double latHeight = latBottom - latTop;
|
||||||
|
|
||||||
|
//Calculate the distance between the specified coordinate and the edge of the map.
|
||||||
|
double longDelta = lon - longLeft;
|
||||||
|
double latDelta = lat - latTop;
|
||||||
|
|
||||||
|
//Calculate the proportion along horizontally, from the left, the coordinate should be.
|
||||||
|
double longProportion = longDelta / longWidth;
|
||||||
|
//Calculate the proportion along vertically, from the top, the coordinate should be.
|
||||||
|
double latProportion = latDelta / latHeight;
|
||||||
|
//System.out.println(latProportion + " " + longProportion);
|
||||||
|
|
||||||
|
|
||||||
|
//Check which pixel dimension of our map is smaller. We use this to ensure that any rendered stuff retains its correct aspect ratio, and that everything is visible on screen.
|
||||||
|
int smallerDimension = Math.min(paneWidth, paneHeight);
|
||||||
|
|
||||||
|
//Calculate the x and y pixel coordinates.
|
||||||
|
//We take the complement of latProportion to flip it.
|
||||||
|
int x = (int) (longProportion * smallerDimension);
|
||||||
|
int y = (int) (latProportion * smallerDimension);
|
||||||
|
|
||||||
|
//Because we try to maintain the correct aspect ratio, we will end up with "spare" pixels along the larger dimension (e.g., width 800, height 600, 200 extra pixels along width).
|
||||||
|
int extraPixels = Math.abs(paneWidth - paneHeight);
|
||||||
|
//We therefore "center" the coordinates along this larger dimension, by adding half of the extra pixels.
|
||||||
|
if (paneWidth > paneHeight) {
|
||||||
|
x += extraPixels / 2;
|
||||||
|
} else {
|
||||||
|
y += extraPixels / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Finally, create the GraphCoordinate.
|
||||||
|
GraphCoordinate graphCoordinate = new GraphCoordinate(x, y);
|
||||||
|
|
||||||
|
|
||||||
|
return graphCoordinate;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the GPS Coordinate to GraphCoordinate.
|
||||||
|
* It is assumed that the provided GPSCoordinate will always be within the GPSCoordinate boundaries of the RaceMap.
|
||||||
|
*
|
||||||
|
* @param coordinate GPSCoordinate representation of Latitude and Longitude.
|
||||||
|
* @return GraphCoordinate that the GPS is coordinates are to be displayed on the map.
|
||||||
|
* @see GraphCoordinate
|
||||||
|
* @see GPSCoordinate
|
||||||
|
*/
|
||||||
|
public GraphCoordinate convertGPS(GPSCoordinate coordinate) {
|
||||||
|
return convertGPS(coordinate.getLatitude(), coordinate.getLongitude());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in new issue