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-2013 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 #include "OgreHeaderPrefix.h"
00047 
00048 
00049 namespace Ogre {
00050 
00086     class _OgreExport Camera : public Frustum
00087     {
00088     public:
00091         class _OgreExport Listener 
00092         {
00093         public:
00094             Listener() {}
00095             virtual ~Listener() {}
00096 
00098             virtual void cameraPreRenderScene(Camera* cam)
00099                         { (void)cam; }
00100 
00102             virtual void cameraPostRenderScene(Camera* cam)
00103                         { (void)cam; }
00104 
00106             virtual void cameraDestroyed(Camera* cam)
00107                         { (void)cam; }
00108 
00109         };
00110     protected:
00112         SceneManager *mSceneMgr;
00113 
00115         Quaternion mOrientation;
00116 
00118         Vector3 mPosition;
00119 
00121         mutable Quaternion mDerivedOrientation;
00122         mutable Vector3 mDerivedPosition;
00123 
00125         mutable Quaternion mRealOrientation;
00126         mutable Vector3 mRealPosition;
00127 
00129         bool mYawFixed;
00131         Vector3 mYawFixedAxis;
00132 
00134         PolygonMode mSceneDetail;
00135 
00137         unsigned int mVisFacesLastRender;
00138 
00140         unsigned int mVisBatchesLastRender;
00141 
00143         static String msMovableType;
00144 
00146         SceneNode* mAutoTrackTarget;
00148         Vector3 mAutoTrackOffset;
00149 
00151         Real mSceneLodFactor;
00153         Real mSceneLodFactorInv;
00154 
00155 
00160         Real mWLeft, mWTop, mWRight, mWBottom;
00162         bool mWindowSet;
00164         mutable vector<Plane>::type mWindowClipPlanes;
00166         mutable bool mRecalcWindow;
00168         Viewport* mLastViewport;
00172         bool mAutoAspectRatio;
00174         Frustum *mCullFrustum;
00176         bool mUseRenderingDistance;
00178         const Camera* mLodCamera;
00179         
00181         bool mUseMinPixelSize;
00183         Real mPixelDisplayRatio;
00184 
00185         typedef vector<Listener*>::type ListenerList;
00186         ListenerList mListeners;
00187 
00188 
00189         // Internal functions for calcs
00190         bool isViewOutOfDate(void) const;
00192         void invalidateFrustum(void) const;
00194         void invalidateView(void) const;
00195 
00196 
00201         virtual void setWindowImpl(void) const;
00202 
00204         virtual vector<Vector4>::type getRayForwardIntersect(const Vector3& anchor, const Vector3 *dir, Real planeOffset) const;
00205 
00206     public:
00209         Camera( const String& name, SceneManager* sm);
00210 
00213         virtual ~Camera();
00214 
00216         virtual void addListener(Listener* l);
00218         virtual void removeListener(Listener* l);
00219 
00222         SceneManager* getSceneManager(void) const;
00223 
00231         void setPolygonMode(PolygonMode sd);
00232 
00235         PolygonMode getPolygonMode(void) const;
00236 
00239         void setPosition(Real x, Real y, Real z);
00240 
00243         void setPosition(const Vector3& vec);
00244 
00247         const Vector3& getPosition(void) const;
00248 
00251         void move(const Vector3& vec);
00252 
00255         void moveRelative(const Vector3& vec);
00256 
00262         void setDirection(Real x, Real y, Real z);
00263 
00266         void setDirection(const Vector3& vec);
00267 
00270         Vector3 getDirection(void) const;
00271 
00274         Vector3 getUp(void) const;
00275 
00278         Vector3 getRight(void) const;
00279 
00288         void lookAt( const Vector3& targetPoint );
00301         void lookAt(Real x, Real y, Real z);
00302 
00305         void roll(const Radian& angle);
00306 
00309         void yaw(const Radian& angle);
00310 
00313         void pitch(const Radian& angle);
00314 
00317         void rotate(const Vector3& axis, const Radian& angle);
00318 
00321         void rotate(const Quaternion& q);
00322 
00342         void setFixedYawAxis( bool useFixed, const Vector3& fixedAxis = Vector3::UNIT_Y );
00343 
00344 
00347         const Quaternion& getOrientation(void) const;
00348 
00351         void setOrientation(const Quaternion& q);
00352 
00357         void _renderScene(Viewport *vp, bool includeOverlays);
00358 
00361         _OgreExport friend std::ostream& operator<<(std::ostream& o, const Camera& c);
00362 
00365         void _notifyRenderedFaces(unsigned int numfaces);
00366 
00369         void _notifyRenderedBatches(unsigned int numbatches);
00370 
00373         unsigned int _getNumRenderedFaces(void) const;
00374 
00377         unsigned int _getNumRenderedBatches(void) const;
00378 
00381         const Quaternion& getDerivedOrientation(void) const;
00384         const Vector3& getDerivedPosition(void) const;
00387         Vector3 getDerivedDirection(void) const;
00390         Vector3 getDerivedUp(void) const;
00393         Vector3 getDerivedRight(void) const;
00394 
00397         const Quaternion& getRealOrientation(void) const;
00400         const Vector3& getRealPosition(void) const;
00403         Vector3 getRealDirection(void) const;
00406         Vector3 getRealUp(void) const;
00409         Vector3 getRealRight(void) const;
00410 
00412         void getWorldTransforms(Matrix4* mat) const;
00413 
00415         const String& getMovableType(void) const;
00416 
00436         void setAutoTracking(bool enabled, SceneNode* const target = 0, 
00437             const Vector3& offset = Vector3::ZERO);
00438 
00439 
00455         void setLodBias(Real factor = 1.0);
00456 
00461         Real getLodBias(void) const;
00462 
00475         virtual void setLodCamera(const Camera* lodCam);
00476 
00483         virtual const Camera* getLodCamera() const;
00484 
00485 
00490         Ray getCameraToViewportRay(Real screenx, Real screeny) const;
00496         void getCameraToViewportRay(Real screenx, Real screeny, Ray* outRay) const;
00497 
00508         PlaneBoundedVolume getCameraToViewportBoxVolume(Real screenLeft, 
00509             Real screenTop, Real screenRight, Real screenBottom, bool includeFarPlane = false);
00510 
00522         void getCameraToViewportBoxVolume(Real screenLeft, 
00523             Real screenTop, Real screenRight, Real screenBottom, 
00524             PlaneBoundedVolume* outVolume, bool includeFarPlane = false);
00525 
00527         Real _getLodBiasInverse(void) const;
00528 
00529 
00531         void _autoTrack(void);
00532 
00533 
00543         virtual void setWindow (Real left, Real top, Real right, Real bottom);
00545         virtual void resetWindow (void);
00547         virtual bool isWindowSet(void) const { return mWindowSet; }
00549         const vector<Plane>::type& getWindowPlanes(void) const;
00550 
00552         Real getBoundingRadius(void) const;
00554         SceneNode* getAutoTrackTarget(void) const { return mAutoTrackTarget; }
00556         const Vector3& getAutoTrackOffset(void) const { return mAutoTrackOffset; }
00557         
00563         Viewport* getViewport(void) const {return mLastViewport;}
00565         void _notifyViewport(Viewport* viewport) {mLastViewport = viewport;}
00566 
00574         void setAutoAspectRatio(bool autoratio);
00575 
00578         bool getAutoAspectRatio(void) const;
00579 
00591         void setCullingFrustum(Frustum* frustum) { mCullFrustum = frustum; }
00593         Frustum* getCullingFrustum(void) const { return mCullFrustum; }
00594 
00599         virtual void forwardIntersect(const Plane& worldPlane, vector<Vector4>::type* intersect3d) const;
00600 
00602         bool isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy = 0) const;
00604         bool isVisible(const Sphere& bound, FrustumPlane* culledBy = 0) const;
00606         bool isVisible(const Vector3& vert, FrustumPlane* culledBy = 0) const;
00608         const Vector3* getWorldSpaceCorners(void) const;
00610         const Plane& getFrustumPlane( unsigned short plane ) const;
00612         bool projectSphere(const Sphere& sphere, 
00613             Real* left, Real* top, Real* right, Real* bottom) const;
00615         Real getNearClipDistance(void) const;
00617         Real getFarClipDistance(void) const;
00619         const Matrix4& getViewMatrix(void) const;
00628         const Matrix4& getViewMatrix(bool ownFrustumOnly) const;
00634         virtual void setUseRenderingDistance(bool use) { mUseRenderingDistance = use; }
00638         virtual bool getUseRenderingDistance(void) const { return mUseRenderingDistance; }
00639 
00646         virtual void synchroniseBaseSettingsWith(const Camera* cam);
00647 
00649         const Vector3& getPositionForViewUpdate(void) const;
00651         const Quaternion& getOrientationForViewUpdate(void) const;
00652 
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 
00681 #include "OgreHeaderSuffix.h"
00682 
00683 #endif // __Camera_H__

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:40