当前位置: 首页>>代码示例>>C++>>正文


C++ BoundingSphere::center方法代码示例

本文整理汇总了C++中BoundingSphere::center方法的典型用法代码示例。如果您正苦于以下问题:C++ BoundingSphere::center方法的具体用法?C++ BoundingSphere::center怎么用?C++ BoundingSphere::center使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BoundingSphere的用法示例。


在下文中一共展示了BoundingSphere::center方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: add

 /**
  * Adds a sphere.    
  */
 void add(const BoundingSphere &sphere)
 {
     const float sCenterMinusCenterLen = vecLength(sphere.center() - m_center);
     if ( sCenterMinusCenterLen > m_radius )
     {
         m_center = (sphere.center() + m_center)/2.0f;
         m_radius = sCenterMinusCenterLen + hgMax(sphere.radius(), m_radius);
     }
     else if ( m_radius < sphere.radius() )
     {
         *this = sphere;
     }
 }
开发者ID:flair2005,项目名称:ThunderVision,代码行数:16,代码来源:boundingsphere.hpp

示例2: convert

Node* OrientationConverter::convert( Node *node )
{
    // Order of operations here is :
    // 1. If world frame option not set, translate to world origin (0,0,0)
    // 2. Rotate to new orientation
    // 3. Scale in new orientation coordinates
    // 4. If an absolute translation was specified then
    //        - translate to absolute translation in world coordinates
    //    else if world frame option not set,
    //        - translate back to model's original origin.
    BoundingSphere bs = node->getBound();
    Matrix C;

    if (_use_world_frame)
    {
        C.makeIdentity();
    }
    else
    {
        C = Matrix::translate( -bs.center() );
        
        if (_trans_set == false)
            T = Matrix::translate( bs.center() );
    }


    osg::Group* root = new osg::Group;
    osg::MatrixTransform* transform = new osg::MatrixTransform;

    transform->setDataVariance(osg::Object::STATIC);
    transform->setMatrix( C * R * S * T );
    
    if (!S.isIdentity())
    {
        #if !defined(OSG_GLES2_AVAILABLE)
            // Add a normalize state. This will be removed if the FlattenStaticTransformsVisitor works
            transform->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
        #endif
    }

    root->addChild(transform);
    transform->addChild(node);

    osgUtil::Optimizer::FlattenStaticTransformsVisitor fstv;
    root->accept(fstv);
    fstv.removeTransforms(root);
    
    return root->getChild(0);
}
开发者ID:151706061,项目名称:OpenSceneGraph,代码行数:49,代码来源:OrientationConverter.cpp

示例3: 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;

}
开发者ID:joevandyk,项目名称:osg,代码行数:49,代码来源:BoundingSphere.cpp

示例4: adjustCamera

void CameraController::adjustCamera( int viewWidth, int viewHeight, double distBetweenAtAndBase )
{
	assert(_camera != NULL);

	Group* group = new Group;
	for (unsigned int i = 0; i < _camera->getNumChildren(); ++i)
	{
		group->addChild(_camera->getChild(i));
	}
	BoundingSphere bounding = group->getBound();
	group->unref();

	double z;
	z = abs(bounding.center().z());

	_camera->setViewport( 0, 0, viewWidth, viewHeight );

	if( bounding.radius() <= 0 )
	{
		return;
	}

	double dist = 0;
	if (viewWidth > viewHeight)
	{
		dist = z + bounding.radius() * COT_CAMERA_FOV_2 * 0.8;
	}
	else
	{
		dist = (z + bounding.radius() * COT_CAMERA_FOV_2) * viewHeight / viewWidth * 0.8;
	}

	_initEye = Vec3d(0, 0, dist);
	_initAt = Vec3d(0, 0, distBetweenAtAndBase);
	_initUp = Vec3d(0, 1, 0);
	_initBase = Vec3d(0, 0, 0);

	_currEye = _initEye;
	_currAt = _initAt;
	_currUp = _initUp;
	_currBase = _initBase;

	_testEye = _currEye;
	_testAt = _currAt;
	_testUp = _currUp;
	_testBase = _currBase;

	_eyeToWorldMatrix.makeTranslate(_initEye);
	_atToWorldMatrix.makeTranslate(_initAt);
	_baseEyeToWorldMatrix.makeTranslate(_initBase);
	_baseAtToWorldMatrix.makeTranslate(_initBase);

	setCameraViewMatrix();
	setCameraProjectionMatrix();
}
开发者ID:ymy88,项目名称:PSDF,代码行数:55,代码来源:CameraController.cpp

示例5: 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;
    }
开发者ID:flair2005,项目名称:ThunderVision,代码行数:21,代码来源:collision.cpp

示例6: 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;
        }

    }
开发者ID:flair2005,项目名称:ThunderVision,代码行数:37,代码来源:collision.cpp

示例7: spherePointDistance

    float spherePointDistance(const BoundingSphere &sphere,
                              const Vec3f &D,
                              const Vec3f &P)
    {
        float distance;

        const Vec3f E = sphere.center() - P;
        if ( !Math::lowestPositiveQuadraticRoot(
                 vecDot(D, D),
                 2.0f*vecDot(D, E),
                 vecDot(E, E) - sphere.radius()*sphere.radius(),
                 &distance) )
        {
            return NoIntersection;
        }

        return distance;
    }
开发者ID:flair2005,项目名称:ThunderVision,代码行数:18,代码来源:collision.cpp

示例8: createPatchGroup

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;
}
开发者ID:2php,项目名称:osgearth,代码行数:20,代码来源:PatchSet.cpp

示例9: sphereTriangleCollision

    float sphereTriangleCollision(
        const BoundingSphere &sphere,
        const Vec3f &dir,
        const Vec3f &p0, const Vec3f &p1,
        const Vec3f &p2, Vec3f *contactPoint)
    {
        Planef trigPlane(p0, p1, p2);
        float d = vecDot(dir, trigPlane.normal);
        float minDist = NoIntersection;

        if  ( vecDot(dir, trigPlane.normal) > 0.0 )
        {
            return NoIntersection;
        }
    
        if ( d == 0.0f )
        {
            if ( trigPlane.distance(sphere.center()) < sphere.radius() )
                return NoIntersection;
        }
        else 
        {
            const Vec3f orign = sphere.center()
                - sphere.radius()*vecNormal(trigPlane.normal);
            const float t = -(trigPlane.d + vecDot(orign, trigPlane.normal)) / d;

            if ( t >= 0.0f )
            {
            
                const Vec3f planePoint = orign + dir * t;
                if ( pointInTriangle(planePoint,
                                     vecNormal(trigPlane.normal),
                                     p0, p1, p2) )
                {
                    *contactPoint = planePoint;
                    return t;
                }
            }
        }

        float dist = spherePointDistance(sphere, dir, p0);
        if ( dist < minDist )
        {
            minDist = dist;
            *contactPoint = p0;
        }

        dist = spherePointDistance(sphere, dir, p1);
        if ( dist < minDist )
        {
            minDist = dist;
            *contactPoint = p1;
        }

        dist = spherePointDistance(sphere, dir, p2);
        if ( dist < minDist )
        {
            minDist = dist;
            *contactPoint = p2;
        }

        Vec3f edgeContactPoint;
        dist = sphereEdgeDistance(sphere, dir, p1, p0, &edgeContactPoint);
        if ( dist < minDist )
        {
            minDist = dist;
            *contactPoint = edgeContactPoint;
        }

        dist = sphereEdgeDistance(sphere, dir, p2, p1, &edgeContactPoint);
        if ( dist < minDist )
        {
            minDist = dist;
            *contactPoint = edgeContactPoint;
        }

        dist = sphereEdgeDistance(sphere, dir, p0, p2, &edgeContactPoint);
        if ( dist < minDist )
        {
            minDist = dist;
            *contactPoint = edgeContactPoint;
        }

        return minDist;
    }
开发者ID:flair2005,项目名称:ThunderVision,代码行数:85,代码来源:collision.cpp


注:本文中的BoundingSphere::center方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。