Overte C++ Documentation
OctreeHeadlessViewer.h
1 //
2 // OctreeHeadlessViewer.h
3 // libraries/octree/src
4 //
5 // Created by Brad Hefta-Gaub on 2/26/14.
6 // Copyright 2014 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_OctreeHeadlessViewer_h
13 #define hifi_OctreeHeadlessViewer_h
14 
15 #include <QtCore/QSharedPointer>
16 
17 #include <OctreeProcessor.h>
18 #include <OctreeQuery.h>
19 
20 
21 // Generic client side Octree renderer class.
22 class OctreeHeadlessViewer : public OctreeProcessor {
23  Q_OBJECT
24 public:
25  OctreeQuery& getOctreeQuery() { return _octreeQuery; }
26 
27  static int parseOctreeStats(QSharedPointer<ReceivedMessage> message, SharedNodePointer sourceNode);
28  static void trackIncomingOctreePacket(const QByteArray& packet, const SharedNodePointer& sendingNode, bool wasStatsPacket);
29 
30 public slots:
31 
32  /*@jsdoc
33  * Updates the entities currently in view.
34  * @function EntityViewer.queryOctree
35  */
36  void queryOctree();
37 
38 
39  // setters for camera attributes
40 
41  /*@jsdoc
42  * Sets the position of the view frustum.
43  * @function EntityViewer.setPosition
44  * @param {Vec3} position - The position of the view frustum.
45  */
46  void setPosition(const glm::vec3& position) { _hasViewFrustum = true; _viewFrustum.setPosition(position); }
47 
48  /*@jsdoc
49  * Sets the orientation of the view frustum.
50  * @function EntityViewer.setOrientation
51  * @param {Quat} orientation - The orientation of the view frustum.
52  */
53  void setOrientation(const glm::quat& orientation) { _hasViewFrustum = true; _viewFrustum.setOrientation(orientation); }
54 
55  /*@jsdoc
56  * Sets the radius of the center "keyhole" in the view frustum.
57  * @function EntityViewer.setCenterRadius
58  * @param {number} radius - The radius of the center "keyhole" in the view frustum.
59  */
60  void setCenterRadius(float radius) { _hasViewFrustum = true; _viewFrustum.setCenterRadius(radius); }
61 
62  /*@jsdoc
63  * Sets the radius of the center "keyhole" in the view frustum.
64  * @function EntityViewer.setKeyholeRadius
65  * @param {number} radius - The radius of the center "keyhole" in the view frustum.
66  * @deprecated This function is deprecated and will be removed. Use {@link EntityViewer.setCenterRadius|setCenterRadius}
67  * instead.
68  */
69  void setKeyholeRadius(float radius) { _hasViewFrustum = true; _viewFrustum.setCenterRadius(radius); } // TODO: remove this legacy support
70 
71 
72  // setters for LOD and PPS
73 
74  /*@jsdoc
75  * @function EntityViewer.setVoxelSizeScale
76  * @param {number} sizeScale - The voxel size scale.
77  * @deprecated This function is deprecated and will be removed.
78  */
79  void setVoxelSizeScale(float sizeScale) { _octreeQuery.setOctreeSizeScale(sizeScale) ; }
80 
81  /*@jsdoc
82  * @function EntityViewer.setBoundaryLevelAdjust
83  * @param {number} boundaryLevelAdjust - The boundary level adjust factor.
84  * @deprecated This function is deprecated and will be removed.
85  */
86  void setBoundaryLevelAdjust(int boundaryLevelAdjust) { _octreeQuery.setBoundaryLevelAdjust(boundaryLevelAdjust); }
87 
88  /*@jsdoc
89  * Sets the maximum number of entity packets to receive from the domain server per second.
90  * @function EntityViewer.setMaxPacketsPerSecond
91  * @param {number} maxPacketsPerSecond - The maximum number of entity packets to receive per second.
92  */
93  void setMaxPacketsPerSecond(int maxPacketsPerSecond) { _octreeQuery.setMaxQueryPacketsPerSecond(maxPacketsPerSecond); }
94 
95  // getters for camera attributes
96 
97  /*@jsdoc
98  * Gets the position of the view frustum.
99  * @function EntityViewer.getPosition
100  * @returns {Vec3} The position of the view frustum.
101  */
102  const glm::vec3& getPosition() const { return _viewFrustum.getPosition(); }
103 
104  /*@jsdoc
105  * Gets the orientation of the view frustum.
106  * @function EntityViewer.getOrientation
107  * @returns {Quat} The orientation of the view frustum.
108  */
109  const glm::quat& getOrientation() const { return _viewFrustum.getOrientation(); }
110 
111 
112  // getters for LOD and PPS
113 
114  /*@jsdoc
115  * @function EntityViewer.getVoxelSizeScale
116  * @returns {number} The voxel size scale.
117  * @deprecated This function is deprecated and will be removed.
118  */
119  float getVoxelSizeScale() const { return _octreeQuery.getOctreeSizeScale(); }
120 
121  /*@jsdoc
122  * @function EntityViewer.getBoundaryLevelAdjust
123  * @returns {number} The boundary level adjust factor.
124  * @deprecated This function is deprecated and will be removed.
125  */
126  int getBoundaryLevelAdjust() const { return _octreeQuery.getBoundaryLevelAdjust(); }
127 
128  /*@jsdoc
129  * Gets the maximum number of entity packets to receive from the domain server per second.
130  * @function EntityViewer.getMaxPacketsPerSecond
131  * @returns {number} The maximum number of entity packets to receive per second.
132  */
133  int getMaxPacketsPerSecond() const { return _octreeQuery.getMaxQueryPacketsPerSecond(); }
134 
135 
136  /*@jsdoc
137  * Gets the number of nodes in the octree.
138  * @function EntityViewer.getOctreeElementsCount
139  * @returns {number} The number of nodes in the octree.
140  */
141  unsigned getOctreeElementsCount() const { return _tree->getOctreeElementsCount(); }
142 
143 private:
144  OctreeQuery _octreeQuery;
145 
146  bool _hasViewFrustum { false };
147  ViewFrustum _viewFrustum;
148 };
149 
150 #endif // hifi_OctreeHeadlessViewer_h