Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

camera.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the QGLViewer library
00004  Copyright (C) 2002-2004  Gilles Debunne (Gilles.Debunne@imag.fr)
00005  Version 1.3.5 Release 8. Packaged on Monday December 22, 2003.
00006 
00007  http://www-imagis.imag.fr/Membres/Gilles.Debunne/CODE/QGLViewer
00008 
00009  libQGLViewer is free software; you can redistribute it and/or modify
00010  it under the terms of the GNU General Public License as published by
00011  the Free Software Foundation; either version 2 of the License, or
00012  (at your option) any later version.
00013 
00014  libQGLViewer is distributed in the hope that it will be useful,
00015  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  GNU General Public License for more details.
00018 
00019  You should have received a copy of the GNU General Public License
00020  along with libQGLViewer; if not, write to the Free Software
00021  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023 *****************************************************************************/
00024 
00025 #ifndef QGLVIEWER_CAMERA_H
00026 #define QGLVIEWER_CAMERA_H
00027 
00028 #include "manipulatedCameraFrame.h"
00029 #include "keyFrameInterpolator.h"
00030 
00031 namespace qglviewer {
00072   class QGLVIEWER_EXPORT Camera : public QObject
00073   {
00074 #ifndef DOXYGEN
00075     friend class ::QGLViewer;
00076 #endif 
00077 
00078     Q_OBJECT        // must include this if you use Qt signals/slots
00079       
00080   public:
00081     Camera();
00083     virtual ~Camera() {};
00084 
00087     enum Type { PERSPECTIVE, ORTHO };
00088 
00091   public:    
00095     Vec position() const { return frame()->position(); };
00099     Quaternion orientation() const { return frame()->orientation(); };
00100 
00101     void getPosition(float& x, float& y, float& z) const;
00102     void getOrientation(float& q0, float& q1, float& q2, float& q3) const;
00103 
00104      public slots:
00107     void setPosition(const Vec& pos) { frame()->setPosition(pos); };
00109     void setPosition(float x, float y, float z) { setPosition(Vec(x,y,z)); };
00110 
00111     void setOrientation(const Quaternion& q);
00113     void setOrientation(float q0, float q1, float q2, float q3) { setOrientation(Quaternion(q0,q1,q2,q3)); };
00114     void setOrientation(float theta, float phi);
00115 
00116     void setCameraFromProjectionMatrix(const float* const m);
00118 
00119     
00122   public slots:
00123     void showEntireScene();
00124 
00125     void fitBoundingBox(const Vec& m, const Vec& M);
00126 
00127     void fitSphere(const Vec& center, float radius);
00129     void fitSphere(float x, float y, float z, float r) { fitSphere(Vec(x,y,z), r); };
00130 
00131     void lookAt(const Vec& target);
00133     void lookAt(float x, float y, float z) { lookAt(Vec(x,y,z)); };
00134 
00135     void centerScene();
00136 
00137     void setUpVector(const Vec& up, bool noMove = true);
00138     void fitScreenRegion(int xa, int ya, int xb, int yb);
00139     
00140     void setFOVToFitScene();
00141   public: // Doxygen thinks it is too smart
00143     void setUpVector(float x, float y, float z, bool noMove = true) { setUpVector(Vec(x,y,z), noMove); };
00144     
00145   public slots:
00146     void interpolateToZoomOnPixel(int x, int y);
00147     void interpolateToFitScene();  
00149 
00150     
00153   public:
00155     float fieldOfView() const { return fieldOfView_; };
00156 
00163     float flySpeed() const { return frame()->flySpeed(); };
00164 
00167     Type type() const { return type_; };
00168       
00170     int mode() const { qWarning("Camera::mode() is obsolete since version 1.3.4, see changeLog"); return -1;};
00171 
00172   public slots:
00187     void setFieldOfView(float f) { fieldOfView_ = f; setDistanceToZeroParallaxPlane(sceneRadius() / tan(f/2.0)); };
00188 
00194     void setFlySpeed(float s) { frame()->setFlySpeed(s); };
00195     void setType(Type type);
00196 
00199     void setMode(int) { qWarning("Camera::setMode() is obsolete since version 1.3.4, see changeLog"); };
00202     void toggleMode() { qWarning("Camera::toggleMode() is obsolete since version 1.3.4, see changeLog"); };
00204 
00205     
00208   public:
00209     virtual float zNear() const;
00210     virtual float zFar()  const;
00214     float zNearCoef() const { return zNearCoef_; };
00215     void getOrthoWidthHeight(GLdouble& w, GLdouble& h) const;
00216 
00218     float aspectRatio() const { return static_cast<float>(screenWidth_)/static_cast<float>(screenHeight_); };
00220     int screenWidth() const { return screenWidth_; };
00222     int screenHeight() const { return screenHeight_; };
00223     float pixelGLRatio(const Vec& pos);
00224 
00225     float distanceToSceneCenter() const;
00226     
00227     Vec upVector() const;
00228     void getUpVector(float& x, float& y, float& z) const;
00229 
00231     Vec viewDirection() const { return frame()->inverseTransformOf(Vec(0.0, 0.0, -1.0)); };
00232     void getViewDirection(float& x, float& y, float& z) const;
00233     
00234     Vec pointUnderPixel(const int x, const int y, bool& found);
00235 
00238     bool isManipulated() const { return frame()->isManipulated(); };
00239 
00240     void getViewport(GLint viewport[4]) const;
00241     
00242   public slots:
00248     void setZNearCoef(float coef) { zNearCoef_ = coef; };
00250 
00251     
00254  public slots:
00255     void setRevolveAroundPoint(const Vec& rap);
00257     void setRevolveAroundPoint(float x, float y, float z) { setRevolveAroundPoint(Vec(x,y,z)); };
00258     bool setRevolveAroundPointFromPixel(int x, int y);
00259     
00260   public:    
00264     Vec revolveAroundPoint() const { return revolveAroundPoint_; };
00265     void getRevolveAroundPoint(float& x, float& y, float& z) const;
00267 
00268     
00275    public:
00279     int nbPaths() const { return nbPaths_; };
00280 
00281     KeyFrameInterpolator* keyFrameInterpolator(unsigned short i) const;
00282 
00283 public slots:
00284     void setKeyFrameInterpolator(unsigned short i, KeyFrameInterpolator* const kfi);
00285 
00286     virtual void addKeyFrame(unsigned short i);
00287     virtual void playKeyFramePath(unsigned short i);
00288     virtual void deleteKeyFramePath(unsigned short i);
00289     virtual void resetKeyFramePath(unsigned short i);
00290 
00291     virtual void drawAllPaths();
00293 
00294     
00297   public:
00299     ManipulatedCameraFrame* frame() const { return frame_; };
00300   public slots:
00318     void setFrame(ManipulatedCameraFrame* const f) { if (!f) return; frame_ = f; };
00320  
00321 
00324   public:
00325     virtual void loadProjectionMatrix(bool reset=true) const;
00326     virtual void loadProjectionMatrixStereo(bool leftBuffer=true) const;
00327     virtual void loadModelViewMatrix(bool reset=true) const;
00328     virtual void loadModelViewMatrixStereo(bool leftBuffer=true) const;
00329 
00330     virtual void getProjectionMatrix(GLdouble m[16]) const;
00331     virtual void getProjectionMatrix(GLfloat m[16]) const;
00332     virtual void getModelViewMatrix(GLdouble m[16]) const; 
00333     virtual void getModelViewMatrix(GLfloat m[16]) const;
00334     virtual void computeModelViewMatrix() const;
00336 
00337     
00342   public:
00343     void getCameraCoordinatesOf(const float src[3], float res[3]) const;
00346     Vec cameraCoordinatesOf(const Vec& src) const { return frame()->coordinatesOf(src); };
00347     void getWorldCoordinatesOf(const float src[3], float res[3]) const;
00350     Vec worldCoordinatesOf(const Vec& src) const { return frame()->inverseCoordinatesOf(src); };
00352 
00353     
00357   public:
00358     Vec projectedCoordinatesOf(const Vec& src) const;
00359     void getProjectedCoordinatesOf(const float src[3], float res[3]) const;
00360     Vec unprojectedCoordinatesOf(const Vec& src) const;
00361     void getUnprojectedCoordinatesOf(const float src[3], float res[3]) const;
00362     void convertClickToLine(int x, int y, float orig[3], float dir[3]) const;
00363     void convertClickToLine(int x, int y, Vec& orig, Vec& dir) const;
00365 
00366         
00369   public slots:
00374     void setHorizontalFieldOfView(float hfov) { setFieldOfView( 2.0 * atan (tan(hfov / 2.0) / aspectRatio()) ); };
00375     
00380     void setIODist(float iod) { IODist_ = iod; };
00381 
00386     void setDistanceToScreen(float dts) { distanceToScreen_ = dts; };
00387 
00396     void setDistanceToZeroParallaxPlane(float dtz) { distanceToZeroParallaxPlane_ = dtz; };
00397 
00402     void setPhysicalScreenWidth(float sw) { physicalScreenWidth_ = sw; };
00403   public:
00410     float horizontalFieldOfView() const { return 2.0 * atan ( tan(fieldOfView()/2.0) * aspectRatio() ); };
00411 
00413     float IODist() const { return IODist_; };
00414 
00417     float distanceToScreen() const { return distanceToScreen_; };
00418 
00421     float distanceToZeroParallaxPlane() const { return distanceToZeroParallaxPlane_; };
00422 
00425     float physicalScreenWidth() const { return physicalScreenWidth_; };
00427 
00428   public:
00431     virtual QDomElement domElement(const QString& name, QDomDocument& doc) const;
00432     virtual void initFromDOMElement(const QDomElement& de);
00434 
00435 
00438   public:  
00442     float sceneRadius() const { return sceneRadius_; };
00443 
00446     Vec sceneCenter() const { return sceneCenter_; };
00447 
00448     void setSceneRadius(float r);
00449     void setSceneBoundingBox(const Vec& m, const Vec& M);
00450     void setSceneCenter(const Vec& sc);
00451     void setSceneCenter(float x, float y, float z);
00452     bool setSceneCenterFromPixel(int x, int y);
00454 
00455 
00456     
00459   public:  
00463     bool cameraPathIsEdited() const { return cameraPathIsEdited_; };
00464 
00465   public slots :
00468     void editCameraPath(bool edit) { cameraPathIsEdited_ = edit; };
00469 
00476     void setWindowWidthAndHeight(int w, int h);
00478 
00479 
00480   private:
00481     // Copy constructor and opertor= are declared private and undefined
00482     // Prevents everyone from trying to use them
00483     Camera(const Camera& v);
00484     Camera& operator=(const Camera& v);
00485 
00486     // F r a m e
00487     ManipulatedCameraFrame* frame_;
00488     
00489     // C a m e r a   p a r a m e t e r s
00490     int screenWidth_, screenHeight_;  // size of the window, in pixels
00491     float fieldOfView_;
00492     float sceneRadius_;
00493     float zNearCoef_;
00494     float orthoCoef_;
00495     Vec sceneCenter_;
00496     Vec revolveAroundPoint_;
00497     Type type_; // PERSPECTIVE or ORTHO
00498     mutable GLdouble modelViewMatrix_[16]; // Buffered model view matrix.
00499 
00500     bool cameraPathIsEdited_; // camera path edition mode
00501     
00502     // S t e r e o   p a r a m e t e r s 
00503     float IODist_;          // inter-ocular distance
00504     float distanceToScreen_;        // in meters
00505     float distanceToZeroParallaxPlane_; // in scene units
00506     float physicalScreenWidth_;     // in meters
00507 
00508     // 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 
00509     enum { nbPaths_ = 12 };
00510     KeyFrameInterpolator* kfi_[nbPaths_];
00511     unsigned short lastActivatedKFNumber_; // Prevents two simultaneous path interpolations
00512   };
00513 
00514 
00516 // #define __WHERE__ "In file "<<__FILE__<<", line n°"<<__LINE__<< ", use "
00517 // #define orientationAxisAngle(x,y,z,a)    { std::cout << __WHERE__ << "getOrientationAxisAngle()." << std::endl; exit(0); }
00518 
00519 } // namespace qglviewer
00520 
00521 #endif // QGLVIEWER_CAMERA_H

Generated on Fri Feb 27 12:01:39 2004 for Glitch by doxygen 1.3.2