AGX Dynamics  2.35.0.1
Camera.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 
47 namespace agxGL
48 {
50  {
51  public:
53 
54  static Camera *load(agx::TiXmlElement *eCamera, agx::Device *device);
55  virtual void configure(agx::TiXmlElement *eCamera) override;
56 
58 
59  public:
61  {
63  ORTHOGONAL
64  };
65 
66  Camera(const agx::Name& name = "camera");
67 
68  void setViewPort(unsigned width, unsigned height);
69 
70 
72  void setProjectionMatrix(const agx::Matrix4x4& matrix);
73 
75  void setProjectionMatrixAsOrtho(double left, double right,
76  double bottom, double top,
77  double zNear, double zFar);
78 
80  void setProjectionMatrixAsFrustum(double left, double right,
81  double bottom, double top,
82  double zNear, double zFar);
83 
84 
87  void setProjectionMatrixAsPerspective(double fovy, double aspectRatio,
88  double zNear, double zFar);
89 
91  inline const agx::Matrix4x4& getProjectionMatrix() const;
92 
95  bool getProjectionMatrixAsOrtho(double& left, double& right,
96  double& bottom, double& top,
97  double& zNear, double& zFar) const;
98 
101  bool getProjectionMatrixAsFrustum(double& left, double& right,
102  double& bottom, double& top,
103  double& zNear, double& zFar) const;
104 
110  bool getProjectionMatrixAsPerspective(double& fovy,double& aspectRatio,
111  double& zNear, double& zFar) const;
112 
113 
115  void setViewMatrix(const agx::Matrix4x4& matrix);
116 
118  inline const agx::Matrix4x4& getViewMatrix() const;
119 
121  void setViewMatrixAsLookAt(const agx::Vec3& eye,const agx::Vec3& center,const agx::Vec3& up);
122 
124  void getViewMatrixAsLookAt(agx::Vec3& eye,agx::Vec3& center,agx::Vec3& up,double lookDistance=1.0) const;
125 
126 
127  void alignUpVector(const agx::Vec3& up = agx::Vec3(0, 0, 1));
129 
130  // void setPosition(const agx::Vec3& position);
131  // void setUpVector(const agx::Vec3& upVector);
132  // void setFocusPoint(const agx::Vec3& focusPoint);
133  // void setLookAtVector(const agx::Vec3& lookAtVector);
134  //
135  // inline agx::Vec3 getPosition();
136  // inline agx::Vec3 getUpVector();
137  // inline agx::Vec3 getFocusPoint();
138  // inline agx::Vec3 getLookAtVector();
139  // inline Real getFov();
140 
141  void move(const agx::Vec3& offset);
142  void moveLocal(const agx::Vec3& offset);
143 
144 
145  void calculatePickRay(const agx::Vec2& mousePoint, agx::Vec3& pos, agx::Vec3& direction);
146 
147  static Camera *mainCamera();
148  static void setMainCamera(Camera *camera);
149 
150  void render();
151  protected:
152  class RenderTask;
153  virtual ~Camera();
156 
157 
158  // void cameraAdjustUpVector();
159 
160  protected:
161  // agx::FrameRef m_transform;
162  // Real m_lookDistance;
171 
172  // agxData::Val<agx::Matrix3x3> m_normalMatrix;
173 
176  // agx::Real m_fov;
177  // agx::AffineMatrix4x4 m_projectionMatrix;
178  // agx::AffineMatrix4x4 m_viewMatrix;
182  };
183 
185 
186 
187  inline const agx::Matrix4x4& Camera::getProjectionMatrix() const { return m_projectionMatrix->get(); }
188  inline const agx::Matrix4x4& Camera::getViewMatrix() const { return m_viewMatrix->get(); }
189 
190  // inline agx::Vec3 Camera::getPosition() { return m_transform->getPosition(); }
191  // inline agx::Vec3 Camera::getUpVector() { return m_up; }
192  // inline agx::Vec3 Camera::getFocusPoint() { return m_focus; }
193  // inline agx::Vec3 Camera::getLookAtVector() { return m_focus - m_transform->getPosition(); }
194  // inline Real Camera::getFov() { return m_fov; }
195 }
196 
197 
198 #endif /* _AGX_CAMERA_H_ */
199 
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGXPHYSICS_EXPORT
Templated value-reference.
Definition: Value.h:257
Abstract representation of a value.
Definition: Value.h:43
void alignUpVector(const agx::Vec3 &up=agx::Vec3(0, 0, 1))
void setViewMatrix(const agx::Matrix4x4 &matrix)
Set the view matrix.
agxData::ValueRefT< agx::Real > m_fovY
Definition: Camera.h:168
agx::Real m_ratio
Definition: Camera.h:174
agxData::ValueRefT< agx::UInt > m_windowWidth
Definition: Camera.h:169
static void setMainCamera(Camera *camera)
@ PERSPECTIVE
Definition: Camera.h:62
agxData::Value::Event::CallbackType m_transformCallback
Definition: Camera.h:179
void moveLocal(const agx::Vec3 &offset)
void setViewPort(unsigned width, unsigned height)
agxData::ValueRefT< agx::Matrix4x4 > m_projectionMatrix
Definition: Camera.h:165
agxData::ValueRefT< agx::UInt > m_windowHeight
Definition: Camera.h:170
void setProjectionMatrixAsFrustum(double left, double right, double bottom, double top, double zNear, double zFar)
Set to a perspective projection.
bool getProjectionMatrixAsPerspective(double &fovy, double &aspectRatio, double &zNear, double &zFar) const
Get the frustum setting of a symmetric perspective projection matrix.
bool getProjectionMatrixAsFrustum(double &left, double &right, double &bottom, double &top, double &zNear, double &zFar) const
Get the frustum setting of a perspective projection matrix.
virtual void configure(agx::TiXmlElement *eCamera) override
void transformCallback(agxData::Value *)
void move(const agx::Vec3 &offset)
Camera(const agx::Name &name="camera")
static Camera * load(agx::TiXmlElement *eCamera, agx::Device *device)
agx::ClockRef m_clock
Definition: Camera.h:175
void setViewMatrixAsLookAt(const agx::Vec3 &eye, const agx::Vec3 &center, const agx::Vec3 &up)
Set to the position and orientation of view matrix, using the same convention as gluLookAt.
bool getProjectionMatrixAsOrtho(double &left, double &right, double &bottom, double &top, double &zNear, double &zFar) const
Get the orthographic settings of the orthographic projection matrix.
void updateFov(agxData::Value *)
void getViewMatrixAsLookAt(agx::Vec3 &eye, agx::Vec3 &center, agx::Vec3 &up, double lookDistance=1.0) const
Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt.
static agx::Model * ClassModel()
void setProjectionMatrixAsPerspective(double fovy, double aspectRatio, double zNear, double zFar)
Create a symmetrical perspective projection, See OpenGL gluPerspective documentation for further deta...
virtual ~Camera()
void setProjectionMatrix(const agx::Matrix4x4 &matrix)
Set the projection matrix.
agx::Vec3 getForwardVector() const
agxData::Value::Event::CallbackType m_projectionCallback
Definition: Camera.h:180
agxData::ValueRefT< agx::AffineMatrix4x4 > m_transform
Definition: Camera.h:163
void setProjectionMatrixAsOrtho(double left, double right, double bottom, double top, double zNear, double zFar)
Set to an orthographic projection.
agxData::ValueRefT< agx::Matrix4x4 > m_viewMatrix
Definition: Camera.h:164
void calculatePickRay(const agx::Vec2 &mousePoint, agx::Vec3 &pos, agx::Vec3 &direction)
const agx::Matrix4x4 & getViewMatrix() const
Get the view matrix.
Definition: Camera.h:188
static Camera * getActiveCamera()
agx::TaskRef m_renderTask
Definition: Camera.h:181
agxData::ValueRefT< agx::Matrix4x4 > m_modelViewProjectionMatrix
Definition: Camera.h:166
const agx::Matrix4x4 & getProjectionMatrix() const
Get the projection matrix.
Definition: Camera.h:187
static Camera * mainCamera()
agxData::ValueRefT< agx::Real > m_fovX
Definition: Camera.h:167
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:39
An agx::Device is an abstract representation of a device on which data can be stored and processed.
Definition: Device.h:58
T CallbackType
Definition: Event.h:37
Matrix class for affine transformations.
Definition: Matrix4x4.h:56
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:41
Representation of a name string.
Definition: Name.h:33
This namespace contains OpenGL specific details for connecting OpenCL/OpenGL.
double Real
Definition: Real.h:42