if (m_isector->getHit())
{
switch(m_mode)
{
case MODE_OBJECT: // pick the object
node = m_isector->getHitObject();
break;
case MODE_GEOMETRY: // pick the geometry
node = m_isector->getHitNode();
break;
case MODE_DOF: // pick the dof
node = getParent(m_isector->getHitNode(), vsDOF::getStaticClassType());
if(node == NULL)
printf("Geometry is not parented by a DOF node\n");
else
printf("dof is %s\n",node->getName());
break;
case MODE_LOD: // pick the lod
// if we don't have a parent whose a lod, return the hit geometry
node = getParent(m_isector->getHitNode(), vsLOD::getStaticClassType());
if(node == NULL)
printf("Geometry is not parented by a LOD node\n");
break;
}
}
關於DOF的選取,關鍵在於物體結構,某個DOF之下包含幾何體,則能選中該DOF。也就是DOF必須作爲某些幾何體的父節點才能被選中,否則就不能選中。
可以採用一種變通方法,選中物體,獲取其全部DOF,然後使用距離判斷。
獲取點擊點的座標:
vuVec3<double> pt;
m_isector->getHitPoint(&pt);
printf("x=%.4f y=%.4f z=%.4f\n",pt[0],pt[1],pt[2]);
然後獲取該物體的全部DOF,計算其中的每一個DOF與點擊點的距離,第一個距離小於設定值S的DOF就可以認爲是被選中的DOF。