]> git.mxchange.org Git - simgear.git/blob - simgear/scene/util/SGCoreOSGDependant.cxx
math: Move lerp function into SGMisc.
[simgear.git] / simgear / scene / util / SGCoreOSGDependant.cxx
1
2
3 // Copyright (C) 2011  Curtis L Olson <curt@flightgear.org>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Library General Public
7 // License as published by the Free Software Foundation; either
8 // version 2 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // Library 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, MA  02110-1301, USA.
18 //
19
20 #ifdef HAVE_CONFIG_H
21 #  include <simgear_config.h>
22 #endif
23
24 #include <simgear/math/SGMath.hxx>
25
26 #include <osg/Math>
27 #include <osg/Matrixd>
28
29 osg::Matrix SGGeod::makeSimulationFrameRelative() const
30 {
31     SGQuatd hlOr = SGQuatd::fromLonLat(*this);
32     return osg::Matrix(toOsg(hlOr));
33 }
34
35 osg::Matrix SGGeod::makeSimulationFrame() const
36 {
37     osg::Matrix result(makeSimulationFrameRelative());
38     SGVec3d coord;
39     SGGeodesy::SGGeodToCart(*this, coord);
40     result.setTrans(toOsg(coord));
41     return result;
42 }
43
44 osg::Matrix SGGeod::makeZUpFrameRelative() const
45 {
46     osg::Matrix result(makeSimulationFrameRelative());
47     // 180 degree rotation around Y axis
48     osg::Quat flip(0.0, 1.0, 0.0, 0.0);
49     result.preMult(osg::Matrix(flip));
50     return result;
51 }
52
53 osg::Matrix SGGeod::makeZUpFrame() const
54 {
55     osg::Matrix result(makeZUpFrameRelative());
56     SGVec3d coord;
57     SGGeodesy::SGGeodToCart(*this, coord);
58     result.setTrans(toOsg(coord));
59     return result;
60 }
61