root/OpenSceneGraph/trunk/include/osg/View @ 8624

Revision 8624, 5.6 kB (checked in by robert, 6 years ago)

From Ulrich Hertlein, "attached are some minor tweaks:

- fixed typos in osgViewer/ViewerBase
- const-ness in include/osg/View findSlaveIndexForCamera
- supported options for STL reader, fixed return values to reflect proper errors
- supported options for DirectX reader, fixed return values
- normals pseudo-loader: scaling normals to a const (but variable) fraction of the bounding sphere radius
"

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under 
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSG_VIEW
15#define OSG_VIEW 1
16
17#include <osg/Camera>
18#include <osg/Light>
19
20#include <OpenThreads/Mutex>
21
22namespace osg {
23
24/** View - maintains a master camera view and a list of slave cameras that are relative to this master camera.
25  * Note, if no slave cameras are attached to the view then the master camera does both the control and implementation of the rendering of the scene,
26  * but if slave cameras are present then the master controls the view onto the scene, while the slaves implement the rendering of the scene.
27*/
28class OSG_EXPORT View : public virtual osg::Object
29{
30    public :
31
32        View();
33
34        View(const osg::View& view, const osg::CopyOp& copyop=CopyOp::SHALLOW_COPY);
35
36        META_Object(osg,View);
37       
38        /** Take all the settings, Camera and Slaves from the passed in view, leaving it empty. */
39        virtual void take(View& rhs);
40
41        /** Options for controlling the global lighting used for the view.*/
42        enum LightingMode
43        {
44            NO_LIGHT,
45            HEADLIGHT,
46            SKY_LIGHT
47        };
48       
49        /** Set the global lighting to use for this view.
50          * Defaults to headlight. */
51        void setLightingMode(LightingMode lightingMode);
52
53        /** Get the global lighting used for this view.*/
54        LightingMode getLightingMode() const { return _lightingMode; }
55
56        /** Get the global light.*/
57        void setLight(osg::Light* light) { _light = light; }
58
59        /** Get the global lighting if assigned.*/
60        osg::Light* getLight() { return _light.get(); }
61
62        /** Get the const global lighting if assigned.*/
63        const osg::Light* getLight() const { return _light.get(); }
64
65        /** Set the master camera of the view. */       
66        void setCamera(osg::Camera* camera);
67
68        /** Get the master camera of the view. */       
69        osg::Camera* getCamera() { return _camera.get(); }
70
71        /** Get the const master camera of the view. */       
72        const osg::Camera* getCamera() const { return _camera.get(); }
73
74        /** Set the frame stamp of the view. */       
75        void setFrameStamp(osg::FrameStamp* fs) { _frameStamp = fs; }
76
77        /** Get the frame stamp of the view. */       
78        osg::FrameStamp* getFrameStamp() { return _frameStamp.get(); }
79
80        /** Get the frame stamp of the view. */       
81        const osg::FrameStamp* getFrameStamp() const { return _frameStamp.get(); }
82
83        /** Slave allows one to up a camera that follows the master with a local offset to the project and view matrices.*/
84        struct Slave
85        {
86            Slave(bool useMastersSceneData=true):
87                _useMastersSceneData(useMastersSceneData) {}
88               
89            Slave(osg::Camera* camera, const osg::Matrixd& projectionOffset, const osg::Matrixd& viewOffset, bool useMastersSceneData=true):
90                _camera(camera),
91                _projectionOffset(projectionOffset),
92                _viewOffset(viewOffset),
93                _useMastersSceneData(useMastersSceneData) {}
94       
95            Slave(const Slave& rhs) :
96                _camera(rhs._camera),
97                _projectionOffset(rhs._projectionOffset),
98                _viewOffset(rhs._viewOffset),
99                _useMastersSceneData(rhs._useMastersSceneData) {}
100
101            Slave& operator = (const Slave& rhs)
102            {
103                _camera = rhs._camera;
104                _projectionOffset = rhs._projectionOffset;
105                _viewOffset = rhs._viewOffset;
106                _useMastersSceneData = rhs._useMastersSceneData;
107                return *this;
108            }
109
110            osg::ref_ptr<osg::Camera>   _camera;
111            osg::Matrixd                _projectionOffset;
112            osg::Matrixd                _viewOffset;
113            bool                        _useMastersSceneData;
114        };
115
116        bool addSlave(osg::Camera* camera, bool useMastersSceneData=true) { return addSlave(camera, osg::Matrix::identity(), osg::Matrix::identity(), useMastersSceneData); }
117
118        bool addSlave(osg::Camera* camera, const osg::Matrix& projectionOffset, const osg::Matrix& viewOffset, bool useMastersSceneData=true);
119
120        bool removeSlave(unsigned int pos);
121
122        unsigned int getNumSlaves() const { return _slaves.size(); }
123
124        Slave& getSlave(unsigned int pos) { return _slaves[pos]; }
125        const Slave& getSlave(unsigned int pos) const { return _slaves[pos]; }
126
127        unsigned int findSlaveIndexForCamera(osg::Camera* camera) const;
128
129        Slave * findSlaveForCamera(osg::Camera* camera);
130
131        void updateSlaves();
132
133        void updateSlave(unsigned int i);
134
135
136    protected :
137
138        virtual ~View();
139
140        virtual osg::GraphicsOperation* createRenderer(osg::Camera*) { return 0; }
141
142        LightingMode                    _lightingMode;
143        osg::ref_ptr<osg::Light>        _light;
144
145        osg::ref_ptr<osg::Camera>       _camera;
146       
147        typedef std::vector<Slave>      Slaves;
148        Slaves                          _slaves;
149
150        osg::ref_ptr<osg::FrameStamp>   _frameStamp;
151};
152
153}
154
155#endif
Note: See TracBrowser for help on using the browser.