]> git.mxchange.org Git - simgear.git/blob - simgear/bvh/BVHTransform.cxx
Fix HTTP unit-test
[simgear.git] / simgear / bvh / BVHTransform.cxx
1 // Copyright (C) 2008 - 2009  Mathias Froehlich - Mathias.Froehlich@web.de
2 //
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.
7 //
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.
12 //
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.
16 //
17
18 #ifdef HAVE_CONFIG_H
19 #  include <simgear_config.h>
20 #endif
21
22 #include "BVHTransform.hxx"
23
24 #include "BVHVisitor.hxx"
25 #include "BVHNode.hxx"
26 #include "BVHGroup.hxx"
27
28 namespace simgear {
29
30 BVHTransform::BVHTransform() :
31     _toWorld(SGMatrixd::unit()),
32     _toLocal(SGMatrixd::unit()),
33     _toWorldAmplification(1),
34     _toLocalAmplification(1)
35 {
36 }
37
38 BVHTransform::~BVHTransform()
39 {
40 }
41
42 void
43 BVHTransform::accept(BVHVisitor& visitor)
44 {
45     visitor.apply(*this);
46 }
47     
48 void
49 BVHTransform::setTransform(const BVHTransform& transform)
50 {
51     _toWorld = transform._toWorld;
52     _toLocal = transform._toLocal;
53     _toWorldAmplification = transform._toWorldAmplification;
54     _toLocalAmplification = transform._toLocalAmplification;
55     invalidateParentBound();
56 }
57
58 void
59 BVHTransform::setToWorldTransform(const SGMatrixd& transform)
60 {
61     _toWorld = transform;
62     invert(_toLocal, transform);
63     updateAmplificationFactors();
64     invalidateParentBound();
65 }
66
67 void
68 BVHTransform::setToLocalTransform(const SGMatrixd& transform)
69 {
70     _toLocal = transform;
71     invert(_toWorld, transform);
72     updateAmplificationFactors();
73     invalidateParentBound();
74 }
75
76 SGSphered
77 BVHTransform::computeBoundingSphere() const
78 {
79     return sphereToWorld(BVHGroup::computeBoundingSphere());
80 }
81
82 void
83 BVHTransform::updateAmplificationFactors()
84 {
85     // Hmm, this is just a hint, true?
86     // But anyway, almost all transforms in a scenegraph will
87     // have them equal to 1 ...
88     double r = norm(vecToWorld(SGVec3d(1, 0, 0)));
89     r = std::max(r, norm(vecToWorld(SGVec3d(0, 1, 0))));
90     r = std::max(r, norm(vecToWorld(SGVec3d(0, 0, 1))));
91     _toWorldAmplification = r;
92     
93     r = norm(vecToLocal(SGVec3d(1, 0, 0)));
94     r = std::max(r, norm(vecToLocal(SGVec3d(0, 1, 0))));
95     r = std::max(r, norm(vecToLocal(SGVec3d(0, 0, 1))));
96     _toLocalAmplification = r;
97 }
98
99 }