自定义包围框尺寸和获取物体长宽高参数

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(*it)->getGeometry();//包围盒本质上是一个给定左下角和右上角的盒子,vuBoxnewBox;//右上角		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);	elsegeometry->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(*it)->getGeometry();//包围盒本质上是一个给定左下角和右上角的盒子,const vuBox &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 ;


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部