1 // Copyright (C) 2006-2009 Mathias Froehlich - Mathias.Froehlich@web.de
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
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 GNU
11 // Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #ifndef SIMGEAR_SCENE_UTILS_OSGMATH_HXX
19 #define SIMGEAR_SCENE_UTILS_OSGMATH_HXX
30 #include <simgear/math/SGMath.hxx>
34 toSG(const osg::Vec2d& v)
35 { return SGVec2d(v[0], v[1]); }
39 toSG(const osg::Vec2f& v)
40 { return SGVec2f(v[0], v[1]); }
44 toOsg(const SGVec2d& v)
45 { return osg::Vec2d(v[0], v[1]); }
49 toOsg(const SGVec2f& v)
50 { return osg::Vec2f(v[0], v[1]); }
54 toSG(const osg::Vec3d& v)
55 { return SGVec3d(v[0], v[1], v[2]); }
59 toSG(const osg::Vec3f& v)
60 { return SGVec3f(v[0], v[1], v[2]); }
64 toOsg(const SGVec3d& v)
65 { return osg::Vec3d(v[0], v[1], v[2]); }
69 toOsg(const SGVec3f& v)
70 { return osg::Vec3f(v[0], v[1], v[2]); }
74 toSG(const osg::Vec4d& v)
75 { return SGVec4d(v[0], v[1], v[2], v[3]); }
79 toSG(const osg::Vec4f& v)
80 { return SGVec4f(v[0], v[1], v[2], v[3]); }
84 toOsg(const SGVec4d& v)
85 { return osg::Vec4d(v[0], v[1], v[2], v[3]); }
89 toOsg(const SGVec4f& v)
90 { return osg::Vec4f(v[0], v[1], v[2], v[3]); }
94 toSG(const osg::Quat& q)
95 { return SGQuatd(q[0], q[1], q[2], q[3]); }
99 toOsg(const SGQuatd& q)
100 { return osg::Quat(q[0], q[1], q[2], q[3]); }
102 // Create a local coordinate frame in the earth-centered frame of
103 // reference. X points north, Z points down.
104 // makeSimulationFrameRelative() only includes rotation.
107 makeSimulationFrameRelative(const SGGeod& geod)
108 { return osg::Matrix(toOsg(SGQuatd::fromLonLat(geod))); }
112 makeSimulationFrame(const SGGeod& geod)
114 osg::Matrix result(makeSimulationFrameRelative(geod));
116 SGGeodesy::SGGeodToCart(geod, coord);
117 result.setTrans(toOsg(coord));
121 // Create a Z-up local coordinate frame in the earth-centered frame
122 // of reference. This is what scenery models, etc. expect.
123 // makeZUpFrameRelative() only includes rotation.
126 makeZUpFrameRelative(const SGGeod& geod)
128 osg::Matrix result(makeSimulationFrameRelative(geod));
129 // 180 degree rotation around Y axis
130 result.preMultRotate(osg::Quat(0.0, 1.0, 0.0, 0.0));
136 makeZUpFrame(const SGGeod& geod)
138 osg::Matrix result(makeZUpFrameRelative(geod));
140 SGGeodesy::SGGeodToCart(geod, coord);
141 result.setTrans(toOsg(coord));