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

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 ;

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值