1 // Copyright (C) 2008 - 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.
19 # include <simgear_config.h>
22 #include "BVHTransform.hxx"
24 #include "BVHVisitor.hxx"
25 #include "BVHNode.hxx"
26 #include "BVHGroup.hxx"
30 BVHTransform::BVHTransform() :
31 _toWorld(SGMatrixd::unit()),
32 _toLocal(SGMatrixd::unit()),
33 _toWorldAmplification(1),
34 _toLocalAmplification(1)
38 BVHTransform::~BVHTransform()
43 BVHTransform::accept(BVHVisitor& visitor)
49 BVHTransform::setTransform(const BVHTransform& transform)
51 _toWorld = transform._toWorld;
52 _toLocal = transform._toLocal;
53 _toWorldAmplification = transform._toWorldAmplification;
54 _toLocalAmplification = transform._toLocalAmplification;
55 invalidateParentBound();
59 BVHTransform::setToWorldTransform(const SGMatrixd& transform)
62 invert(_toLocal, transform);
63 updateAmplificationFactors();
64 invalidateParentBound();
68 BVHTransform::setToLocalTransform(const SGMatrixd& transform)
71 invert(_toWorld, transform);
72 updateAmplificationFactors();
73 invalidateParentBound();
77 BVHTransform::computeBoundingSphere() const
79 return sphereToWorld(BVHGroup::computeBoundingSphere());
83 BVHTransform::updateAmplificationFactors()
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;
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;