1 // placementtrans.hxx -- class for carrying transforms for placing models in the world
3 // Written by Mathias Froehlich, started April 2005.
5 // Copyright (C) 2005 Mathias Froehlich
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 # include <simgear_config.h>
27 # error This library requires C++
30 #include <simgear/compiler.h>
31 #include <simgear/constants.h>
33 #include "placementtrans.hxx"
35 SGPlacementTransform::SGPlacementTransform(void) :
36 _placement_offset(0, 0, 0),
37 _scenery_center(0, 0, 0),
45 SGPlacementTransform::~SGPlacementTransform(void)
50 SGPlacementTransform::computeLocalToWorldMatrix(osg::Matrix& matrix,
51 osg::NodeVisitor*) const
54 for (int i = 0; i < 3; ++i) {
55 for (int j = 0; j < 3; ++j) {
56 t(j, i) = _rotation(i, j);
58 t(3, i) = _placement_offset(i) - _scenery_center(i);
61 if (_referenceFrame == RELATIVE_RF)
69 SGPlacementTransform::computeWorldToLocalMatrix(osg::Matrix& matrix,
70 osg::NodeVisitor*) const
73 for (int i = 0; i < 3; ++i) {
74 for (int j = 0; j < 3; ++j) {
75 t(j, i) = _rotation(i, j);
77 t(3, i) = _placement_offset(i) - _scenery_center(i);
79 t = osg::Matrix::inverse(t);
81 if (_referenceFrame == RELATIVE_RF)