From fa2036385387dda5b185ef62e15b35b357d79b33 Mon Sep 17 00:00:00 2001 From: frohlich Date: Thu, 5 Mar 2009 06:06:02 +0000 Subject: [PATCH] First step for something doing static friction stuff. 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 | 3 +++ simgear/scene/bvh/BVHLineSegmentVisitor.hxx | 5 +++++ simgear/scene/bvh/BVHMotionTransform.cxx | 4 +++- simgear/scene/bvh/BVHMotionTransform.hxx | 7 +++++++ simgear/scene/bvh/BVHNearestPointVisitor.hxx | 11 ++++++++--- simgear/scene/bvh/BVHNode.cxx | 8 ++++++++ simgear/scene/bvh/BVHNode.hxx | 7 +++++++ simgear/scene/util/SGSceneUserData.hxx | 7 ++++++- 8 files changed, 47 insertions(+), 5 deletions(-) diff --git a/simgear/scene/bvh/BVHLineSegmentVisitor.cxx b/simgear/scene/bvh/BVHLineSegmentVisitor.cxx index 6475ce2b..7ba9a944 100644 --- a/simgear/scene/bvh/BVHLineSegmentVisitor.cxx +++ b/simgear/scene/bvh/BVHLineSegmentVisitor.cxx @@ -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; } diff --git a/simgear/scene/bvh/BVHLineSegmentVisitor.hxx b/simgear/scene/bvh/BVHLineSegmentVisitor.hxx index 5801e5d3..cca02588 100644 --- a/simgear/scene/bvh/BVHLineSegmentVisitor.hxx +++ b/simgear/scene/bvh/BVHLineSegmentVisitor.hxx @@ -23,6 +23,7 @@ #include #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; }; diff --git a/simgear/scene/bvh/BVHMotionTransform.cxx b/simgear/scene/bvh/BVHMotionTransform.cxx index d97b66f1..4188f329 100644 --- a/simgear/scene/bvh/BVHMotionTransform.cxx +++ b/simgear/scene/bvh/BVHMotionTransform.cxx @@ -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(); } diff --git a/simgear/scene/bvh/BVHMotionTransform.hxx b/simgear/scene/bvh/BVHMotionTransform.hxx index 6e51e7ee..e3d2d375 100644 --- a/simgear/scene/bvh/BVHMotionTransform.hxx +++ b/simgear/scene/bvh/BVHMotionTransform.hxx @@ -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; }; } diff --git a/simgear/scene/bvh/BVHNearestPointVisitor.hxx b/simgear/scene/bvh/BVHNearestPointVisitor.hxx index c5f1add8..1c07c66a 100644 --- a/simgear/scene/bvh/BVHNearestPointVisitor.hxx +++ b/simgear/scene/bvh/BVHNearestPointVisitor.hxx @@ -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; }; diff --git a/simgear/scene/bvh/BVHNode.cxx b/simgear/scene/bvh/BVHNode.cxx index 5d8f39f3..d4b1ca5f 100644 --- a/simgear/scene/bvh/BVHNode.cxx +++ b/simgear/scene/bvh/BVHNode.cxx @@ -18,6 +18,7 @@ #include "BVHNode.hxx" #include +#include #include namespace simgear { @@ -31,6 +32,13 @@ BVHNode::~BVHNode() { } +BVHNode::Id +BVHNode::getNewId() +{ + static SGAtomic id(0); + return ++id; +} + void BVHNode::addParent(BVHNode* parent) { diff --git a/simgear/scene/bvh/BVHNode.hxx b/simgear/scene/bvh/BVHNode.hxx index 3bdce72f..10a0a957 100644 --- a/simgear/scene/bvh/BVHNode.hxx +++ b/simgear/scene/bvh/BVHNode.hxx @@ -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; diff --git a/simgear/scene/util/SGSceneUserData.hxx b/simgear/scene/util/SGSceneUserData.hxx index 6acd5068..e47703b9 100644 --- a/simgear/scene/util/SGSceneUserData.hxx +++ b/simgear/scene/util/SGSceneUserData.hxx @@ -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; } -- 2.39.5