本文整理汇总了C++中osg::BoundingBox类的典型用法代码示例。如果您正苦于以下问题:C++ BoundingBox类的具体用法?C++ BoundingBox怎么用?C++ BoundingBox使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BoundingBox类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateCalculatedNearFar
bool CullVisitor::updateCalculatedNearFar(const osg::Matrix& matrix,const osg::BoundingBox& bb)
{
// efficient computation of near and far, only taking into account the nearest and furthest
// corners of the bounding box.
value_type d_near = distance(bb.corner(_bbCornerNear),matrix);
value_type d_far = distance(bb.corner(_bbCornerFar),matrix);
if (d_near>d_far)
{
std::swap(d_near,d_far);
if ( !EQUAL_F(d_near, d_far) )
{
OSG_WARN<<"Warning: CullVisitor::updateCalculatedNearFar(.) near>far in range calculation,"<< std::endl;
OSG_WARN<<" correcting by swapping values d_near="<<d_near<<" dfar="<<d_far<< std::endl;
}
}
if (d_far<0.0)
{
// whole object behind the eye point so disguard
return false;
}
if (d_near<_computed_znear) _computed_znear = d_near;
if (d_far>_computed_zfar) _computed_zfar = d_far;
return true;
}
示例2: getExtents
void TXPArchive::getExtents(osg::BoundingBox& extents)
{
TileInfo sw, ne;
trpg2iPoint tileExtents;
this->GetHeader()->GetLodSize(0, tileExtents);
this->getTileInfo(0, 0, 0, sw);
this->getTileInfo(tileExtents.x-1, tileExtents.y-1, 0, ne);
extents.set(sw.bbox._min, sw.bbox._max);
extents.expandBy(ne.bbox);
}
示例3:
osg::BoundingSphere
TileNode::computeBound() const
{
osg::BoundingSphere bs;
if (_surface.valid())
{
bs = _surface->getBound();
const osg::BoundingBox bbox = _surface->getAlignedBoundingBox();
_tileKeyValue.a() = std::max( (bbox.xMax()-bbox.xMin()), (bbox.yMax()-bbox.yMin()) );
}
return bs;
}
示例4: serializeBoundingBox
void ComputeAABBOnBoneVisitor::serializeBoundingBox(const osg::BoundingBox &bb,
const osg::Matrix &transform,
osgAnimation::Bone &b,
float ratio) {
osg::Vec3 center = bb.center();
double halfLenghtX = (bb._max.x() - bb._min.x()) * 0.50;
double halfLenghtY = (bb._max.y() - bb._min.y()) * 0.50;
double halfLenghtZ = (bb._max.z() - bb._min.z()) * 0.50;
halfLenghtX *= ratio;
halfLenghtY *= ratio;
halfLenghtZ *= ratio;
osg::BoundingBox serializedBB;
serializedBB.expandBy(osg::Vec3(center.x() - halfLenghtX, center.y() + halfLenghtY, center.z() + halfLenghtZ) * transform);
serializedBB.expandBy(osg::Vec3(center.x() - halfLenghtX, center.y() + halfLenghtY, center.z() - halfLenghtZ) * transform);
serializedBB.expandBy(osg::Vec3(center.x() - halfLenghtX, center.y() - halfLenghtY, center.z() - halfLenghtZ) * transform);
serializedBB.expandBy(osg::Vec3(center.x() - halfLenghtX, center.y() - halfLenghtY, center.z() + halfLenghtZ) * transform);
serializedBB.expandBy(osg::Vec3(center.x() + halfLenghtX, center.y() + halfLenghtY, center.z() + halfLenghtZ) * transform);
serializedBB.expandBy(osg::Vec3(center.x() + halfLenghtX, center.y() + halfLenghtY, center.z() - halfLenghtZ) * transform);
serializedBB.expandBy(osg::Vec3(center.x() + halfLenghtX, center.y() - halfLenghtY, center.z() - halfLenghtZ) * transform);
serializedBB.expandBy(osg::Vec3(center.x() + halfLenghtX, center.y() - halfLenghtY, center.z() + halfLenghtZ) * transform);
b.setUserValue("AABBonBone_min", serializedBB._min);
b.setUserValue("AABBonBone_max", serializedBB._max);
}
示例5: applyBoundingBox
void ComputeBoundsVisitor::applyBoundingBox(const osg::BoundingBox& bbox)
{
if (_matrixStack.empty()) _bb.expandBy(bbox);
else if (bbox.valid())
{
const osg::Matrix& matrix = _matrixStack.back();
_bb.expandBy(bbox.corner(0) * matrix);
_bb.expandBy(bbox.corner(1) * matrix);
_bb.expandBy(bbox.corner(2) * matrix);
_bb.expandBy(bbox.corner(3) * matrix);
_bb.expandBy(bbox.corner(4) * matrix);
_bb.expandBy(bbox.corner(5) * matrix);
_bb.expandBy(bbox.corner(6) * matrix);
_bb.expandBy(bbox.corner(7) * matrix);
}
}
示例6:
osg::Vec3 Curve::mapTo( const osg::Vec3 p, osg::BoundingBox originRect, osg::BoundingBox newRect )
{
osg::Vec3 newPos = p-originRect.center();
osg::Vec3 originSpace = originRect._max-originRect._min;
osg::Vec3 scaleFactor = (newRect._max-newRect._min);
if ( originSpace.x() ) scaleFactor.x() /= originSpace.x();
else scaleFactor.x() = 0.0;
if ( originSpace.y() ) scaleFactor.y() /= originSpace.y();
else scaleFactor.y() = 0.0;
if ( originSpace.z() ) scaleFactor.z() /= originSpace.z();
else scaleFactor.z() = 0.0;
newPos = osg::Vec3(newPos.x()*scaleFactor.x(), newPos.y()*scaleFactor.y(), newPos.z()*scaleFactor.z());
return newPos+newRect.center();
}
示例7: setupClipStateSet
void Style::setupClipStateSet(const osg::BoundingBox& extents, osg::StateSet* stateset)
{
unsigned int clipTextureUnit = 1;
stateset->setAttributeAndModes( new osg::AlphaFunc(osg::AlphaFunc::GREATER, 0.0f), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
stateset->setTextureAttributeAndModes( clipTextureUnit, _clipTexture.get(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
osg::Matrixd matrix = osg::Matrixd::translate(osg::Vec3(-extents.xMin(), -extents.yMin(), -extents.zMin()))*
osg::Matrixd::scale(osg::Vec3(1.0f/(extents.xMax()-extents.xMin()), 1.0f/(extents.yMax()-extents.yMin()), 1.0f));
osg::ref_ptr<osg::TexGen> texgen = new osg::TexGen;
texgen->setPlanesFromMatrix(matrix);
texgen->setMode(osg::TexGen::OBJECT_LINEAR);
stateset->setTextureAttributeAndModes( clipTextureUnit, texgen.get(), osg::StateAttribute::ON);
}
示例8: setUseVertexBufferObjects
BboxDrawable::BboxDrawable( const osg::BoundingBox& box, const BBoxSymbol &bboxSymbol ) :
osg::Geometry()
{
setUseVertexBufferObjects(true);
float margin = bboxSymbol.margin().isSet() ? bboxSymbol.margin().value() : 2.f;
osg::Vec3Array* v = new osg::Vec3Array();
if ( bboxSymbol.geom().isSet() && bboxSymbol.geom().value() == BBoxSymbol::GEOM_BOX_ORIENTED )
{
float h = box.yMax() - box.yMin() + 2.f * margin;
v->push_back( osg::Vec3(box.xMax()+margin+h/2.f, box.yMax()+margin-h/2.f, 0) );
}
v->push_back( osg::Vec3(box.xMax()+margin, box.yMax()+margin, 0) );
v->push_back( osg::Vec3(box.xMin()-margin, box.yMax()+margin, 0) );
v->push_back( osg::Vec3(box.xMin()-margin, box.yMin()-margin, 0) );
v->push_back( osg::Vec3(box.xMax()+margin, box.yMin()-margin, 0) );
setVertexArray(v);
if ( v->getVertexBufferObject() )
v->getVertexBufferObject()->setUsage(GL_STATIC_DRAW_ARB);
osg::Vec4Array* c = new osg::Vec4Array();
if ( bboxSymbol.fill().isSet() )
{
c->push_back( bboxSymbol.fill()->color() );
addPrimitiveSet( new osg::DrawArrays(GL_POLYGON, 0, v->getNumElements()) );
}
if ( bboxSymbol.border().isSet() )
{
c->push_back( bboxSymbol.border()->color() );
if ( bboxSymbol.border()->width().isSet() )
getOrCreateStateSet()->setAttribute( new osg::LineWidth( bboxSymbol.border()->width().value() ));
addPrimitiveSet( new osg::DrawArrays(GL_LINE_LOOP, 0, v->getNumElements()) );
}
setColorArray( c );
setColorBinding( osg::Geometry::BIND_PER_PRIMITIVE_SET );
// add the static "isText=true" uniform; this is a hint for the annotation shaders
// if they get installed.
static osg::ref_ptr<osg::Uniform> s_isTextUniform = new osg::Uniform(osg::Uniform::BOOL, AnnotationUtils::UNIFORM_IS_TEXT());
s_isTextUniform->set( false );
getOrCreateStateSet()->addUniform( s_isTextUniform.get() );
// Disable culling since this bounding box will eventually be drawn in screen space.
#if OSG_MIN_VERSION_REQUIRED(3,4,0)
setCullingActive(false);
#endif
}
示例9:
void
HorizonTileCuller::set(const osg::BoundingBox& bbox)
{
// Adjust the horizon ellipsoid based on the minimum Z value of the tile;
// necessary because a tile that's below the ellipsoid (ocean floor, e.g.)
// may be visible even if it doesn't pass the horizon-cone test. In such
// cases we need a more conservative ellipsoid.
double zMin = bbox.corner(0).z();
if ( zMin < 0.0 )
{
_horizonProto.setEllipsoid( osg::EllipsoidModel(_radiusEquator + zMin, _radiusPolar + zMin) );
}
// consider the uppermost 4 points of the tile-aligned bounding box.
// (the last four corners of the bbox are the "zmax" corners.)
for(unsigned i=0; i<4; ++i)
{
_points[i] = bbox.corner(4+i) * _local2world;
}
}
示例10: ComputeBoundingBoxByRotation
void ComputeBoundingBoxByRotation(osg::BoundingBox & InOut,osg::Vec3 BBCenter,float BBSize,osg::Matrixd Rotation)
{
osg::BoundingBox bb;
bb.set(BBCenter.x()-BBSize,BBCenter.y()-BBSize,BBCenter.z()-BBSize,BBCenter.x()+BBSize,BBCenter.y()+BBSize,BBCenter.z()+BBSize);
osg::BoundingBox Tbb;
for(unsigned int i=0;i<8;i++)
{
Tbb.expandBy(Rotation.preMult(bb.corner(i)));
}
InOut.set(Tbb.xMin(),Tbb.yMin(),Tbb.zMin(),Tbb.xMax(),Tbb.yMax(),Tbb.zMax());
}
示例11: setUseVertexBufferObjects
BboxDrawable::BboxDrawable( const osg::BoundingBox& box, const BBoxSymbol &bboxSymbol ) :
osg::Geometry()
{
setUseVertexBufferObjects(true);
float margin = bboxSymbol.margin().isSet() ? bboxSymbol.margin().value() : 2.f;
osg::Vec3Array* v = new osg::Vec3Array();
if ( bboxSymbol.geom().isSet() && bboxSymbol.geom().value() == BBoxSymbol::GEOM_BOX_ORIENTED )
{
float h = box.yMax() - box.yMin() + 2.f * margin;
v->push_back( osg::Vec3(box.xMax()+margin+h/2.f, box.yMax()+margin-h/2.f, 0) );
}
v->push_back( osg::Vec3(box.xMax()+margin, box.yMax()+margin, 0) );
v->push_back( osg::Vec3(box.xMin()-margin, box.yMax()+margin, 0) );
v->push_back( osg::Vec3(box.xMin()-margin, box.yMin()-margin, 0) );
v->push_back( osg::Vec3(box.xMax()+margin, box.yMin()-margin, 0) );
setVertexArray(v);
if ( v->getVertexBufferObject() )
v->getVertexBufferObject()->setUsage(GL_STATIC_DRAW_ARB);
osg::Vec4Array* c = new osg::Vec4Array(osg::Array::BIND_PER_PRIMITIVE_SET);
if ( bboxSymbol.fill().isSet() )
{
c->push_back( bboxSymbol.fill()->color() );
osg::DrawElements* de = new osg::DrawElementsUByte(GL_TRIANGLE_STRIP);
de->addElement(0);
de->addElement(1);
de->addElement(3);
de->addElement(2);
addPrimitiveSet(de);
//addPrimitiveSet( new osg::DrawArrays(GL_POLYGON, 0, v->getNumElements()) );
}
if ( bboxSymbol.border().isSet() )
{
c->push_back( bboxSymbol.border()->color() );
if ( bboxSymbol.border()->width().isSet() )
getOrCreateStateSet()->setAttribute( new osg::LineWidth( bboxSymbol.border()->width().value() ));
addPrimitiveSet( new osg::DrawArrays(GL_LINE_LOOP, 0, v->getNumElements()) );
}
setColorArray( c );
// Disable culling since this bounding box will eventually be drawn in screen space.
setCullingActive(false);
}
示例12: apply
void apply(osg::Node &node)
{
osg::Transform *mt;
osg::Geode *geo;
osg::ref_ptr<osg::RefMatrix> M = matStack.back();
if ((geo = dynamic_cast<osg::Geode *>(&node)))
{
unsigned int i;
osg::BoundingBox bb;
for (i = 0; i < geo->getNumDrawables(); i++)
{
bb.expandBy(geo->getDrawable(i)->getBound());
}
if (M.get())
{
bbox.expandBy(osg::Vec3(bb.xMin(), bb.yMin(), bb.zMin()) * *M);
bbox.expandBy(osg::Vec3(bb.xMax(), bb.yMax(), bb.zMax()) * *M);
}
else
{
bbox.expandBy(osg::Vec3(bb.xMin(), bb.yMin(), bb.zMin()));
bbox.expandBy(osg::Vec3(bb.xMax(), bb.yMax(), bb.zMax()));
}
}
if ((mt = dynamic_cast<osg::Transform *>(&node)))
{
osg::ref_ptr<osg::RefMatrix> matrix = new osg::RefMatrix;
mt->computeLocalToWorldMatrix(*matrix, this);
matStack.push_back(matrix);
}
traverse(node);
if ((mt = dynamic_cast<osg::Transform *>(&node)))
{
matStack.pop_back();
}
}
示例13: Horizon
void
HorizonTileCuller::set(const SpatialReference* srs,
const osg::Matrix& local2world,
const osg::BoundingBox& bbox)
{
if (!_horizon.valid() && srs->isGeographic())
{
_horizon = new Horizon();
}
if (_horizon.valid())
{
_horizon->setEllipsoid(*srs->getEllipsoid());
//_radiusPolar = srs->getEllipsoid()->getRadiusPolar();
//_radiusEquator = srs->getEllipsoid()->getRadiusEquator();
//_local2world = local2world;
// Adjust the horizon ellipsoid based on the minimum Z value of the tile;
// necessary because a tile that's below the ellipsoid (ocean floor, e.g.)
// may be visible even if it doesn't pass the horizon-cone test. In such
// cases we need a more conservative ellipsoid.
double zMin = (double)std::min( bbox.corner(0).z(), 0.0f );
zMin = std::max(zMin, -25000.0); // approx the lowest point on earth * 2
_horizon->setEllipsoid( osg::EllipsoidModel(
srs->getEllipsoid()->getRadiusEquator() + zMin,
srs->getEllipsoid()->getRadiusPolar() + zMin) );
// consider the uppermost 4 points of the tile-aligned bounding box.
// (the last four corners of the bbox are the "zmax" corners.)
for(unsigned i=0; i<4; ++i)
{
_points[i] = bbox.corner(4+i) * local2world;
}
//_bs.set(bbox.center() * _local2world, bbox.radius());
}
}
示例14: defined
bool DebugShadowMap::ViewData::DebugBoundingBox
( const osg::BoundingBox & bb, const char * name )
{
bool result = false;
#if defined( _DEBUG ) || defined( DEBUG )
if( !name ) name = "";
osg::BoundingBox & bb_prev = _boundingBoxMap[ std::string( name ) ];
result = bb.center() != bb_prev.center() || bb.radius() != bb_prev.radius();
if( result )
std::cout << "Box<" << name << "> ("
<< ( bb._max._v[0] + bb._min._v[0] ) * 0.5 << " "
<< ( bb._max._v[1] + bb._min._v[1] ) * 0.5 << " "
<< ( bb._max._v[2] + bb._min._v[2] ) * 0.5 << ") ["
<< ( bb._max._v[0] - bb._min._v[0] ) << " "
<< ( bb._max._v[1] - bb._min._v[1] ) << " "
<< ( bb._max._v[2] - bb._min._v[2] ) << "] "
<< std::endl;
bb_prev = bb;
#endif
return result;
}
示例15: GetBoundingBox
bool GetBoundingBox(osg::BoundingBox & BB, dtCore::DeltaDrawable & drawable)
{
osg::Node* node = drawable.GetOSGNode();
if (node != 0)
{
dtUtil::BoundingBoxVisitor bbv;
node->accept(bbv);
// no copy constructor for osg::BB...
BB.set(bbv.mBoundingBox._min, bbv.mBoundingBox._max);
return true;
}
LOG_WARNING("No valid osg node of drawable when asking for bounding box.");
return false;
}