3 * Copyright (C) 2006 Mathias Froehlich
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.
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.
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,
22 #ifndef SG_SCENE_UPDATEVISITOR_HXX
23 #define SG_SCENE_UPDATEVISITOR_HXX
25 #include <osg/NodeVisitor>
26 #include <osgUtil/UpdateVisitor>
28 #include "simgear/math/SGMath.hxx"
30 class SGUpdateVisitor : public osgUtil::UpdateVisitor {
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);
39 void setViewData(const SGVec3d& globalEyePos,
40 const SGQuatd& globalViewOrientation)
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));
51 void setSceneryCenter(const SGVec3d& sceneryCenter)
53 mSceneryCenter = sceneryCenter;
56 void setVisibility(double visibility)
58 mVisibility = visibility;
59 mSqrVisibility = visibility*visibility;
62 double getVisibility() const
63 { return mVisibility; }
64 double getSqrVisibility() const
65 { return mSqrVisibility; }
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; }
82 void setLight(const SGVec3f& direction, const SGVec4f& ambient,
83 const SGVec4f& diffuse, const SGVec4f& specular)
85 mLightDirection = direction;
86 mAmbientLight = ambient;
87 mDiffuseLight = diffuse;
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; }
100 SGGeod mGlobalGeodEyePos;
101 SGVec3d mGlobalEyePos;
102 SGQuatd mGlobalViewOr;
103 SGQuatd mGlobalHorizLocalOr;
104 SGVec3d mHorizLocalNorth;
105 SGVec3d mHorizLocalEast;
106 SGVec3d mHorizLocalDown;
108 SGVec3d mSceneryCenter;
111 double mSqrVisibility;
113 SGVec3f mLightDirection;
114 SGVec4f mAmbientLight;
115 SGVec4f mDiffuseLight;
116 SGVec4f mSpecularLight;