00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifdef HAVE_CONFIG_H
00019 # include <simgear_config.h>
00020 #endif
00021
00022 #include "BVHTransform.hxx"
00023
00024 #include "BVHVisitor.hxx"
00025 #include "BVHNode.hxx"
00026 #include "BVHGroup.hxx"
00027
00028 namespace simgear {
00029
00030 BVHTransform::BVHTransform() :
00031 _toWorld(SGMatrixd::unit()),
00032 _toLocal(SGMatrixd::unit()),
00033 _toWorldAmplification(1),
00034 _toLocalAmplification(1)
00035 {
00036 }
00037
00038 BVHTransform::~BVHTransform()
00039 {
00040 }
00041
00042 void
00043 BVHTransform::accept(BVHVisitor& visitor)
00044 {
00045 visitor.apply(*this);
00046 }
00047
00048 void
00049 BVHTransform::setTransform(const BVHTransform& transform)
00050 {
00051 _toWorld = transform._toWorld;
00052 _toLocal = transform._toLocal;
00053 _toWorldAmplification = transform._toWorldAmplification;
00054 _toLocalAmplification = transform._toLocalAmplification;
00055 invalidateParentBound();
00056 }
00057
00058 void
00059 BVHTransform::setToWorldTransform(const SGMatrixd& transform)
00060 {
00061 _toWorld = transform;
00062 invert(_toLocal, transform);
00063 updateAmplificationFactors();
00064 invalidateParentBound();
00065 }
00066
00067 void
00068 BVHTransform::setToLocalTransform(const SGMatrixd& transform)
00069 {
00070 _toLocal = transform;
00071 invert(_toWorld, transform);
00072 updateAmplificationFactors();
00073 invalidateParentBound();
00074 }
00075
00076 SGSphered
00077 BVHTransform::computeBoundingSphere() const
00078 {
00079 return sphereToWorld(BVHGroup::computeBoundingSphere());
00080 }
00081
00082 void
00083 BVHTransform::updateAmplificationFactors()
00084 {
00085
00086
00087
00088 double r = norm(vecToWorld(SGVec3d(1, 0, 0)));
00089 r = std::max(r, norm(vecToWorld(SGVec3d(0, 1, 0))));
00090 r = std::max(r, norm(vecToWorld(SGVec3d(0, 0, 1))));
00091 _toWorldAmplification = r;
00092
00093 r = norm(vecToLocal(SGVec3d(1, 0, 0)));
00094 r = std::max(r, norm(vecToLocal(SGVec3d(0, 1, 0))));
00095 r = std::max(r, norm(vecToLocal(SGVec3d(0, 0, 1))));
00096 _toLocalAmplification = r;
00097 }
00098
00099 }