|
仿照demo中风吹旗子的程序,绳索和布料是没问题,但一到3D的软体模型就会异常。参考了bullet示例中softbody创建软体语句建了个球,保证了和osg模型的顶点数,起始位置以及半径都相符,但运行之后是一个球体表面生出很多刺,怎么都不是一个正常的球
以下是创建球体的函数代码
osg::Node* maketube( btSoftRigidDynamicsWorld* bw )
{
osg::ref_ptr< osg::Geode > geode( new osg::Geode );
//在osg中创建球体的语句
osg::Geometry* geom = osgwTools::makeGeodesicSphere(osg::Matrix::translate(0, 0,5),3,512);
geode->addDrawable( geom );
// Set up for dynamic data buffer objects
geom->setDataVariance( osg::Object:YNAMIC );
geom->setUseDisplayList( false );
geom->setUseVertexBufferObjects( true );
geom->getOrCreateVertexBufferObject()->setUsage( GL_DYNAMIC_DRAW );
// Set up for dynamic data buffer objects
geom->setDataVariance( osg::Object::DYNAMIC );
geom->setUseDisplayList( false );
geom->setUseVertexBufferObjects( true );
// geom->getOrCreateVertexBufferObject()->setUsage( GL_DYNAMIC_DRAW );
// 这段大括号内是材质贴图的部分,可忽略
{
osg::StateSet* stateSet( geom->getOrCreateStateSet() );
osg:ightModel* lm( new osg::LightModel() );
lm->setTwoSided( true );
stateSet->setAttributeAndModes( lm );
const std::string texName( "fort_mchenry_flag.jpg" );
osg::Texture2D* tex( new osg::Texture2D(
osgDB::readImageFile( texName ) ) );
if( ( tex == NULL ) || ( tex->getImage() == NULL ) )
osg::notify( osg::WARN ) << "Unable to read texture: \"" << texName << "\"." << std::endl;
else
{
tex->setResizeNonPowerOfTwoHint( false );
stateSet->setTextureAttributeAndModes( 0, tex );
}
}
//创建软体球的语句
btSoftBody* softBody=btSoftBodyHelpers::CreateEllipsoid(worldInfo,btVector3(0,0,5),
btVector3(1,1,1)*3,
512);
//设置软体球的物理参数
softBody->m_materials[0]->m_kLST = 0.1;
softBody->m_cfg.kDF = 1;
softBody->m_cfg.kDP = 0.001; // fun factor...
softBody->m_cfg.kPR = 2500;
softBody->setTotalMass(30,true);
softBody->setWindVelocity( btVector3( 50., 0., 0. ) );
softBody->setTotalMass( 1. );
bw->addSoftBody( softBody );
geom->setUpdateCallback( new MeshUpdater( softBody,512 ) );
return( geode.release() );
}
|
|