Overte C++ Documentation
View.h
1 //
2 // View.h
3 // libraries/workload/src/workload
4 //
5 // Created by Sam Gateau 2018.03.05
6 // Copyright 2018 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_workload_View_h
13 #define hifi_workload_View_h
14 
15 #include <memory>
16 #include <vector>
17 #include <glm/glm.hpp>
18 #include <glm/gtc/constants.hpp>
19 
20 #include "Region.h"
21 
22 class ViewFrustum;
23 
24 namespace workload {
25 
26 using Sphere = glm::vec4;
27 
28 class View {
29 public:
30  View() = default;
31  View(const View& view) = default;
32 
33  // View attributes:
34 
35  // direction
36  glm::vec3 direction{ 0.0f, 0.0f, -1.0f };
37 
38  // Max radius
39  float maxRadius{ FLT_MAX };
40 
41  // Fov stores the half field of view angle, and tan/cos/sin ready to go, default is fov of 90deg
42  glm::vec4 fov_halfAngle_tan_cos_sin { glm::quarter_pi<float>(), 1.0f, glm::root_two<float>() * 0.5f, glm::root_two<float>() * 0.5f};
43 
44  // Origin position
45  glm::vec3 origin{ 0.0f };
46 
47  // Origin radius
48  float originRadius{ 0.5f };
49 
50  // N regions distances
51  glm::vec2 regionBackFronts[Region::NUM_TRACKED_REGIONS];
52 
53  // N regions spheres
54  Sphere regions[Region::NUM_TRACKED_REGIONS];
55 
56  // Set fov properties from angle
57  void setFov(float angleRad);
58 
59  // Helper function to force the direction in the XZ plane
60  void makeHorizontal();
61 
62  static View evalFromFrustum(const ViewFrustum& frustum, const glm::vec3& offset = glm::vec3());
63  static Sphere evalRegionSphere(const View& view, float originRadius, float maxDistance);
64 
65  static void updateRegionsDefault(View& view);
66  static void updateRegionsFromBackFronts(View& view);
67  static void updateRegionsFromBackFrontDistances(View& view, const float* configDistances);
68 };
69 
70 using Views = std::vector<View>;
71 
72 } // namespace workload
73 
74 #endif // hifi_workload_View_h