OgreCamera.h

Go to the documentation of this file.
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         SceneManager *mSceneMgr;
00112 
00114         Quaternion mOrientation;
00115 
00117         Vector3 mPosition;
00118 
00120         mutable Quaternion mDerivedOrientation;
00121         mutable Vector3 mDerivedPosition;
00122 
00124         mutable Quaternion mRealOrientation;
00125         mutable Vector3 mRealPosition;
00126 
00128         bool mYawFixed;
00130         Vector3 mYawFixedAxis;
00131 
00133         PolygonMode mSceneDetail;
00134 
00136         unsigned int mVisFacesLastRender;
00137 
00139         unsigned int mVisBatchesLastRender;
00140 
00142         static String msMovableType;
00143 
00145         SceneNode* mAutoTrackTarget;
00147         Vector3 mAutoTrackOffset;
00148 
00149         // Scene LOD factor used to adjust overall LOD
00150         Real mSceneLodFactor;
00152         Real mSceneLodFactorInv;
00153 
00154 
00159         Real mWLeft, mWTop, mWRight, mWBottom;
00161         bool mWindowSet;
00163         mutable vector<Plane>::type mWindowClipPlanes;
00164         // Was viewing window changed.
00165         mutable bool mRecalcWindow;
00167         Viewport* mLastViewport;
00171         bool mAutoAspectRatio;
00173         Frustum *mCullFrustum;
00175         bool mUseRenderingDistance;
00177         const Camera* mLodCamera;
00178 
00179         typedef vector<Listener*>::type ListenerList;
00180         ListenerList mListeners;
00181 
00182 
00183         // Internal functions for calcs
00184         bool isViewOutOfDate(void) const;
00186         void invalidateFrustum(void) const;
00188         void invalidateView(void) const;
00189 
00190 
00195         virtual void setWindowImpl(void) const;
00196 
00198         virtual vector<Vector4>::type getRayForwardIntersect(const Vector3& anchor, const Vector3 *dir, Real planeOffset) const;
00199 
00200     public:
00203         Camera( const String& name, SceneManager* sm);
00204 
00207         virtual ~Camera();
00208 
00210         virtual void addListener(Listener* l);
00212         virtual void removeListener(Listener* l);
00213 
00216         SceneManager* getSceneManager(void) const;
00217 
00225         void setPolygonMode(PolygonMode sd);
00226 
00229         PolygonMode getPolygonMode(void) const;
00230 
00233         void setPosition(Real x, Real y, Real z);
00234 
00237         void setPosition(const Vector3& vec);
00238 
00241         const Vector3& getPosition(void) const;
00242 
00245         void move(const Vector3& vec);
00246 
00249         void moveRelative(const Vector3& vec);
00250 
00256         void setDirection(Real x, Real y, Real z);
00257 
00260         void setDirection(const Vector3& vec);
00261 
00262         /* Gets the camera's direction.
00263         */
00264         Vector3 getDirection(void) const;
00265 
00268         Vector3 getUp(void) const;
00269 
00272         Vector3 getRight(void) const;
00273 
00282         void lookAt( const Vector3& targetPoint );
00295         void lookAt(Real x, Real y, Real z);
00296 
00299         void roll(const Radian& angle);
00300 
00303         void yaw(const Radian& angle);
00304 
00307         void pitch(const Radian& angle);
00308 
00311         void rotate(const Vector3& axis, const Radian& angle);
00312 
00315         void rotate(const Quaternion& q);
00316 
00336         void setFixedYawAxis( bool useFixed, const Vector3& fixedAxis = Vector3::UNIT_Y );
00337 
00338 
00341         const Quaternion& getOrientation(void) const;
00342 
00345         void setOrientation(const Quaternion& q);
00346 
00351         void _renderScene(Viewport *vp, bool includeOverlays);
00352 
00355         _OgreExport friend std::ostream& operator<<(std::ostream& o, const Camera& c);
00356 
00359         void _notifyRenderedFaces(unsigned int numfaces);
00360 
00363         void _notifyRenderedBatches(unsigned int numbatches);
00364 
00367         unsigned int _getNumRenderedFaces(void) const;
00368 
00371         unsigned int _getNumRenderedBatches(void) const;
00372 
00375         const Quaternion& getDerivedOrientation(void) const;
00378         const Vector3& getDerivedPosition(void) const;
00381         Vector3 getDerivedDirection(void) const;
00384         Vector3 getDerivedUp(void) const;
00387         Vector3 getDerivedRight(void) const;
00388 
00391         const Quaternion& getRealOrientation(void) const;
00394         const Vector3& getRealPosition(void) const;
00397         Vector3 getRealDirection(void) const;
00400         Vector3 getRealUp(void) const;
00403         Vector3 getRealRight(void) const;
00404 
00406         const String& getMovableType(void) const;
00407 
00427         void setAutoTracking(bool enabled, SceneNode* target = 0, 
00428             const Vector3& offset = Vector3::ZERO);
00429 
00430 
00446         void setLodBias(Real factor = 1.0);
00447 
00452         Real getLodBias(void) const;
00453 
00466         virtual void setLodCamera(const Camera* lodCam);
00467 
00474         virtual const Camera* getLodCamera() const;
00475 
00476 
00481         Ray getCameraToViewportRay(Real screenx, Real screeny) const;
00487         void getCameraToViewportRay(Real screenx, Real screeny, Ray* outRay) const;
00488 
00499         PlaneBoundedVolume getCameraToViewportBoxVolume(Real screenLeft, 
00500             Real screenTop, Real screenRight, Real screenBottom, bool includeFarPlane = false);
00501 
00513         void getCameraToViewportBoxVolume(Real screenLeft, 
00514             Real screenTop, Real screenRight, Real screenBottom, 
00515             PlaneBoundedVolume* outVolume, bool includeFarPlane = false);
00516 
00518         Real _getLodBiasInverse(void) const;
00519 
00520 
00522         void _autoTrack(void);
00523 
00524 
00534         virtual void setWindow (Real Left, Real Top, Real Right, Real Bottom);
00536         virtual void resetWindow (void);
00538         virtual bool isWindowSet(void) const { return mWindowSet; }
00540         const vector<Plane>::type& getWindowPlanes(void) const;
00541 
00543         Real getBoundingRadius(void) const;
00545         SceneNode* getAutoTrackTarget(void) const { return mAutoTrackTarget; }
00547         const Vector3& getAutoTrackOffset(void) const { return mAutoTrackOffset; }
00548         
00554         Viewport* getViewport(void) const {return mLastViewport;}
00556         void _notifyViewport(Viewport* viewport) {mLastViewport = viewport;}
00557 
00565         void setAutoAspectRatio(bool autoratio);
00566 
00569         bool getAutoAspectRatio(void) const;
00570 
00582         void setCullingFrustum(Frustum* frustum) { mCullFrustum = frustum; }
00584         Frustum* getCullingFrustum(void) const { return mCullFrustum; }
00585 
00590         virtual void forwardIntersect(const Plane& worldPlane, vector<Vector4>::type* intersect3d) const;
00591 
00593         bool isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy = 0) const;
00595         bool isVisible(const Sphere& bound, FrustumPlane* culledBy = 0) const;
00597         bool isVisible(const Vector3& vert, FrustumPlane* culledBy = 0) const;
00599         const Vector3* getWorldSpaceCorners(void) const;
00601         const Plane& getFrustumPlane( unsigned short plane ) const;
00603         bool projectSphere(const Sphere& sphere, 
00604             Real* left, Real* top, Real* right, Real* bottom) const;
00606         Real getNearClipDistance(void) const;
00608         Real getFarClipDistance(void) const;
00610         const Matrix4& getViewMatrix(void) const;
00619         const Matrix4& getViewMatrix(bool ownFrustumOnly) const;
00625         virtual void setUseRenderingDistance(bool use) { mUseRenderingDistance = use; }
00629         virtual bool getUseRenderingDistance(void) const { return mUseRenderingDistance; }
00630 
00637         virtual void synchroniseBaseSettingsWith(const Camera* cam);
00638 
00640         const Vector3& getPositionForViewUpdate(void) const;
00642         const Quaternion& getOrientationForViewUpdate(void) const;
00643      };
00647 } // namespace Ogre
00648 #endif

Copyright © 2008 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:51