MinGfx Toolkit  1.0
A minimal library for writing cross-platform (Windows, OSX, linux) graphics programs.
unicam.h
Go to the documentation of this file.
1 /*
2  This file is part of the MinGfx Project.
3 
4  Copyright (c) 2017,2018 Regents of the University of Minnesota.
5  All Rights Reserved.
6 
7  Original Author(s) of this File:
8  Dan Keefe, 2018, University of Minnesota
9 
10  Author(s) of Significant Updates/Modifications to the File:
11  ...
12  */
13 
14 #ifndef SRC_UNICAM_H_
15 #define SRC_UNICAM_H_
16 
17 #include "quick_shapes.h"
18 #include "point2.h"
19 #include "point3.h"
20 #include "vector2.h"
21 #include "vector3.h"
22 
23 
24 namespace mingfx {
25 
26 
105 class UniCam {
106 public:
107 
110 
112  UniCam(const Matrix4 &initialViewMatrix);
113 
114  virtual ~UniCam();
115 
116 
117  // To make the interaction work, the following set of functions need to be
118  // called from your GraphicsApp or whatever main application class you use
119  // to receive user input events and a draw callback.
120 
132  void OnButtonDown(const Point2 &normalizedMousePos, float mouseZ);
133 
142  void OnDrag(const Point2 &normalizedMousePos);
143 
152  void OnButtonUp(const Point2 &normalizedMousePos);
153 
159  void AdvanceAnimation(double dt);
160 
166  void Draw(const Matrix4 &projectionMatrix);
167 
168 
179 
180 
184 
188 
189 
190  // -------------
191 
194  void set_view_matrix(Matrix4 viewMatrix);
195 
202  void set_default_depth(float d);
203 
204 
205 private:
206 
207  void recalc_angular_vel();
208 
209  enum class UniCamState {
210  START,
211  PAN_DOLLY_ROT_DECISION,
212  PAN_DOLLY_DECISION,
213  ROT_WAIT_FOR_SECOND_CLICK,
214  PAN,
215  DOLLY,
216  ROT,
217  SPINNING
218  };
219  UniCamState state_;
220 
221  Point2 mouseLast_;
222  double elapsedTime_;
223 
224  Point2 initialClickPos_;
225  bool hitGeometry_;
226  Point3 hitPoint_;
227 
228  bool rotInitialized_;
229  Point3 rotLastIPoint_;
230  float boundingSphereRad_;
231  Point3 boundingSphereCtr_;
232  double rotLastTime_;
233  std::vector<std::pair<double, double>> rotAngularVelBuffer_;
234  double rotAngularVel_;
235  Vector3 rotAxis_;
236 
237  bool dollyInitialized_;
238  float dollyFactor_;
239  float defaultDepth_;
240 
241  bool showIcon_;
242  QuickShapes quickShapes_;
243 
244  Matrix4 V_;
245  Matrix4 Vstart_;
246 
247  // saved from the last draw call in order to unproject the mouse pos
248  Matrix4 Pdraw_;
249 };
250 
251 
252 } // end namespace
253 
254 #endif
255 
256 
A 4x4 transformation matrix stored internally as an array of floats in column-major order so as to be...
Definition: matrix4.h:50
A 2D Point with floating point coordinates, used for storing 2D texture coordinates,...
Definition: point2.h:28
A 3D Point with floating point coordinates, used for storing vertices and all sorts of other 3D graph...
Definition: point3.h:52
This class provides a quick way to draw shapes for use in debugging or simple scenes.
Definition: quick_shapes.h:69
This implements a user interface for controlling the camera with the mouse.
Definition: unicam.h:105
void OnButtonUp(const Point2 &normalizedMousePos)
Attach this to the corresponding button up event, for example, call this from within GraphicsApp::OnR...
void OnDrag(const Point2 &normalizedMousePos)
Attach this to the corresponding mouse move event, for example, call this from within GraphicsApp::On...
Point3 eye()
Returns the "eye" point (i.e., focal point) of the camera in world space coordinates.
void set_view_matrix(Matrix4 viewMatrix)
This is not required, but you may use this if you wish to set an initial view matrix or reset the vie...
UniCam()
Creates a UniCam object with an initial view matrix = identity.
void set_default_depth(float d)
This sets the depth of the center of rotation for the case when the user's click does not intersect a...
Vector3 look()
Returns the look direction (i.e., -Z axis of the camera matrix) in world space coordinates.
void OnButtonDown(const Point2 &normalizedMousePos, float mouseZ)
Attach this to whatever mouse button you wish, for example, call this from within GraphicsApp::OnRigh...
void AdvanceAnimation(double dt)
Attach this to a callback that can be used to control animation. Within GraphicsApp::UpdateSimulation...
void Draw(const Matrix4 &projectionMatrix)
Finally, attach this to your draw callback routine. Within GraphicsApp::DrawUsingOpenGL(),...
UniCam(const Matrix4 &initialViewMatrix)
Creates a UniCam object with the supplied initial view matrix.
Matrix4 view_matrix()
Access the camera view matrix created by the UniCam interactions via this method and use it to draw t...
virtual ~UniCam()
A 3D Vector with floating point coordinates, used for storing normals and all sorts of other 3D graph...
Definition: vector3.h:62
Namespace for the MinGfx Toolkit.
Definition: aabb.h:21