⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 camera.h

📁 最新osg包
💻 H
📖 第 1 页 / 共 2 页
字号:
/* -*-c++-*- Producer - Copyright (C) 2001-2004  Don Burns * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version.  The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * OpenSceneGraph Public License for more details. */#ifndef OSGPRODUCER_CAMERA#define OSGPRODUCER_CAMERA#include <osg/Referenced>#include <osg/Matrix>#include <osg/Vec3>#include "RenderSurface.h"#include <vector>namespace osgProducer {class CameraGroup;class RenderSurface;/**    \class Camera    \brief A Camera provides a programming interface for 3D     graphics applications by means of an abstract camera analogy     The Camera contains a Lens class and has a RenderSurface.  Methods     are provided to give the programmer control over the OpenGL PROJECTION     matrix throught the Lens and over the initial MODELVIEW matrix through     the camera's position and attitude.      The programmer must provide a class derived from Camera::SceneHandler    to prepare and render the scene.  The Camera does not provide direct     control over rendering itself.  */      class Camera : public osg::Referenced{    public :         /**             \class SceneHandler            \brief A Scene Handler handles the preparation and rendering                   of a scene for Camera         */        /**             \class Lens            \brief A Lens provides control over the PROJECTION matrix.            It is entirely contained within the Camera class.  A Lens may             be of type Perspective or Orthographic and set with one of the             setFrustum, setProjection() or setOrtho().  The Lens type is             implied by the method used to set it */         class Lens : public osg::Referenced         {            public :                /** Projection types */                enum Projection {                    Perspective,                    Orthographic,                    Manual                };                Lens();                /** setMatrix() exists to allow external projection-management tools                    (like elumens' spiclops) to do their magic and still work with producer */                void setMatrix( const osg::Matrix::value_type matrix[16] );                /** Set the Projection type to be of Perspective and provide                    the following parameters to set the Projection matrix.                         hfov  - Horizontal Field of View in degrees                         vfov  - Vertical Field of View in degrees                         nearClip  - Distance from the viewer to the near plane of the                                  viewing frustum.                         farClip   - Distance from the viewer to the far plane of the                                  viewing frustum.                         xshear- Assymetrical shear in viewing frustum in the horizontal                                  direction.  Value given in normalized device coordinates                                  (see setShear() below).                         yshear- Assymetrical shear in viewing frustum in the vertical                                  direction.  Value given in normalized device coordinates                                  (see setShear() below).                 */                void setPerspective( double hfov, double vfov,                         double nearClip, double farClip );                /** Set the Projection type to be of Perspective and provide                    the dimensions of the left, right, bottom, top, nearClip and farClip                    extents of the viewing frustum as indicated.                         xshear- Assymetrical shear in viewing frustum in the horizontal                                  direction.  Value given in normalized device coordinates                                  (see setShear() below).                         yshear- Assymetrical shear in viewing frustum in the vertical                                  direction.  Value given in normalized device coordinates                                  (see setShear() below).                 */                void setFrustum( double left, double right,                                  double bottom, double top,                                  double nearClip, double farClip );                /** Set the Projection type to be of Orthographic and provide                     the left, right, bottom dimensions of the 2D rectangle*/                   void setOrtho( double left, double right,                         double bottom, double top,                         double nearClip, double farClip  );                /** convertToOrtho() converts the current perspective view to an                     orthographic view with dimensions that conserve the scale of the                     objects at distance d.                     convertToPerspective() converts the current orthographic view                     to a perspective view with parameters that conserve the scale of                    objects at distance d. */                bool convertToOrtho( float d);                bool convertToPerspective( float d);                /** apply the lens.  This generates a projection matrix for OpenGL */                void apply(float xshear=0.0f, float yshear=0.0);                void generateMatrix( float xshear, float yshear, osg::Matrix::value_type matrix[16] );                Projection getProjectionType() const { return _projection; }                void getParams( double &left, double &right, double &bottom, double &top,                                double &nearClip, double &farClip ); //, double &xshear, double &yshear );                float getHorizontalFov() const { return osg::RadiansToDegrees(_hfov); }                float getVerticalFov() const { return osg::RadiansToDegrees(_vfov); }                void setAutoAspect(bool ar) { _auto_aspect = ar; }                bool getAutoAspect() const { return _auto_aspect; }                void setAspectRatio( double aspectRatio );                double getAspectRatio() { return _aspect_ratio; }            protected:                ~Lens(){}                /* Internal convenience methods */                bool getFrustum( double& left, double& right,                                       double& bottom, double& top,                                       double& zNear, double& zFar ) const;                bool getOrtho( double& left, double& right,                                       double& bottom, double& top,                                       double& zNear, double& zFar ) const;            private :                   double _ortho_left, _ortho_right, _ortho_bottom, _ortho_top;                double _left, _right, _bottom, _top, _nearClip, _farClip;                Projection _projection;                double _aspect_ratio;                bool _auto_aspect;                float _hfov, _vfov;                osg::Matrix::value_type _matrix[16];            private :                void _updateFOV( void );        };        struct Offset {            enum MultiplyMethod {                PreMultiply,                PostMultiply            };            double _xshear;            double _yshear;            osg::Matrix::value_type _matrix[16];            MultiplyMethod _multiplyMethod;            Offset():                _xshear(0.0),                _yshear(0.0),                _multiplyMethod(PreMultiply) {}        };    public :        Camera( void );        void setRenderSurface( RenderSurface *rs ) { _rs = rs; }        RenderSurface *getRenderSurface() { return _rs.get(); }        const RenderSurface *getRenderSurface() const { return _rs.get(); }        void setRenderSurfaceWindowRectangle( int x, int y, unsigned int width, unsigned int height, bool resize=true )        { _rs->setWindowRectangle(x,y,width,height, resize); }        void  setLens( Lens *lens )         {             if( _lens.get() != lens )                _lens = lens; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -