camera.h
Go to the documentation of this file.
1 /****************************************************************************
2 
3  Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
4 
5  This file is part of the QGLViewer library version 2.4.0.
6 
7  http://www.libqglviewer.com - contact@libqglviewer.com
8 
9  This file may be used under the terms of the GNU General Public License
10  versions 2.0 or 3.0 as published by the Free Software Foundation and
11  appearing in the LICENSE file included in the packaging of this file.
12  In addition, as a special exception, Gilles Debunne gives you certain
13  additional rights, described in the file GPL_EXCEPTION in this package.
14 
15  libQGLViewer uses dual licensing. Commercial/proprietary software must
16  purchase a libQGLViewer Commercial License.
17 
18  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
19  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 
21 *****************************************************************************/
22 
23 #ifndef QGLVIEWER_CAMERA_H
24 #define QGLVIEWER_CAMERA_H
25 
26 #include "manipulatedCameraFrame.h"
27 #include "keyFrameInterpolator.h"
28 
29 namespace qglviewer {
81  class QGLVIEWER_EXPORT Camera : public QObject
82  {
83 #ifndef DOXYGEN
84  friend class ::QGLViewer;
85 #endif
86 
87  Q_OBJECT
88 
89  public:
90  Camera();
91  virtual ~Camera();
92 
93  Camera(const Camera& camera);
94  Camera& operator=(const Camera& camera);
95 
96 
102  enum Type { PERSPECTIVE, ORTHOGRAPHIC };
103 
106  public:
114  Vec position() const { return frame()->position(); };
115 
123  Vec upVector() const
124  {
125  return frame()->inverseTransformOf(Vec(0.0, 1.0, 0.0));
126  }
134  Vec viewDirection() const { return frame()->inverseTransformOf(Vec(0.0, 0.0, -1.0)); };
135 
142  Vec rightVector() const
143  {
144  return frame()->inverseTransformOf(Vec(1.0, 0.0, 0.0));
145  }
146 
151  Quaternion orientation() const { return frame()->orientation(); };
152 
153  void setFromModelViewMatrix(const GLdouble* const modelViewMatrix);
154  void setFromProjectionMatrix(const float matrix[12]);
155 
156  public Q_SLOTS:
158  void setPosition(const Vec& pos) { frame()->setPosition(pos); };
159  void setOrientation(const Quaternion& q);
160  void setOrientation(float theta, float phi);
161  void setUpVector(const Vec& up, bool noMove=true);
162  void setViewDirection(const Vec& direction);
164 
165 
168  public Q_SLOTS:
169  void lookAt(const Vec& target);
170  void showEntireScene();
171  void fitSphere(const Vec& center, float radius);
172  void fitBoundingBox(const Vec& min, const Vec& max);
173  void fitScreenRegion(const QRect& rectangle);
174  void centerScene();
175  void interpolateToZoomOnPixel(const QPoint& pixel);
176  void interpolateToFitScene();
177  void interpolateTo(const Frame& fr, float duration);
179 
180 
183  public:
196  Type type() const { return type_; };
197 
208  float fieldOfView() const { return fieldOfView_; };
209 
217  float horizontalFieldOfView() const { return 2.0 * atan ( tan(fieldOfView()/2.0) * aspectRatio() ); };
218 
223  float aspectRatio() const { return static_cast<float>(screenWidth_)/static_cast<float>(screenHeight_); };
228  int screenWidth() const { return screenWidth_; };
233  int screenHeight() const { return screenHeight_; };
234  void getViewport(GLint viewport[4]) const;
235  float pixelGLRatio(const Vec& position) const;
236 
248  float zNearCoefficient() const { return zNearCoef_; };
267  float zClippingCoefficient() const { return zClippingCoef_; }
268 
269  virtual float zNear() const;
270  virtual float zFar() const;
271  virtual void getOrthoWidthHeight(GLdouble& halfWidth, GLdouble& halfHeight) const;
272  void getFrustumPlanesCoefficients(GLdouble coef[6][4]) const;
273 
274  public Q_SLOTS:
275  void setType(Type type);
276 
280  void setFieldOfView(float fov) { fieldOfView_ = fov; setFocusDistance(sceneRadius() / tan(fov/2.0)); };
281 
287  void setHorizontalFieldOfView(float hfov) { setFieldOfView( 2.0 * atan (tan(hfov / 2.0) / aspectRatio()) ); };
288 
289  void setFOVToFitScene();
290 
303  void setAspectRatio(float aspect) { setScreenWidthAndHeight(int(100.0*aspect), 100); };
304 
305  void setScreenWidthAndHeight(int width, int height);
307  void setZNearCoefficient(float coef) { zNearCoef_ = coef; };
309  void setZClippingCoefficient(float coef) { zClippingCoef_ = coef; }
311 
312 
315  public:
325  float sceneRadius() const { return sceneRadius_; };
326 
338  Vec sceneCenter() const { return sceneCenter_; };
339  float distanceToSceneCenter() const;
340 
341  public Q_SLOTS:
342  void setSceneRadius(float radius);
343  void setSceneCenter(const Vec& center);
344  bool setSceneCenterFromPixel(const QPoint& pixel);
345  void setSceneBoundingBox(const Vec& min, const Vec& max);
347 
348 
351  public Q_SLOTS:
352  void setRevolveAroundPoint(const Vec& rap);
353  bool setRevolveAroundPointFromPixel(const QPoint& pixel);
354 
355  public:
361  Vec revolveAroundPoint() const { return frame()->revolveAroundPoint(); };
363 
364 
367  public:
372  ManipulatedCameraFrame* frame() const { return frame_; };
373  public Q_SLOTS:
374  void setFrame(ManipulatedCameraFrame* const mcf);
376 
377 
380  public:
381  KeyFrameInterpolator* keyFrameInterpolator(int i) const;
382 
383 public Q_SLOTS:
384  void setKeyFrameInterpolator(int i, KeyFrameInterpolator* const kfi);
385 
386  virtual void addKeyFrameToPath(int i);
387  virtual void playPath(int i);
388  virtual void deletePath(int i);
389  virtual void resetPath(int i);
390  virtual void drawAllPaths();
392 
393 
396  public:
397  virtual void loadProjectionMatrix(bool reset=true) const;
398  virtual void loadModelViewMatrix(bool reset=true) const;
399  void computeProjectionMatrix() const;
400  void computeModelViewMatrix() const;
401 
402  virtual void loadProjectionMatrixStereo(bool leftBuffer=true) const;
403  virtual void loadModelViewMatrixStereo(bool leftBuffer=true) const;
404 
405  void getProjectionMatrix(GLdouble m[16]) const;
406  void getModelViewMatrix(GLdouble m[16]) const;
407  void getModelViewProjectionMatrix(GLdouble m[16]) const;
408 
409 #ifndef DOXYGEN
410  // Required for windows which otherwise silently fills
411  void getProjectionMatrix(GLfloat m[16]) const;
412  void getModelViewMatrix(GLfloat m[16]) const;
413 #endif
414 
415 
416 
419 #ifndef DOXYGEN
420  static void drawCamera(float scale=1.0, float aspectRatio=1.33, float fieldOfView=M_PI/4.0);
421 #endif
422  virtual void draw(bool drawFarPlane=true, float scale=1.0) const;
424 
425 
428  public:
435  Vec cameraCoordinatesOf(const Vec& src) const { return frame()->coordinatesOf(src); };
440  Vec worldCoordinatesOf(const Vec& src) const { return frame()->inverseCoordinatesOf(src); };
441  void getCameraCoordinatesOf(const float src[3], float res[3]) const;
442  void getWorldCoordinatesOf(const float src[3], float res[3]) const;
444 
445 
448  public:
449  Vec projectedCoordinatesOf(const Vec& src, const Frame* frame=NULL) const;
450  Vec unprojectedCoordinatesOf(const Vec& src, const Frame* frame=NULL) const;
451  void getProjectedCoordinatesOf(const float src[3], float res[3], const Frame* frame=NULL) const;
452  void getUnprojectedCoordinatesOf(const float src[3], float res[3], const Frame* frame=NULL) const;
453  void convertClickToLine(const QPoint& pixel, Vec& orig, Vec& dir) const;
454  Vec pointUnderPixel(const QPoint& pixel, bool& found) const;
456 
457 
460  public:
468  float flySpeed() const { return frame()->flySpeed(); };
469  public Q_SLOTS:
473  void setFlySpeed(float speed) { frame()->setFlySpeed(speed); };
475 
476 
479  public:
484  float IODistance() const { return IODistance_; };
485 
493  float physicalDistanceToScreen() const { return physicalScreenWidth() / 2.0f / tan(horizontalFieldOfView() / 2.0); };
494 
499  float physicalScreenWidth() const { return physicalScreenWidth_; };
500 
511  float focusDistance() const { return focusDistance_; };
512  public Q_SLOTS:
514  void setIODistance(float distance) { IODistance_ = distance; };
515 
516 #ifndef DOXYGEN
517 
518  void setPhysicalDistanceToScreen(float distance) { Q_UNUSED(distance); qWarning("setPhysicalDistanceToScreen is deprecated, use setPhysicalScreenWidth instead"); };
519 #endif
520 
522  void setPhysicalScreenWidth(float width) { physicalScreenWidth_ = width; };
523 
525  void setFocusDistance(float distance) { focusDistance_ = distance; };
527 
528 
531  public:
532  virtual QDomElement domElement(const QString& name, QDomDocument& document) const;
533  public Q_SLOTS:
534  virtual void initFromDOMElement(const QDomElement& element);
536 
537 
538  private:
539  // F r a m e
541 
542  // C a m e r a p a r a m e t e r s
543  int screenWidth_, screenHeight_; // size of the window, in pixels
544  float fieldOfView_; // in radians
546  float sceneRadius_; // OpenGL units
547  float zNearCoef_;
549  float orthoCoef_;
550  Type type_; // PERSPECTIVE or ORTHOGRAPHIC
551  mutable GLdouble modelViewMatrix_[16]; // Buffered model view matrix.
552  mutable GLdouble projectionMatrix_[16]; // Buffered projection matrix.
553 
554  // S t e r e o p a r a m e t e r s
555  float IODistance_; // inter-ocular distance, in meters
556  float focusDistance_; // in scene units
557  float physicalScreenWidth_; // in meters
558 
559  // P o i n t s o f V i e w s a n d K e y F r a m e s
560  QMap<int, KeyFrameInterpolator*> kfi_;
562  };
563 
564 } // namespace qglviewer
565 
566 #endif // QGLVIEWER_CAMERA_H
void setAspectRatio(float aspect)
Definition: camera.h:303
float sceneRadius_
Definition: camera.h:546
A keyFrame Catmull-Rom Frame interpolator.
float horizontalFieldOfView() const
Definition: camera.h:217
void setHorizontalFieldOfView(float hfov)
Definition: camera.h:287
The ManipulatedCameraFrame class represents a ManipulatedFrame with Camera specific mouse bindings...
float zClippingCoefficient() const
Definition: camera.h:267
float zClippingCoef_
Definition: camera.h:548
float focusDistance() const
Definition: camera.h:511
void setPhysicalScreenWidth(float width)
Definition: camera.h:522
float physicalDistanceToScreen() const
Definition: camera.h:493
float physicalScreenWidth_
Definition: camera.h:557
float zNearCoef_
Definition: camera.h:547
QMap< int, KeyFrameInterpolator * > kfi_
Definition: camera.h:560
static void drawCamera(float scale)
#define M_PI
void setZClippingCoefficient(float coef)
Definition: camera.h:309
int screenWidth() const
Definition: camera.h:228
#define Q_SLOTS
Definition: config.h:119
float IODistance() const
Definition: camera.h:484
#define QGLVIEWER_EXPORT
Definition: config.h:75
Type type() const
Definition: camera.h:196
ManipulatedCameraFrame * frame() const
Definition: camera.h:372
void setFocusDistance(float distance)
Definition: camera.h:525
The Vec class represents 3D positions and 3D vectors.
Definition: vec.h:69
float sceneRadius() const
Definition: camera.h:325
ManipulatedCameraFrame * frame_
Definition: camera.h:540
void setZNearCoefficient(float coef)
Definition: camera.h:307
float physicalScreenWidth() const
Definition: camera.h:499
float focusDistance_
Definition: camera.h:556
KeyFrameInterpolator * interpolationKfi_
Definition: camera.h:561
float fieldOfView_
Definition: camera.h:544
Vec revolveAroundPoint() const
Definition: camera.h:361
Vec upVector() const
Definition: camera.h:123
float zNearCoefficient() const
Definition: camera.h:248
int screenHeight() const
Definition: camera.h:233
Quaternion orientation() const
Definition: camera.h:151
A perspective or orthographic camera.
Definition: camera.h:81
The Quaternion class represents 3D rotations and orientations.
Definition: quaternion.h:66
void setPosition(const Vec &pos)
Definition: camera.h:158
float orthoCoef_
Definition: camera.h:549
Vec rightVector() const
Definition: camera.h:142
The Frame class represents a coordinate system, defined by a position and an orientation.
Definition: frame.h:126
float fieldOfView() const
Definition: camera.h:208
float IODistance_
Definition: camera.h:555
Vec worldCoordinatesOf(const Vec &src) const
Definition: camera.h:440
void setIODistance(float distance)
Definition: camera.h:514
float flySpeed() const
Definition: camera.h:468
void setFlySpeed(float speed)
Definition: camera.h:473
Vec cameraCoordinatesOf(const Vec &src) const
Definition: camera.h:435
float aspectRatio() const
Definition: camera.h:223
void setPhysicalDistanceToScreen(float distance)
Definition: camera.h:518
Vec viewDirection() const
Definition: camera.h:134
Vec position() const
Definition: camera.h:114
Vec sceneCenter() const
Definition: camera.h:338
void setFieldOfView(float fov)
Definition: camera.h:280


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Mon Jun 10 2019 14:00:24