SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SRCamera.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2013 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 /// \author James Hughes
30 /// \date February 2013
31 
32 #ifndef SPIRE_APPSPECIFIC_SCIRUN_SRUNCAMERA_H
33 #define SPIRE_APPSPECIFIC_SCIRUN_SRUNCAMERA_H
34 
36 
37 #include <spire/src/Common.h>
38 #include <arc-look-at/ArcLookAt.hpp>
39 
40 namespace SCIRun {
41 namespace Gui {
42 
43 /// Basic camera class for spire, mimicking SCIRun v4.
44 class SRCamera
45 {
46 public:
47  SRCamera(SRInterface& iface, std::shared_ptr<spire::Interface> spire);
48  virtual ~SRCamera();
49 
50  // V = View matrix
51  // IV = Inverse view matrix
52  // P = Projection matrix
53  // m = multiplication
54  const spire::M44& getWorldToProjection() const {return mPIV;}
55  const spire::M44& getWorldToView() const {return mIV;}
56  const spire::M44& getViewToWorld() const {return mV;}
57  const spire::M44& getViewToProjection() const {return mP;}
58 
59  /// Sets this camera to use a perspective projection transformation.
60  void setAsPerspective();
61 
62  /// Sets this camera to use an orthographic projection transformation.
63  void setAsOrthographic(float halfWidth, float halfHeight);
64 
65  /// Sets the current view transform (view to world space).
66  /// \xxx This should be removed.
67  void applyTransform();
68 
69  /// Handle mouse down.
70  void mouseDownEvent(const glm::ivec2& pos, SRInterface::MouseButton btn);
71 
72  /// Handle mouse movement.
73  void mouseMoveEvent(const glm::ivec2& pos, SRInterface::MouseButton btn);
74 
75  /// Handle mouse wheel event.
76  void mouseWheelEvent(int32_t delta);
77 
78  /// Perform autoview.
79  void doAutoView(const Core::Geometry::BBox& bbox);
80 
81  /// Default camera settings
82  /// @{
83  static float getDefaultFOVY() {return 32.0f * (spire::PI / 180.0f);}
84  static float getDefaultZNear() {return 0.1f;}
85  static float getDefaultZFar() {return 100000.0f;}
86  /// @}
87 
88 private:
89 
90  void buildTransform();
91  spire::V2 calculateScreenSpaceCoords(const glm::ivec2& mousePos);
92 
93  spire::M44 mPIV; ///< Projection * Inverse View transformation.
94  spire::M44 mIV; ///< Inverse view transformation.
95  spire::M44 mV; ///< View matrix.
96  spire::M44 mP; ///< Projection transformation.
97  size_t mTrafoSeq; ///< Current sequence of the view transform.
98  ///< Helps us determine when a camera is 'dirty'.
99 
100  bool mPerspective; ///< True if we are using a perspective
101  ///< transformation.
102  float mFOV; ///< Field of view.
103  float mZNear; ///< Position of near plane along view vec.
104  float mZFar; ///< Position of far plane along view vec.
105 
106  SRInterface& mInterface; ///< SRInterface.
107  std::shared_ptr<spire::Interface> mSpire;
108 
109  std::shared_ptr<CPM_LOOK_AT_NS::ArcLookAt> mArcLookAt;
110 
111 };
112 
113 } // namespace Gui
114 } // namespace SCIRun
115 
116 #endif
Basic camera class for spire, mimicking SCIRun v4.
Definition: SRCamera.h:44
void setAsPerspective()
Sets this camera to use a perspective projection transformation.
Definition: SRCamera.cc:63
MouseButton
Definition: SRInterface.h:68
static float getDefaultZFar()
Definition: SRCamera.h:85
const spire::M44 & getViewToProjection() const
Definition: SRCamera.h:57
void setAsOrthographic(float halfWidth, float halfHeight)
Sets this camera to use an orthographic projection transformation.
Definition: SRCamera.cc:73
const spire::M44 & getWorldToProjection() const
Definition: SRCamera.h:54
Definition: BBox.h:46
static float getDefaultFOVY()
Definition: SRCamera.h:83
void mouseMoveEvent(const glm::ivec2 &pos, SRInterface::MouseButton btn)
Handle mouse movement.
Definition: SRCamera.cc:118
SRCamera(SRInterface &iface, std::shared_ptr< spire::Interface > spire)
Definition: SRCamera.cc:41
const spire::M44 & getViewToWorld() const
Definition: SRCamera.h:56
void doAutoView(const Core::Geometry::BBox &bbox)
Perform autoview.
Definition: SRCamera.cc:146
const spire::M44 & getWorldToView() const
Definition: SRCamera.h:55
Definition: SRInterface.h:54
static float getDefaultZNear()
Definition: SRCamera.h:84
void mouseWheelEvent(int32_t delta)
Handle mouse wheel event.
Definition: SRCamera.cc:137
void applyTransform()
Definition: SRCamera.cc:93
void mouseDownEvent(const glm::ivec2 &pos, SRInterface::MouseButton btn)
Handle mouse down.
Definition: SRCamera.cc:111
virtual ~SRCamera()
Definition: SRCamera.cc:58