All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
DebugRendererHelpers.h
1 #pragma once
2 
3 #include <vector>
4 #include <algorithm>
5 
6 #include "Streaming.h"
7 #include "RenderCamera.h"
8 #include "VectorMath.h"
9 #include "Plane.h"
10 
11 namespace Eegeo
12 {
13  namespace DebugRendering
14  {
15  template <typename T>
16  static inline bool IsExpired(const T& drawData)
17  {
18  return drawData.Lifetime <= 0.0f;
19  }
20 
21  template <typename T>
22  static void UpdateCommandLifetimes(std::vector<T>& drawDatas, float dt)
23  {
24  for(int i = 0; i < drawDatas.size(); ++i)
25  {
26  // TODO: Common base class for render data? Currently using duck-typing
27  drawDatas[i].Lifetime -= dt;
28  }
29  }
30 
31  template <typename T>
32  static void RemoveExpiredCommands(std::vector<T>& drawData)
33  {
34  drawData.erase(std::remove_if(drawData.begin(), drawData.end(), IsExpired<T>), drawData.end());
35  }
36 
37 
38  inline bool IsInCamera(const dv3& position, const float sphereRadius, const Camera::RenderCamera& renderCamera)
39  {
40  const Geometry::Frustum& frustum = renderCamera.GetFrustum();
41  Eegeo::dv3 cameraRelativePosition = position - renderCamera.GetEcefLocation();
42 
43  bool inCamera = true;
44 
45  for (size_t i = 0; i < Eegeo::Geometry::Frustum::PLANES_COUNT; ++i)
46  {
47  const Eegeo::Geometry::Plane& p = frustum.planes[i];
48  double signedDist = p.a * cameraRelativePosition.GetX() + p.b * cameraRelativePosition.GetY() + p.c * cameraRelativePosition.GetZ() + p.d;
49 
50  if (signedDist + sphereRadius < 0.0f)
51  {
52  inCamera = false;
53  break;
54  }
55  }
56 
57  return inCamera;
58  }
59  }
60 }
61