//自行設置包圍框
//默認值爲2,設置包圍盒;其他值則不渲染顯示包圍盒
void SetObjRenderStrategy(const vpObject *pObj,int mode=2)
{
if(!pObj)
return ;
//包圍盒
vrRenderStrategyBounds *m_strategyBounds;
m_strategyBounds = new vrRenderStrategyBounds();
m_strategyBounds->ref();
m_strategyBounds->setLineWidth( 2.0f );
m_strategyBounds->setColor( 1.0f, 0.0f, 0.0f, 1.0f );
m_strategyBounds->setWireframeEnable(true);
// set the render strategy on all geometries for the object
//設置物體參數
//設置長 寬 高(具體值可以自行設置)
float fxValue=0.2,fyValue=0.2,fzValue=0.2;
//預擴大值(具體值可以自行設置)
float fRowValue=0.05,fColValue=0.05,fTopValue=0.05;
vrGeometry *geometry;
vpObject::const_iterator_geometry it, ite = pObj->end_geometry();
for (it=pObj->begin_geometry();it!=ite;++it)
{
if ((*it)->isExactClassType(vsGeometry::getStaticClassType()))
{
geometry = static_cast<vsGeometry *>(*it)->getGeometry();
//包圍盒本質上是一個給定左下角和右上角的盒子,
vuBox<float>newBox;
//右上角
newBox.m_max[0]=fxValue/2.0+fColValue;
newBox.m_max[1]=fyValue/2.0+fRowValue;
newBox.m_max[2]=fzValue/2.0+fTopValue;
//左下角
newBox.m_min[0]=-fxValue/2.0-fColValue;;
newBox.m_min[1]=-fyValue/2.0-fRowValue;
newBox.m_min[2]=-fzValue/2.0-fTopValue;
geometry->setBounds(newBox);
if(mode==2)
geometry->setRenderStrategy(m_strategyBounds);
else
geometry->setRenderStrategy(NULL);
}//end of if
}// end of for
}
//以包圍盒的方式獲取物體的長寬高
/// 以包圍盒的方式獲取物體的長寬高
void GetObjectLengthWidthHeight(const vpObject *pObj, float &Length, float & Width,float & Height )
{
if(!pObj)
return ;
vrGeometry *geometry;
vpObject::const_iterator_geometry it, ite = pObj->end_geometry();
for (it=pObj->begin_geometry();it!=ite;++it)
{
if ((*it)->isExactClassType(vsGeometry::getStaticClassType()))
{
geometry = static_cast<vsGeometry *>(*it)->getGeometry();
//包圍盒本質上是一個給定左下角和右上角的盒子,
const vuBox<float> &box=geometry->getBounds();
Width=box.m_max[0]-box.m_min[0];
Length=box.m_max[1]-box.m_min[1];
Height=box.m_max[2]-box.m_min[2];
} //end of if
}//end of for
}