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


C# Vertex.cross方法代码示例

本文整理汇总了C#中Vertex.cross方法的典型用法代码示例。如果您正苦于以下问题:C# Vertex.cross方法的具体用法?C# Vertex.cross怎么用?C# Vertex.cross使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vertex的用法示例。


在下文中一共展示了Vertex.cross方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RayTriangleIntersection

        /// <summary>
        /// Adapted from http://www.cs.virginia.edu/~gfx/Courses/2003/ImageSynthesis/papers/Acceleration/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf
        /// </summary>
        /// <param name="origin">Origin point of the ray</param>
        /// <param name="direction">Unit vector representing the direction of the ray</param>
        /// <param name="vert0">Position of the first triangle corner</param>
        /// <param name="vert1">Position of the second triangle corner</param>
        /// <param name="vert2">Position of the third triangle corner</param>
        /// <param name="collisionPoint">The collision point in the triangle</param>
        /// <returns>True if the ray passes through the triangle, otherwise false</returns>
        static bool RayTriangleIntersection(Vertex origin, Vertex direction, Vertex vert0, Vertex vert1, Vertex vert2, out Vertex collisionPoint)
        {
            const float EPSILON = 0.00001f;

            Vertex edge1, edge2, pvec;
            float determinant, invDeterminant;

            // Find vectors for two edges sharing vert0
            edge1 = vert1 - vert0;
            edge2 = vert2 - vert0;

            // Begin calculating the determinant
            pvec = direction.cross(edge2);

            // If the determinant is near zero, ray lies in plane of triangle
            determinant = edge1.dot(pvec);

            if (determinant > -EPSILON && determinant < EPSILON)
            {
                collisionPoint = (Vertex)Vertex.Zero;
                return false;
            }

            invDeterminant = 1f / determinant;

            // Calculate distance from vert0 to ray origin
            Vertex tvec = origin - vert0;

            // Calculate U parameter and test bounds
            float u = tvec.dot(pvec) * invDeterminant;
            if (u < 0.0f || u > 1.0f)
            {
                collisionPoint = (Vertex)Vertex.Zero;
                return false;
            }

            // Prepare to test V parameter
            Vertex qvec = tvec.cross(edge1);

            // Calculate V parameter and test bounds
            float v = direction.dot(qvec) * invDeterminant;
            if (v < 0.0f || u + v > 1.0f)
            {
                collisionPoint = (Vertex)Vertex.Zero;
                return false;
            }

            //t = Vertex.Dot(edge2, qvec) * invDeterminant;

            collisionPoint = new Vertex(
                vert0.X + u * (vert1.X - vert0.X) + v * (vert2.X - vert0.X),
                vert0.Y + u * (vert1.Y - vert0.Y) + v * (vert2.Y - vert0.Y),
                vert0.Z + u * (vert1.Z - vert0.Z) + v * (vert2.Z - vert0.Z));

            return true;
        }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:66,代码来源:MeshedObject.cs


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