Avogadro  1.1.0
/home/kitware/dashboards/avogadro/libavogadro/src/camera.h
00001 /**********************************************************************
00002   Camera - Class for representing the view.
00003 
00004   Copyright (c) 2007-2008 Benoit Jacob
00005   Copyright (c) 2007 Donald Ephraim Curtis
00006   Copyright (c) 2007 Carsten Niehaus
00007   Copyright (c) 2007-2008 Marcus D. Hanwell
00008   Copyright (c) 2007-2009 Geoff Hutchison
00009         Copyright (C) 2011 David C. Lonie
00010 
00011   This file is part of the Avogadro molecular editor project.
00012   For more information, see <http://avogadro.openmolecules.net/>
00013 
00014   Avogadro is free software; you can redistribute it and/or modify
00015   it under the terms of the GNU General Public License as published by
00016   the Free Software Foundation; either version 2 of the License, or
00017   (at your option) any later version.
00018 
00019   Avogadro is distributed in the hope that it will be useful,
00020   but WITHOUT ANY WARRANTY; without even the implied warranty of
00021   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022   GNU General Public License for more details.
00023 
00024   You should have received a copy of the GNU General Public License
00025   along with this program; if not, write to the Free Software
00026   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00027   02110-1301, USA.
00028  **********************************************************************/
00029 
00030 #ifndef CAMERA_H
00031 #define CAMERA_H
00032 
00033 #include <avogadro/global.h>
00034 #include <Eigen/Geometry>
00035 #include <QPoint>
00036 
00037 namespace Avogadro {
00038 
00039   class GLWidget;
00040 
00069   class CameraPrivate;
00070   class A_EXPORT Camera
00071   {
00072     protected:
00073       friend class GLWidget;
00076       void setParent(const GLWidget *glwidget);
00077 
00078     public:
00083       explicit Camera(const GLWidget *parent = 0, double angleOfViewY = 40.0);
00085       virtual ~Camera();
00089       Camera(const Camera *camera);
00092       const GLWidget *parent() const;
00096       void setAngleOfViewY(double angleOfViewY);
00099       double angleOfViewY() const;
00103       void setModelview(const Eigen::Transform3d &matrix);
00107       const Eigen::Transform3d & modelview() const;
00111       Eigen::Transform3d & modelview();
00119       void applyPerspective() const;
00126       void applyProjection() const;
00132       void applyModelview() const;
00137       void initializeViewPoint();
00144       double distance(const Eigen::Vector3d & point) const;
00152       void translate(const Eigen::Vector3d &vector);
00161       void pretranslate(const Eigen::Vector3d &vector);
00176       void rotate(const double &angle, const Eigen::Vector3d &axis);
00191       void prerotate(const double &angle, const Eigen::Vector3d &axis);
00192 
00205       void scale(double coefficient);
00206 
00217       Eigen::Vector3d unProject(const Eigen::Vector3d& v) const;
00218 
00234       Eigen::Vector3d unProject(const QPoint& p, const Eigen::Vector3d& ref) const;
00235 
00249       Eigen::Vector3d unProject(const QPoint& p) const;
00250 
00259       Eigen::Vector3d project(const Eigen::Vector3d& v) const;
00260 
00266       Eigen::Vector3d backTransformedXAxis() const;
00267 
00273       Eigen::Vector3d backTransformedYAxis() const;
00274 
00280       Eigen::Vector3d backTransformedZAxis() const;
00281 
00286       Eigen::Vector3d transformedXAxis() const;
00287 
00292       Eigen::Vector3d transformedYAxis() const;
00293 
00298       Eigen::Vector3d transformedZAxis() const;
00299 
00312       bool nearClippingPlane(Eigen::Vector3d *normal, Eigen::Vector3d *point);
00313 
00324       void normalize();
00325 
00332       double scalingCoefficient();
00333 
00334     private:
00335       CameraPrivate * const d;
00336 
00342       Eigen::Vector3d V4toV3DivW(const Eigen::Vector4d & v4) {
00343         return v4.start<3>()/v4.w();
00344       }
00345   };
00346 
00347 } // end namespace Avogadro
00348 
00349 #endif // __CAMERA_H