From Tim Moore, "Double precision versions of BoundingBox and BoundingSphere are useful for doing computations in world coordinates, especially when working with a geocentric scene. By default, these classes are built using floats, so templated versions fill a need. I've used the double precision templates to fix some problems with ViewDependentShadow, which will follow shortly.
"
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
#include <osg/BoundingBox>
|
||||
#include <osg/BoundingSphere>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
void BoundingBox::expandBy(const BoundingBox& bb)
|
||||
{
|
||||
if (!bb.valid()) return;
|
||||
|
||||
if(bb._min.x()<_min.x()) _min.x() = bb._min.x();
|
||||
if(bb._max.x()>_max.x()) _max.x() = bb._max.x();
|
||||
|
||||
if(bb._min.y()<_min.y()) _min.y() = bb._min.y();
|
||||
if(bb._max.y()>_max.y()) _max.y() = bb._max.y();
|
||||
|
||||
if(bb._min.z()<_min.z()) _min.z() = bb._min.z();
|
||||
if(bb._max.z()>_max.z()) _max.z() = bb._max.z();
|
||||
}
|
||||
|
||||
|
||||
void BoundingBox::expandBy(const BoundingSphere& sh)
|
||||
{
|
||||
if (!sh.valid()) return;
|
||||
|
||||
if(sh._center.x()-sh._radius<_min.x()) _min.x() = sh._center.x()-sh._radius;
|
||||
if(sh._center.x()+sh._radius>_max.x()) _max.x() = sh._center.x()+sh._radius;
|
||||
|
||||
if(sh._center.y()-sh._radius<_min.y()) _min.y() = sh._center.y()-sh._radius;
|
||||
if(sh._center.y()+sh._radius>_max.y()) _max.y() = sh._center.y()+sh._radius;
|
||||
|
||||
if(sh._center.z()-sh._radius<_min.z()) _min.z() = sh._center.z()-sh._radius;
|
||||
if(sh._center.z()+sh._radius>_max.z()) _max.z() = sh._center.z()+sh._radius;
|
||||
}
|
||||
@@ -1,209 +0,0 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
#include <osg/BoundingSphere>
|
||||
#include <osg/BoundingBox>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
void BoundingSphere::expandBy(const Vec3f& v)
|
||||
{
|
||||
if (valid())
|
||||
{
|
||||
vec_type dv = v-_center;
|
||||
value_type r = dv.length();
|
||||
if (r>_radius)
|
||||
{
|
||||
value_type dr = (r-_radius)*0.5;
|
||||
_center += dv*(dr/r);
|
||||
_radius += dr;
|
||||
} // else do nothing as vertex is within sphere.
|
||||
}
|
||||
else
|
||||
{
|
||||
_center = v;
|
||||
_radius = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BoundingSphere::expandRadiusBy(const Vec3f& v)
|
||||
{
|
||||
if (valid())
|
||||
{
|
||||
value_type r = (v-_center).length();
|
||||
if (r>_radius) _radius = r;
|
||||
// else do nothing as vertex is within sphere.
|
||||
}
|
||||
else
|
||||
{
|
||||
_center = v;
|
||||
_radius = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BoundingSphere::expandBy(const Vec3d& v)
|
||||
{
|
||||
if (valid())
|
||||
{
|
||||
vec_type dv = v-_center;
|
||||
value_type r = dv.length();
|
||||
if (r>_radius)
|
||||
{
|
||||
value_type dr = (r-_radius)*0.5;
|
||||
_center += dv*(dr/r);
|
||||
_radius += dr;
|
||||
} // else do nothing as vertex is within sphere.
|
||||
}
|
||||
else
|
||||
{
|
||||
_center = v;
|
||||
_radius = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BoundingSphere::expandRadiusBy(const Vec3d& v)
|
||||
{
|
||||
if (valid())
|
||||
{
|
||||
value_type r = (v-_center).length();
|
||||
if (r>_radius) _radius = r;
|
||||
// else do nothing as vertex is within sphere.
|
||||
}
|
||||
else
|
||||
{
|
||||
_center = v;
|
||||
_radius = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BoundingSphere::expandBy(const BoundingSphere& sh)
|
||||
{
|
||||
// ignore operation if incomming BoundingSphere is invalid.
|
||||
if (!sh.valid()) return;
|
||||
|
||||
// This sphere is not set so use the inbound sphere
|
||||
if (!valid())
|
||||
{
|
||||
_center = sh._center;
|
||||
_radius = sh._radius;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Calculate d == The distance between the sphere centers
|
||||
double d = ( _center - sh.center() ).length();
|
||||
|
||||
// New sphere is already inside this one
|
||||
if ( d + sh.radius() <= _radius )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// New sphere completely contains this one
|
||||
if ( d + _radius <= sh.radius() )
|
||||
{
|
||||
_center = sh._center;
|
||||
_radius = sh._radius;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Build a new sphere that completely contains the other two:
|
||||
//
|
||||
// The center point lies halfway along the line between the furthest
|
||||
// points on the edges of the two spheres.
|
||||
//
|
||||
// Computing those two points is ugly - so we'll use similar triangles
|
||||
double new_radius = (_radius + d + sh.radius() ) * 0.5;
|
||||
double ratio = ( new_radius - _radius ) / d ;
|
||||
|
||||
_center[0] += ( sh.center()[0] - _center[0] ) * ratio;
|
||||
_center[1] += ( sh.center()[1] - _center[1] ) * ratio;
|
||||
_center[2] += ( sh.center()[2] - _center[2] ) * ratio;
|
||||
|
||||
_radius = new_radius;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void BoundingSphere::expandRadiusBy(const BoundingSphere& sh)
|
||||
{
|
||||
if (sh.valid())
|
||||
{
|
||||
if (valid())
|
||||
{
|
||||
value_type r = (sh._center-_center).length()+sh._radius;
|
||||
if (r>_radius) _radius = r;
|
||||
// else do nothing as vertex is within sphere.
|
||||
}
|
||||
else
|
||||
{
|
||||
_center = sh._center;
|
||||
_radius = sh._radius;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BoundingSphere::expandBy(const BoundingBox& bb)
|
||||
{
|
||||
if (bb.valid())
|
||||
{
|
||||
if (valid())
|
||||
{
|
||||
BoundingBox newbb(bb);
|
||||
|
||||
for(unsigned int c=0;c<8;++c)
|
||||
{
|
||||
Vec3 v = bb.corner(c)-_center; // get the direction vector from corner
|
||||
v.normalize(); // normalise it.
|
||||
v *= -_radius; // move the vector in the opposite direction distance radius.
|
||||
v += _center; // move to absolute position.
|
||||
newbb.expandBy(v); // add it into the new bounding box.
|
||||
}
|
||||
|
||||
_center = newbb.center();
|
||||
_radius = newbb.radius();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_center = bb.center();
|
||||
_radius = bb.radius();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BoundingSphere::expandRadiusBy(const BoundingBox& bb)
|
||||
{
|
||||
if (bb.valid())
|
||||
{
|
||||
if (valid())
|
||||
{
|
||||
for(unsigned int c=0;c<8;++c)
|
||||
{
|
||||
expandRadiusBy(bb.corner(c));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_center = bb.center();
|
||||
_radius = bb.radius();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,8 +197,6 @@ ADD_LIBRARY(${LIB_NAME}
|
||||
BlendColor.cpp
|
||||
BlendEquation.cpp
|
||||
BlendFunc.cpp
|
||||
BoundingBox.cpp
|
||||
BoundingSphere.cpp
|
||||
BufferObject.cpp
|
||||
Camera.cpp
|
||||
CameraView.cpp
|
||||
|
||||
Reference in New Issue
Block a user