本文整理汇总了C#中Mesh.Intersect方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.Intersect方法的具体用法?C# Mesh.Intersect怎么用?C# Mesh.Intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mesh
的用法示例。
在下文中一共展示了Mesh.Intersect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Pick
public int Pick(Single ptX, Single ptY, Mesh meshtochk)
{
Vector3 v;
Matrix matProj, matView, matInverse, matWorld;
Matrix m;
Vector3 rayOrigin, rayDir;
Vector3 rayObjOrigin, rayObjDirection;
bool hasHit;
int iHit;
iHit = 0;
hasHit = false;
matProj = OuterSpace.device.Transform.Projection; //OuterSpace.device.GetTransform(TransformType.Projection)
matView = OuterSpace.device.Transform.View; //OuterSpace.device.GetTransform(TransformType.View)
matWorld = OuterSpace.device.Transform.World; //OuterSpace.device.GetTransform(TransformType.World)
v.X = (((2.0F * ptX) / OuterSpace.device.Viewport.Width) - 1) / matProj.M11;
v.Y = -(((2.0F * ptY) / OuterSpace.device.Viewport.Height) - 1) / matProj.M22;
v.Z = 1.0F;
m = Matrix.Invert(matView);
// Transform the screen space pick ray into 3D space
rayDir.X = v.X * m.M11 + v.Y * m.M21 + v.Z * m.M31;
rayDir.Y = v.X * m.M12 + v.Y * m.M22 + v.Z * m.M32;
rayDir.Z = v.X * m.M13 + v.Y * m.M23 + v.Z * m.M33;
rayOrigin.X = m.M41;
rayOrigin.Y = m.M42;
rayOrigin.Z = m.M43;
// Use inverse of matrix
matInverse = Matrix.Invert(matWorld);
// Transform ray origin and direction by inv matrix
rayObjOrigin = Vector3.TransformCoordinate(rayOrigin, matInverse);
rayObjDirection = Vector3.TransformNormal(rayDir, matInverse);
rayObjDirection = Vector3.Normalize(rayObjDirection);
for (int i = 0; i < 8; i++)
{
hasHit = Geometry.SphereBoundProbe(bndSphere[i].center, bndSphere[i].radius,
rayObjOrigin, rayObjDirection);
if (hasHit)
{
iHit = i;
break;
}
}
if (!hasHit) // see if it hit the station anywhere
{
hasHit = meshtochk.Intersect(rayObjOrigin, rayObjDirection);
if (hasHit) iHit = -1; //hit station
}
return iHit;
}
示例2: TestIntersectWithMouse
public static bool TestIntersectWithMouse(Mesh mshMesh, object objViewport, Matrix mtxProjection, Matrix mtxView, Matrix mtxWorld, int iX, int iY, out IntersectInformation iiInfo)
{
// Create ray for intersection test
Vector3 near = new Vector3(iX, iY, 0);
Vector3 far = new Vector3(iX, iY, 1);
//unproject the near and far vectors to 3D space
near.Unproject(objViewport, mtxProjection, mtxView, mtxWorld);
far.Unproject(objViewport, mtxProjection, mtxView, mtxWorld);
//subtract the near vector from the far vector to get our ray
far.Subtract(near);
return mshMesh.Intersect(near,far, out iiInfo);
}
示例3: IsMouseOver
/// <summary>
/// Check is mouse over a mesh.
/// </summary>
/// <param name="mesh">Mesh to check</param>
/// <param name="dev">device which is ready to render</param>
private bool IsMouseOver(Mesh mesh, Device dev)
{
Vector3 rayPos = new Vector3(DrawArgs.LastMousePosition.X, DrawArgs.LastMousePosition.Y, dev.Viewport.MinZ);
Vector3 rayDir = new Vector3(DrawArgs.LastMousePosition.X, DrawArgs.LastMousePosition.Y, dev.Viewport.MaxZ);
rayPos.Unproject(dev.Viewport, dev.Transform.Projection, dev.Transform.View, dev.Transform.World);
rayDir.Unproject(dev.Viewport, dev.Transform.Projection, dev.Transform.View, dev.Transform.World);
return mesh.Intersect(rayPos, rayDir);
}
示例4: MeshPick
/// <summary>
/// The mesh pick.
/// </summary>
/// <param name="x">The x.</param>
/// <param name="y">The y.</param>
/// <param name="mesh">The mesh.</param>
/// <param name="mat">The mat.</param>
/// <returns>The mesh pick.</returns>
/// <remarks></remarks>
public bool MeshPick(float x, float y, Mesh mesh, Matrix mat)
{
Vector3 s = Vector3.Unproject(
new Vector3(x, y, 0), device.Viewport, device.Transform.Projection, device.Transform.View, mat);
Vector3 d = Vector3.Unproject(
new Vector3(x, y, 1), device.Viewport, device.Transform.Projection, device.Transform.View, mat);
Vector3 rPosition = s;
Vector3 rDirection = Vector3.Normalize(d - s);
if (mesh.Intersect(rPosition, rDirection))
{
return true;
}
else
{
return false;
}
}