camera.cpp
38 Camera::Camera()
39 : frame_(NULL), fieldOfView_(M_PI/4.0f), modelViewMatrixIsUpToDate_(false), projectionMatrixIsUpToDate_(false)
263 // make ORTHOGRAPHIC frustum fit PERSPECTIVE (at least in plane normal to viewDirection(), passing
597 float shift = halfWidth * IODistance() / physicalScreenWidth(); // * current window width / full screen width
760 qWarning("setRevolveAroundPointFromPixel() is deprecated, use setPivotPointFromPixel() instead");
824 return 2.0 * fabs((frame()->coordinatesOf(position)).z) * tan(fieldOfView()/2.0) / screenHeight();
891 interpolationKfi_->addKeyFrame(Frame(0.3f*frame()->position() + 0.7f*target, frame()->orientation()), 0.4f);
975 glReadPixels(pixel.x(), screenHeight()-1-pixel.y(), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
1088 const float distX = (pointX-newCenter).norm() / orthoCoef_ / ((aspectRatio() < 1.0) ? 1.0 : aspectRatio());
1089 const float distY = (pointY-newCenter).norm() / orthoCoef_ / ((aspectRatio() < 1.0) ? 1.0/aspectRatio() : 1.0);
1121 frame()->setPosition(pivotPoint() - (frame()->orientation()*q).rotate(frame()->coordinatesOf(pivotPoint())));
1254 Vec Camera::worldCoordinatesOf(const Vec& src) const { return frame()->inverseCoordinatesOf(src); }
1644 void Camera::getProjectedCoordinatesOf(const float src[3], float res[3], const Frame* frame) const
1652 void Camera::getUnprojectedCoordinatesOf(const float src[3], float res[3], const Frame* frame) const
1780 for (QMap<int, KeyFrameInterpolator*>::ConstIterator it = kfi_.begin(), end=kfi_.end(); it != end; ++it)
1838 for (QMap<int, KeyFrameInterpolator*>::ConstIterator it = kfi_.begin(), end=kfi_.end(); it != end; ++it)
1898 /* Although the scene does not change when a camera is loaded, restore the saved center and radius values.
1957 orig = Vec((2.0 * pixel.x() / screenWidth() - 1.0)*w, -(2.0 * pixel.y() / screenHeight() - 1.0)*h, 0.0);
virtual float zNear() const
Returns the near clipping plane distance used by the Camera projection matrix.
Definition: camera.cpp:211
virtual QDomElement domElement(const QString &name, QDomDocument &document) const
Returns an XML QDomElement that represents the Camera.
Definition: camera.cpp:1811
void fitScreenRegion(const QRect &rectangle)
Moves the Camera so that the rectangular screen region defined by rectangle (pixel units...
Definition: camera.cpp:1058
float distanceToSceneCenter() const
Returns the distance from the Camera center to sceneCenter(), projected along the Camera Z axis...
Definition: camera.cpp:303
KeyFrameInterpolator * keyFrameInterpolator(int i) const
Returns the KeyFrameInterpolator that defines the Camera path number i.
Definition: camera.cpp:1664
A keyFrame Catmull-Rom Frame interpolator.
Definition: keyFrameInterpolator.h:126
Vec projectedCoordinatesOf(const Vec &src, const Frame *frame=NULL) const
Returns the screen projected coordinates of a point src defined in the frame coordinate system...
Definition: camera.cpp:1584
void getCameraCoordinatesOf(const float src[3], float res[3]) const
Same as cameraCoordinatesOf(), but with float[3] parameters (src and res may be identical pointers)...
Definition: camera.cpp:1482
Definition: camera.h:29
The ManipulatedCameraFrame class represents a ManipulatedFrame with Camera specific mouse bindings...
Definition: manipulatedCameraFrame.h:47
void setFromProjectionMatrix(const float matrix[12])
Defines the Camera position(), orientation() and fieldOfView() from a projection matrix.
Definition: camera.cpp:1332
float pixelGLRatio(const Vec &position) const
Returns the ratio between pixel and OpenGL units at position.
Definition: camera.cpp:819
void getWorldCoordinatesOf(const float src[3], float res[3]) const
Same as worldCoordinatesOf(), but with float[3] parameters (src and res may be identical pointers)...
Definition: camera.cpp:1490
Vec pivotPoint() const
The point the Camera pivots around with the QGLViewer::ROTATE mouse binding.
Definition: camera.cpp:1275
Vec sceneCenter() const
Returns the position of the scene center, defined in the world coordinate system. ...
Definition: camera.h:297
void getModelViewProjectionMatrix(GLfloat m[16]) const
Overloaded getModelViewProjectionMatrix(GLdouble m[16]) method using a float array instead...
Definition: camera.cpp:693
float flySpeed() const
Returns the fly speed, expressed in OpenGL units.
Definition: manipulatedCameraFrame.h:156
void setSceneBoundingBox(const Vec &min, const Vec &max)
Similar to setSceneRadius() and setSceneCenter(), but the scene limits are defined by a (world axis a...
Definition: camera.cpp:723
Vec worldCoordinatesOf(const Vec &src) const
Returns the world coordinates of the point whose position src is defined in the Camera coordinate sys...
Definition: camera.cpp:1254
Vec pointUnderPixel(const QPoint &pixel, bool &found) const
Returns the coordinates of the 3D point located at pixel (x,y) on screen.
Definition: camera.cpp:971
Vec unprojectedCoordinatesOf(const Vec &src, const Frame *frame=NULL) const
Returns the world unprojected coordinates of a point src defined in the screen coordinate system...
Definition: camera.cpp:1631
void stopInterpolation()
Stops an interpolation started with startInterpolation().
Definition: keyFrameInterpolator.cpp:145
Quaternion orientation() const
Returns the Camera orientation, defined in the world coordinate system.
Definition: camera.cpp:1237
void setFrame(Frame *const frame)
Sets the frame() associated to the KeyFrameInterpolator.
Definition: keyFrameInterpolator.cpp:55
virtual void drawAllPaths()
Draws all the Camera paths defined by the keyFrameInterpolator().
Definition: camera.cpp:1778
void startInterpolation(int period=-1)
Starts the interpolation process.
Definition: keyFrameInterpolator.cpp:126
Vec pivotPoint() const
Returns the point the ManipulatedCameraFrame pivot point, around which the camera rotates...
Definition: manipulatedCameraFrame.h:75
void fitSphere(const Vec ¢er, float radius)
Moves the Camera so that the sphere defined by (center, radius) is visible and fits in the frustum...
Definition: camera.cpp:1020
void setOrientationWithConstraint(Quaternion &orientation)
Same as setOrientation(), but orientation is modified so that the potential constraint() of the Frame...
Definition: frame.cpp:631
float focusDistance() const
Returns the focus distance used by stereo display, expressed in OpenGL units.
Definition: camera.h:452
virtual void initFromDOMElement(const QDomElement &element)
Restores the Camera state from a QDomElement created by domElement().
Definition: camera.cpp:1869
Vec upVector() const
Returns the normalized up vector of the Camera, defined in the world coordinate system.
Definition: camera.cpp:1209
int screenWidth() const
Returns the width (in pixels) of the Camera screen.
Definition: camera.h:190
virtual void loadProjectionMatrixStereo(bool leftBuffer=true) const
Same as loadProjectionMatrix() but for a stereo setup.
Definition: camera.cpp:536
virtual void loadModelViewMatrix(bool reset=true) const
Loads the OpenGL GL_MODELVIEW matrix with the modelView matrix corresponding to the Camera...
Definition: camera.cpp:500
void setZClippingCoefficient(float coef)
Sets the zClippingCoefficient() value.
Definition: camera.h:268
Vec rightVector() const
Returns the normalized right vector of the Camera, defined in the world coordinate system...
Definition: camera.cpp:1228
void setKeyFrameInterpolator(int i, KeyFrameInterpolator *const kfi)
Sets the KeyFrameInterpolator that defines the Camera path of index i.
Definition: camera.cpp:1690
static void drawCamera(float scale=1.0, float aspectRatio=1.33, float fieldOfView=M_PI/4.0)
This method has been deprecated in libQGLViewer version 2.2.0.
Definition: camera.cpp:1967
FARSA_UTIL_TEMPLATE const T max(const T &t1, const U &t2)
bool setSceneCenterFromPixel(const QPoint &pixel)
setSceneCenter() to the result of pointUnderPixel(pixel).
Definition: camera.cpp:745
Vec viewDirection() const
Returns the normalized view direction of the Camera, defined in the world coordinate system...
Definition: camera.cpp:1220
ManipulatedCameraFrame * frame() const
Returns the ManipulatedCameraFrame attached to the Camera.
Definition: camera.h:334
void setFieldOfView(float fov)
Sets the vertical fieldOfView() of the Camera (in radians).
Definition: camera.cpp:245
void setFocusDistance(float distance)
Sets the focusDistance(), in OpenGL scene units.
Definition: camera.h:466
void getProjectionMatrix(GLfloat m[16]) const
Overloaded getProjectionMatrix(GLdouble m[16]) method using a float array instead.
Definition: camera.cpp:629
virtual void loadModelViewMatrixStereo(bool leftBuffer=true) const
Same as loadModelViewMatrix() but for a stereo setup.
Definition: camera.cpp:591
void interpolateTo(const Frame &fr, float duration)
Smoothly interpolates the Camera on a KeyFrameInterpolator path so that it goes to fr...
Definition: camera.cpp:942
int screenHeight() const
Returns the height (in pixels) of the Camera screen.
Definition: camera.h:195
Vec coordinatesOf(const Vec &src) const
Returns the Frame coordinates of a point src defined in the world coordinate system (converts from wo...
Definition: frame.cpp:702
float fieldOfView() const
Returns the vertical field of view of the Camera (in radians).
Definition: camera.h:170
void setOrientation(const Quaternion &q)
Sets the Camera orientation(), defined in the world coordinate system.
Definition: camera.cpp:1150
void resetInterpolation()
Stops the interpolation and resets interpolationTime() to the firstTime().
Definition: keyFrameInterpolator.cpp:156
void convertClickToLine(const QPoint &pixel, Vec &orig, Vec &dir) const
Gives the coefficients of a 3D half-line passing through the Camera eye and pixel (x...
Definition: camera.cpp:1940
void showEntireScene()
Moves the Camera so that the entire scene is visible.
Definition: camera.cpp:987
void rotate(Quaternion &q)
Same as rotate(const Quaternion&) but q may be modified to satisfy the rotation constraint().
Definition: frame.cpp:376
void addKeyFrame(const Frame &frame)
Appends a new keyFrame to the path.
Definition: keyFrameInterpolator.cpp:236
virtual void getOrthoWidthHeight(GLdouble &halfWidth, GLdouble &halfHeight) const
Returns the halfWidth and halfHeight of the Camera orthographic frustum.
Definition: camera.cpp:324
Vec cameraCoordinatesOf(const Vec &src) const
Returns the Camera frame coordinates of a point src defined in world coordinates. ...
Definition: camera.cpp:1248
void setFromRotatedBasis(const Vec &X, const Vec &Y, const Vec &Z)
Sets the Quaternion from the three rotated vectors of an orthogonal basis.
Definition: quaternion.cpp:182
void setScreenWidthAndHeight(int width, int height)
Sets Camera screenWidth() and screenHeight() (expressed in pixels).
Definition: camera.cpp:166
void getProjectedCoordinatesOf(const float src[3], float res[3], const Frame *frame=NULL) const
Same as projectedCoordinatesOf(), but with float parameters (src and res can be identical pointers)...
Definition: camera.cpp:1644
Quaternion orientation() const
Returns the orientation of the Frame, defined in the world coordinate system.
Definition: frame.cpp:546
void setFlySpeed(float speed)
Sets the flySpeed(), defined in OpenGL units.
Definition: manipulatedCameraFrame.h:139
float aspectRatio() const
Returns the Camera aspect ratio defined by screenWidth() / screenHeight().
Definition: camera.h:185
void setPositionWithConstraint(Vec &position)
Same as setPosition(), but position is modified so that the potential constraint() of the Frame is sa...
Definition: frame.cpp:621
virtual void addKeyFrameToPath(int i)
Adds the current Camera position() and orientation() as a keyFrame to the path number i...
Definition: camera.cpp:1710
bool interpolationIsStarted() const
Returns true when the interpolation is being performed.
Definition: keyFrameInterpolator.h:266
bool setPivotPointFromPixel(const QPoint &pixel)
The pivotPoint() is set to the point located under pixel on screen.
Definition: camera.cpp:796
virtual void loadProjectionMatrix(bool reset=true) const
Loads the OpenGL GL_PROJECTION matrix with the Camera projection matrix.
Definition: camera.cpp:463
virtual float zFar() const
Returns the far clipping plane distance used by the Camera projection matrix.
Definition: camera.cpp:236
void setPhysicalScreenWidth(float width)
Sets the physical screen (monitor or projected wall) width (in meters).
Definition: camera.h:463
void interpolateToFitScene()
Interpolates the Camera on a one second KeyFrameInterpolator path so that the entire scene fits the s...
Definition: camera.cpp:913
void projectOnLine(const Vec &origin, const Vec &direction)
Translates the Frame so that its position() lies on the line defined by origin and direction (defined...
Definition: frame.cpp:1133
void getFrustumPlanesCoefficients(GLdouble coef[6][4]) const
Returns the 6 plane equations of the Camera frustum.
Definition: camera.cpp:2121
float zClippingCoefficient() const
Returns the coefficient used to position the near and far clipping planes.
Definition: camera.h:229
virtual void deletePath(int i)
Deletes the keyFrameInterpolator() of index i.
Definition: camera.cpp:1762
void computeProjectionMatrix() const
Computes the projection matrix associated with the Camera.
Definition: camera.cpp:350
virtual void initFromDOMElement(const QDomElement &element)
Restores the KeyFrameInterpolator state from a QDomElement created by domElement().
Definition: keyFrameInterpolator.cpp:647
The Quaternion class represents 3D rotations and orientations.
Definition: quaternion.h:66
virtual void draw(bool drawFarPlane=true, float scale=1.0) const
Draws a representation of the Camera in the 3D world.
Definition: camera.cpp:1993
float physicalScreenWidth() const
Returns the physical screen width, in meters.
Definition: camera.h:440
void setReferenceFrame(const Frame *const refFrame)
Sets the referenceFrame() of the Frame.
Definition: frame.cpp:665
void setPivotPoint(const Vec &point)
Changes the pivotPoint() to point (defined in the world coordinate system).
Definition: camera.cpp:770
void setPosition(const Vec &position)
Sets the position() of the Frame, defined in the world coordinate system.
Definition: frame.cpp:443
void centerScene()
Moves the Camera so that its sceneCenter() is projected on the center of the window.
Definition: camera.cpp:997
void fitBoundingBox(const Vec &min, const Vec &max)
Moves the Camera so that the (world axis aligned) bounding box (min, max) is entirely visible...
Definition: camera.cpp:1044
virtual void playPath(int i)
Makes the Camera follow the path of keyFrameInterpolator() number i.
Definition: camera.cpp:1726
void setViewDirection(const Vec &direction)
Rotates the Camera so that its viewDirection() is direction (defined in the world coordinate system)...
Definition: camera.cpp:1161
void lookAt(const Vec &target)
Sets the Camera orientation(), so that it looks at point target (defined in the world coordinate syst...
Definition: camera.cpp:1008
void setFromModelViewMatrix(const GLdouble *const modelViewMatrix)
Sets the Camera's position() and orientation() from an OpenGL ModelView matrix.
Definition: camera.cpp:1294
void setUpVector(const Vec &up, bool noMove=true)
Rotates the Camera so that its upVector() becomes up (defined in the world coordinate system)...
Definition: camera.cpp:1116
void setPosition(const Vec &pos)
Sets the Camera position() (the eye), defined in the world coordinate system.
Definition: camera.cpp:1240
float IODistance() const
Returns the user's inter-ocular distance (in meters).
Definition: camera.h:425
void getModelViewMatrix(GLfloat m[16]) const
Overloaded getModelViewMatrix(GLdouble m[16]) method using a float array instead. ...
Definition: camera.cpp:662
void getViewport(GLint viewport[4]) const
Fills viewport with the Camera OpenGL viewport.
Definition: camera.cpp:1502
void setFOVToFitScene()
Changes the Camera fieldOfView() so that the entire scene (defined by QGLViewer::sceneCenter() and QG...
Definition: camera.cpp:861
FARSA_UTIL_TEMPLATE const T min(const T &t1, const U &t2)
The Frame class represents a coordinate system, defined by a position and an orientation.
Definition: frame.h:121
Vec position() const
Returns the Camera position (the eye), defined in the world coordinate system.
Definition: camera.cpp:1200
void setPivotPoint(const Vec &point)
Sets the pivotPoint(), defined in the world coordinate system.
Definition: manipulatedCameraFrame.h:77
Vec rotate(const Vec &v) const
Returns the image of v by the Quaternion rotation.
Definition: quaternion.cpp:76
void setOrientation(const Quaternion &orientation)
Sets the orientation() of the Frame, defined in the world coordinate system.
Definition: frame.cpp:505
Vec inverseCoordinatesOf(const Vec &src) const
Returns the world coordinates of the point whose position in the Frame coordinate system is src (conv...
Definition: frame.cpp:715
Vec position() const
Returns the position of the Frame, defined in the world coordinate system.
Definition: frame.cpp:537
float sceneRadius() const
Returns the radius of the scene observed by the Camera.
Definition: camera.h:284
float horizontalFieldOfView() const
Returns the horizontal field of view of the Camera (in radians).
Definition: camera.h:179
void interpolateToZoomOnPixel(const QPoint &pixel)
Makes the Camera smoothly zoom on the pointUnderPixel() pixel.
Definition: camera.cpp:875
Vec inverseTransformOf(const Vec &src) const
Returns the world transform of the vector whose coordinates in the Frame coordinate system is src (co...
Definition: frame.cpp:856
virtual void resetPath(int i)
Resets the path of the keyFrameInterpolator() number i.
Definition: camera.cpp:1741
void computeModelViewMatrix() const
Computes the modelView matrix associated with the Camera's position() and orientation().
Definition: camera.cpp:400
virtual void initFromDOMElement(const QDomElement &element)
Restores the ManipulatedCameraFrame state from a QDomElement created by domElement().
Definition: manipulatedCameraFrame.cpp:158
float zNearCoefficient() const
Returns the coefficient which is used to set zNear() when the Camera is inside the sphere defined by ...
Definition: camera.h:210
void getUnprojectedCoordinatesOf(const float src[3], float res[3], const Frame *frame=NULL) const
Same as unprojectedCoordinatesOf(), but with float parameters (src and res can be identical pointers)...
Definition: camera.cpp:1652