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 http://glc-lib.sourceforge.net 00007 00008 GLC-lib is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU Lesser General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 GLC-lib is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public License 00019 along with GLC-lib; if not, write to the Free Software 00020 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 00022 *****************************************************************************/ 00023 00025 00026 #ifndef GLC_CAMERA_H_ 00027 #define GLC_CAMERA_H_ 00028 00029 #include "../glc_object.h" 00030 #include "../maths/glc_vector3d.h" 00031 #include "../maths/glc_matrix4x4.h" 00032 00033 #include "../glc_config.h" 00034 00037 00041 00042 00043 class GLC_LIB_EXPORT GLC_Camera : 00044 public GLC_Object 00045 { 00047 00049 00050 public: 00052 00053 GLC_Camera(); 00054 00056 /* VectUp and VectCam could not be parallel 00057 * VectUp could not be NULL 00058 * VectCam could not be NULL */ 00059 GLC_Camera(const GLC_Point3d &, const GLC_Point3d &, const GLC_Vector3d &); 00060 00062 GLC_Camera(const GLC_Camera&); 00064 00066 00068 00069 public: 00071 inline double distEyeTarget(void) const 00072 {return (m_Eye - m_Target).length();} 00073 00075 inline GLC_Point3d eye(void) const 00076 {return m_Eye;} 00077 00079 inline GLC_Point3d target(void) const 00080 {return m_Target;} 00081 00083 inline GLC_Vector3d upVector(void) const 00084 {return m_VectUp;} 00085 00087 inline GLC_Vector3d forward(void) const 00088 {return m_Target - m_Eye;} 00089 00091 inline GLC_Vector3d sideVector() const 00092 {return ((m_Target - m_Eye).normalize() ^ m_VectUp).normalize();} 00093 00095 inline GLC_Matrix4x4 viewMatrix(void) const 00096 {return m_ModelViewMatrix;} 00097 00099 bool operator==(const GLC_Camera&) const; 00100 00102 bool isAlmostEqualTo(const GLC_Camera&, const double distanceAccuracy=0.05) const; 00103 00105 inline GLC_Vector3d defaultUpVector() const 00106 {return m_DefaultVectUp;} 00107 00109 GLC_Camera frontView() const; 00110 00112 GLC_Camera rearView() const; 00113 00115 GLC_Camera rightView() const; 00116 00118 GLC_Camera leftView() const; 00119 00121 GLC_Camera topView() const; 00122 00124 GLC_Camera bottomView() const; 00125 00127 00128 GLC_Camera isoView() const; 00129 00131 inline GLC_Matrix4x4 modelViewMatrix() const 00132 { 00133 GLC_Matrix4x4 translate(-m_Eye); 00134 GLC_Matrix4x4 modelView= GLC_Matrix4x4(m_ModelViewMatrix * translate); 00135 return modelView; 00136 } 00137 00139 00141 00143 00144 public: 00146 GLC_Camera& orbit(GLC_Vector3d VectOldPoss, GLC_Vector3d VectCurPoss); 00147 00149 GLC_Camera& pan(GLC_Vector3d VectDep); 00150 00152 00153 GLC_Camera& zoom(double factor); 00154 00156 GLC_Camera& move(const GLC_Matrix4x4 &MatMove); 00157 00159 GLC_Camera& rotateAround(const GLC_Vector3d&, const double&, const GLC_Point3d&); 00160 00162 GLC_Camera& rotateAroundTarget(const GLC_Vector3d&, const double&); 00163 00165 GLC_Camera& translate(const GLC_Vector3d &VectTrans); 00166 00168 /* VectUp and VectCam could not be parallel 00169 * VectUp could not be NULL 00170 * VectCam could not be NULL */ 00171 GLC_Camera& setCam(GLC_Point3d Eye, GLC_Point3d Target, GLC_Vector3d Up); 00172 00174 GLC_Camera& setCam(const GLC_Camera&); 00175 00177 GLC_Camera& setEyeCam(const GLC_Point3d &Eye); 00178 00180 GLC_Camera& setTargetCam(const GLC_Point3d &Target); 00181 00183 GLC_Camera& setUpCam(const GLC_Vector3d &Up); 00184 00186 GLC_Camera& setDistEyeTarget(double Longueur); 00187 00189 GLC_Camera& setDistTargetEye(double Longueur); 00190 00192 GLC_Camera& operator=(const GLC_Camera&); 00193 00195 00196 inline GLC_Camera& setDefaultUpVector(const GLC_Vector3d& up) 00197 { 00198 Q_ASSERT((up == glc::X_AXIS) || (up == glc::Y_AXIS) || (up == glc::Z_AXIS)); 00199 m_DefaultVectUp= up; 00200 return *this; 00201 } 00202 00204 inline void setFrontView() 00205 {setCam(frontView());} 00206 00208 inline void setRearView() 00209 {setCam(rearView());} 00210 00212 inline void setRightView() 00213 {setCam(rightView());} 00214 00216 inline void setLeftView() 00217 {setCam(leftView());} 00218 00220 inline void setTopView() 00221 {setCam(topView());} 00222 00224 inline void setBottomView() 00225 {setCam(bottomView());} 00226 00228 00229 inline void setIsoView() 00230 {setCam(isoView());} 00231 00233 00235 00237 00238 public: 00240 void glExecute(); 00241 00243 00245 // Private services Functions 00247 private: 00249 void createMatComp(void); 00250 00251 00253 // Private Member 00255 private: 00257 GLC_Point3d m_Eye; 00258 00260 GLC_Point3d m_Target; 00261 00263 GLC_Vector3d m_VectUp; 00264 00266 GLC_Matrix4x4 m_ModelViewMatrix; 00267 00269 GLC_Vector3d m_DefaultVectUp; 00270 }; 00271 #endif //GLC_CAMERA_H_