• Skip to content
  • Skip to link menu
KDE 4.5 API Reference
  • KDE API Reference
  • kdeedu
  • Sitemap
  • Contact Us
 

kalzium

Avogadro::Camera

Avogadro::Camera Class Reference

Representation of the camera looking at the molecule. More...

#include <avogadro/camera.h>

List of all members.

Public Member Functions

 Camera (const Camera *camera)
 Camera (const GLWidget *parent=0, double angleOfViewY=40.0)
virtual ~Camera ()
double angleOfViewY () const
void applyModelview () const
void applyPerspective () const
Eigen::Vector3d backTransformedXAxis () const
Eigen::Vector3d backTransformedYAxis () const
Eigen::Vector3d backTransformedZAxis () const
double distance (const Eigen::Vector3d &point) const
void initializeViewPoint ()
Eigen::Transform3d & modelview ()
const Eigen::Transform3d & modelview () const
void normalize ()
const GLWidget * parent () const
void prerotate (const double &angle, const Eigen::Vector3d &axis)
void pretranslate (const Eigen::Vector3d &vector)
Eigen::Vector3d project (const Eigen::Vector3d &v) const
void rotate (const double &angle, const Eigen::Vector3d &axis)
void setAngleOfViewY (double angleOfViewY)
void setModelview (const Eigen::Transform3d &matrix)
Eigen::Vector3d transformedXAxis () const
Eigen::Vector3d transformedYAxis () const
Eigen::Vector3d transformedZAxis () const
void translate (const Eigen::Vector3d &vector)
Eigen::Vector3d unProject (const QPoint &p) const
Eigen::Vector3d unProject (const QPoint &p, const Eigen::Vector3d &ref) const
Eigen::Vector3d unProject (const Eigen::Vector3d &v) const

Protected Member Functions

void setParent (const GLWidget *glwidget)

Detailed Description

Representation of the camera looking at the molecule.

Author:
Benoit Jacob

This class represents a camera looking at the molecule loaded in a GLWidget. It stores the parameters describing the camera and a pointer to the parent GLWidget. It uses this to retrieve information about the molecule being looked at, automatically setting up the OpenGL projection matrix to ensure that the molecule will not be clipped. It also provides a method to initialize a nice default viewpoint of the molecule. In order to setup the OpenGL matrices before rendering the molecule, do the following:

    // setup the OpenGL projection matrix using the camera
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    camera.applyPerspective();

    // setup the OpenGL modelview matrix using the camera
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    camera.applyModelview();

The reason why Camera class does not provide a single method to do all of this is that in some cases you don't want to. For instance, when doing OpenGL selection, you want to call gluPickMatrix() right before Camera::applyPerspective().

Definition at line 65 of file src/camera.h.


Constructor & Destructor Documentation

Avogadro::Camera::Camera ( const GLWidget *  parent = 0,
double  angleOfViewY = 40.0 
) [explicit]

The constructor.

Parameters:
parent the GLWidget parent of this camera instance.
angleOfViewY the vertical viewing angle in degrees.
See also:
setParent(), setAngleOfViewY()

Definition at line 46 of file camera.cpp.

Avogadro::Camera::~Camera (  )  [virtual]

The destructor.

Definition at line 54 of file camera.cpp.

Avogadro::Camera::Camera ( const Camera *  camera  ) 

The copy constructor - it is useful to be able to copy the Camera.

Definition at line 59 of file camera.cpp.


Member Function Documentation

double Avogadro::Camera::angleOfViewY (  )  const
Returns:
the vertical viewing angle in degrees.
See also:
setAngleOfViewY()

Definition at line 98 of file camera.cpp.

void Avogadro::Camera::applyModelview (  )  const

Calls glMultMatrix() with the camera's "modelview" matrix.

Should be called only in GL_MODELVIEW matrix mode. Example code is given in the class's comment.

See also:
applyPerspective(), initializeViewPoint()

Definition at line 202 of file camera.cpp.

void Avogadro::Camera::applyPerspective (  )  const

Calls gluPerspective() with parameters automatically chosen for rendering the GLWidget's molecule with this camera.

Should be called only in GL_PROJECTION matrix mode. Example code is given in the class's comment.

See also:
applyModelview(), initializeViewPoint()

Definition at line 188 of file camera.cpp.

Eigen::Vector3d Avogadro::Camera::backTransformedXAxis (  )  const

Returns a unit vector pointing toward the right, expressed in the scene's coordinate system.

This is simply the unit vector that is mapped to (1,0,0) by the camera rotation.

Definition at line 237 of file camera.cpp.

Eigen::Vector3d Avogadro::Camera::backTransformedYAxis (  )  const

Returns a unit vector pointing upward, expressed in the scene's coordinate system.

This is simply the unit vector that is mapped to (0,1,0) by the camera rotation.

Definition at line 242 of file camera.cpp.

Eigen::Vector3d Avogadro::Camera::backTransformedZAxis (  )  const

Returns a unit vector pointing toward the camera, expressed in the scene's coordinate system.

This is simply the unit vector that is mapped to (0,0,1) by the camera rotation.

Definition at line 247 of file camera.cpp.

double Avogadro::Camera::distance ( const Eigen::Vector3d &  point  )  const

Returns the distance between point and the camera.

For instance, to determine the distance between a molecule's center and the camera, do:

          double d = camera.distance( molecule.center() );

Definition at line 125 of file camera.cpp.

void Avogadro::Camera::initializeViewPoint (  ) 

Sets up the camera so that it gives a nice view of the molecule loaded in the parent GLWidget.

Typically you would call this method right after loading a molecule.

See also:
applyPerspective(), applyModelview()

Definition at line 145 of file camera.cpp.

Eigen::Transform3d & Avogadro::Camera::modelview (  ) 
Returns:
a non-constant reference to the 4x4 "modelview" matrix representing the camera orientation and position
See also:
setModelview(), const Eigen::Transform3d & modelview() const

Definition at line 140 of file camera.cpp.

const Eigen::Transform3d & Avogadro::Camera::modelview (  )  const
Returns:
a constant reference to the 4x4 "modelview" matrix representing the camera orientation and position
See also:
setModelview(), Eigen::Transform3d & modelview()

Definition at line 135 of file camera.cpp.

void Avogadro::Camera::normalize (  ) 

The linear component (ie the 3x3 topleft block) of the camera matrix must always be a rotation.

But after several hundreds of operations on it, it can drift farther and farther away from being a rotation. This method normalizes the camera matrix so that the linear component is guaranteed to be a rotation. Concretely, it performs a Gram-Schmidt orthonormalization to transform the linear component into a nearby rotation.

The bottom row must always have entries 0, 0, 0, 1. This function overwrites the bottom row with these values.

Definition at line 72 of file camera.cpp.

const GLWidget * Avogadro::Camera::parent (  )  const
Returns:
a pointer to the parent GLWidget
See also:
setParent()

Definition at line 88 of file camera.cpp.

void Avogadro::Camera::prerotate ( const double &  angle,
const Eigen::Vector3d &  axis 
)

Multiply the camera's "modelview" matrix on the left by the rotation of the given angle and axis.

Because the rotation is applied on the left, the axis vector is understood in the the coordinate system obtained by applying the camera's matrix to the molecule's coordinate system. Use this method if you want to give the impression that the camera is rotating while the molecule remains fixed.

After the rotation is multiplied, a normalization is performed to ensure that the camera matrix remains sane.

Warning:
This is NOT the equivalent of the OpenGL function glRotate().
Parameters:
angle the rotation angle in radians
axis a unit vector around which to rotate. This MUST be a unit vector, i.e. axis.norm() must be close to 1.
See also:
prerotate()

Definition at line 119 of file camera.cpp.

void Avogadro::Camera::pretranslate ( const Eigen::Vector3d &  vector  ) 

Multiply the camera's "modelview" matrix on the left by the translation of given vector.

Because the translation is applied on the left, the vector is understood in the coordinate system obtained by applying the camera's matrix to the molecule's coordinate system. Use this method if you want to give the impression that the camera is moving while the molecule remains fixed.

Warning:
This is NOT the equivalent of the OpenGL function glTranslate().
Parameters:
vector the translation vector
See also:
translate(), translationVector()

Definition at line 108 of file camera.cpp.

Eigen::Vector3d Avogadro::Camera::project ( const Eigen::Vector3d &  v  )  const

Performs a projection from space coordinates to window coordinates.

Parameters:
v the vector to project, expressed in space coordinates.
Returns:
vector containing the projected screen coordinates.
See also:
unProject(const Eigen::Vector3d&), unProject(const QPoint&), unProject(const QPoint&, const Eigen::Vector3d&)

Definition at line 226 of file camera.cpp.

void Avogadro::Camera::rotate ( const double &  angle,
const Eigen::Vector3d &  axis 
)

Multiply the camera's "modelview" matrix on the right by the rotation of the given angle and axis.

As the rotation is applied on the right, the axis vector is understood in the molecule's coordinate system. Use this method if you want to give the impression that the molecule is rotating while the camera remains fixed. This is the equivalent of the OpenGL function glRotate(), except that here the angle is expressed in radians, not in degrees.

After the rotation is multiplied, a normalization is performed to ensure that the camera matrix remains sane.

Parameters:
angle the rotation angle in radians
axis a unit vector around which to rotate. This MUST be a unit vector, i.e. axis.norm() must be close to 1.
See also:
prerotate()

Definition at line 113 of file camera.cpp.

void Avogadro::Camera::setAngleOfViewY ( double  angleOfViewY  ) 

Sets the vertical viewing angle.

Parameters:
angleOfViewY the new vertical viewing angle in degrees.
See also:
angleOfViewY()

Definition at line 93 of file camera.cpp.

void Avogadro::Camera::setModelview ( const Eigen::Transform3d &  matrix  ) 

Sets 4x4 "modelview" matrix representing the camera orientation and position.

Parameters:
matrix the matrix to copy from
See also:
Eigen::Transform3d & modelview(), applyModelview()

Definition at line 130 of file camera.cpp.

void Avogadro::Camera::setParent ( const GLWidget *  glwidget  )  [protected]

Sets which GLWidget owns this camera.

See also:
parent()

Definition at line 67 of file camera.cpp.

Eigen::Vector3d Avogadro::Camera::transformedXAxis (  )  const

Returns a unit vector pointing in the x direction, expressed in the space coordinate system.

Definition at line 252 of file camera.cpp.

Eigen::Vector3d Avogadro::Camera::transformedYAxis (  )  const

Returns a unit vector pointing in the y direction, expressed in the space coordinate system.

Definition at line 257 of file camera.cpp.

Eigen::Vector3d Avogadro::Camera::transformedZAxis (  )  const

Returns a unit vector pointing in the z direction, expressed in the space coordinate system.

Definition at line 262 of file camera.cpp.

void Avogadro::Camera::translate ( const Eigen::Vector3d &  vector  ) 

Multiply the camera's "modelview" matrix on the right by the translation of the given vector.

As the translation is applied on the right, the vector is understood in the molecule's coordinate system. Use this method if you want to give the impression that the molecule is moving while the camera remains fixed. This is the equivalent of the OpenGL function glTranslate().

Parameters:
vector the translation vector
See also:
pretranslate(), translationVector()

Definition at line 103 of file camera.cpp.

Eigen::Vector3d Avogadro::Camera::unProject ( const QPoint &  p  )  const

Performs an unprojection from window coordinates to space coordinates, into the plane passing through the molecule's center and parallel to the screen.

Thus the returned vector is a point belonging to that plane. This is equivalent to

         unProject( p, center() );
Parameters:
p the point to unproject, expressed in window coordinates.
Returns:
vector containing the unprojected space coordinates.
See also:
unProject(const Eigen::Vector3d&), unProject(const QPoint&, const Eigen::Vector3d&), project()

Definition at line 221 of file camera.cpp.

Eigen::Vector3d Avogadro::Camera::unProject ( const QPoint &  p,
const Eigen::Vector3d &  ref 
) const

Performs an unprojection from window coordinates to space coordinates, into the plane passing through a given reference point and parallel to the screen.

Thus the returned vector is a point of that plane. The rationale is that when unprojecting 2D window coords to 3D space coords, there are a priori infinitely many solutions, and one has to be choose. This is equivalent to choosing a plane parallel to the screen.

Parameters:
p the point to unproject, expressed in window coordinates.
ref the reference point, determining the plane into which to unproject. If you don't know what to put here, see the other unProject(const QPoint&) method.
Returns:
vector containing the unprojected space coordinates
See also:
unProject(const Eigen::Vector3d&), unProject(const QPoint&), project()

Definition at line 216 of file camera.cpp.

Eigen::Vector3d Avogadro::Camera::unProject ( const Eigen::Vector3d &  v  )  const

Performs an unprojection from window coordinates to space coordinates.

Parameters:
v The vector to unproject, expressed in window coordinates. Thus v.x() and v.y() are the x and y coords of the pixel to unproject. v.z() represents it's "z-distance". If you don't know what value to put in v.z(), see the other unProject(const QPoint&) method.
Returns:
vector of the unprojected space coordinates
See also:
unProject(const QPoint&), project()

Definition at line 207 of file camera.cpp.


The documentation for this class was generated from the following files:
  • src/camera.h
  • camera.cpp

kalzium

Skip menu "kalzium"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeedu

Skip menu "kdeedu"
  •     lib
  • kalzium
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  •   stepcore
Generated for kdeedu by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal