00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org 00006 00007 Copyright (c) 2000-2009 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 #ifndef __Camera_H__ 00029 #define __Camera_H__ 00030 00031 // Default options 00032 #include "OgrePrerequisites.h" 00033 00034 #include "OgreString.h" 00035 #include "OgreMovableObject.h" 00036 00037 // Matrices & Vectors 00038 #include "OgreMatrix4.h" 00039 #include "OgreVector3.h" 00040 #include "OgrePlane.h" 00041 #include "OgreQuaternion.h" 00042 #include "OgreCommon.h" 00043 #include "OgreFrustum.h" 00044 #include "OgreRay.h" 00045 #include "OgrePlaneBoundedVolume.h" 00046 00047 00048 namespace Ogre { 00049 00085 class _OgreExport Camera : public Frustum 00086 { 00087 public: 00090 class _OgreExport Listener 00091 { 00092 public: 00093 Listener() {} 00094 virtual ~Listener() {} 00095 00097 virtual void cameraPreRenderScene(Camera* cam) 00098 { (void)cam; } 00099 00101 virtual void cameraPostRenderScene(Camera* cam) 00102 { (void)cam; } 00103 00105 virtual void cameraDestroyed(Camera* cam) 00106 { (void)cam; } 00107 00108 }; 00109 protected: 00111 String mName; 00113 SceneManager *mSceneMgr; 00114 00116 Quaternion mOrientation; 00117 00119 Vector3 mPosition; 00120 00122 mutable Quaternion mDerivedOrientation; 00123 mutable Vector3 mDerivedPosition; 00124 00126 mutable Quaternion mRealOrientation; 00127 mutable Vector3 mRealPosition; 00128 00130 bool mYawFixed; 00132 Vector3 mYawFixedAxis; 00133 00135 PolygonMode mSceneDetail; 00136 00138 unsigned int mVisFacesLastRender; 00139 00141 unsigned int mVisBatchesLastRender; 00142 00144 static String msMovableType; 00145 00147 SceneNode* mAutoTrackTarget; 00149 Vector3 mAutoTrackOffset; 00150 00151 // Scene LOD factor used to adjust overall LOD 00152 Real mSceneLodFactor; 00154 Real mSceneLodFactorInv; 00155 00156 00161 Real mWLeft, mWTop, mWRight, mWBottom; 00163 bool mWindowSet; 00165 mutable vector<Plane>::type mWindowClipPlanes; 00166 // Was viewing window changed. 00167 mutable bool mRecalcWindow; 00169 Viewport* mLastViewport; 00173 bool mAutoAspectRatio; 00175 Frustum *mCullFrustum; 00177 bool mUseRenderingDistance; 00179 const Camera* mLodCamera; 00180 00181 typedef vector<Listener*>::type ListenerList; 00182 ListenerList mListeners; 00183 00184 00185 // Internal functions for calcs 00186 bool isViewOutOfDate(void) const; 00188 void invalidateFrustum(void) const; 00190 void invalidateView(void) const; 00191 00192 00197 virtual void setWindowImpl(void) const; 00198 00200 virtual vector<Vector4>::type getRayForwardIntersect(const Vector3& anchor, const Vector3 *dir, Real planeOffset) const; 00201 00202 public: 00205 Camera( const String& name, SceneManager* sm); 00206 00209 virtual ~Camera(); 00210 00212 virtual void addListener(Listener* l); 00214 virtual void removeListener(Listener* l); 00215 00218 SceneManager* getSceneManager(void) const; 00219 00222 virtual const String& getName(void) const; 00223 00224 00232 void setPolygonMode(PolygonMode sd); 00233 00236 PolygonMode getPolygonMode(void) const; 00237 00240 void setPosition(Real x, Real y, Real z); 00241 00244 void setPosition(const Vector3& vec); 00245 00248 const Vector3& getPosition(void) const; 00249 00252 void move(const Vector3& vec); 00253 00256 void moveRelative(const Vector3& vec); 00257 00263 void setDirection(Real x, Real y, Real z); 00264 00267 void setDirection(const Vector3& vec); 00268 00269 /* Gets the camera's direction. 00270 */ 00271 Vector3 getDirection(void) const; 00272 00275 Vector3 getUp(void) const; 00276 00279 Vector3 getRight(void) const; 00280 00289 void lookAt( const Vector3& targetPoint ); 00302 void lookAt(Real x, Real y, Real z); 00303 00306 void roll(const Radian& angle); 00307 00310 void yaw(const Radian& angle); 00311 00314 void pitch(const Radian& angle); 00315 00318 void rotate(const Vector3& axis, const Radian& angle); 00319 00322 void rotate(const Quaternion& q); 00323 00343 void setFixedYawAxis( bool useFixed, const Vector3& fixedAxis = Vector3::UNIT_Y ); 00344 00345 00348 const Quaternion& getOrientation(void) const; 00349 00352 void setOrientation(const Quaternion& q); 00353 00358 void _renderScene(Viewport *vp, bool includeOverlays); 00359 00362 _OgreExport friend std::ostream& operator<<(std::ostream& o, const Camera& c); 00363 00366 void _notifyRenderedFaces(unsigned int numfaces); 00367 00370 void _notifyRenderedBatches(unsigned int numbatches); 00371 00374 unsigned int _getNumRenderedFaces(void) const; 00375 00378 unsigned int _getNumRenderedBatches(void) const; 00379 00382 const Quaternion& getDerivedOrientation(void) const; 00385 const Vector3& getDerivedPosition(void) const; 00388 Vector3 getDerivedDirection(void) const; 00391 Vector3 getDerivedUp(void) const; 00394 Vector3 getDerivedRight(void) const; 00395 00398 const Quaternion& getRealOrientation(void) const; 00401 const Vector3& getRealPosition(void) const; 00404 Vector3 getRealDirection(void) const; 00407 Vector3 getRealUp(void) const; 00410 Vector3 getRealRight(void) const; 00411 00413 const String& getMovableType(void) const; 00414 00434 void setAutoTracking(bool enabled, SceneNode* target = 0, 00435 const Vector3& offset = Vector3::ZERO); 00436 00437 00453 void setLodBias(Real factor = 1.0); 00454 00459 Real getLodBias(void) const; 00460 00473 virtual void setLodCamera(const Camera* lodCam); 00474 00481 virtual const Camera* getLodCamera() const; 00482 00483 00488 Ray getCameraToViewportRay(Real screenx, Real screeny) const; 00494 void getCameraToViewportRay(Real screenx, Real screeny, Ray* outRay) const; 00495 00506 PlaneBoundedVolume getCameraToViewportBoxVolume(Real screenLeft, 00507 Real screenTop, Real screenRight, Real screenBottom, bool includeFarPlane = false); 00508 00520 void getCameraToViewportBoxVolume(Real screenLeft, 00521 Real screenTop, Real screenRight, Real screenBottom, 00522 PlaneBoundedVolume* outVolume, bool includeFarPlane = false); 00523 00525 Real _getLodBiasInverse(void) const; 00526 00527 00529 void _autoTrack(void); 00530 00531 00541 virtual void setWindow (Real Left, Real Top, Real Right, Real Bottom); 00543 virtual void resetWindow (void); 00545 virtual bool isWindowSet(void) const { return mWindowSet; } 00547 const vector<Plane>::type& getWindowPlanes(void) const; 00548 00550 Real getBoundingRadius(void) const; 00552 SceneNode* getAutoTrackTarget(void) const { return mAutoTrackTarget; } 00554 const Vector3& getAutoTrackOffset(void) const { return mAutoTrackOffset; } 00555 00561 Viewport* getViewport(void) const {return mLastViewport;} 00563 void _notifyViewport(Viewport* viewport) {mLastViewport = viewport;} 00564 00572 void setAutoAspectRatio(bool autoratio); 00573 00576 bool getAutoAspectRatio(void) const; 00577 00589 void setCullingFrustum(Frustum* frustum) { mCullFrustum = frustum; } 00591 Frustum* getCullingFrustum(void) const { return mCullFrustum; } 00592 00597 virtual void forwardIntersect(const Plane& worldPlane, vector<Vector4>::type* intersect3d) const; 00598 00600 bool isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy = 0) const; 00602 bool isVisible(const Sphere& bound, FrustumPlane* culledBy = 0) const; 00604 bool isVisible(const Vector3& vert, FrustumPlane* culledBy = 0) const; 00606 const Vector3* getWorldSpaceCorners(void) const; 00608 const Plane& getFrustumPlane( unsigned short plane ) const; 00610 bool projectSphere(const Sphere& sphere, 00611 Real* left, Real* top, Real* right, Real* bottom) const; 00613 Real getNearClipDistance(void) const; 00615 Real getFarClipDistance(void) const; 00617 const Matrix4& getViewMatrix(void) const; 00626 const Matrix4& getViewMatrix(bool ownFrustumOnly) const; 00632 virtual void setUseRenderingDistance(bool use) { mUseRenderingDistance = use; } 00636 virtual bool getUseRenderingDistance(void) const { return mUseRenderingDistance; } 00637 00644 virtual void synchroniseBaseSettingsWith(const Camera* cam); 00645 00647 const Vector3& getPositionForViewUpdate(void) const; 00649 const Quaternion& getOrientationForViewUpdate(void) const; 00650 }; 00654 } // namespace Ogre 00655 #endif
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sat Apr 24 18:00:31 2010