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-2012 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
    00180         bool mUseMinPixelSize;
    00182         Real mPixelDisplayRatio;
    00183
    00184         typedef vector<Listener*>::type ListenerList;
    00185         ListenerList mListeners;
    00186
    00187
    00188         // Internal functions for calcs
    00189         bool isViewOutOfDate(void) const;
    00191         void invalidateFrustum(void) const;
    00193         void invalidateView(void) const;
    00194
    00195
    00200         virtual void setWindowImpl(void) const;
    00201
    00203         virtual vector<Vector4>::type getRayForwardIntersect(const Vector3& anchor, const Vector3 *dir, Real planeOffset) const;
    00204
    00205     public:
    00208         Camera( const String& name, SceneManager* sm);
    00209
    00212         virtual ~Camera();
    00213
    00215         virtual void addListener(Listener* l);
    00217         virtual void removeListener(Listener* l);
    00218
    00221         SceneManager* getSceneManager(void) const;
    00222
    00230         void setPolygonMode(PolygonMode sd);
    00231
    00234         PolygonMode getPolygonMode(void) const;
    00235
    00238         void setPosition(Real x, Real y, Real z);
    00239
    00242         void setPosition(const Vector3& vec);
    00243
    00246         const Vector3& getPosition(void) const;
    00247
    00250         void move(const Vector3& vec);
    00251
    00254         void moveRelative(const Vector3& vec);
    00255
    00261         void setDirection(Real x, Real y, Real z);
    00262
    00265         void setDirection(const Vector3& vec);
    00266
    00267         /* Gets the camera's direction.
    00268         */
    00269         Vector3 getDirection(void) const;
    00270
    00273         Vector3 getUp(void) const;
    00274
    00277         Vector3 getRight(void) const;
    00278
    00287         void lookAt( const Vector3& targetPoint );
    00300         void lookAt(Real x, Real y, Real z);
    00301
    00304         void roll(const Radian& angle);
    00305
    00308         void yaw(const Radian& angle);
    00309
    00312         void pitch(const Radian& angle);
    00313
    00316         void rotate(const Vector3& axis, const Radian& angle);
    00317
    00320         void rotate(const Quaternion& q);
    00321
    00341         void setFixedYawAxis( bool useFixed, const Vector3& fixedAxis = Vector3::UNIT_Y );
    00342
    00343
    00346         const Quaternion& getOrientation(void) const;
    00347
    00350         void setOrientation(const Quaternion& q);
    00351
    00356         void _renderScene(Viewport *vp, bool includeOverlays);
    00357
    00360         _OgreExport friend std::ostream& operator<<(std::ostream& o, const Camera& c);
    00361
    00364         void _notifyRenderedFaces(unsigned int numfaces);
    00365
    00368         void _notifyRenderedBatches(unsigned int numbatches);
    00369
    00372         unsigned int _getNumRenderedFaces(void) const;
    00373
    00376         unsigned int _getNumRenderedBatches(void) const;
    00377
    00380         const Quaternion& getDerivedOrientation(void) const;
    00383         const Vector3& getDerivedPosition(void) const;
    00386         Vector3 getDerivedDirection(void) const;
    00389         Vector3 getDerivedUp(void) const;
    00392         Vector3 getDerivedRight(void) const;
    00393
    00396         const Quaternion& getRealOrientation(void) const;
    00399         const Vector3& getRealPosition(void) const;
    00402         Vector3 getRealDirection(void) const;
    00405         Vector3 getRealUp(void) const;
    00408         Vector3 getRealRight(void) const;
    00409
    00411         void getWorldTransforms(Matrix4* mat) const;
    00412
    00414         const String& getMovableType(void) const;
    00415
    00435         void setAutoTracking(bool enabled, SceneNode* const target = 0,
    00436             const Vector3& offset = Vector3::ZERO);
    00437
    00438
    00454         void setLodBias(Real factor = 1.0);
    00455
    00460         Real getLodBias(void) const;
    00461
    00474         virtual void setLodCamera(const Camera* lodCam);
    00475
    00482         virtual const Camera* getLodCamera() const;
    00483
    00484
    00489         Ray getCameraToViewportRay(Real screenx, Real screeny) const;
    00495         void getCameraToViewportRay(Real screenx, Real screeny, Ray* outRay) const;
    00496
    00507         PlaneBoundedVolume getCameraToViewportBoxVolume(Real screenLeft,
    00508             Real screenTop, Real screenRight, Real screenBottom, bool includeFarPlane = false);
    00509
    00521         void getCameraToViewportBoxVolume(Real screenLeft,
    00522             Real screenTop, Real screenRight, Real screenBottom,
    00523             PlaneBoundedVolume* outVolume, bool includeFarPlane = false);
    00524
    00526         Real _getLodBiasInverse(void) const;
    00527
    00528
    00530         void _autoTrack(void);
    00531
    00532
    00542         virtual void setWindow (Real Left, Real Top, Real Right, Real Bottom);
    00544         virtual void resetWindow (void);
    00546         virtual bool isWindowSet(void) const { return mWindowSet; }
    00548         const vector<Plane>::type& getWindowPlanes(void) const;
    00549
    00551         Real getBoundingRadius(void) const;
    00553         SceneNode* getAutoTrackTarget(void) const { return mAutoTrackTarget; }
    00555         const Vector3& getAutoTrackOffset(void) const { return mAutoTrackOffset; }
    00556
    00562         Viewport* getViewport(void) const {return mLastViewport;}
    00564         void _notifyViewport(Viewport* viewport) {mLastViewport = viewport;}
    00565
    00573         void setAutoAspectRatio(bool autoratio);
    00574
    00577         bool getAutoAspectRatio(void) const;
    00578
    00590         void setCullingFrustum(Frustum* frustum) { mCullFrustum = frustum; }
    00592         Frustum* getCullingFrustum(void) const { return mCullFrustum; }
    00593
    00598         virtual void forwardIntersect(const Plane& worldPlane, vector<Vector4>::type* intersect3d) const;
    00599
    00601         bool isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy = 0) const;
    00603         bool isVisible(const Sphere& bound, FrustumPlane* culledBy = 0) const;
    00605         bool isVisible(const Vector3& vert, FrustumPlane* culledBy = 0) const;
    00607         const Vector3* getWorldSpaceCorners(void) const;
    00609         const Plane& getFrustumPlane( unsigned short plane ) const;
    00611         bool projectSphere(const Sphere& sphere,
    00612             Real* left, Real* top, Real* right, Real* bottom) const;
    00614         Real getNearClipDistance(void) const;
    00616         Real getFarClipDistance(void) const;
    00618         const Matrix4& getViewMatrix(void) const;
    00627         const Matrix4& getViewMatrix(bool ownFrustumOnly) const;
    00633         virtual void setUseRenderingDistance(bool use) { mUseRenderingDistance = use; }
    00637         virtual bool getUseRenderingDistance(void) const { return mUseRenderingDistance; }
    00638
    00645         virtual void synchroniseBaseSettingsWith(const Camera* cam);
    00646
    00648         const Vector3& getPositionForViewUpdate(void) const;
    00650         const Quaternion& getOrientationForViewUpdate(void) const;
    00651
    00657         void setUseMinPixelSize(bool enable) { mUseMinPixelSize = enable; }
    00661         bool getUseMinPixelSize() const { return mUseMinPixelSize; }
    00662
    00673         Real getPixelDisplayRatio() const { return mPixelDisplayRatio; }
    00674
    00675      };
    00679 } // namespace Ogre
    00680 #endif

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:20