23 #ifndef QGLVIEWER_CAMERA_H
24 #define QGLVIEWER_CAMERA_H
26 #include "manipulatedCameraFrame.h"
27 #include "keyFrameInterpolator.h"
81 class QGLVIEWER_EXPORT
Camera :
public QObject
84 friend class ::QGLViewer;
102 enum Type { PERSPECTIVE, ORTHOGRAPHIC };
125 return frame()->inverseTransformOf(
Vec(0.0, 1.0, 0.0));
144 return frame()->inverseTransformOf(
Vec(1.0, 0.0, 0.0));
153 void setFromModelViewMatrix(
const GLdouble*
const modelViewMatrix);
154 void setFromProjectionMatrix(
const float matrix[12]);
160 void setOrientation(
float theta,
float phi);
161 void setUpVector(
const Vec& up,
bool noMove=
true);
162 void setViewDirection(
const Vec& direction);
169 void lookAt(
const Vec& target);
170 void showEntireScene();
171 void fitSphere(
const Vec& center,
float radius);
173 void fitScreenRegion(
const QRect& rectangle);
175 void interpolateToZoomOnPixel(
const QPoint& pixel);
176 void interpolateToFitScene();
177 void interpolateTo(
const Frame& fr,
float duration);
223 float aspectRatio()
const {
return static_cast<float>(screenWidth_)/static_cast<float>(screenHeight_); };
234 void getViewport(GLint viewport[4])
const;
235 float pixelGLRatio(
const Vec& position)
const;
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;
275 void setType(Type type);
280 void setFieldOfView(
float fov) { fieldOfView_ = fov; setFocusDistance(sceneRadius() / tan(fov/2.0)); };
289 void setFOVToFitScene();
303 void setAspectRatio(
float aspect) { setScreenWidthAndHeight(
int(100.0*aspect), 100); };
305 void setScreenWidthAndHeight(
int width,
int height);
339 float distanceToSceneCenter()
const;
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);
352 void setRevolveAroundPoint(
const Vec& rap);
353 bool setRevolveAroundPointFromPixel(
const QPoint& pixel);
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();
397 virtual void loadProjectionMatrix(
bool reset=
true)
const;
398 virtual void loadModelViewMatrix(
bool reset=
true)
const;
399 void computeProjectionMatrix()
const;
400 void computeModelViewMatrix()
const;
402 virtual void loadProjectionMatrixStereo(
bool leftBuffer=
true)
const;
403 virtual void loadModelViewMatrixStereo(
bool leftBuffer=
true)
const;
405 void getProjectionMatrix(GLdouble m[16])
const;
406 void getModelViewMatrix(GLdouble m[16])
const;
407 void getModelViewProjectionMatrix(GLdouble m[16])
const;
411 void getProjectionMatrix(GLfloat m[16])
const;
412 void getModelViewMatrix(GLfloat m[16])
const;
420 static void drawCamera(
float scale=1.0,
float aspectRatio=1.33,
float fieldOfView=M_PI/4.0);
422 virtual void draw(
bool drawFarPlane=
true,
float scale=1.0)
const;
441 void getCameraCoordinatesOf(
const float src[3],
float res[3])
const;
442 void getWorldCoordinatesOf(
const float src[3],
float res[3])
const;
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;
468 float flySpeed()
const {
return frame()->flySpeed(); };
546 virtual QDomElement domElement(
const QString& name, QDomDocument& document)
const;
548 virtual void initFromDOMElement(
const QDomElement& element);
557 int screenWidth_, screenHeight_;
562 float zClippingCoef_;
565 mutable GLdouble modelViewMatrix_[16];
566 mutable GLdouble projectionMatrix_[16];
570 float focusDistance_;
571 float physicalDistanceToScreen_;
572 float physicalScreenWidth_;
575 QMap<int, KeyFrameInterpolator*> kfi_;
581 #endif // QGLVIEWER_CAMERA_H