camera.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
00004 
00005  This file is part of the QGLViewer library version 2.4.0.
00006 
00007  http://www.libqglviewer.com - contact@libqglviewer.com
00008 
00009  This file may be used under the terms of the GNU General Public License 
00010  versions 2.0 or 3.0 as published by the Free Software Foundation and
00011  appearing in the LICENSE file included in the packaging of this file.
00012  In addition, as a special exception, Gilles Debunne gives you certain 
00013  additional rights, described in the file GPL_EXCEPTION in this package.
00014 
00015  libQGLViewer uses dual licensing. Commercial/proprietary software must
00016  purchase a libQGLViewer Commercial License.
00017 
00018  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00019  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00020 
00021 *****************************************************************************/
00022 
00023 #ifndef QGLVIEWER_CAMERA_H
00024 #define QGLVIEWER_CAMERA_H
00025 
00026 #include "manipulatedCameraFrame.h"
00027 #include "keyFrameInterpolator.h"
00028 
00029 namespace qglviewer {
00081   class QGLVIEWER_EXPORT Camera : public QObject
00082   {
00083 #ifndef DOXYGEN
00084     friend class ::QGLViewer;
00085 #endif
00086 
00087     Q_OBJECT
00088 
00089   public:
00090     Camera();
00091     virtual ~Camera();
00092 
00093     Camera(const Camera& camera);
00094     Camera& operator=(const Camera& camera);
00095 
00096 
00102     enum Type { PERSPECTIVE, ORTHOGRAPHIC };
00103 
00106   public:
00114     Vec position() const { return frame()->position(); };
00115 
00123     Vec upVector() const
00124     {
00125       return frame()->inverseTransformOf(Vec(0.0, 1.0, 0.0));
00126     }
00134     Vec viewDirection() const { return frame()->inverseTransformOf(Vec(0.0, 0.0, -1.0)); };
00135 
00142     Vec rightVector() const
00143     {
00144       return frame()->inverseTransformOf(Vec(1.0, 0.0, 0.0));
00145     }
00146 
00151     Quaternion orientation() const { return frame()->orientation(); };
00152 
00153     void setFromModelViewMatrix(const GLdouble* const modelViewMatrix);
00154     void setFromProjectionMatrix(const float matrix[12]);
00155 
00156   public Q_SLOTS:
00158     void setPosition(const Vec& pos) { frame()->setPosition(pos); };
00159     void setOrientation(const Quaternion& q);
00160     void setOrientation(float theta, float phi);
00161     void setUpVector(const Vec& up, bool noMove=true);
00162     void setViewDirection(const Vec& direction);
00164 
00165 
00168   public Q_SLOTS:
00169     void lookAt(const Vec& target);
00170     void showEntireScene();
00171     void fitSphere(const Vec& center, float radius);
00172     void fitBoundingBox(const Vec& min, const Vec& max);
00173     void fitScreenRegion(const QRect& rectangle);
00174     void centerScene();
00175     void interpolateToZoomOnPixel(const QPoint& pixel);
00176     void interpolateToFitScene();
00177     void interpolateTo(const Frame& fr, float duration);
00179 
00180 
00183   public:
00196     Type type() const { return type_; };
00197 
00208     float fieldOfView() const { return fieldOfView_; };
00209 
00217     float horizontalFieldOfView() const { return 2.0 * atan ( tan(fieldOfView()/2.0) * aspectRatio() ); };
00218 
00223     float aspectRatio() const { return static_cast<float>(screenWidth_)/static_cast<float>(screenHeight_); };
00228     int screenWidth() const { return screenWidth_; };
00233     int screenHeight() const { return screenHeight_; };
00234     void getViewport(GLint viewport[4]) const;
00235     float pixelGLRatio(const Vec& position) const;
00236 
00248     float zNearCoefficient() const { return zNearCoef_; };
00267     float zClippingCoefficient() const { return zClippingCoef_; }
00268 
00269     virtual float zNear() const;
00270     virtual float zFar()  const;
00271     virtual void getOrthoWidthHeight(GLdouble& halfWidth, GLdouble& halfHeight) const;
00272     void getFrustumPlanesCoefficients(GLdouble coef[6][4]) const;
00273 
00274   public Q_SLOTS:
00275     void setType(Type type);
00276 
00280     void setFieldOfView(float fov) { fieldOfView_ = fov; setFocusDistance(sceneRadius() / tan(fov/2.0)); };
00281 
00287     void setHorizontalFieldOfView(float hfov) { setFieldOfView( 2.0 * atan (tan(hfov / 2.0) / aspectRatio()) ); };
00288 
00289     void setFOVToFitScene();
00290 
00303     void setAspectRatio(float aspect) { setScreenWidthAndHeight(int(100.0*aspect), 100); };
00304 
00305     void setScreenWidthAndHeight(int width, int height);
00307     void setZNearCoefficient(float coef) { zNearCoef_ = coef; };
00309     void setZClippingCoefficient(float coef) { zClippingCoef_ = coef; }
00311 
00312 
00315   public:
00325     float sceneRadius() const { return sceneRadius_; };
00326 
00338     Vec sceneCenter() const { return sceneCenter_; };
00339     float distanceToSceneCenter() const;
00340 
00341   public Q_SLOTS:
00342     void setSceneRadius(float radius);
00343     void setSceneCenter(const Vec& center);
00344     bool setSceneCenterFromPixel(const QPoint& pixel);
00345     void setSceneBoundingBox(const Vec& min, const Vec& max);
00347 
00348 
00351  public Q_SLOTS:
00352     void setRevolveAroundPoint(const Vec& rap);
00353     bool setRevolveAroundPointFromPixel(const QPoint& pixel);
00354 
00355   public:
00361     Vec revolveAroundPoint() const { return frame()->revolveAroundPoint(); };
00363 
00364 
00367   public:
00372     ManipulatedCameraFrame* frame() const { return frame_; };
00373   public Q_SLOTS:
00374     void setFrame(ManipulatedCameraFrame* const mcf);
00376 
00377 
00380    public:
00381     KeyFrameInterpolator* keyFrameInterpolator(int i) const;
00382 
00383 public Q_SLOTS:
00384     void setKeyFrameInterpolator(int i, KeyFrameInterpolator* const kfi);
00385 
00386     virtual void addKeyFrameToPath(int i);
00387     virtual void playPath(int i);
00388     virtual void deletePath(int i);
00389     virtual void resetPath(int i);
00390     virtual void drawAllPaths();
00392 
00393 
00396   public:
00397     virtual void loadProjectionMatrix(bool reset=true) const;
00398     virtual void loadModelViewMatrix(bool reset=true) const;
00399     void computeProjectionMatrix() const;
00400     void computeModelViewMatrix() const;
00401 
00402     virtual void loadProjectionMatrixStereo(bool leftBuffer=true) const;
00403     virtual void loadModelViewMatrixStereo(bool leftBuffer=true) const;
00404 
00405     void getProjectionMatrix(GLdouble m[16]) const;
00406     void getModelViewMatrix(GLdouble m[16]) const;
00407         void getModelViewProjectionMatrix(GLdouble m[16]) const;
00408 
00409 #ifndef DOXYGEN
00410     // Required for windows which otherwise silently fills
00411     void getProjectionMatrix(GLfloat m[16]) const;
00412     void getModelViewMatrix(GLfloat m[16]) const;
00413 #endif
00414 
00415 
00416     
00419 #ifndef DOXYGEN
00420     static void drawCamera(float scale=1.0, float aspectRatio=1.33, float fieldOfView=M_PI/4.0);
00421 #endif
00422     virtual void draw(bool drawFarPlane=true, float scale=1.0) const;
00424 
00425     
00428   public:
00435     Vec cameraCoordinatesOf(const Vec& src) const { return frame()->coordinatesOf(src); };
00440     Vec worldCoordinatesOf(const Vec& src) const { return frame()->inverseCoordinatesOf(src); };
00441     void getCameraCoordinatesOf(const float src[3], float res[3]) const;
00442     void getWorldCoordinatesOf(const float src[3], float res[3]) const;
00444 
00445 
00448   public:
00449     Vec projectedCoordinatesOf(const Vec& src, const Frame* frame=NULL) const;
00450     Vec unprojectedCoordinatesOf(const Vec& src, const Frame* frame=NULL) const;
00451     void getProjectedCoordinatesOf(const float src[3], float res[3], const Frame* frame=NULL) const;
00452     void getUnprojectedCoordinatesOf(const float src[3], float res[3], const Frame* frame=NULL) const;
00453     void convertClickToLine(const QPoint& pixel, Vec& orig, Vec& dir) const;
00454     Vec pointUnderPixel(const QPoint& pixel, bool& found) const;
00456 
00457 
00460   public:
00468     float flySpeed() const { return frame()->flySpeed(); };
00469   public Q_SLOTS:
00473     void setFlySpeed(float speed) { frame()->setFlySpeed(speed); };
00475 
00476 
00479   public:
00484     float IODistance() const { return IODistance_; };
00485 
00493     float physicalDistanceToScreen() const { return physicalScreenWidth() / 2.0f / tan(horizontalFieldOfView() / 2.0); };
00494 
00499     float physicalScreenWidth() const { return physicalScreenWidth_; };
00500 
00511     float focusDistance() const { return focusDistance_; };
00512   public Q_SLOTS:
00514     void setIODistance(float distance) { IODistance_ = distance; };
00515 
00516 #ifndef DOXYGEN
00517 
00518         void setPhysicalDistanceToScreen(float distance) { Q_UNUSED(distance); qWarning("setPhysicalDistanceToScreen is deprecated, use setPhysicalScreenWidth instead"); };
00519 #endif
00520 
00522     void setPhysicalScreenWidth(float width) { physicalScreenWidth_ = width; };
00523 
00525     void setFocusDistance(float distance) { focusDistance_ = distance; };
00527 
00528 
00531   public:
00532     virtual QDomElement domElement(const QString& name, QDomDocument& document) const;
00533   public Q_SLOTS:
00534     virtual void initFromDOMElement(const QDomElement& element);
00536 
00537 
00538   private:
00539     // F r a m e
00540     ManipulatedCameraFrame* frame_;
00541 
00542     // C a m e r a   p a r a m e t e r s
00543     int screenWidth_, screenHeight_;  // size of the window, in pixels
00544     float fieldOfView_; // in radians
00545     Vec sceneCenter_;
00546     float sceneRadius_; // OpenGL units
00547     float zNearCoef_;
00548     float zClippingCoef_;
00549     float orthoCoef_;
00550     Type type_; // PERSPECTIVE or ORTHOGRAPHIC
00551     mutable GLdouble modelViewMatrix_[16]; // Buffered model view matrix.
00552     mutable GLdouble projectionMatrix_[16]; // Buffered projection matrix.
00553 
00554     // S t e r e o   p a r a m e t e r s
00555     float IODistance_;               // inter-ocular distance, in meters
00556     float focusDistance_;            // in scene units
00557     float physicalScreenWidth_;      // in meters
00558 
00559     // 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
00560     QMap<int, KeyFrameInterpolator*> kfi_;
00561     KeyFrameInterpolator* interpolationKfi_;
00562   };
00563 
00564 } // namespace qglviewer
00565 
00566 #endif // QGLVIEWER_CAMERA_H


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Thu Feb 11 2016 23:51:19