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 {
35 // Need to traverse all children, else some LOD nodes do not get updated
36 // Note that the broad number of updates is not done due to
37 // the update callback in the global position node.
38 setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN);
41 void setViewData(const SGVec3d& globalEyePos,
42 const SGQuatd& globalViewOrientation)
44 mGlobalGeodEyePos = SGGeod::fromCart(globalEyePos);
45 mGlobalEyePos = globalEyePos;
46 mGlobalViewOr = globalViewOrientation;
47 mGlobalHorizLocalOr = SGQuatd::fromLonLat(mGlobalGeodEyePos);
48 mHorizLocalNorth = mGlobalHorizLocalOr.backTransform(SGVec3d(1, 0, 0));
49 mHorizLocalEast = mGlobalHorizLocalOr.backTransform(SGVec3d(0, 1, 0));
50 mHorizLocalDown = mGlobalHorizLocalOr.backTransform(SGVec3d(0, 0, 1));
53 void setVisibility(double visibility)
55 if (mVisibility == visibility)
57 mVisibility = visibility;
58 mSqrVisibility = visibility*visibility;
60 double m_log01 = -log( 0.01 );
61 double sqrt_m_log01 = sqrt( m_log01 );
62 double fog_exp_density = m_log01 / visibility;
63 double fog_exp2_density = sqrt_m_log01 / visibility;
64 double ground_exp2_punch_through = sqrt_m_log01 / (visibility * 1.5);
65 double rwy_exp2_punch_through, taxi_exp2_punch_through;
66 if ( visibility < 8000 ) {
67 rwy_exp2_punch_through = sqrt_m_log01 / (visibility * 2.5);
68 taxi_exp2_punch_through = sqrt_m_log01 / (visibility * 1.5);
70 rwy_exp2_punch_through = sqrt_m_log01 / ( 8000 * 2.5 );
71 taxi_exp2_punch_through = sqrt_m_log01 / ( 8000 * 1.5 );
74 mFogExpDensity = fog_exp_density;
75 mFogExp2Density = fog_exp2_density;
76 mRunwayFogExp2Density = rwy_exp2_punch_through;
77 mTaxiFogExp2Density = taxi_exp2_punch_through;
78 mGroundLightsFogExp2Density = ground_exp2_punch_through;
81 double getVisibility() const
82 { return mVisibility; }
83 double getSqrVisibility() const
84 { return mSqrVisibility; }
86 double getFogExpDensity() const
87 { return mFogExpDensity; }
88 double getFogExp2Density() const
89 { return mFogExp2Density; }
90 double getRunwayFogExp2Density() const
91 { return mRunwayFogExp2Density; }
92 double getTaxiFogExp2Density() const
93 { return mTaxiFogExp2Density; }
94 double getGroundLightsFogExp2Density() const
95 { return mGroundLightsFogExp2Density; }
97 const SGVec3d& getGlobalEyePos() const
98 { return mGlobalEyePos; }
99 const SGGeod& getGeodEyePos() const
100 { return mGlobalGeodEyePos; }
101 const SGQuatd& getGlobalViewOr() const
102 { return mGlobalViewOr; }
103 const SGQuatd& getGlobalHorizLocalOr() const
104 { return mGlobalViewOr; }
105 const SGVec3d& getHorizLocalNorth() const
106 { return mHorizLocalNorth; }
107 const SGVec3d& getHorizLocalEast() const
108 { return mHorizLocalEast; }
109 const SGVec3d& getHorizLocalDown() const
110 { return mHorizLocalDown; }
112 void setLight(const SGVec3f& direction, const SGVec4f& ambient,
113 const SGVec4f& diffuse, const SGVec4f& specular,
114 const SGVec4f& fogColor, double sunAngleDeg)
116 mLightDirection = direction;
117 mAmbientLight = ambient;
118 mDiffuseLight = diffuse;
119 mSpecularLight = specular;
120 mFogColor = fogColor;
121 mSunAngleDeg = sunAngleDeg;
124 const SGVec3f& getLightDirection() const
125 { return mLightDirection; }
126 const SGVec4f& getAmbientLight() const
127 { return mAmbientLight; }
128 const SGVec4f& getDiffuseLight() const
129 { return mDiffuseLight; }
130 const SGVec4f& getSpecularLight() const
131 { return mSpecularLight; }
132 const SGVec4f& getFogColor() const
133 { return mFogColor; }
135 double getSunAngleDeg() const
136 { return mSunAngleDeg; }
139 SGGeod mGlobalGeodEyePos;
140 SGVec3d mGlobalEyePos;
141 SGQuatd mGlobalViewOr;
142 SGQuatd mGlobalHorizLocalOr;
143 SGVec3d mHorizLocalNorth;
144 SGVec3d mHorizLocalEast;
145 SGVec3d mHorizLocalDown;
148 double mSqrVisibility;
149 double mFogExpDensity;
150 double mFogExp2Density;
151 double mRunwayFogExp2Density;
152 double mTaxiFogExp2Density;
153 double mGroundLightsFogExp2Density;
155 SGVec3f mLightDirection;
156 SGVec4f mAmbientLight;
157 SGVec4f mDiffuseLight;
158 SGVec4f mSpecularLight;