From: frohlich Date: Sun, 15 Mar 2009 11:03:37 +0000 (+0000) Subject: Preparations for improoved timing behaviour. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5b63f0755abbfb17212498ee0eab8590fd2d079d;p=simgear.git Preparations for improoved timing behaviour. Modified Files: simgear/scene/bvh/BVHMotionTransform.cxx simgear/scene/bvh/BVHMotionTransform.hxx simgear/scene/bvh/BVHSubTreeCollector.cxx --- diff --git a/simgear/scene/bvh/BVHMotionTransform.cxx b/simgear/scene/bvh/BVHMotionTransform.cxx index 4188f329..f86668ed 100644 --- a/simgear/scene/bvh/BVHMotionTransform.cxx +++ b/simgear/scene/bvh/BVHMotionTransform.cxx @@ -31,6 +31,7 @@ BVHMotionTransform::BVHMotionTransform() : _linearVelocity(0, 0, 0), _angularVelocity(0, 0, 0), _referenceTime(0), + _startTime(0), _endTime(0), _id(0) { @@ -56,6 +57,7 @@ BVHMotionTransform::setTransform(const BVHMotionTransform& transform) _linearVelocity = transform._linearVelocity; _angularVelocity = transform._angularVelocity; _referenceTime = transform._referenceTime; + _startTime = transform._startTime; _endTime = transform._endTime; _id = transform._id; invalidateParentBound(); @@ -85,7 +87,8 @@ BVHMotionTransform::computeBoundingSphere() const SGSphered sphere(BVHGroup::computeBoundingSphere()); if (sphere.empty()) return sphere; - SGVec3d centerStart = _toWorldReference.xformPt(sphere.getCenter()); + SGMatrixd toWorldStart = getToWorldTransform(_startTime); + SGVec3d centerStart = toWorldStart.xformPt(sphere.getCenter()); SGMatrixd toWorldEnd = getToWorldTransform(_endTime); SGVec3d centerEnd = toWorldEnd.xformPt(sphere.getCenter()); double rad = 0.5*length(centerStart - centerEnd) + sphere.getRadius(); diff --git a/simgear/scene/bvh/BVHMotionTransform.hxx b/simgear/scene/bvh/BVHMotionTransform.hxx index e3d2d375..d1a401e3 100644 --- a/simgear/scene/bvh/BVHMotionTransform.hxx +++ b/simgear/scene/bvh/BVHMotionTransform.hxx @@ -50,6 +50,11 @@ public: const double& getReferenceTime() const { return _referenceTime; } + void setStartTime(const double& startTime) + { _startTime = startTime; } + const double& getStartTime() const + { return _startTime; } + void setEndTime(const double& endTime) { _endTime = endTime; } const double& getEndTime() const @@ -57,9 +62,9 @@ public: SGMatrixd getToWorldTransform(const double& t) const { - double dt = t - _referenceTime; - if (0 == dt) + if (t == _referenceTime) return _toWorldReference; + double dt = t - _referenceTime; SGMatrixd matrix(_toWorldReference); matrix.postMultRotate(SGQuatd::fromAngleAxis(dt*_angularVelocity)); matrix.postMultTranslate(dt*_linearVelocity); @@ -67,9 +72,9 @@ public: } SGMatrixd getToLocalTransform(const double& t) const { - double dt = _referenceTime - t; - if (0 == dt) + if (t == _referenceTime) return _toLocalReference; + double dt = _referenceTime - t; SGMatrixd matrix(_toLocalReference); matrix.preMultRotate(SGQuatd::fromAngleAxis(dt*_angularVelocity)); matrix.preMultTranslate(dt*_linearVelocity); @@ -110,6 +115,7 @@ private: SGVec3d _angularVelocity; double _referenceTime; + double _startTime; double _endTime; Id _id; diff --git a/simgear/scene/bvh/BVHSubTreeCollector.cxx b/simgear/scene/bvh/BVHSubTreeCollector.cxx index d8c6017f..1e3484ec 100644 --- a/simgear/scene/bvh/BVHSubTreeCollector.cxx +++ b/simgear/scene/bvh/BVHSubTreeCollector.cxx @@ -90,7 +90,7 @@ BVHSubTreeCollector::apply(BVHMotionTransform& transform) return; SGSphered sphere = _sphere; - _sphere = transform.sphereToLocal(sphere, transform.getReferenceTime()); + _sphere = transform.sphereToLocal(sphere, transform.getStartTime()); _sphere.expandBy(transform.sphereToLocal(sphere, transform.getEndTime())); NodeList parentNodeList;