]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/placementtrans.cxx
Win32 compilation fix
[simgear.git] / simgear / scene / model / placementtrans.cxx
1 // placementtrans.hxx -- class for carrying transforms for placing models in the world
2 //
3 // Written by Mathias Froehlich, started April 2005.
4 //
5 // Copyright (C) 2005 Mathias Froehlich
6 //
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.
11 //
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.
16 //
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.
20 //
21
22 #ifdef HAVE_CONFIG_H
23 #  include <simgear_config.h>
24 #endif
25
26 #ifndef __cplusplus
27 # error This library requires C++
28 #endif
29
30 #include <simgear/compiler.h>
31 #include <simgear/constants.h>
32
33 #include "placementtrans.hxx"
34
35 SGPlacementTransform::SGPlacementTransform(void) :
36   _placement_offset(0, 0, 0),
37   _scenery_center(0, 0, 0),
38   _rotation(1, 0, 0, 0,
39             0, 1, 0, 0,
40             0, 0, 1, 0,
41             0, 0, 0, 1)
42 {
43 }
44
45 SGPlacementTransform::~SGPlacementTransform(void)
46 {
47 }
48
49 bool
50 SGPlacementTransform::computeLocalToWorldMatrix(osg::Matrix& matrix,
51                                                 osg::NodeVisitor*) const
52 {
53   osg::Matrix t;
54   for (int i = 0; i < 3; ++i) {
55     for (int j = 0; j < 3; ++j) {
56       t(j, i) = _rotation(i, j);
57     }
58     t(3, i) = _placement_offset(i) - _scenery_center(i);
59   }
60   
61   if (_referenceFrame == RELATIVE_RF)
62     matrix.preMult(t);
63   else
64     matrix = t;
65   return true;
66 }
67
68 bool
69 SGPlacementTransform::computeWorldToLocalMatrix(osg::Matrix& matrix,
70                                                 osg::NodeVisitor*) const
71 {
72   osg::Matrix t;
73   for (int i = 0; i < 3; ++i) {
74     for (int j = 0; j < 3; ++j) {
75       t(j, i) = _rotation(i, j);
76     }
77     t(3, i) = _placement_offset(i) - _scenery_center(i);
78   }
79   t = osg::Matrix::inverse(t);
80
81   if (_referenceFrame == RELATIVE_RF)
82     matrix.postMult(t);
83   else
84     matrix = t;
85   return true;
86 }