本文整理汇总了C++中BoundingSphere类的典型用法代码示例。如果您正苦于以下问题:C++ BoundingSphere类的具体用法?C++ BoundingSphere怎么用?C++ BoundingSphere使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BoundingSphere类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BoundingSphere
BoundingSphere LOD::computeBound() const
{
if (_centerMode==USER_DEFINED_CENTER && _radius>=0.0f)
{
return BoundingSphere(_userDefinedCenter,_radius);
}
else if (_centerMode==UNION_OF_BOUNDING_SPHERE_AND_USER_DEFINED && _radius>=0.0f)
{
BoundingSphere bs = BoundingSphere(_userDefinedCenter,_radius);
bs.expandBy(Group::computeBound());
//alternative (used in TxpPagedLOD)
// bs.expandRadiusBy(Group::computeBound());
return bs;
}
else
{
return Group::computeBound();
}
}
示例2: IntersectBoundingSphere
IntersectData BoundingSphere::IntersectBoundingSphere(const BoundingSphere& other) const
{
//The radius is the distance from any point on the sphere to the center.
//
//Therefore, by adding the radius of two spheres together, the result is
//the distance between the centers of the spheres when they are touching.
float radiusDistance = m_radius + other.GetRadius();
float centerDistance = (other.GetCenter() - m_center).Length();
//Since the radiusDistance is the distance bwteen the centers of the
//spheres are when they're touching, you can subtract that from the
//distance between the centers of the spheres to get the actual distance
//between the two spheres.
float distance = centerDistance - radiusDistance;
//Spheres can only be intersecting if the distance between them is less
//than 0.
return IntersectData(distance < 0, distance);
}
示例3: glusCreateConef
ModelEntitySP PrimitiveEntityFactory::createConePrimitiveEntity(const string& name, float scaleX, float scaleY, float scaleZ, const SurfaceMaterialSP& surfaceMaterial, const vector<AnimationStackSP>& allAnimStacks) const
{
ModelFactory modelFactory;
GLUSshape shape;
float halfExtend = 0.5f;
float radius = 0.5f;
uint32_t numberSlices = 32;
uint32_t numberStacks = 32;
glusCreateConef(&shape, halfExtend, radius, numberSlices, numberStacks);
BoundingSphere boundingSphere;
boundingSphere.setRadius(glusLengthf(halfExtend, radius, 0.0f));
return ModelEntitySP(new ModelEntity(name, modelFactory.createModel(name, boundingSphere, shape, surfaceMaterial, allAnimStacks), scaleX, scaleY, scaleZ));
}
示例4: glusCreateTorusf
ModelEntitySP PrimitiveEntityFactory::createTorusPrimitiveEntity(const string& name, float scaleX, float scaleY, float scaleZ, const SurfaceMaterialSP& surfaceMaterial, const vector<AnimationStackSP>& allAnimStacks) const
{
ModelFactory modelFactory;
GLUSshape shape;
float innerRadius = 0.25f;
float outerRadius = 0.5f;
uint32_t numberSlices = 32;
uint32_t numberStacks = 32;
glusCreateTorusf(&shape, innerRadius, outerRadius, numberSlices, numberStacks);
BoundingSphere boundingSphere;
boundingSphere.setRadius(outerRadius);
return ModelEntitySP(new ModelEntity(name, modelFactory.createModel(name, boundingSphere, shape, surfaceMaterial, allAnimStacks), scaleX, scaleY, scaleZ));
}
示例5: computeBound
BoundingSphere Transform::computeBound() const
{
BoundingSphere bsphere = Group::computeBound();
if (!bsphere.valid()) return bsphere;
// note, NULL pointer for NodeVisitor, so compute's need
// to handle this case gracefully, normally this should not be a problem.
Matrix l2w;
computeLocalToWorldMatrix(l2w,NULL);
Vec3 xdash = bsphere._center;
xdash.x() += bsphere._radius;
xdash = xdash*l2w;
Vec3 ydash = bsphere._center;
ydash.y() += bsphere._radius;
ydash = ydash*l2w;
Vec3 zdash = bsphere._center;
zdash.z() += bsphere._radius;
zdash = zdash*l2w;
bsphere._center = bsphere._center*l2w;
xdash -= bsphere._center;
float len_xdash = xdash.length();
ydash -= bsphere._center;
float len_ydash = ydash.length();
zdash -= bsphere._center;
float len_zdash = zdash.length();
bsphere._radius = len_xdash;
if (bsphere._radius<len_ydash) bsphere._radius = len_ydash;
if (bsphere._radius<len_zdash) bsphere._radius = len_zdash;
return bsphere;
}
示例6: computeBound
BoundingSphere Switch::computeBound() const
{
BoundingSphere bsphere;
if (_children.empty())
{
return bsphere;
}
// note, special handling of the case when a child is an Transform,
// such that only Transforms which are relative to their parents coordinates frame (i.e this group)
// are handled, Transform relative to and absolute reference frame are ignored.
BoundingBox bb;
bb.init();
for(unsigned int pos=0;pos<_children.size();++pos)
{
const osg::Transform* transform = _children[pos]->asTransform();
if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF)
{
if( _values[pos] == true )
bb.expandBy(_children[pos]->getBound());
}
}
if (!bb.valid())
{
return bsphere;
}
bsphere._center = bb.center();
bsphere._radius = 0.0f;
for(unsigned int pos=0;pos<_children.size();++pos)
{
const osg::Transform* transform = _children[pos]->asTransform();
if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF)
{
if( _values[pos] == true )
bsphere.expandRadiusBy(_children[pos]->getBound());
}
}
return bsphere;
}
示例7: BoundingSphere
/*!
* creates a BoundingSphere which encloses all given bvhNodes and adds all children
* to this parent
*/
void DeformableBvhNode::createBoundingSphere(const std::list<DeformableBvhNode*>& bvhNodes) {
//std::cout << "DeformableBvhNode::createBoundingSphere(const std::list<DeformableBvhNode*>& bvhNodes)" << std::endl;
BoundingSphere* bv = 0;
for (std::list<DeformableBvhNode*>::const_iterator iter = bvhNodes.begin();
iter != bvhNodes.end();
++iter) {
if (bv == 0) {
bv = new BoundingSphere(*((BoundingSphere*)((*iter)->getBoundingVolume())));
} else {
bv->mergeWith((BoundingSphere*)((*iter)->getBoundingVolume()));
}
}
mBoundingVolume = bv;
}
示例8: computeBound
BoundingSphere Geode::computeBound() const
{
BoundingSphere bsphere;
_bbox.init();
DrawableList::const_iterator itr;
for(itr=_drawables.begin();
itr!=_drawables.end();
++itr)
{
_bbox.expandBy((*itr)->getBound());
}
if (_bbox.valid())
{
bsphere.expandBy(_bbox);
}
return bsphere;
}
示例9: createPatch
Node* PatchSet::createPatchGroup(const std::string& filename,
PatchOptions* poptions)
{
PatchGroup* pgroup = new PatchGroup;
pgroup->setOptions(poptions);
Transform* patch = createPatch(filename, poptions);
BoundingSphere bsphere = patch->getBound();
pgroup->setCenter(bsphere.center());
if (poptions->getPatchLevel() >= _maxLevel)
{
pgroup->addChild(patch, 0.0, 1e10);
}
else
{
pgroup->addChild(patch, 0.0, 1.0);
pgroup->setRange(1, 1.0, 1e10);
pgroup->setFileName(1, "foo.osgearth_engine_seamless_patch");
}
return pgroup;
}
示例10: sphereSphereCollision
bool sphereSphereCollision(const BoundingSphere &M,
const Vec3f &vel,
const BoundingSphere &S)
{
const Vec3f e = M.center() - S.center();
const float r = S.radius() + M.radius();
if ( vecLength(e) < r )
return true;
const float delta = Math::square(vecDot(e, vel))
- vecDot(vel, vel) * (vecDot(e, e) - r*r);
if ( delta < 0.0f )
return false;
const float t = (-vecDot(e, vel) - std::sqrt(delta)) / vecDot(vel, vel);
if ( t < 0.0f || t > 1.0f )
return false;
return true;
}
示例11: IntersectingRayAgainstSphere
bool BasicPrimitiveTests::IntersectingRayAgainstSphere(const Ray & ray, const BoundingSphere & sphere, float & rtn_t)
{
/*
Main idea:
- Ray is substituted into sphere equation. Then solve quadratic formula for intersection.
- Test if intersection is within segment/ray endpoints
-> Use dot(X-C, X-C) = exp(r, 2)
-> As sphere equation.
Solving for "t":
-> Quadratic equation in "t" encountered.
-> where b = dot(m, d)
-> where c = dot(m, m) - r*r
-> where m = P-C
-> t = -b + sqrt(exp(b, 2) - c)
-> t = -b - sqrt(exp(b, 2) - c)
Notes:
-> Number of real roots => number of intersections:
-> Categorized by discriminant d = exp(b, 2) - c
-> May have false intersection with t < 0 when ray starts from inside sphere.
*/
Eigen::Vector3f m = ray.GetOrigin() - sphere.GetCenter();
float b = (m).dot(ray.GetDirection());
float c = m.dot(m);
if (c > 0.0f && b > 0.0f)
{
//Case: Ray origin outside of sphere and points away. => No Intersections.
return false;
}
float discriminant = b * b - c;
if (discriminant < 0.0f)
{
//Case: Misses sphere
return false;
}
else
{
//Case: Hits sphere. Calculate smallest t.
rtn_t = -b - sqrt(discriminant);
if (rtn_t < 0.0f)
{
rtn_t = 0.0f;
}
return true;
}
}
示例12: IsVisible
//----------------------------------------------------------------------------
bool Culler::IsVisible (BoundingSphere const& sphere)
{
if (sphere.GetRadius() == 0.0f)
{
// The node is a dummy node and cannot be visible.
return false;
}
// Start with the last pushed plane, which is potentially the most
// restrictive plane.
int index = mPlaneQuantity - 1;
unsigned int mask = (1u << index);
for (int i = 0; i < mPlaneQuantity; ++i, --index, mask >>= 1)
{
if (mPlaneState & mask)
{
int side = sphere.WhichSide(mPlane[index]);
if (side < 0)
{
// The object is on the negative side of the plane, so
// cull it.
return false;
}
if (side > 0)
{
// The object is on the positive side of plane. There is
// no need to compare subobjects against this plane, so
// mark it as inactive.
mPlaneState &= ~mask;
}
}
}
return true;
}
示例13: sphereEdgeDistance
float sphereEdgeDistance(
const BoundingSphere &sphere,
const Vec3f &D,
const Vec3f &A,
const Vec3f &B,
Vec3f *contactPoint)
{
const Vec3f AB = B - A;
const Vec3f C = sphere.center() - A;
const float AB2 = vecDot(AB, AB);
const float AB_dot_C = vecDot(C, AB);
const float AB_dot_D = vecDot(AB, D);
float minR;
if ( !Math::lowestPositiveQuadraticRoot(
vecDot(D, D) - Math::square(AB_dot_D)/AB2,
2.0f*(vecDot(C, D) - (AB_dot_D*AB_dot_C)/AB2),
vecDot(C, C) - Math::square(sphere.radius())
- Math::square(AB_dot_C)/AB2,
&minR) )
{
return NoIntersection;
}
const ud::Vec3f intersect = sphere.center() + D*minR - A;
const float t = vecDot(AB, intersect);
if ( 0.0f <= t && t <= AB2 )
{
*contactPoint = A + AB * t;
return minR;
}
else
{
return NoIntersection;
}
}
示例14: IntersectSphere
IntersectData Plane::IntersectSphere(const BoundingSphere& other) const
{
//Calculating the dot product between the Plane's normal and the Sphere's
//center gets how far the sphere's center is along the Plane's normal.
//
//Adding the distance adjusts this value based on how far the Plane itself
//is along the normal.
//
//The end result of this is how far the Sphere's center is from the Plane.
//The absolute value is taken so that this result is always positive.
float distanceFromSphereCenter =
(float)fabs(m_normal.Dot(other.GetCenter()) + m_distance);
//As long as the distanceFromSphereCenter is valid and positive, then
//the distance from the sphere can be calculated simply by subtracting
//it's radius.
float distanceFromSphere = distanceFromSphereCenter - other.GetRadius();
//The only time the plane can be intersecting the sphere is if the sphere
//has less than 0 distance from the plane. Otherwise, if there is distance
//between the plane and sphere, then there must be a gap between the
//plane and sphere, and they cannot be intersecting.
return IntersectData(distanceFromSphere < 0, m_normal * distanceFromSphere);
}
示例15: expandBy
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;
}