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


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

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


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

示例1: 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

示例2: 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

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

示例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: scaleParameters

void ViroManipulator::scaleParameters( const BoundingSphere BB ){
	if ( !BB.valid() ) return;

	//double scaleFactor = BB.radius() * 0.001;
	double scaleFactor = BB.radius() * 0.0001;
	
	//printf("Model Scale Factor: %.4f\n", scaleFactor);

	//BumpDistance        = _safeBD * scaleFactor;
	//AvoidanceDistance   = _safeAD * scaleFactor;
	Acceleration        = _safeAccel * scaleFactor;
	SurfaceSpeedLimiter = Acceleration * 0.1;
	//_AvoidanceReaction = scaleFactor * 5e-8;

	//osg::notify(ALWAYS)<<"Acceleration = " << Acceleration <<std::endl;
	//osg::notify(ALWAYS)<<"Bump-Distance = " << BumpDistance <<std::endl;
	//osg::notify(ALWAYS)<<"Avoidance-Distance = " << AvoidanceDistance <<std::endl;
}
开发者ID:flyskyosg,项目名称:virtualrome,代码行数:18,代码来源:ViroManipulator.cpp

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

示例8: 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

示例9: main

int main(int argc, char** argv)
{
    osg::ArgumentParser arguments(&argc,argv);
    osgViewer::Viewer viewer(arguments);

    if (arguments.argc() <= 1) {
        cerr << "Need a scene.\n";
        return 1;
    }

    osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
    if (!loadedModel) {
        cerr << "couldn't load " << argv[1] << "\n";
        return 1;
    }
    osgUtil::Optimizer optimizer;
    optimizer.optimize(loadedModel.get());
    const BoundingSphere bound = loadedModel->getBound();
    const float displacement = 2.25 * bound.radius();
    Group* scene = new Group;
    StateSet* rootSS = scene->getOrCreateStateSet();

    Shader* vertexShader = new Shader(Shader::VERTEX);
    vertexShader->setShaderSource(vertexShaderSource);
    Shader* fragmentShader = new Shader(Shader::FRAGMENT);
    fragmentShader->setShaderSource(fragmentShaderSource);
    Program* prog = new Program;
    prog->addShader(vertexShader);
    prog->addShader(fragmentShader);
    prog->addBindUniformBlock("colors0", 0);
    rootSS->setAttributeAndModes(prog, StateAttribute::ON);
    // Place 3 instances of the loaded model with different uniform
    // blocks for each.
    //
    // The blocksize is known because of the std140 format.
    const unsigned blockSize = 20 * sizeof(GLfloat);
    ref_ptr<FloatArray> colorArray
        = new FloatArray(&colors1[0],
                         &colors1[sizeof(colors1) / sizeof(GLfloat)]);
    ref_ptr<UniformBufferObject> ubo = new UniformBufferObject;
    colorArray->setBufferObject(ubo.get());
    Group* group1 = new Group;
    StateSet* ss1 = group1->getOrCreateStateSet();
    group1->addChild(loadedModel.get());
    scene->addChild(group1);
    ref_ptr<UniformBufferBinding> ubb1
        = new UniformBufferBinding(0, ubo.get(), 0, blockSize);
    ss1->setAttributeAndModes(ubb1.get(), StateAttribute::ON);

    ref_ptr<FloatArray> colorArray2
        = new FloatArray(&colors2[0],
                         &colors2[sizeof(colors2) / sizeof(GLfloat)]);
    ref_ptr<UniformBufferObject> ubo2 = new UniformBufferObject;
    colorArray2->setBufferObject(ubo2.get());
    MatrixTransform* group2 = new MatrixTransform;
    Matrix mat2 = Matrix::translate(-displacement, 0.0, 0.0);
    group2->setMatrix(mat2);
    StateSet* ss2 = group2->getOrCreateStateSet();
    group2->addChild(loadedModel.get());
    scene->addChild(group2);
    ref_ptr<UniformBufferBinding> ubb2
        = new UniformBufferBinding(0, ubo2.get(), 0, blockSize);
    ss2->setAttributeAndModes(ubb2.get(), StateAttribute::ON);

    ref_ptr<FloatArray> colorArray3
        = new FloatArray(&colors2[0],
                         &colors2[sizeof(colors2) / sizeof(GLfloat)]);
    ref_ptr<UniformBufferObject> ubo3 = new UniformBufferObject;
    colorArray3->setBufferObject(ubo3.get());
    MatrixTransform* group3 = new MatrixTransform;
    Matrix mat3 = Matrix::translate(displacement, 0.0, 0.0);
    group3->setMatrix(mat3);
    StateSet* ss3 = group3->getOrCreateStateSet();
    group3->addChild(loadedModel.get());
    scene->addChild(group3);
    ref_ptr<UniformBufferBinding> ubb3
        = new UniformBufferBinding(0, ubo3.get(), 0, blockSize);
    ubb3->setUpdateCallback(new UniformBufferCallback);
    ubb3->setDataVariance(Object::DYNAMIC);
    ss3->setAttributeAndModes(ubb3.get(), StateAttribute::ON);

    viewer.setSceneData(scene);
    viewer.realize();
    return viewer.run();
}
开发者ID:151706061,项目名称:OpenSceneGraph,代码行数:85,代码来源:osguniformbuffer.cpp

示例10: main

int main(int argc, char **argv)
{
   // use an ArgumentParser object to manage the program arguments.
   osg::ArgumentParser arguments(&argc,argv);
   
   // read the first useful arguments for creating video geode
   int camNumber=0;
   arguments.read("--cam",camNumber);
   int imWidth = 640;
   arguments.read("--width",imWidth);
   int imHeight = 480;
   arguments.read("--height",imHeight);
   int threshold = 230;
   arguments.read("--thres",threshold);
   // do we want to use a movie?
   movieName="";
   arguments.read("--video", movieName);
   if(!movieName.empty())
      cout<<"Movie name: "<<movieName<<endl;
   
   // we need the scene's state set to enable the light for the entire scene
	scene = new Group();
	lightStateSet = scene->getOrCreateStateSet();
	lightStateSet->ref();
	
   /*cout<<"Number of arguments: "<<arguments.argc()<<endl;
   movieName = "";
   if(arguments.argc() >= 3 && arguments.isString(2)){
      movieName = arguments[2];
      cout<<"Movie name: "<<movieName<<endl;
   }*/
   
	// create VideoGeometry
	try {
		videoGeode = new VideoGeode(movieName,camNumber,imWidth,imHeight);
		videoGeode->setThreshold(threshold);
		// stars / starfield
		Material *material = new Material();
		material->setEmission(Material::FRONT, Vec4(1.0f, 1.0f, 1.0f, 1.0f));
		material->setAmbient(Material::FRONT,  Vec4(1.0f, 1.0f, 1.0f, 1.0f));
		material->setShininess(Material::FRONT, 25.0f);
		// creating a video plane
		videoGeode->prepareMaterial(material);
      //videoPlane = videoGeode->createVideoPlane(1,1, true);
      videoPlane = videoGeode->createVideoPlane(2,2, true);
      videoPlane->setPosition(Vec3(0,0,0));
	} catch (char *e) {
		std::cerr << e;
	}
	
   scene->addChild(videoPlane);
   
      
   // load the nodes from the commandline arguments.
   model = new PositionAttitudeTransform();
        
   Node *osgModel = osgDB::readNodeFiles(arguments);
   
   // if not loaded assume no arguments passed in, try use default mode instead.
   if (!osgModel) osgModel = osgDB::readNodeFile("cessna.osg"); // I can't get Xcode to search in this directory (OSG_FILE_PATH) so this does not work
   
   if (osgModel)
   {
      // Resizing the model so that it fits in the window
      BoundingSphere bs = osgModel->getBound();
      float bsR = bs.radius();
      float targetSize = 1.0f; // we set up the projection matrix as an ortho 2d between -1 and 1 --> hence the radius of the model should be of size 1
      float factor = targetSize / bsR;
      std::cout << "Model Bounding Sphere radius is: " << bsR << std::endl;
      std::cout << "Scale factor is: " << factor << std::endl;
      model->setScale(osg::Vec3d(factor,factor,factor));
   }
   
   // Adding the model to the PAT node
   model->addChild(osgModel);
   
   //Group *scene = startup();
	//if (!scene) return 1;
   
   // create a light
	lightSource = new LightSource();
	lightSource->setLight(createLight(Vec4(0.9f, 0.9f, 0.9f, 1.0f)));
	// enable the light for the entire scene
	lightSource->setLocalStateSetModes(StateAttribute::ON);
	lightSource->setStateSetModes(*lightStateSet, StateAttribute::ON);
	
	lightTransform = new PositionAttitudeTransform();
	lightTransform->addChild(lightSource);
	lightTransform->setPosition(Vec3(0, 0, 100));
   
   // Adding the 3D model to the scene
   scene->addChild(lightTransform);
   scene->addChild(model);
   
   
   // Testing the movie
   //osg::Image* image = osgDB::readImageFile(arguments[2]);
   
   //cout<<"Number of arguments: "<<arguments.argc()<<endl;
   
//.........这里部分代码省略.........
开发者ID:SPhoenixx,项目名称:NAM,代码行数:101,代码来源:main-VideoGeometry.cpp


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