AGX Dynamics  2.37.3.2
Camera.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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:
52  static agx::Model *ClassModel();
53 
54  static Camera *load(agx::TiXmlElement *eCamera, agx::Device *device);
55  virtual void configure(agx::TiXmlElement *eCamera) override;
56 
57  static Camera *getActiveCamera();
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));
128  agx::Vec3 getForwardVector() const;
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();
154  void transformCallback(agxData::Value *);
155  void updateFov(agxData::Value *);
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 
agxData::Value::Event::CallbackType m_projectionCallback
Definition: Camera.h:180
agxData::ValueRefT< agx::Matrix4x4 > m_viewMatrix
Definition: Camera.h:164
agxData::ValueRefT< agx::Real > m_fovX
Definition: Camera.h:167
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:48
Matrix class for affine transformations.
Definition: EulerAngles.h:34
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Representation of a name string.
Definition: Name.h:32
Templated value-reference.
Definition: Value.h:262
agxData::ValueRefT< agx::Matrix4x4 > m_projectionMatrix
Definition: Camera.h:165
void get(QuatT< T > &q) const
agxData::ValueRefT< agx::Matrix4x4 > m_modelViewProjectionMatrix
Definition: Camera.h:166
agxData::Value::Event::CallbackType m_transformCallback
Definition: Camera.h:179
Templated callback with one argument.
Definition: Callback.h:100
agxData::ValueRefT< agx::AffineMatrix4x4 > m_transform
Definition: Camera.h:163
agx::ClockRef m_clock
Definition: Camera.h:175
const agx::Matrix4x4 & getViewMatrix() const
Get the view matrix.
Definition: Camera.h:188
const agx::Matrix4x4 & getProjectionMatrix() const
Get the projection matrix.
Definition: Camera.h:187
agxData::ValueRefT< agx::Real > m_fovY
Definition: Camera.h:168
agx::Real m_ratio
Definition: Camera.h:174
double Real
Definition: Real.h:42
agxData::ValueRefT< agx::UInt > m_windowWidth
Definition: Camera.h:169
This namespace contains OpenGL specific details for connecting OpenCL/OpenGL.
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:170
agx::TaskRef m_renderTask
Definition: Camera.h:181