|
本帖最后由 libei278214081 于 2014-5-12 10:20 编辑
先声明下,可能比较长,但是又不得不贴的代码。
问题描述:人有15个关节点,我想在相连关节点之间的连杆上花包围盒把人全部都包围起来。
但是却发现只包围了右脚的连杆,而且包围也不正确呢,为什么正方体那么大。
test = new osg::Group();
test->setNodeMask(0);
osg::ref_ptr <osg::MatrixTransform> m_test[15];
for ( int i = 0 ; i < 15; i++ )
{
m_test = new osg::MatrixTransform;
}
osg::ref_ptr <osg::MatrixTransform> *mt_person = m_test;
osg::ref_ptr<osg::Geode> md_geode[15];
for ( int i = 0 ; i < 15; i++ )
{
md_geode = new osg::Geode();
}
osg::ref_ptr <osg::Geode> *mdpt_geode = md_geode;
osg::ComputeBoundsVisitor boundvistor[15];
osg::BoundingBox boundingbox[15];
osg::ref_ptr<osg::ShapeDrawable> sd[15];
for (int i = 0; i < 15; i++)
{
sd = new osg::ShapeDrawable( new osg::Box(osg::Vec3(0.0f,0.0f,0.0f),1.0f));
mdpt_geode -> addDrawable( sd );
mdpt_geode -> setDrawable( i,sd );
sd->setColor( osg::Vec4(1,0,0,1) );
osg::StateSet *state=sd->getOrCreateStateSet();
osg:olygonMode* pm = new osg::PolygonMode(
osg::PolygonMode::FRONT_AND_BACK,
osg::PolygonMode:INE );
state->setAttributeAndModes( pm );
osg::LineWidth* lw = new osg::LineWidth( 3.f );
state->setAttribute( lw );
mdpt_geode -> accept( boundvistor );
boundingbox = boundvistor.getBoundingBox();
mt_person -> addChild(mdpt_geode);
mt_person->setMatrix( osg::Matrix::scale( boundingbox.xMax() - boundingbox.xMin(),
boundingbox.yMax() - boundingbox.yMin(),boundingbox.zMax() - boundingbox.zMin())
* osg::Matrix::translate(boundingbox.center()) );
mtest -> addChild(mt_person);
mtest -> setChild(i, mt_person);
}
mPerson -> dirtyBound();
运行截图:
|
-
|