All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CoordinateConversion.h
Go to the documentation of this file.
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
9 #include "Rendering.h"
10 #include "Camera.h"
11 #include "Terrain.h"
12 #include "VectorMath.h"
13 #include "EarthConstants.h"
14 #include "LatLongAltitude.h"
15 #include "MortonKey.h"
16 #include "CubeMap.h"
17 #include <math.h>
18 
21 namespace Eegeo
22 {
23  namespace Space
24  {
30  inline Eegeo::dv3 ConvertLatLongAltitudeToEcef(double latitudeInRadians, double longitudeInRadians, double altitudeInMetres)
31  {
32  // Note: implementation is in .h due to client request.
33  double radius = EarthConstants::Radius + altitudeInMetres;
34 
35  double x = radius * cos(latitudeInRadians) * cos(longitudeInRadians);
36  double y = radius * cos(latitudeInRadians) * sin(longitudeInRadians);
37  double z = radius * sin(latitudeInRadians);
38 
39  return Eegeo::dv3(-y, z, x);
40  }
41 
45  inline dv3 ConvertLatLongAltitudeToEcef(const LatLongAltitude& latLongAltitude)
46  {
47  return ConvertLatLongAltitudeToEcef(latLongAltitude.GetLatitude(), latLongAltitude.GetLongitude(), latLongAltitude.GetAltitude());
48  }
49 
55  const LatLongAltitude& latLongAltitude,
56  int level)
57  {
58  dv3 ecefPosition = ConvertLatLongAltitudeToEcef(latLongAltitude);
59  return Eegeo::Space::CubeMap::EcefToKey(ecefPosition, level);
60  }
61 
67  inline LatLongAltitude ConvertEcefToLatLongAltitude(double x, double y, double z)
68  {
69  // Note: implementation is in .h due to client request.
70  double p = sqrt((z * z) + (-x * -x));
71 
72  double lat = atan(y / p);
73  double lon = atan2(-x, z);
74  double alt = (p / cos(lat)) - EarthConstants::Radius;
75 
76  return LatLongAltitude(lat, lon, alt);
77  }
78 
82  inline LatLongAltitude ConvertEcefToLatLongAltitude(const dv3& ecefPosition)
83  {
84  return ConvertEcefToLatLongAltitude(ecefPosition.GetX(), ecefPosition.GetY(), ecefPosition.GetZ());
85  }
86 
91  {
92  return Space::CubeMap::KeyToECEF(key);
93  }
94 
101  const Eegeo::Camera::RenderCamera& renderCamera,
102  const Eegeo::Rendering::ScreenProperties& screenProperties);
103 
111  bool TryConvertScreenCoordinatesToLatLongAltitude(int screenPixelCoordinateX,
112  int screenPixelCoordinateY,
113  const Eegeo::Camera::RenderCamera& renderCamera,
115  LatLongAltitude& result);
116  }
117 }