Updates NEWS file for 0.9.0 release.
Added default computeBound() implementation to osg::Drawable which uses a PrimtiveFunctor to compute the bounding box in a generic way, that will work for all Drawable subclasses that implement the accept(PrimitiveFunctor&).
This commit is contained in:
@@ -3,19 +3,6 @@
|
||||
|
||||
using namespace osg;
|
||||
|
||||
void BoundingBox::expandBy(const Vec3& v)
|
||||
{
|
||||
if(v.x()<_min.x()) _min.x() = v.x();
|
||||
if(v.x()>_max.x()) _max.x() = v.x();
|
||||
|
||||
if(v.y()<_min.y()) _min.y() = v.y();
|
||||
if(v.y()>_max.y()) _max.y() = v.y();
|
||||
|
||||
if(v.z()<_min.z()) _min.z() = v.z();
|
||||
if(v.z()>_max.z()) _max.z() = v.z();
|
||||
}
|
||||
|
||||
|
||||
void BoundingBox::expandBy(const BoundingBox& bb)
|
||||
{
|
||||
if (!bb.valid()) return;
|
||||
|
||||
@@ -227,3 +227,77 @@ void Drawable::setAppCallback(AppCallback* ac)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ComputeBound : public Drawable::PrimitiveFunctor
|
||||
{
|
||||
ComputeBound():_vertices(0) {}
|
||||
|
||||
virtual void setVertexArray(unsigned int,Vec3* vertices) { _vertices = vertices; }
|
||||
|
||||
virtual void drawArrays(GLenum,GLint first,GLsizei count)
|
||||
{
|
||||
if (_vertices)
|
||||
{
|
||||
osg::Vec3* vert = _vertices+first;
|
||||
for(;count>0;--count,++vert)
|
||||
{
|
||||
_bb.expandBy(*vert);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void drawElements(GLenum,GLsizei count,GLubyte* indices)
|
||||
{
|
||||
if (_vertices)
|
||||
{
|
||||
for(;count>0;--count,++indices)
|
||||
{
|
||||
_bb.expandBy(_vertices[*indices]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void drawElements(GLenum,GLsizei count,GLushort* indices)
|
||||
{
|
||||
if (_vertices)
|
||||
{
|
||||
for(;count>0;--count,++indices)
|
||||
{
|
||||
_bb.expandBy(_vertices[*indices]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void drawElements(GLenum,GLsizei count,GLuint* indices)
|
||||
{
|
||||
if (_vertices)
|
||||
{
|
||||
for(;count>0;--count,++indices)
|
||||
{
|
||||
_bb.expandBy(_vertices[*indices]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void begin(GLenum) {}
|
||||
virtual void vertex(const Vec3& vert) { _bb.expandBy(vert); }
|
||||
virtual void vertex(float x,float y,float z) { _bb.expandBy(x,y,z); }
|
||||
virtual void end() {}
|
||||
|
||||
Vec3* _vertices;
|
||||
BoundingBox _bb;
|
||||
};
|
||||
|
||||
const bool Drawable::computeBound() const
|
||||
{
|
||||
ComputeBound cb;
|
||||
|
||||
Drawable* non_const_this = const_cast<Drawable*>(this);
|
||||
non_const_this->accept(cb);
|
||||
|
||||
_bbox = cb._bb;
|
||||
_bbox_computed = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -416,6 +416,7 @@ void GeoSet::computeNumVerts() const
|
||||
}
|
||||
|
||||
|
||||
// just use the base Drawable's PrimitiveFunctor based implementation.
|
||||
const bool GeoSet::computeBound() const
|
||||
{
|
||||
_bbox.init();
|
||||
|
||||
@@ -222,25 +222,25 @@ void Geometry::accept(PrimitiveFunctor& functor)
|
||||
|
||||
}
|
||||
|
||||
|
||||
const bool Geometry::computeBound() const
|
||||
{
|
||||
_bbox.init();
|
||||
|
||||
const Vec3Array* coords = dynamic_cast<const Vec3Array*>(_vertexArray.get());
|
||||
if (coords)
|
||||
{
|
||||
for(Vec3Array::const_iterator itr=coords->begin();
|
||||
itr!=coords->end();
|
||||
++itr)
|
||||
{
|
||||
_bbox.expandBy(*itr);
|
||||
}
|
||||
}
|
||||
_bbox_computed = true;
|
||||
|
||||
return _bbox.valid();
|
||||
}
|
||||
// just use the base Drawable's PrimitiveFunctor based implementation.
|
||||
// const bool Geometry::computeBound() const
|
||||
// {
|
||||
// _bbox.init();
|
||||
//
|
||||
// const Vec3Array* coords = dynamic_cast<const Vec3Array*>(_vertexArray.get());
|
||||
// if (coords)
|
||||
// {
|
||||
// for(Vec3Array::const_iterator itr=coords->begin();
|
||||
// itr!=coords->end();
|
||||
// ++itr)
|
||||
// {
|
||||
// _bbox.expandBy(*itr);
|
||||
// }
|
||||
// }
|
||||
// _bbox_computed = true;
|
||||
//
|
||||
// return _bbox.valid();
|
||||
// }
|
||||
|
||||
bool Geometry::verifyBindings() const
|
||||
{
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <osg/LOD>
|
||||
#include <osg/Transparency>
|
||||
#include <osg/Geode>
|
||||
#include <osg/GeoSet>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/Material>
|
||||
#include <osg/Texture>
|
||||
|
||||
Reference in New Issue
Block a user