API Documentation
Loading...
Searching...
No Matches
Camera.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Design
28File: Camera
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/Model.h>
34#include <NDEVR/SelectionInfo.h>
35#include <NDEVR/SnapLocation.h>
36#include <NDEVR/CameraBackground.h>
37#include <NDEVR/AutoZoomFocus.h>
38#include <NDEVR/CameraAnimation.h>
39#include <NDEVR/Resource.h>
40#include <NDEVR/Time.h>
41#include <NDEVR/TimeSpan.h>
42#include <NDEVR/BaseValues.h>
43#include <NDEVR/Vector.h>
44#include <NDEVR/Angle.h>
45#include <NDEVR/BasicResourceListener.h>
46#if NDEVR_VIEWPORT
47namespace NDEVR
48{
49 class ViewportFormat;
50
51 /**--------------------------------------------------------------------------------------------------
52 \brief A core object representing a user view as well as convenience functions for moving this view
53 through 3D space.
54 **/
55 class NDEVR_DESIGN_API Camera : public Model
56 {
57 public:
58 Resource<Vertex<3, fltp08>> offset;
59 Resource<Vector<3, Angle<fltp08>>> orientation;
60 Resource<Vertex<3, fltp08>> target;
61
62 Resource<fltp08> near_plane;
63 Resource<fltp08> far_plane;
64 Resource<fltp08> zoom_extent_mult;
65
66 Resource<Vector<2, Angle<fltp08>>> perspective_fov;
67 Resource<Vector<2, fltp08>> orthographic_fov;
68
69 Resource<Time> last_update_time;
70 Resource<bool> location_lock;
71 Resource<bool> rotation_lock;
72 Resource<bool> is_orthographic;
73 Resource<bool> is_exposed;
74 Resource<fltp08> plane_intercept_value;
75 Resource<fltp08> orthographic_perspective_ratio;
76 Resource<SelectionInfo> selection_info;
77
78 DynamicPointer<Dictionary<UUID, bool>> visible_items;
79
80 public:
81 Camera(Model& camera);
82 Camera(const Camera& camera);
83 const Ray<3, fltp08>& getLookat() const;
84 bool refreshMovement(const Time& current_time, const DesignObjectLookup* lookup, const TimeSpan& time_out = TimeSpan(0.2));
85 void refreshFocusBounds(const DesignObjectLookup* lookup);
86
87 void clearAnimations();
88 void move(const Ray<3, fltp08>& distance);
89 void move(const Ray<3, fltp08>& distance, const CameraAnimation& original);
90 void zoom(fltp08 distance_mult, const CameraAnimation& original);
91 void moveForward(fltp08 distance);
92 void moveHorizontal(fltp08 distance);
93 void moveVertical(fltp08 distance);
94 void move(fltp08 horizontal_distance, fltp08 vertical_distance);
95 void move(fltp08 horizontal_distance, fltp08 vertical_distance, const CameraAnimation& original);
96 void lookHorizontal(fltp08 percent);
97 void lookVertical(fltp08 percent);
98 void look(fltp08 horz_percent, fltp08 vert_percent);
99 void look(fltp08 horz_percent, fltp08 vert_percent, const CameraAnimation& original);
100
101 void moveHorizontalPercent(fltp08 percent);
102 void moveVerticalPercent(fltp08 percent);
103 void movePercent(fltp08 horizontal_percent, fltp08 vertical_percent);
104 void movePercent(fltp08 horizontal_percent, fltp08 vertical_percent, const CameraAnimation& original);
105 void panPercent(fltp08 horizontal_percent, fltp08 vertical_percent, const CameraAnimation& original);
106 void addAnimation(CameraAnimation animation, bool clear_current_animations = true);
107 void addZoomAnimation(fltp08 distance_mult, const TimeSpan& time, bool clear_animations = true);
108 void addLookatAnimation(Vector<3, fltp08> lookat, const TimeSpan& time, bool clear_animations = true);
109 void addIsOrthographicAnimation(bool is_orthographic, const TimeSpan& time, bool clear_animations = true);
110 void addOrbitAnimation(Vector<3, fltp08> target, Vector<3, Angle<fltp08>> orient, fltp08 zoom, bool face_target, const TimeSpan& time, bool clear_animations = true);
111 void setAutoZoomFocus(AutoZoomFocus focus);
112 void addZoomToExtentsAnimation(SnapLocation location, Bounds<3, fltp08> object, const TimeSpan& time, bool use_true_extents = true, bool clear_animations = true, Vector<3, Angle<fltp08>> angle_offsets = Vector<3, Angle<fltp08>>(Angle<fltp08>(0)));
113 void addZoomToExtentsAnimation(Bounds<3, fltp08> object, const TimeSpan& time, bool use_true_extents = true, bool clear_animations = true, Vector<3, Angle<fltp08>> angle_offsets = Vector<3, Angle<fltp08>>(Angle<fltp08>(0)));
114 void addZoomToExtentsAnimation(Vector<3, Angle<fltp08>> orientation, Bounds<3, fltp08> object, const TimeSpan& time, bool use_true_extents = true, bool clear_animations = true);
115 void addZoomMultiplierAnimation(fltp08 multiplier, const TimeSpan& time, bool clear_animations = true);
116 void postUpdateBackground();
117 void clearAutozoomFocus();
118 bool hasFullAutoFocus() const;
119 void readMetaData();
120 void writeMetaData();
121 SnapLocation currentSnapLocation() const;
122 SnapLocation preferredSnapLocation() const;
123 bool hasWorldGridAlignment() const;
124 void copyFrom(const Camera& object);
125 void updateGridSpacing();
126 bool isUserCamera() const;
127 void setupFromFormat(const ViewportFormat& format);
128 ViewportFormat format() const;
129 bool isObjectPotentiallyVisibleToCamera(const UUID& id) const;
130 [[nodiscard]] Matrix<fltp08> getLookatTransform() const;
131 void setLookatTransform(const Matrix<fltp08>& transform);
132 //Converts to range -1.0 to 1.0 based off of current window size
133 Vertex<2, fltp08> toScreenSpace(const Vector<2, fltp04>& pixel_location) const;
134 Vertex<3, fltp08> toWorldSpaceFromPixelSpace(const Vector<2, fltp04>& pixel_location, fltp08 depth_percent) const;
135 Vertex<3, fltp08> toWorldSpaceFromViewSpace(const Vector<2, fltp08>& view_location, fltp08 depth_percent) const;
136 SelectionInfo createSelectionInfo() const;
137 SelectionInfo createSelectionInfo(const Vector<2, fltp04>& pixel_location) const;
138 SelectionInfo createSelectionInfo(const Bounds<2, fltp04>& pixel_location) const;
139 SelectionInfo createSelectionInfo(const Polygon<fltp04>& pixel_location) const;
140 Vector<3, Angle<fltp08>> gotoOrientation() const;
141 Vector<2, Angle<fltp08>> activeFOV() const;
142 Vector<2, fltp08> activeOrthoSize() const;
143 Vector<3, fltp08> gotoLocation() const;
144 Bounds<3, fltp08> getOrthographicBounds() const;
145 Bounds<2, Angle<fltp08>> getPerspectiveBounds() const;
146 Vector<2, uint04> windowSize() const;
147 fltp08 pixelThickness() const;
148 void setPixelThickness(fltp08 thickness);
149 void setNearPlaneBounds(const Bounds<1, fltp08>& near_plane_bounds) { m_near_plane_bounds = near_plane_bounds; }
150 void setFarPlaneBounds(const Bounds<1, fltp08>& near_plane_bounds) { m_far_plane_bounds = near_plane_bounds; }
151 const Bounds<1, fltp08>& nearPlaneBounds() const { return m_near_plane_bounds; }
152 const Bounds<1, fltp08>& farPlaneBounds() const { return m_far_plane_bounds; }
153
154 Matrix<fltp08> projectionMatrix() const;
155 void setWindowSize(const Vector<2, uint04>& size);
156 void setUseReferenceSize(bool use_reference_size);
157 fltp08 calculatedReferenceSize() const;
158 void setReferenceSize(fltp08 size);
159 Vector<2, Angle<fltp08>> getRotateAroundPoint(const Vector<3, fltp04>& vCenter) const;
160 Bounds<3, fltp08> getFocusBounds() const { return m_autozoom_focus.bounds; }
161 void setFocusBounds(const Bounds<3, fltp08>& bounds) { m_autozoom_focus.bounds = bounds; }
162 //Vector<3, fltp08> lastReference() const { return m_last_refrence; }
163 const CameraBackground& cameraBackground() const { return m_camera_background; }
164 CameraBackground& cameraBackground() { return m_camera_background; }
165 private:
166 void _zoomToTargetModel(const Model& model, const DesignObjectLookup* lookup);
167 void _setupListeners();
168 Bounds<3, fltp08> boundsOfTargets(const DesignObjectLookup* lookup) const;
169 private:
170 Ray<2, uint04> m_window_size;
171 fltp08 m_reference_size;
172
173 Bounds<1, fltp08> m_near_plane_bounds;
174 Bounds<1, fltp08> m_far_plane_bounds;
175
176 Ray<3, fltp08> m_lookat;
177 Ray<3, fltp08> m_up_direction;
178 fltp08 m_pixel_thickness;
179 Vertex<3, fltp08> m_goto_initial_offset;
180 Vertex<3, fltp08> m_goto_initial_target;
181 Vector<3, Angle<fltp08>> m_goto_initial_orientation;
182 Vector<2, fltp08> m_goto_initial_ortho_bounds;
183 fltp08 m_goto_initial_zoom_extent_mult;
184 AutoZoomFocus m_autozoom_focus;
185 CameraBackground m_camera_background;
186 Matrix<fltp08> m_custom_transform;
187 Buffer<CameraAnimation> m_animations;
188 BasicResourceListener m_units_listener;
189 SnapLocation m_default_snap = SnapLocation::e_no_snap;
190 bool m_use_reference_size = true;
191 bool m_refresh_background = false;
192 private:
193 void executeAnimations(Time current_time);
194 };
195};//End namespace NDEVR
196#endif
197
198
#define NDEVR_DESIGN_API
Definition DLLInfo.h:55
Definition ACIColor.h:37
SnapLocation
A list of directions that a view can be pointed relative to an object or scene.
Definition ViewLocation.h:40
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149