#region 依射线 选中Mesh的一个区域
///
/// 依射线 选中Mesh的一个区域
///
///
射线的横坐标
///
射线的纵坐标
///
选中区域序号
public int PickArea(int para_iX, int para_iY)
{
// 由横纵坐标产生选取射线
Vector3 nearVector = new Vector3(para_iX, para_iY, 0);
Vector3 farVector = new Vector3(para_iX, para_iY, 1);
//device.Transform.World = ((CLoadXFile)g_arrayListX[i]).meshWorld;
nearVector.Unproject(device.Viewport, device.Transform.Projection, device.Transform.View, device.Transform.World);
farVector.Unproject(device.Viewport, device.Transform.Projection, device.Transform.View, device.Transform.World);
farVector.Subtract(nearVector);
IntersectInformation closetHit = new IntersectInformation();
bool bIntersect = mesh.Intersect(nearVector, farVector, out closetHit);
if (!bIntersect)
{
return -1;
}
AttributeRange[] ar = mesh.GetAttributeTable();
int iNumberArea = -1;
int iFaceIdx = closetHit.FaceIndex;
for (int j = 0; j < ar.Length; j++)
{
if (iFaceIdx >= ar[j].FaceStart)
{
if (iFaceIdx <= ar[j].FaceStart + ar[j].FaceCount - 1)
{
iNumberArea = j;
break;
}
}
}
return iNumberArea;
}
#endregion
发表于 @
2007年03月22日 11:41:00 | | 编辑|
举报| 收藏