当前位置: 首页>>代码示例>>C#>>正文


C# Mesh.Intersect方法代码示例

本文整理汇总了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;
        }
开发者ID:GreggBzz,项目名称:Outerspace,代码行数:59,代码来源:Starport.cs

示例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);
        }
开发者ID:NeuroRoboticTech,项目名称:AnimatLabVersion1,代码行数:15,代码来源:Util_DX.cs

示例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);
 }
开发者ID:beginor,项目名称:WorldWind,代码行数:13,代码来源:MyChart.cs

示例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;
            }
        }
开发者ID:nolenfelten,项目名称:Blam_BSP,代码行数:29,代码来源:Renderer.cs


注:本文中的Mesh.Intersect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。