# 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-2006 Torus Knot Software Ltd
    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 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef __Camera_H__
    00030 #define __Camera_H__
    00031
    00032 // Default options
    00033 #include "OgrePrerequisites.h"
    00034
    00035 #include "OgreString.h"
    00036 #include "OgreMovableObject.h"
    00037
    00038 // Matrices & Vectors
    00039 #include "OgreMatrix4.h"
    00040 #include "OgreVector3.h"
    00041 #include "OgrePlane.h"
    00042 #include "OgreQuaternion.h"
    00043 #include "OgreCommon.h"
    00044 #include "OgreFrustum.h"
    00045 #include "OgreRay.h"
    00046 #include "OgrePlaneBoundedVolume.h"
    00047
    00048
    00049 namespace Ogre {
    00050
    00051
    00052
    00081     class _OgreExport Camera : public Frustum
    00082     {
    00083     protected:
    00085         String mName;
    00087         SceneManager *mSceneMgr;
    00088
    00090         Quaternion mOrientation;
    00091
    00093         Vector3 mPosition;
    00094
    00096         mutable Quaternion mDerivedOrientation;
    00097         mutable Vector3 mDerivedPosition;
    00098
    00100         mutable Quaternion mRealOrientation;
    00101         mutable Vector3 mRealPosition;
    00102
    00104         bool mYawFixed;
    00106         Vector3 mYawFixedAxis;
    00107
    00109         PolygonMode mSceneDetail;
    00110
    00112         unsigned int mVisFacesLastRender;
    00113
    00115         unsigned int mVisBatchesLastRender;
    00116
    00118         static String msMovableType;
    00119
    00121         SceneNode* mAutoTrackTarget;
    00123         Vector3 mAutoTrackOffset;
    00124
    00125         // Scene LOD factor used to adjust overall LOD
    00126         Real mSceneLodFactor;
    00128         Real mSceneLodFactorInv;
    00129
    00130
    00135         Real mWLeft, mWTop, mWRight, mWBottom;
    00137         bool mWindowSet;
    00139         mutable std::vector<Plane> mWindowClipPlanes;
    00140         // Was viewing window changed.
    00141         mutable bool mRecalcWindow;
    00143         Viewport* mLastViewport;
    00147         bool mAutoAspectRatio;
    00149         Frustum *mCullFrustum;
    00151         bool mUseRenderingDistance;
    00153         const Camera* mLodCamera;
    00154
    00155
    00156         // Internal functions for calcs
    00157         bool isViewOutOfDate(void) const;
    00159         void invalidateFrustum(void) const;
    00161         void invalidateView(void) const;
    00162
    00163
    00168         virtual void setWindowImpl(void) const;
    00169
    00171         virtual std::vector<Vector4> getRayForwardIntersect(const Vector3& anchor, const Vector3 *dir, Real planeOffset) const;
    00172
    00173     public:
    00176         Camera( const String& name, SceneManager* sm);
    00177
    00180         virtual ~Camera();
    00181
    00182
    00185         SceneManager* getSceneManager(void) const;
    00186
    00189         virtual const String& getName(void) const;
    00190
    00191
    00199         void setPolygonMode(PolygonMode sd);
    00200
    00203         PolygonMode getPolygonMode(void) const;
    00204
    00207         void setPosition(Real x, Real y, Real z);
    00208
    00211         void setPosition(const Vector3& vec);
    00212
    00215         const Vector3& getPosition(void) const;
    00216
    00219         void move(const Vector3& vec);
    00220
    00223         void moveRelative(const Vector3& vec);
    00224
    00230         void setDirection(Real x, Real y, Real z);
    00231
    00234         void setDirection(const Vector3& vec);
    00235
    00236         /* Gets the camera's direction.
    00237         */
    00238         Vector3 getDirection(void) const;
    00239
    00242         Vector3 getUp(void) const;
    00243
    00246         Vector3 getRight(void) const;
    00247
    00256         void lookAt( const Vector3& targetPoint );
    00269         void lookAt(Real x, Real y, Real z);
    00270
    00273         void roll(const Radian& angle);
    00274
    00277         void yaw(const Radian& angle);
    00278
    00281         void pitch(const Radian& angle);
    00282
    00285         void rotate(const Vector3& axis, const Radian& angle);
    00286
    00289         void rotate(const Quaternion& q);
    00290
    00310         void setFixedYawAxis( bool useFixed, const Vector3& fixedAxis = Vector3::UNIT_Y );
    00311
    00312
    00315         const Quaternion& getOrientation(void) const;
    00316
    00319         void setOrientation(const Quaternion& q);
    00320
    00325         void _renderScene(Viewport *vp, bool includeOverlays);
    00326
    00329         _OgreExport friend std::ostream& operator<<(std::ostream& o, const Camera& c);
    00330
    00333         void _notifyRenderedFaces(unsigned int numfaces);
    00334
    00337         void _notifyRenderedBatches(unsigned int numbatches);
    00338
    00341         unsigned int _getNumRenderedFaces(void) const;
    00342
    00345         unsigned int _getNumRenderedBatches(void) const;
    00346
    00349         const Quaternion& getDerivedOrientation(void) const;
    00352         const Vector3& getDerivedPosition(void) const;
    00355         Vector3 getDerivedDirection(void) const;
    00358         Vector3 getDerivedUp(void) const;
    00361         Vector3 getDerivedRight(void) const;
    00362
    00365         const Quaternion& getRealOrientation(void) const;
    00368         const Vector3& getRealPosition(void) const;
    00371         Vector3 getRealDirection(void) const;
    00374         Vector3 getRealUp(void) const;
    00377         Vector3 getRealRight(void) const;
    00378
    00380         const String& getMovableType(void) const;
    00381
    00401         void setAutoTracking(bool enabled, SceneNode* target = 0,
    00402             const Vector3& offset = Vector3::ZERO);
    00403
    00404
    00420         void setLodBias(Real factor = 1.0);
    00421
    00426         Real getLodBias(void) const;
    00427
    00440         virtual void setLodCamera(const Camera* lodCam);
    00441
    00448         virtual const Camera* getLodCamera() const;
    00449
    00450
    00455         Ray getCameraToViewportRay(Real screenx, Real screeny) const;
    00461         void getCameraToViewportRay(Real screenx, Real screeny, Ray* outRay) const;
    00462
    00473         PlaneBoundedVolume getCameraToViewportBoxVolume(Real screenLeft,
    00474             Real screenTop, Real screenRight, Real screenBottom, bool includeFarPlane = false);
    00475
    00487         void getCameraToViewportBoxVolume(Real screenLeft,
    00488             Real screenTop, Real screenRight, Real screenBottom,
    00489             PlaneBoundedVolume* outVolume, bool includeFarPlane = false);
    00490
    00492         Real _getLodBiasInverse(void) const;
    00493
    00494
    00496         void _autoTrack(void);
    00497
    00498
    00508         virtual void setWindow (Real Left, Real Top, Real Right, Real Bottom);
    00510         virtual void resetWindow (void);
    00512         virtual bool isWindowSet(void) const { return mWindowSet; }
    00514         const std::vector<Plane>& getWindowPlanes(void) const;
    00515
    00517         Real getBoundingRadius(void) const;
    00519         SceneNode* getAutoTrackTarget(void) const { return mAutoTrackTarget; }
    00521         const Vector3& getAutoTrackOffset(void) const { return mAutoTrackOffset; }
    00522
    00528         Viewport* getViewport(void) const {return mLastViewport;}
    00530         void _notifyViewport(Viewport* viewport) {mLastViewport = viewport;}
    00531
    00539         void setAutoAspectRatio(bool autoratio);
    00540
    00543         bool getAutoAspectRatio(void) const;
    00544
    00556         void setCullingFrustum(Frustum* frustum) { mCullFrustum = frustum; }
    00558         Frustum* getCullingFrustum(void) const { return mCullFrustum; }
    00559
    00564         virtual void forwardIntersect(const Plane& worldPlane, std::vector<Vector4>* intersect3d) const;
    00565
    00567         bool isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy = 0) const;
    00569         bool isVisible(const Sphere& bound, FrustumPlane* culledBy = 0) const;
    00571         bool isVisible(const Vector3& vert, FrustumPlane* culledBy = 0) const;
    00573         const Vector3* getWorldSpaceCorners(void) const;
    00575         const Plane& getFrustumPlane( unsigned short plane ) const;
    00577         bool projectSphere(const Sphere& sphere,
    00578             Real* left, Real* top, Real* right, Real* bottom) const;
    00580         Real getNearClipDistance(void) const;
    00582         Real getFarClipDistance(void) const;
    00584         const Matrix4& getViewMatrix(void) const;
    00593         const Matrix4& getViewMatrix(bool ownFrustumOnly) const;
    00599         virtual void setUseRenderingDistance(bool use) { mUseRenderingDistance = use; }
    00603         virtual bool getUseRenderingDistance(void) const { return mUseRenderingDistance; }
    00604
    00611         virtual void synchroniseBaseSettingsWith(const Camera* cam);
    00612
    00614         const Vector3& getPositionForViewUpdate(void) const;
    00616         const Quaternion& getOrientationForViewUpdate(void) const;
    00617      };
    00618
    00619 } // namespace Ogre
    00620 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sat Apr 11 13:46:39 2009