All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
EegeoUpdateParameters.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "VectorMath.h"
6 #include "ScreenProperties.h"
7 #include "SpaceHelpers.h"
8 #include "RenderCamera.h"
9 #include "IStreamingVolume.h"
10 #include "EarthConstants.h"
11 
12 namespace
13 {
14  // todo: should be Eegeo::Space::EarthConstants::MaxElevation + Eegeo::Space::EarthConstants::Radius + some constant?
15  const double EVEREST_ALTITUDE = 9000.0 + Eegeo::Space::EarthConstants::Radius;
16  const double EVEREST_ALTITUDE_SQR = EVEREST_ALTITUDE*EVEREST_ALTITUDE;
17 }
18 
19 namespace Eegeo
20 {
21  class EegeoUpdateParameters
22  {
23  float m_frameDeltaSeconds;
24  dv3 m_ecefLocation;
25  dv3 m_ecefInterestPoint;
26  m44 m_viewMatrix;
27  m44 m_projectionMatrix;
28  m44 m_viewProjectionMatrix;
29  Streaming::IStreamingVolume& m_streamingVolume;
30  Rendering::ScreenProperties m_screenProperties;
31 
32  public:
33  EegeoUpdateParameters(float frameDeltaSeconds,
34  const dv3& ecefLocation,
35  const dv3& ecefInterestPoint,
36  const m44& viewMatrix,
37  const m44& projectionMatrix,
38  Streaming::IStreamingVolume& streamingVolume,
39  const Rendering::ScreenProperties& screenProperties)
40  : m_frameDeltaSeconds(frameDeltaSeconds)
41  , m_ecefLocation(ecefLocation)
42  , m_ecefInterestPoint(ecefInterestPoint)
43  , m_viewMatrix(viewMatrix)
44  , m_projectionMatrix(projectionMatrix)
45  , m_streamingVolume(streamingVolume)
46  , m_screenProperties(screenProperties)
47  {
48  // Patch for MPLY-8155: Interest point altitude shouldn't ever be > terrain height
49  // At very high altitudes, this breaks CameraFrustumStreamingVolume's concept of altitude and LOD level
50  Eegeo_ASSERT(m_ecefInterestPoint.LengthSq() <= EVEREST_ALTITUDE_SQR, "Interest point altitude is too high. ");
51  Eegeo::m44::Mul(m_viewProjectionMatrix, ProjectionMatrix(), ViewMatrix());
52  }
53 
54  float FrameDeltaSeconds() const { return m_frameDeltaSeconds; }
55 
56  double Altitude() const { return Eegeo::Space::SpaceHelpers::GetAltitude(EcefLocation()); }
57 
58  const dv3& EcefLocation() const { return m_ecefLocation; }
59 
60  const dv3& EcefInterestPoint() const { return m_ecefInterestPoint; }
61 
62  const m44& ViewMatrix() const { return m_viewMatrix; }
63 
64  const m44& ProjectionMatrix() const { return m_projectionMatrix; }
65 
66  Streaming::IStreamingVolume& StreamingVolume() const { return m_streamingVolume; }
67 
68  const Rendering::ScreenProperties& ScreenProperties() const { return m_screenProperties; }
69 
70  const m44& ViewProjectionMatrix() const { return m_viewProjectionMatrix; }
71  };
72 
73  inline Camera::RenderCamera RenderCameraFromEegeoUpdateParameters(const EegeoUpdateParameters& eegeoUpdateParameters)
74  {
75  Camera::RenderCamera renderCamera;
76 
77  renderCamera.SetViewport(0.f,
78  0.f,
79  eegeoUpdateParameters.ScreenProperties().GetScreenWidth(),
80  eegeoUpdateParameters.ScreenProperties().GetScreenHeight());
81 
82  m33 viewOrientation(eegeoUpdateParameters.ViewMatrix());
83  m33 cameraModel;
84  m33::Inverse(cameraModel, viewOrientation);
85  m44 projection(eegeoUpdateParameters.ProjectionMatrix());
86  dv3 ecefLocation(eegeoUpdateParameters.EcefLocation());
87 
88  renderCamera.SetOrientationMatrix(cameraModel);
89  renderCamera.SetEcefLocation(ecefLocation);
90  renderCamera.SetProjectionMatrix(projection);
91 
92  return renderCamera;
93  }
94 }