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
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;
_linearVelocity = SGVec3d::zeros();
_angularVelocity = SGVec3d::zeros();
_material = data.getMaterial(triangle.getMaterialIndex());
+ _id = 0;
_haveHit = true;
}
#include <simgear/scene/material/mat.hxx>
#include "BVHVisitor.hxx"
+#include "BVHNode.hxx"
namespace simgear {
_lineSegment(lineSegment),
_time(t),
_material(0),
+ _id(0),
_haveHit(false)
{ }
virtual ~BVHLineSegmentVisitor()
{ return _angularVelocity; }
const SGMaterial* getMaterial() const
{ return _material; }
+ BVHNode::Id getId() const
+ { return _id; }
virtual void apply(BVHGroup& group);
virtual void apply(BVHTransform& transform);
SGVec3d _linearVelocity;
SGVec3d _angularVelocity;
const SGMaterial* _material;
+ BVHNode::Id _id;
bool _haveHit;
};
_linearVelocity(0, 0, 0),
_angularVelocity(0, 0, 0),
_referenceTime(0),
- _endTime(0)
+ _endTime(0),
+ _id(0)
{
}
_angularVelocity = transform._angularVelocity;
_referenceTime = transform._referenceTime;
_endTime = transform._endTime;
+ _id = transform._id;
invalidateParentBound();
}
return SGSphered(center, radius);
}
+ void setId(Id id)
+ { _id = id; }
+ Id getId() const
+ { return _id; }
+
private:
virtual SGSphered computeBoundingSphere() const;
void updateAmplificationFactors();
double _referenceTime;
double _endTime;
+
+ Id _id;
};
}
_sphere(sphere),
_time(t),
_material(0),
+ _id(0),
_havePoint(false)
{ }
_linearVelocity = toWorld.xformVec(_linearVelocity);
_angularVelocity = toWorld.xformVec(_angularVelocity);
_point = toWorld.xformPt(_point);
+ if (!_id)
+ _id = transform.getId();
}
_havePoint |= havePoint;
_sphere.setCenter(sphere.getCenter());
// 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)
{ return _angularVelocity; }
const SGMaterial* getMaterial() const
{ return _material; }
+ BVHNode::Id getId() const
+ { return _id; }
- bool getHavePoint() const
- { return _havePoint; }
bool empty() const
{ return !_havePoint; }
SGVec3d _linearVelocity;
SGVec3d _angularVelocity;
const SGMaterial* _material;
-
+ BVHNode::Id _id;
+
bool _havePoint;
};
#include "BVHNode.hxx"
#include <algorithm>
+#include <simgear/structure/SGAtomic.hxx>
#include <simgear/math/SGGeometry.hxx>
namespace simgear {
{
}
+BVHNode::Id
+BVHNode::getNewId()
+{
+ static SGAtomic id(0);
+ return ++id;
+}
+
void
BVHNode::addParent(BVHNode* parent)
{
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;
{ _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; }