コード例 #1
0
bool DXFWriterNodeVisitor::writeHeader(const osg::BoundingSphere &bound)
{
    if ( _layers.empty() ) {
        return false;
    }
    _fout << "999\n written by OpenSceneGraph" << std::endl;

    _fout << "0\nSECTION\n2\nHEADER\n";
    _fout << "9\n$ACADVER\n1\nAC1006\n"; // specify minimum autocad version AC1006=R10

    _fout << "9\n$EXTMIN\n10\n"<<bound.center().x()-bound.radius()<<"\n20\n"<<bound.center().y()-bound.radius()<<"\n30\n"<<bound.center().z()-bound.radius()<<"\n";
    _fout << "9\n$EXTMAX\n10\n"<<bound.center().x()+bound.radius()<<"\n20\n"<<bound.center().y()+bound.radius()<<"\n30\n"<<bound.center().z()+bound.radius()<<"\n";

    _fout << "0\nENDSEC\n0\nSECTION\n2\nTABLES\n";
    _fout << "0\nTABLE\n2\nLAYER\n";

    for (std::vector<Layer>::iterator itr=_layers.begin();itr!=_layers.end();itr++) {
        if ( itr->_color ) {
            _fout<<"0\nLAYER\n2\n"<<itr->_name<<"\n70\n0\n62\n"<<itr->_color<<"\n6\nContinuous\n"; // color by layer
        } else {
            _fout<<"0\nLAYER\n2\n"<<itr->_name<<"\n70\n0\n62\n255\n6\nContinuous\n";  // most apps won't read 24bit color without a color value in header
        }
    }

    _fout << "0\nENDTAB\n0\nENDSEC\n";

    _fout << "0\nSECTION\n2\nENTITIES\n";
    _firstPass=false;
    _count=0;

    return true;
}
コード例 #2
0
void OrbitCameraManipulator::zoomToBoundingSphere( const osg::BoundingSphere& bs, double ratio_w )
{
	osg::Vec3f bs_center( bs.center() );
	double bs_radius = bs.radius();
	if( bs_radius <= 0.0 )
	{
		bs_radius = 2.0;
		bs_center._v[2] = 0.5;
	}

	m_rotate_center.set( bs.center() );

	osg::Vec3d eye_lookat(m_eye - m_lookat);
	eye_lookat.normalize();

	// define animation path
	if( m_animation_data )
	{
		osg::Vec3d target_lookat( bs.center() );

		double d_eye = bs_radius/sin( osg::DegreesToRadians(m_fovy*0.5) );
		osg::Vec3d target_eye( target_lookat + eye_lookat*d_eye );

		m_animation_data->m_start_eye.set( m_eye );
		m_animation_data->m_start_lookat.set( m_lookat );
		m_animation_data->m_start_up.set( m_up );

		m_animation_data->m_target_eye.set( target_eye );
		m_animation_data->m_target_lookat.set( target_lookat );
		m_animation_data->m_target_up.set( m_up );

		m_animation_data->_animationTime = 0.6;
		m_animation_data->start( -1 );
	}
}
コード例 #3
0
ファイル: MxCore.cpp プロジェクト: kubark42/osgworks
void MxCore::lookAtAndFit( const osg::BoundingSphere& bs )
{
    // Look at the bounding sphere center.
    osg::Vec3d newDir = bs.center() - _position;
    newDir.normalize();
    setDir( newDir );

    // Set the eve position distance so that the sphere fits into the minimum FOV.
    double minFov = ( _aspect < 1. ) ? ( _aspect * _fovy ) : _fovy;
    const double distance = osgwMx::computeInitialDistanceFromFOVY( bs, minFov );
    setPosition( bs.center() - ( newDir * distance ) );
}
コード例 #4
0
ファイル: StandardShadowMap.cpp プロジェクト: 4ker/osg
void StandardShadowMap::ViewData::aimShadowCastingCamera(
                                        const osg::BoundingSphere &bs,
                                        const osg::Light *light,
                                        const osg::Vec4 &lightPos,
                                        const osg::Vec3 &lightDir,
                                        const osg::Vec3 &lightUpVector
                                        /* by default = osg::Vec3( 0, 1 0 )*/ )
{
    osg::Matrixd & view = _camera->getViewMatrix();
    osg::Matrixd & projection = _camera->getProjectionMatrix();

    osg::Vec3 up = lightUpVector;
    if( up.length2() <= 0 )  up.set( 0,1,0 );

    osg::Vec3d position(lightPos.x(), lightPos.y(), lightPos.z());
    if (lightPos[3]==0.0)   // infinite directional light
    {
        // make an orthographic projection
        // set the position far away along the light direction
        position = bs.center() - lightDir * bs.radius() * 2;
    }

    float centerDistance = (position-bs.center()).length();
    float znear = centerDistance-bs.radius();
    float zfar  = centerDistance+bs.radius();
    float zNearRatio = 0.001f;
    if (znear<zfar*zNearRatio)
        znear = zfar*zNearRatio;

    if ( lightPos[3]!=0.0 ) {  // positional light
        if( light->getSpotCutoff() < 180.0f) // also needs znear zfar estimates
        {
            float spotAngle = light->getSpotCutoff();
            projection.makePerspective( spotAngle * 2, 1.0, znear, zfar);
            view.makeLookAt(position,position+lightDir,up);
        } else { // standard omnidirectional positional light
            float top   = (bs.radius()/centerDistance)*znear;
            float right = top;

            projection.makeFrustum(-right,right,-top,top,znear,zfar);
            view.makeLookAt(position,bs.center(),up );
        }
    }
    else    // directional light
    {
            float top   = bs.radius();
            float right = top;
            projection.makeOrtho(-right, right, -top, top, znear, zfar);
            view.makeLookAt(position,bs.center(),up);
    }
}
コード例 #5
0
ファイル: CovisePlugin.cpp プロジェクト: nixz/covise
void CovisePlugin::expandBoundingSphere(osg::BoundingSphere &bsphere)
{
    if (coVRMSController::instance()->isCluster() && coVRDistributionManager::instance().isActive())
    {
        struct BSphere
        {
            double x, y, z, radius;
        };
        BSphere b_sphere;
        b_sphere.x = bsphere.center()[0];
        b_sphere.y = bsphere.center()[1];
        b_sphere.z = bsphere.center()[2];
        b_sphere.radius = bsphere.radius();

        if (coVRMSController::instance()->isMaster())
        {
            coVRMSController::SlaveData result(sizeof(b_sphere));

            if (coVRMSController::instance()->readSlaves(&result) < 0)
            {
                std::cerr << "VRSceneGraph::getBoundingSphere err: sync error";
                return;
            }

            BSphere bs;
            for (std::vector<void *>::iterator i = result.data.begin();
                 i != result.data.end(); ++i)
            {
                memcpy(&bs, *i, sizeof(bs));
                osg::BoundingSphere otherBs = osg::BoundingSphere(osg::Vec3(bs.x, bs.y, bs.z), bs.radius);
                bsphere.expandBy(otherBs);
            }

            b_sphere.x = bsphere.center()[0];
            b_sphere.y = bsphere.center()[1];
            b_sphere.z = bsphere.center()[2];
            b_sphere.radius = bsphere.radius();

            coVRMSController::instance()->sendSlaves(&b_sphere, sizeof(b_sphere));
        }
        else
        {
            coVRMSController::instance()->sendMaster(&b_sphere, sizeof(b_sphere));
            coVRMSController::instance()->readMaster(&b_sphere, sizeof(b_sphere));
            bsphere = osg::BoundingSphere(osg::Vec3(b_sphere.x, b_sphere.y, b_sphere.z), b_sphere.radius);
        }
    }
}