]> git.mxchange.org Git - simgear.git/commitdiff
First step for something doing static friction stuff.
authorfrohlich <frohlich>
Thu, 5 Mar 2009 06:06:02 +0000 (06:06 +0000)
committerTim Moore <timoore@redhat.com>
Thu, 5 Mar 2009 09:32:06 +0000 (10:32 +0100)
Add an id field to identify BVHMotionTransforms.
Provide a factory for ids.
Use that to identify velocity data.
Track the lowermost id in the visitors.

Modified Files:
simgear/scene/bvh/BVHLineSegmentVisitor.cxx
simgear/scene/bvh/BVHLineSegmentVisitor.hxx
  simgear/scene/bvh/BVHMotionTransform.cxx
simgear/scene/bvh/BVHMotionTransform.hxx
simgear/scene/bvh/BVHNearestPointVisitor.hxx
simgear/scene/bvh/BVHNode.cxx simgear/scene/bvh/BVHNode.hxx
simgear/scene/util/SGSceneUserData.cxx
simgear/scene/util/SGSceneUserData.hxx

simgear/scene/bvh/BVHLineSegmentVisitor.cxx
simgear/scene/bvh/BVHLineSegmentVisitor.hxx
simgear/scene/bvh/BVHMotionTransform.cxx
simgear/scene/bvh/BVHMotionTransform.hxx
simgear/scene/bvh/BVHNearestPointVisitor.hxx
simgear/scene/bvh/BVHNode.cxx
simgear/scene/bvh/BVHNode.hxx
simgear/scene/util/SGSceneUserData.hxx

index 6475ce2b1472743926f7d804a8b79251ee5be374..7ba9a9444db69f56e61658702e134343b7aedfb7 100644 (file)
@@ -97,6 +97,8 @@ BVHLineSegmentVisitor::apply(BVHMotionTransform& transform)
         SGVec3d localEnd = _lineSegment.getEnd();
         _lineSegment.set(lineSegment.getStart(), toWorld.xformPt(localEnd));
         _normal = toWorld.xformVec(_normal);
+        if (!_id)
+            _id = transform.getId();
     } else {
         _lineSegment = lineSegment;
         _haveHit = haveHit;
@@ -143,6 +145,7 @@ BVHLineSegmentVisitor::apply(const BVHStaticTriangle& triangle,
     _linearVelocity = SGVec3d::zeros();
     _angularVelocity = SGVec3d::zeros();
     _material = data.getMaterial(triangle.getMaterialIndex());
+    _id = 0;
     _haveHit = true;
 }
 
index 5801e5d37c5fafeb8da06fc0a0a93c6557036567..cca02588bbdf1a571cebff938b71ab2cc8d890aa 100644 (file)
@@ -23,6 +23,7 @@
 #include <simgear/scene/material/mat.hxx>
 
 #include "BVHVisitor.hxx"
+#include "BVHNode.hxx"
 
 namespace simgear {
 
@@ -33,6 +34,7 @@ public:
         _lineSegment(lineSegment),
         _time(t),
         _material(0),
+        _id(0),
         _haveHit(false)
     { }
     virtual ~BVHLineSegmentVisitor()
@@ -54,6 +56,8 @@ public:
     { return _angularVelocity; }
     const SGMaterial* getMaterial() const
     { return _material; }
+    BVHNode::Id getId() const
+    { return _id; }
 
     virtual void apply(BVHGroup& group);
     virtual void apply(BVHTransform& transform);
@@ -84,6 +88,7 @@ private:
     SGVec3d _linearVelocity;
     SGVec3d _angularVelocity;
     const SGMaterial* _material;
+    BVHNode::Id _id;
     
     bool _haveHit;
 };
index d97b66f10cc06abea41e5dbe62893b094db644f6..4188f329c583ca43f76568642c909b0f2083b0e6 100644 (file)
@@ -31,7 +31,8 @@ BVHMotionTransform::BVHMotionTransform() :
     _linearVelocity(0, 0, 0),
     _angularVelocity(0, 0, 0),
     _referenceTime(0),
-    _endTime(0)
+    _endTime(0),
+    _id(0)
 {
 }
 
@@ -56,6 +57,7 @@ BVHMotionTransform::setTransform(const BVHMotionTransform& transform)
     _angularVelocity = transform._angularVelocity;
     _referenceTime = transform._referenceTime;
     _endTime = transform._endTime;
+    _id = transform._id;
     invalidateParentBound();
 }
 
index 6e51e7eeadad998b5c12931c1cc9e4db61a7ca47..e3d2d375b2388be7ff5f1777bc4ad7a4dd7229f5 100644 (file)
@@ -92,6 +92,11 @@ public:
         return SGSphered(center, radius);
     }
 
+    void setId(Id id)
+    { _id = id; }
+    Id getId() const
+    { return _id; }
+
 private:
     virtual SGSphered computeBoundingSphere() const;
     void updateAmplificationFactors();
@@ -106,6 +111,8 @@ private:
 
     double _referenceTime;
     double _endTime;
+
+    Id _id;
 };
 
 }
index c5f1add83b509bedbd20ee3428bd925953978bad..1c07c66acb8fd99352383181ba24216d8c158a51 100644 (file)
@@ -42,6 +42,7 @@ public:
         _sphere(sphere),
         _time(t),
         _material(0),
+        _id(0),
         _havePoint(false)
     { }
     
@@ -91,6 +92,8 @@ public:
             _linearVelocity = toWorld.xformVec(_linearVelocity);
             _angularVelocity = toWorld.xformVec(_angularVelocity);
             _point = toWorld.xformPt(_point);
+            if (!_id)
+                _id = transform.getId();
         }
         _havePoint |= havePoint;
         _sphere.setCenter(sphere.getCenter());
@@ -123,6 +126,7 @@ public:
         // The trick is to decrease the radius of the search sphere.
         _sphere.setRadius(length(closest - _sphere.getCenter()));
         _havePoint = true;
+        _id = 0;
     }
     
     void setSphere(const SGSphered& sphere)
@@ -138,9 +142,9 @@ public:
     { return _angularVelocity; }
     const SGMaterial* getMaterial() const
     { return _material; }
+    BVHNode::Id getId() const
+    { return _id; }
     
-    bool getHavePoint() const
-    { return _havePoint; }
     bool empty() const
     { return !_havePoint; }
     
@@ -152,7 +156,8 @@ private:
     SGVec3d _linearVelocity;
     SGVec3d _angularVelocity;
     const SGMaterial* _material;
-    
+    BVHNode::Id _id;
+
     bool _havePoint;
 };
 
index 5d8f39f3a03c8e61e2a78639c48caa1ff0146925..d4b1ca5f44284ea43e14d03d2a8425f46f6cf5be 100644 (file)
@@ -18,6 +18,7 @@
 #include "BVHNode.hxx"
 
 #include <algorithm>
+#include <simgear/structure/SGAtomic.hxx>
 #include <simgear/math/SGGeometry.hxx>
 
 namespace simgear {
@@ -31,6 +32,13 @@ BVHNode::~BVHNode()
 {
 }
 
+BVHNode::Id
+BVHNode::getNewId()
+{
+    static SGAtomic id(0);
+    return ++id;
+}
+
 void
 BVHNode::addParent(BVHNode* parent)
 {
index 3bdce72ff2552c5931967a1300bb6ce22fbae2b1..10a0a957f3ae305aca373a0e8b6abbcf9631769d 100644 (file)
@@ -45,6 +45,13 @@ public:
         return _boundingSphere;
     }
     virtual SGSphered computeBoundingSphere() const = 0;
+
+    /// A unique id for some kind of BVHNodes.
+    /// Currently only motions transforms.
+    typedef unsigned Id;
+
+    // Factory to get a new id
+    static Id getNewId();
     
 protected:
     friend class BVHGroup;
index 6acd50685f9d3eac68d0ab219a8ff53eed83eb32..e47703b9e358f7417ebdb6e3681db8637b263635 100644 (file)
@@ -48,9 +48,14 @@ public:
   { _bvhNode = bvhNode; }
 
   struct Velocity : public SGReferenced {
-    Velocity() : linear(SGVec3d::zeros()), angular(SGVec3d::zeros()) {}
+    Velocity() :
+        linear(SGVec3d::zeros()),
+        angular(SGVec3d::zeros()),
+        id(simgear::BVHNode::getNewId())
+    {}
     SGVec3d linear;
     SGVec3d angular;
+    simgear::BVHNode::Id id;
   };
   const Velocity* getVelocity() const
   { return _velocity; }