@@ -57,7 +57,7 @@ extern glm::mat4x4& viewMat;
5757extern double & fov; // in the y direction
5858extern ProjectionMode& projectionMode;
5959
60- // "Flying" view
60+ // "Flying" view members
6161extern bool & midflight;
6262extern float & flightStartTime;
6363extern float & flightEndTime;
@@ -75,85 +75,104 @@ extern const double defaultFov;
7575
7676// === View methods
7777
78- void processTranslate (glm::vec2 delta);
79- void processRotate (glm::vec2 startP, glm::vec2 endP);
80- void processClipPlaneShift (double amount);
81- void processZoom (double amount);
82- void processKeyboardNavigation (ImGuiIO& io);
78+ // == Get/Set the current camera view in the user's window
8379
84- void setWindowSize (int width, int height);
85- std::tuple<int , int > getWindowSize ();
86- std::tuple<int , int > getBufferSize ();
87- void setViewToCamera (const CameraParameters& p);
88- CameraParameters getCameraParametersForCurrentView ();
80+ // Get various camera matrices and data for the current view
81+ CameraParameters getCameraParametersForCurrentView (); // contains all of this info
82+ // (these friendly helpers to get the same info as ^^^)
83+ glm::mat4 getCameraViewMatrix ();
84+ void setCameraViewMatrix (glm::mat4 newMat);
85+ glm::mat4 getCameraPerspectiveMatrix ();
86+ glm::vec3 getCameraWorldPosition ();
87+ void getCameraFrame (glm::vec3& lookDir, glm::vec3& upDir, glm::vec3& rightDir);
88+ glm::vec3 getUpVec ();
89+ glm::vec3 getFrontVec ();
8990
90- // Invalidating the view:
91- // The view is invalid if the viewMat has NaN entries.
92- // It is set to invalid initially, but we call ensureViewValid() before any renders.
93- // This ensures we never try to render with an invalid view, but also allows the user to
94- // set custom views if they wish, without them getting overwritten.
95- void invalidateView ();
96- void ensureViewValid ();
91+ // Set the camera extrinsics to look at a particular location
92+ void setViewToCamera (const CameraParameters& p);
93+ void lookAt (glm::vec3 cameraLocation, glm::vec3 target, bool flyTo = false );
94+ void lookAt (glm::vec3 cameraLocation, glm::vec3 target, glm::vec3 upDir, bool flyTo = false );
9795
9896// The "home" view looks at the center of the scene's bounding box.
9997glm::mat4 computeHomeView ();
10098void resetCameraToHomeView ();
10199void flyToHomeView ();
102100
103- // Set the camera extrinsics to look at a particular location
104- void lookAt (glm::vec3 cameraLocation, glm::vec3 target, bool flyTo = false );
105- void lookAt (glm::vec3 cameraLocation, glm::vec3 target, glm::vec3 upDir, bool flyTo = false );
101+ // Move the camera with a 'flight' where the camera's position is briefly animated
102+ void startFlightTo (const CameraParameters& p, float flightLengthInSeconds = .4 );
103+ void startFlightTo (const glm::mat4& T, float targetFov, float flightLengthInSeconds = .4 );
104+ void immediatelyEndFlight ();
105+
106+
107+ // == Properties of the view/window
108+
109+ // Set the size of the OS window
110+ // Set in logical pixels, which might be different from actual buffer pixels on
111+ // high-DPI screens
112+ void setWindowSize (int width, int height);
113+ std::tuple<int , int > getWindowSize ();
114+ std::tuple<int , int > getBufferSize ();
115+
116+ // UpDir is the canonical up-axis for the scene, effects how the home view is oriented,
117+ // and the axis about which navigations like the default turntable rotates.
118+ void setUpDir (UpDir newUpDir, bool animateFlight = false );
119+ UpDir getUpDir ();
120+
121+ // FrontDir is the canonical forward-axis for the scene, effects how the home view is oriented
122+ void setFrontDir (FrontDir newFrontDir, bool animateFlight = false );
123+ FrontDir getFrontDir ();
124+
125+ // What kind of navigation is used, such as Turntable, Free, etc.
126+ void setNavigateStyle (NavigateStyle newNavigateStyle, bool animateFlight = false );
127+ NavigateStyle getNavigateStyle ();
128+
129+ // Can the OS window be resized by the user?
130+ void setWindowResizable (bool isResizable);
131+ bool getWindowResizable ();
106132
107- // Get various camera matrices and data for the current view
108- glm::mat4 getCameraViewMatrix ();
109- void setCameraViewMatrix (glm::mat4 newMat);
110- glm::mat4 getCameraPerspectiveMatrix ();
111- glm::vec3 getCameraWorldPosition ();
112- void getCameraFrame (glm::vec3& lookDir, glm::vec3& upDir, glm::vec3& rightDir);
133+
134+ // == Utility functions related to the view
113135
114136// Get world geometry corresponding to a screen pixel (e.g. from a mouse click)
115137glm::vec3 screenCoordsToWorldRay (glm::vec2 screenCoords);
116138glm::vec3 bufferCoordsToWorldRay (int xPos, int yPos);
117139glm::vec3 screenCoordsToWorldPosition (glm::vec2 screenCoords); // queries the depth buffer to get full position
118140
119- // Flight-related
120- void startFlightTo (const CameraParameters& p, float flightLengthInSeconds = .4 );
121- void startFlightTo (const glm::mat4& T, float targetFov, float flightLengthInSeconds = .4 );
122- void immediatelyEndFlight ();
123-
124141// Get and set camera from json string
125142std::string getViewAsJson ();
126143void setViewFromJson (std::string jsonData, bool flyTo);
127- // DEPRACTED: old names for avove
128- std::string getCameraJson ();
144+ std::string getCameraJson (); // DEPRACTED: old names for avove
129145void setCameraFromJson (std::string jsonData, bool flyTo);
130146
131- // Other helpers
147+ // Misc helpers
132148std::string to_string (ProjectionMode mode);
133149std::string to_string (NavigateStyle style);
134150std::tuple<int , int > screenCoordsToBufferInds (glm::vec2 screenCoords);
135151
136- // Internal helpers. Should probably not be called in user code.
137- void buildViewGui ();
138- void updateFlight (); // Note: uses wall-clock time, so should generally be called exactly once at the beginning of each
139- // iteration
152+ // == Internal helpers. Should probably not be called in user code.
140153
154+ // Build view-related ImGUI UI
155+ void buildViewGui ();
141156
142- // == Setters, getters, etc
143-
144- void setUpDir (UpDir newUpDir, bool animateFlight = false );
145- UpDir getUpDir ();
146- glm::vec3 getUpVec ();
157+ // Update the current flight animation, if there is one
158+ // Note: uses wall-clock time, should be called exactly once at the beginning of each iteration
159+ void updateFlight ();
147160
148- void setFrontDir (FrontDir newFrontDir, bool animateFlight = false );
149- FrontDir getFrontDir ();
150- glm::vec3 getFrontVec ();
161+ // Invalidating the view:
162+ // The view is invalid if the viewMat has NaN entries.
163+ // It is set to invalid initially, but we call ensureViewValid() before any renders.
164+ // This ensures we never try to render with an invalid view, but also allows the user to
165+ // set custom views if they wish, without them getting overwritten.
166+ void invalidateView ();
167+ void ensureViewValid ();
151168
152- void setNavigateStyle (NavigateStyle newNavigateStyle, bool animateFlight = false );
153- NavigateStyle getNavigateStyle ();
169+ // Process user inputs which affect the view
170+ void processTranslate (glm::vec2 delta);
171+ void processRotate (glm::vec2 startP, glm::vec2 endP);
172+ void processClipPlaneShift (double amount);
173+ void processZoom (double amount);
174+ void processKeyboardNavigation (ImGuiIO& io);
154175
155- void setWindowResizable (bool isResizable);
156- bool getWindowResizable ();
157176
158177} // namespace view
159178} // namespace polyscope
0 commit comments