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
This commit is contained in:
frohlich 2009-03-05 06:06:02 +00:00 committed by Tim Moore
parent 2564432e71
commit fa20363853
8 changed files with 47 additions and 5 deletions

View File

@ -97,6 +97,8 @@ BVHLineSegmentVisitor::apply(BVHMotionTransform& transform)
SGVec3d localEnd = _lineSegment.getEnd(); SGVec3d localEnd = _lineSegment.getEnd();
_lineSegment.set(lineSegment.getStart(), toWorld.xformPt(localEnd)); _lineSegment.set(lineSegment.getStart(), toWorld.xformPt(localEnd));
_normal = toWorld.xformVec(_normal); _normal = toWorld.xformVec(_normal);
if (!_id)
_id = transform.getId();
} else { } else {
_lineSegment = lineSegment; _lineSegment = lineSegment;
_haveHit = haveHit; _haveHit = haveHit;
@ -143,6 +145,7 @@ BVHLineSegmentVisitor::apply(const BVHStaticTriangle& triangle,
_linearVelocity = SGVec3d::zeros(); _linearVelocity = SGVec3d::zeros();
_angularVelocity = SGVec3d::zeros(); _angularVelocity = SGVec3d::zeros();
_material = data.getMaterial(triangle.getMaterialIndex()); _material = data.getMaterial(triangle.getMaterialIndex());
_id = 0;
_haveHit = true; _haveHit = true;
} }

View File

@ -23,6 +23,7 @@
#include <simgear/scene/material/mat.hxx> #include <simgear/scene/material/mat.hxx>
#include "BVHVisitor.hxx" #include "BVHVisitor.hxx"
#include "BVHNode.hxx"
namespace simgear { namespace simgear {
@ -33,6 +34,7 @@ public:
_lineSegment(lineSegment), _lineSegment(lineSegment),
_time(t), _time(t),
_material(0), _material(0),
_id(0),
_haveHit(false) _haveHit(false)
{ } { }
virtual ~BVHLineSegmentVisitor() virtual ~BVHLineSegmentVisitor()
@ -54,6 +56,8 @@ public:
{ return _angularVelocity; } { return _angularVelocity; }
const SGMaterial* getMaterial() const const SGMaterial* getMaterial() const
{ return _material; } { return _material; }
BVHNode::Id getId() const
{ return _id; }
virtual void apply(BVHGroup& group); virtual void apply(BVHGroup& group);
virtual void apply(BVHTransform& transform); virtual void apply(BVHTransform& transform);
@ -84,6 +88,7 @@ private:
SGVec3d _linearVelocity; SGVec3d _linearVelocity;
SGVec3d _angularVelocity; SGVec3d _angularVelocity;
const SGMaterial* _material; const SGMaterial* _material;
BVHNode::Id _id;
bool _haveHit; bool _haveHit;
}; };

View File

@ -31,7 +31,8 @@ BVHMotionTransform::BVHMotionTransform() :
_linearVelocity(0, 0, 0), _linearVelocity(0, 0, 0),
_angularVelocity(0, 0, 0), _angularVelocity(0, 0, 0),
_referenceTime(0), _referenceTime(0),
_endTime(0) _endTime(0),
_id(0)
{ {
} }
@ -56,6 +57,7 @@ BVHMotionTransform::setTransform(const BVHMotionTransform& transform)
_angularVelocity = transform._angularVelocity; _angularVelocity = transform._angularVelocity;
_referenceTime = transform._referenceTime; _referenceTime = transform._referenceTime;
_endTime = transform._endTime; _endTime = transform._endTime;
_id = transform._id;
invalidateParentBound(); invalidateParentBound();
} }

View File

@ -92,6 +92,11 @@ public:
return SGSphered(center, radius); return SGSphered(center, radius);
} }
void setId(Id id)
{ _id = id; }
Id getId() const
{ return _id; }
private: private:
virtual SGSphered computeBoundingSphere() const; virtual SGSphered computeBoundingSphere() const;
void updateAmplificationFactors(); void updateAmplificationFactors();
@ -106,6 +111,8 @@ private:
double _referenceTime; double _referenceTime;
double _endTime; double _endTime;
Id _id;
}; };
} }

View File

@ -42,6 +42,7 @@ public:
_sphere(sphere), _sphere(sphere),
_time(t), _time(t),
_material(0), _material(0),
_id(0),
_havePoint(false) _havePoint(false)
{ } { }
@ -91,6 +92,8 @@ public:
_linearVelocity = toWorld.xformVec(_linearVelocity); _linearVelocity = toWorld.xformVec(_linearVelocity);
_angularVelocity = toWorld.xformVec(_angularVelocity); _angularVelocity = toWorld.xformVec(_angularVelocity);
_point = toWorld.xformPt(_point); _point = toWorld.xformPt(_point);
if (!_id)
_id = transform.getId();
} }
_havePoint |= havePoint; _havePoint |= havePoint;
_sphere.setCenter(sphere.getCenter()); _sphere.setCenter(sphere.getCenter());
@ -123,6 +126,7 @@ public:
// The trick is to decrease the radius of the search sphere. // The trick is to decrease the radius of the search sphere.
_sphere.setRadius(length(closest - _sphere.getCenter())); _sphere.setRadius(length(closest - _sphere.getCenter()));
_havePoint = true; _havePoint = true;
_id = 0;
} }
void setSphere(const SGSphered& sphere) void setSphere(const SGSphered& sphere)
@ -138,9 +142,9 @@ public:
{ return _angularVelocity; } { return _angularVelocity; }
const SGMaterial* getMaterial() const const SGMaterial* getMaterial() const
{ return _material; } { return _material; }
BVHNode::Id getId() const
{ return _id; }
bool getHavePoint() const
{ return _havePoint; }
bool empty() const bool empty() const
{ return !_havePoint; } { return !_havePoint; }
@ -152,6 +156,7 @@ private:
SGVec3d _linearVelocity; SGVec3d _linearVelocity;
SGVec3d _angularVelocity; SGVec3d _angularVelocity;
const SGMaterial* _material; const SGMaterial* _material;
BVHNode::Id _id;
bool _havePoint; bool _havePoint;
}; };

View File

@ -18,6 +18,7 @@
#include "BVHNode.hxx" #include "BVHNode.hxx"
#include <algorithm> #include <algorithm>
#include <simgear/structure/SGAtomic.hxx>
#include <simgear/math/SGGeometry.hxx> #include <simgear/math/SGGeometry.hxx>
namespace simgear { namespace simgear {
@ -31,6 +32,13 @@ BVHNode::~BVHNode()
{ {
} }
BVHNode::Id
BVHNode::getNewId()
{
static SGAtomic id(0);
return ++id;
}
void void
BVHNode::addParent(BVHNode* parent) BVHNode::addParent(BVHNode* parent)
{ {

View File

@ -46,6 +46,13 @@ public:
} }
virtual SGSphered computeBoundingSphere() const = 0; 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: protected:
friend class BVHGroup; friend class BVHGroup;
void addParent(BVHNode* parent); void addParent(BVHNode* parent);

View File

@ -48,9 +48,14 @@ public:
{ _bvhNode = bvhNode; } { _bvhNode = bvhNode; }
struct Velocity : public SGReferenced { 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 linear;
SGVec3d angular; SGVec3d angular;
simgear::BVHNode::Id id;
}; };
const Velocity* getVelocity() const const Velocity* getVelocity() const
{ return _velocity; } { return _velocity; }