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();
_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;
}

View 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;
};

View 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();
}

View 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;
};
}

View 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;
};

View 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)
{

View 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;

View 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; }