glc_camera.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  Copyright (C) 2009 Laurent Bauer
00006  Version 2.0.0, packaged on July 2010.
00007 
00008  http://glc-lib.sourceforge.net
00009 
00010  GLC-lib is free software; you can redistribute it and/or modify
00011  it under the terms of the GNU Lesser General Public License as published by
00012  the Free Software Foundation; either version 3 of the License, or
00013  (at your option) any later version.
00014 
00015  GLC-lib is distributed in the hope that it will be useful,
00016  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  GNU Lesser General Public License for more details.
00019 
00020  You should have received a copy of the GNU Lesser General Public License
00021  along with GLC-lib; if not, write to the Free Software
00022  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023 
00024 *****************************************************************************/
00025 
00027 
00028 #ifndef GLC_CAMERA_H_
00029 #define GLC_CAMERA_H_
00030 
00031 #include "../glc_object.h"
00032 #include "../maths/glc_vector3d.h"
00033 #include "../maths/glc_matrix4x4.h"
00034 
00035 #include "../glc_config.h"
00036 
00039 
00043 
00044 
00045 class GLC_LIB_EXPORT GLC_Camera :
00046         public GLC_Object
00047 {
00049 
00051 
00052 public:
00054 
00055    GLC_Camera();
00056 
00058         /* VectUp and VectCam could not be parallel
00059          * VectUp could not be NULL
00060          * VectCam could not be NULL */
00061    GLC_Camera(const GLC_Point3d &, const GLC_Point3d &, const GLC_Vector3d &);
00062 
00064    GLC_Camera(const GLC_Camera&);
00066 
00068 
00070 
00071 public:
00073         inline double distEyeTarget(void) const
00074         {return (m_Eye - m_Target).length();}
00075 
00077         inline GLC_Point3d eye(void) const
00078         {return m_Eye;}
00079 
00081         inline GLC_Point3d target(void) const
00082         {return m_Target;}
00083 
00085         inline GLC_Vector3d upVector(void) const
00086         {return m_VectUp;}
00087 
00089         inline GLC_Vector3d forward(void) const
00090         {return m_Target - m_Eye;}
00091 
00093         inline GLC_Vector3d sideVector() const
00094         {return ((m_Target - m_Eye).normalize() ^ m_VectUp).normalize();}
00095 
00097         inline GLC_Matrix4x4 viewMatrix(void) const
00098         {return m_ModelViewMatrix;}
00099 
00101         bool operator==(const GLC_Camera&) const;
00102 
00104     bool isAlmostEqualTo(const GLC_Camera&, const double distanceAccuracy=0.05) const;
00105 
00107         inline GLC_Vector3d defaultUpVector() const
00108         {return m_DefaultVectUp;}
00109 
00111         GLC_Camera frontView() const;
00112 
00114         GLC_Camera rearView() const;
00115 
00117         GLC_Camera rightView() const;
00118 
00120         GLC_Camera leftView() const;
00121 
00123         GLC_Camera topView() const;
00124 
00126         GLC_Camera bottomView() const;
00127 
00129 
00130         GLC_Camera isoView() const;
00131 
00133         inline GLC_Matrix4x4 modelViewMatrix() const
00134         {
00135                 GLC_Matrix4x4 translate(-m_Eye);
00136                 GLC_Matrix4x4 modelView= GLC_Matrix4x4(m_ModelViewMatrix * translate);
00137                 return modelView;
00138         }
00139 
00141 
00143 
00145 
00146 public:
00148         GLC_Camera& orbit(GLC_Vector3d VectOldPoss, GLC_Vector3d VectCurPoss);
00149 
00151         GLC_Camera& pan(GLC_Vector3d VectDep);
00152 
00154 
00155         GLC_Camera& zoom(double factor);
00156 
00158         GLC_Camera& move(const GLC_Matrix4x4 &MatMove);
00159 
00161         GLC_Camera& rotateAround(const GLC_Vector3d&, const double&, const GLC_Point3d&);
00162 
00164         GLC_Camera& rotateAroundTarget(const GLC_Vector3d&, const double&);
00165 
00167         GLC_Camera& translate(const GLC_Vector3d &VectTrans);
00168 
00170         /* VectUp and VectCam could not be parallel
00171          * VectUp could not be NULL
00172          * VectCam could not be NULL */
00173         GLC_Camera& setCam(GLC_Point3d Eye, GLC_Point3d Target, GLC_Vector3d Up);
00174 
00176         GLC_Camera& setCam(const GLC_Camera&);
00177 
00179         GLC_Camera& setEyeCam(const GLC_Point3d &Eye);
00180 
00182         GLC_Camera& setTargetCam(const GLC_Point3d &Target);
00183 
00185         GLC_Camera& setUpCam(const GLC_Vector3d &Up);
00186 
00188         GLC_Camera& setDistEyeTarget(double Longueur);
00189 
00191         GLC_Camera& setDistTargetEye(double Longueur);
00192 
00194         GLC_Camera& operator=(const GLC_Camera&);
00195 
00197 
00198         inline GLC_Camera& setDefaultUpVector(const GLC_Vector3d& up)
00199         {
00200                 Q_ASSERT((up == glc::X_AXIS) || (up == glc::Y_AXIS) || (up == glc::Z_AXIS));
00201                 m_DefaultVectUp= up;
00202                 return *this;
00203         }
00204 
00206         inline void setFrontView()
00207         {setCam(frontView());}
00208 
00210         inline void setRearView()
00211         {setCam(rearView());}
00212 
00214         inline void setRightView()
00215         {setCam(rightView());}
00216 
00218         inline void setLeftView()
00219         {setCam(leftView());}
00220 
00222         inline void setTopView()
00223         {setCam(topView());}
00224 
00226         inline void setBottomView()
00227         {setCam(bottomView());}
00228 
00230 
00231         inline void setIsoView()
00232         {setCam(isoView());}
00233 
00235 
00237 
00239 
00240 public:
00242    void glExecute();
00243 
00245 
00247 // Private services Functions
00249 private:
00251         void createMatComp(void);
00252 
00253 
00255 // Private Member
00257 private:
00259         GLC_Point3d m_Eye;
00260 
00262         GLC_Point3d m_Target;
00263 
00265         GLC_Vector3d m_VectUp;
00266 
00268         GLC_Matrix4x4 m_ModelViewMatrix;
00269 
00271         GLC_Vector3d m_DefaultVectUp;
00272 };
00273 #endif //GLC_CAMERA_H_

SourceForge.net Logo

©2005-2010 Laurent Ribon