]> git.mxchange.org Git - simgear.git/blob - simgear/scene/util/SGUpdateVisitor.hxx
Modified Files:
[simgear.git] / simgear / scene / util / SGUpdateVisitor.hxx
1 /* -*-c++-*-
2  *
3  * Copyright (C) 2006 Mathias Froehlich 
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18  * MA 02110-1301, USA.
19  *
20  */
21
22 #ifndef SG_SCENE_UPDATEVISITOR_HXX
23 #define SG_SCENE_UPDATEVISITOR_HXX
24
25 #include <osg/NodeVisitor>
26 #include <osgUtil/UpdateVisitor>
27
28 #include "simgear/math/SGMath.hxx"
29
30 class SGUpdateVisitor : public osgUtil::UpdateVisitor {
31 public:
32   SGUpdateVisitor()
33   {
34     // Need to traverse all children, else some LOD nodes do not get updated
35     // Note that the broad number of updates is not done due to
36     // the update callback in the global position node.
37     setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN);
38   }
39   void setViewData(const SGVec3d& globalEyePos,
40                    const SGQuatd& globalViewOrientation)
41   {
42     mGlobalGeodEyePos = SGGeod::fromCart(globalEyePos);
43     mGlobalEyePos = globalEyePos;
44     mGlobalViewOr = globalViewOrientation;
45     mGlobalHorizLocalOr = SGQuatd::fromLonLat(mGlobalGeodEyePos);
46     mHorizLocalNorth = mGlobalHorizLocalOr.backTransform(SGVec3d(1, 0, 0));
47     mHorizLocalEast = mGlobalHorizLocalOr.backTransform(SGVec3d(0, 1, 0));
48     mHorizLocalDown = mGlobalHorizLocalOr.backTransform(SGVec3d(0, 0, 1));
49   }
50
51   void setSceneryCenter(const SGVec3d& sceneryCenter)
52   {
53     mSceneryCenter = sceneryCenter;
54   }
55
56   void setVisibility(double visibility)
57   {
58     mVisibility = visibility;
59     mSqrVisibility = visibility*visibility;
60   }
61
62   double getVisibility() const
63   { return mVisibility; }
64   double getSqrVisibility() const
65   { return mSqrVisibility; }
66
67   const SGVec3d& getGlobalEyePos() const
68   { return mGlobalEyePos; }
69   const SGGeod& getGeodEyePos() const
70   { return mGlobalGeodEyePos; }
71   const SGQuatd& getGlobalViewOr() const
72   { return mGlobalViewOr; }
73   const SGQuatd& getGlobalHorizLocalOr() const
74   { return mGlobalViewOr; }
75   const SGVec3d& getHorizLocalNorth() const
76   { return mHorizLocalNorth; }
77   const SGVec3d& getHorizLocalEast() const
78   { return mHorizLocalEast; }
79   const SGVec3d& getHorizLocalDown() const
80   { return mHorizLocalDown; }
81
82   void setLight(const SGVec3f& direction, const SGVec4f& ambient,
83                 const SGVec4f& diffuse, const SGVec4f& specular)
84   {
85     mLightDirection = direction;
86     mAmbientLight = ambient;
87     mDiffuseLight = diffuse;
88   }
89
90   const SGVec3f& getLightDirection() const
91   { return mLightDirection; }
92   const SGVec4f& getAmbientLight() const
93   { return mAmbientLight; }
94   const SGVec4f& getDiffuseLight() const
95   { return mDiffuseLight; }
96   const SGVec4f& getSpecularLight() const
97   { return mSpecularLight; }
98
99 private:
100   SGGeod mGlobalGeodEyePos;
101   SGVec3d mGlobalEyePos;
102   SGQuatd mGlobalViewOr;
103   SGQuatd mGlobalHorizLocalOr;
104   SGVec3d mHorizLocalNorth;
105   SGVec3d mHorizLocalEast;
106   SGVec3d mHorizLocalDown;
107
108   SGVec3d mSceneryCenter;
109
110   double mVisibility;
111   double mSqrVisibility;
112
113   SGVec3f mLightDirection;
114   SGVec4f mAmbientLight;
115   SGVec4f mDiffuseLight;
116   SGVec4f mSpecularLight;
117 };
118
119 #endif