AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Camera.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
18  *
19  * This library is open source and may be redistributed and/or modified under
20  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
21  * (at your option) any later version. The full license is in LICENSE file
22  * included with this distribution, and on the openscenegraph.org website.
23  *
24  * This library is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * OpenSceneGraph Public License for more details.
28 */
29 
30 
31 
32 
33 //\todo We must check if we can use OSG camera code, otherwise we must rewrite...
34 
35 
36 
37 #ifndef AGXGL_CAMERA_H
38 #define AGXGL_CAMERA_H
39 
40 #include <agx/agxPhysics_export.h>
41 #include <agx/Object.h>
42 #include <agx/Vec3.h>
43 #include <agx/Clock.h>
44 #include <agx/Matrix4x4.h>
45 #include <agx/AffineMatrix4x4.h>
46 
48 namespace agxGL
49 {
51  {
52  public:
53  static agx::Model *ClassModel();
54 
55  static Camera *load(agx::TiXmlElement *eCamera, agx::Device *device);
56  virtual void configure(agx::TiXmlElement *eCamera) override;
57 
58  static Camera *getActiveCamera();
59 
60  public:
62  {
64  ORTHOGONAL
65  };
66 
67  Camera(const agx::Name& name = "camera");
68 
69  void setViewPort(unsigned width, unsigned height);
70 
71 
73  void setProjectionMatrix(const agx::Matrix4x4& matrix);
74 
76  void setProjectionMatrixAsOrtho(double left, double right,
77  double bottom, double top,
78  double zNear, double zFar);
79 
81  void setProjectionMatrixAsFrustum(double left, double right,
82  double bottom, double top,
83  double zNear, double zFar);
84 
85 
88  void setProjectionMatrixAsPerspective(double fovy, double aspectRatio,
89  double zNear, double zFar);
90 
92  inline const agx::Matrix4x4& getProjectionMatrix() const;
93 
96  bool getProjectionMatrixAsOrtho(double& left, double& right,
97  double& bottom, double& top,
98  double& zNear, double& zFar) const;
99 
102  bool getProjectionMatrixAsFrustum(double& left, double& right,
103  double& bottom, double& top,
104  double& zNear, double& zFar) const;
105 
111  bool getProjectionMatrixAsPerspective(double& fovy,double& aspectRatio,
112  double& zNear, double& zFar) const;
113 
114 
116  void setViewMatrix(const agx::Matrix4x4& matrix);
117 
119  inline const agx::Matrix4x4& getViewMatrix() const;
120 
122  void setViewMatrixAsLookAt(const agx::Vec3& eye,const agx::Vec3& center,const agx::Vec3& up);
123 
125  void getViewMatrixAsLookAt(agx::Vec3& eye,agx::Vec3& center,agx::Vec3& up,double lookDistance=1.0) const;
126 
127 
128  void alignUpVector(const agx::Vec3& up = agx::Vec3(0, 0, 1));
129  agx::Vec3 getForwardVector() const;
130 
131  // void setPosition(const agx::Vec3& position);
132  // void setUpVector(const agx::Vec3& upVector);
133  // void setFocusPoint(const agx::Vec3& focusPoint);
134  // void setLookAtVector(const agx::Vec3& lookAtVector);
135  //
136  // inline agx::Vec3 getPosition();
137  // inline agx::Vec3 getUpVector();
138  // inline agx::Vec3 getFocusPoint();
139  // inline agx::Vec3 getLookAtVector();
140  // inline Real getFov();
141 
142  void move(const agx::Vec3& offset);
143  void moveLocal(const agx::Vec3& offset);
144 
145 
146  void calculatePickRay(const agx::Vec2& mousePoint, agx::Vec3& pos, agx::Vec3& direction);
147 
148  static Camera *mainCamera();
149  static void setMainCamera(Camera *camera);
150 
151  void render();
152  protected:
153  class RenderTask;
154  virtual ~Camera();
155  void transformCallback(agxData::Value *);
156  void updateFov(agxData::Value *);
157 
158 
159  // void cameraAdjustUpVector();
160 
161  protected:
162  // agx::FrameRef m_transform;
163  // Real m_lookDistance;
172 
173  // agxData::Val<agx::Matrix3x3> m_normalMatrix;
174 
177  // agx::Real m_fov;
178  // agx::AffineMatrix4x4 m_projectionMatrix;
179  // agx::AffineMatrix4x4 m_viewMatrix;
183  };
184 
186 
187 
189  inline const agx::Matrix4x4& Camera::getViewMatrix() const { return m_viewMatrix->get(); }
190 
191  // inline agx::Vec3 Camera::getPosition() { return m_transform->getPosition(); }
192  // inline agx::Vec3 Camera::getUpVector() { return m_up; }
193  // inline agx::Vec3 Camera::getFocusPoint() { return m_focus; }
194  // inline agx::Vec3 Camera::getLookAtVector() { return m_focus - m_transform->getPosition(); }
195  // inline Real Camera::getFov() { return m_fov; }
196 }
197 
198 
199 #endif /* _AGX_CAMERA_H_ */
200 
agxData::Value::Event::CallbackType m_projectionCallback
Definition: Camera.h:181
agxData::ValueRefT< agx::Matrix4x4 > m_viewMatrix
Definition: Camera.h:165
agxData::ValueRefT< agx::Real > m_fovX
Definition: Camera.h:168
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:38
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:40
Abstract representation of a value.
Definition: Value.h:42
Matrix class for affine transformations.
Definition: EulerAngles.h:36
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
Representation of a name string.
Definition: Name.h:32
agxData::ValueRefT< agx::Matrix4x4 > m_projectionMatrix
Definition: Camera.h:166
agxData::ValueRefT< agx::Matrix4x4 > m_modelViewProjectionMatrix
Definition: Camera.h:167
agxData::Value::Event::CallbackType m_transformCallback
Definition: Camera.h:180
Templated callback with one argument.
Definition: Callback.h:100
agxData::ValueRefT< agx::AffineMatrix4x4 > m_transform
Definition: Camera.h:164
agx::ClockRef m_clock
Definition: Camera.h:176
T * get() const
Definition: ref_ptr.h:256
agxData::ValueRefT< agx::Real > m_fovY
Definition: Camera.h:169
const agx::Matrix4x4 & getViewMatrix() const
Get the view matrix.
Definition: Camera.h:189
agx::Real m_ratio
Definition: Camera.h:175
double Real
Definition: Real.h:42
agxData::ValueRefT< agx::UInt > m_windowWidth
Definition: Camera.h:170
An agx::Device is an abstract representation of a device on which data can be stored and processed...
Definition: Device.h:57
agxData::ValueRefT< agx::UInt > m_windowHeight
Definition: Camera.h:171
const agx::Matrix4x4 & getProjectionMatrix() const
Get the projection matrix.
Definition: Camera.h:188
agx::TaskRef m_renderTask
Definition: Camera.h:182