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.
18 #include "BVHTransform.hxx"
20 #include "BVHVisitor.hxx"
21 #include "BVHNode.hxx"
22 #include "BVHGroup.hxx"
26 BVHTransform::BVHTransform() :
27 _toWorld(SGMatrixd::unit()),
28 _toLocal(SGMatrixd::unit()),
29 _toWorldAmplification(1),
30 _toLocalAmplification(1)
34 BVHTransform::~BVHTransform()
39 BVHTransform::accept(BVHVisitor& visitor)
45 BVHTransform::setTransform(const BVHTransform& transform)
47 _toWorld = transform._toWorld;
48 _toLocal = transform._toLocal;
49 _toWorldAmplification = transform._toWorldAmplification;
50 _toLocalAmplification = transform._toLocalAmplification;
51 invalidateParentBound();
55 BVHTransform::setToWorldTransform(const SGMatrixd& transform)
58 invert(_toLocal, transform);
59 updateAmplificationFactors();
60 invalidateParentBound();
64 BVHTransform::setToLocalTransform(const SGMatrixd& transform)
67 invert(_toWorld, transform);
68 updateAmplificationFactors();
69 invalidateParentBound();
73 BVHTransform::computeBoundingSphere() const
75 return sphereToWorld(BVHGroup::computeBoundingSphere());
79 BVHTransform::updateAmplificationFactors()
81 // Hmm, this is just a hint, true?
82 // But anyway, almost all transforms in a scenegraph will
83 // have them equal to 1 ...
84 double r = norm(vecToWorld(SGVec3d(1, 0, 0)));
85 r = std::max(r, norm(vecToWorld(SGVec3d(0, 1, 0))));
86 r = std::max(r, norm(vecToWorld(SGVec3d(0, 0, 1))));
87 _toWorldAmplification = r;
89 r = norm(vecToLocal(SGVec3d(1, 0, 0)));
90 r = std::max(r, norm(vecToLocal(SGVec3d(0, 1, 0))));
91 r = std::max(r, norm(vecToLocal(SGVec3d(0, 0, 1))));
92 _toLocalAmplification = r;