Vega Prime包围盒设置、尺寸大小、几何中心的获取
//自行设置包围框
//默认值为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
}
获取单个物体的几何中心
const vuSphere< double >& bsphere = WxpVP::pObjectPicked->getBounds();
double x = bsphere.m_ctr[0];
double y = bsphere.m_ctr[1];
double z = bsphere.m_ctr[2];
CString str;
str.Format("center observer at: %f %f %f\n", x, y, z );
AfxMessageBox(str);
return ;