00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://ogre.sourceforge.net/ 00006 00007 Copyright © 2000-2002 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 #ifndef __Camera_H__ 00026 #define __Camera_H__ 00027 00028 // Default options 00029 #include "OgrePrerequisites.h" 00030 00031 #include "OgreString.h" 00032 #include "OgreMovableObject.h" 00033 00034 // Matrices & Vectors 00035 #include "OgreMatrix4.h" 00036 #include "OgreVector3.h" 00037 #include "OgrePlane.h" 00038 #include "OgreQuaternion.h" 00039 #include "OgreCommon.h" 00040 #include "OgreFrustum.h" 00041 00042 00043 namespace Ogre { 00044 00047 enum ProjectionType 00048 { 00049 PT_ORTHOGRAPHIC, 00050 PT_PERSPECTIVE 00051 }; 00052 00053 00082 class _OgreExport Camera : public MovableObject 00083 { 00084 protected: 00086 String mName; 00088 SceneManager *mSceneMgr; 00089 00091 Quaternion mOrientation; 00092 00094 Vector3 mPosition; 00095 00097 mutable Quaternion mLastParentOrientation; 00098 mutable Vector3 mLastParentPosition; 00099 00101 mutable Quaternion mDerivedOrientation; 00102 mutable Vector3 mDerivedPosition; 00103 00105 Real mFOVy; 00107 Real mFarDist; 00109 Real mNearDist; 00111 Real mAspect; 00113 bool mYawFixed; 00115 Vector3 mYawFixedAxis; 00116 00118 mutable Plane mFrustumPlanes[6]; 00119 00121 ProjectionType mProjType; 00123 SceneDetailLevel mSceneDetail; 00124 00125 00127 mutable Matrix4 mProjMatrix; 00129 mutable Matrix4 mStandardProjMatrix; 00131 mutable Matrix4 mViewMatrix; 00133 mutable bool mRecalcFrustum; 00135 mutable bool mRecalcView; 00136 00140 mutable Real mCoeffL[2], mCoeffR[2], mCoeffB[2], mCoeffT[2]; 00141 00142 00143 // Internal functions for calcs 00144 void updateFrustum(void) const; 00145 void updateView(void) const; 00146 bool isViewOutOfDate(void) const; 00147 bool isFrustumOutOfDate(void) const; 00148 00150 unsigned int mVisFacesLastRender; 00151 00153 static String msMovableType; 00154 00156 SceneNode* mAutoTrackTarget; 00158 Vector3 mAutoTrackOffset; 00159 00160 // Scene LOD factor used to adjust overall LOD 00161 Real mSceneLodFactor; 00163 Real mSceneLodFactorInv; 00164 00166 bool mReflect; 00167 Matrix4 mReflectMatrix; 00168 Plane mReflectPlane; 00169 00170 public: 00173 Camera( const String& name, SceneManager* sm); 00174 00177 virtual ~Camera(); 00178 00179 00182 SceneManager* getSceneManager(void) const; 00183 00186 virtual const String& getName(void) const; 00187 00190 void setProjectionType(ProjectionType pt); 00191 00194 ProjectionType getProjectionType(void) const; 00195 00203 void setDetailLevel(SceneDetailLevel sd); 00204 00207 SceneDetailLevel getDetailLevel(void) const; 00208 00211 void setPosition(Real x, Real y, Real z); 00212 00215 void setPosition(const Vector3& vec); 00216 00219 const Vector3& getPosition(void) const; 00220 00223 void move(const Vector3& vec); 00224 00227 void moveRelative(const Vector3& vec); 00228 00234 void setDirection(Real x, Real y, Real z); 00235 00238 void setDirection(const Vector3& vec); 00239 00240 /* Gets the camera's direction. 00241 */ 00242 Vector3 getDirection(void) const; 00243 00244 00253 void lookAt( const Vector3& targetPoint ); 00266 void lookAt(Real x, Real y, Real z); 00267 00270 void roll(Real degrees); 00271 00274 void yaw(Real degrees); 00275 00278 void pitch(Real degrees); 00279 00282 void rotate(const Vector3& axis, Real degrees); 00283 00286 void rotate(const Quaternion& q); 00287 00302 void setFixedYawAxis( bool useFixed, const Vector3& fixedAxis = Vector3::UNIT_Y ); 00303 00316 void setFOVy(Real fovy); 00317 00320 Real getFOVy(void) const; 00321 00333 void setNearClipDistance(Real nearDist); 00334 00337 Real getNearClipDistance(void) const; 00338 00355 void setFarClipDistance(Real farDist); 00356 00359 Real getFarClipDistance(void) const; 00360 00369 void setAspectRatio(Real ratio); 00370 00373 Real getAspectRatio(void) const; 00374 00382 const Matrix4& getProjectionMatrix(void) const; 00394 const Matrix4& getStandardProjectionMatrix(void) const; 00395 00398 const Matrix4& getViewMatrix(void) const; 00399 00404 const Plane& getFrustumPlane( FrustumPlane plane ) const; 00405 00417 bool isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy = 0) const; 00418 00430 bool isVisible(const Sphere& bound, FrustumPlane* culledBy = 0) const; 00431 00443 bool isVisible(const Vector3& vert, FrustumPlane* culledBy = 0) const; 00444 00447 const Quaternion& getOrientation(void) const; 00448 00451 void setOrientation(const Quaternion& q); 00452 00457 void _renderScene(Viewport *vp, bool includeOverlays); 00458 00461 friend std::ostream& operator<<(std::ostream& o, Camera& c); 00462 00465 void _notifyRenderedFaces(unsigned int numfaces); 00466 00469 unsigned int _getNumRenderedFaces(void) const; 00470 00473 Quaternion getDerivedOrientation(void) const; 00476 Vector3 getDerivedPosition(void) const; 00479 Vector3 getDerivedDirection(void) const; 00480 00482 void _notifyCurrentCamera(Camera* cam); 00483 00485 const AxisAlignedBox& getBoundingBox(void) const; 00486 00488 Real getBoundingRadius(void) const; 00489 00491 void _updateRenderQueue(RenderQueue* queue); 00492 00494 const String& getMovableType(void) const; 00495 00515 void setAutoTracking(bool enabled, SceneNode* target = 0, 00516 const Vector3& offset = Vector3::ZERO); 00517 00518 00534 void setLodBias(Real factor = 1.0); 00535 00540 Real getLodBias(void) const; 00541 00547 void enableReflection(const Plane& p); 00548 00550 void disableReflection(void); 00551 00553 bool isReflected(void) { return mReflect; } 00555 const Matrix4& getReflectionMatrix(void) { return mReflectMatrix; } 00557 const Plane& getReflectionPlane(void) { return mReflectPlane; } 00558 00560 Real _getLodBiasInverse(void) const; 00561 00562 00564 void _autoTrack(void); 00565 }; 00566 00567 } // namespace Ogre 00568 #endif
Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:04 2004