]> git.mxchange.org Git - simgear.git/commitdiff
Preparations for improoved timing behaviour.
authorfrohlich <frohlich>
Sun, 15 Mar 2009 11:03:37 +0000 (11:03 +0000)
committerTim Moore <timoore@redhat.com>
Wed, 18 Mar 2009 06:53:50 +0000 (07:53 +0100)
Modified Files:
simgear/scene/bvh/BVHMotionTransform.cxx
simgear/scene/bvh/BVHMotionTransform.hxx
simgear/scene/bvh/BVHSubTreeCollector.cxx

simgear/scene/bvh/BVHMotionTransform.cxx
simgear/scene/bvh/BVHMotionTransform.hxx
simgear/scene/bvh/BVHSubTreeCollector.cxx

index 4188f329c583ca43f76568642c909b0f2083b0e6..f86668ed587e6dc6ae04c2aae846e6dc116bf7d8 100644 (file)
@@ -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();
index e3d2d375b2388be7ff5f1777bc4ad7a4dd7229f5..d1a401e38f704141778938e91cb37591292ff843 100644 (file)
@@ -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;
index d8c6017f072dba6ae2e792594142ec493a229285..1e3484ece3990644d20ca549acd1ad8bf5590fb2 100644 (file)
@@ -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;