GetTriangle() public abstract method

Gets the triangle vertex positions at a given index.
public abstract GetTriangle ( int triangleIndex, Microsoft.Xna.Framework.Vector3 &v1, Microsoft.Xna.Framework.Vector3 &v2, Microsoft.Xna.Framework.Vector3 &v3 ) : void
triangleIndex int First index of a triangle's vertices in the index buffer.
v1 Microsoft.Xna.Framework.Vector3 First vertex of the triangle.
v2 Microsoft.Xna.Framework.Vector3 Second vertex of the triangle.
v3 Microsoft.Xna.Framework.Vector3 Third vertex of the triangle.
return void
Beispiel #1
0
        ///<summary>
        /// Tests a ray against the triangle mesh.
        ///</summary>
        ///<param name="ray">Ray to test against the mesh.</param>
        /// <param name="maximumLength">Maximum length of the ray in units of the ray direction's length.</param>
        /// <param name="sidedness">Sidedness to apply to the mesh for the ray cast.</param>
        ///<param name="hits">Hit data for the ray, if any.</param>
        ///<returns>Whether or not the ray hit the mesh.</returns>
        public bool RayCast(Ray ray, float maximumLength, TriangleSidedness sidedness, IList <RayHit> hits)
        {
            var hitElements = Resources.GetIntList();

            tree.GetOverlaps(ray, maximumLength, hitElements);
            for (int i = 0; i < hitElements.Count; i++)
            {
                Vector3 v1, v2, v3;
                data.GetTriangle(hitElements[i], out v1, out v2, out v3);
                RayHit hit;
                if (Toolbox.FindRayTriangleIntersection(ref ray, maximumLength, sidedness, ref v1, ref v2, ref v3, out hit))
                {
                    hits.Add(hit);
                }
            }
            Resources.GiveBack(hitElements);
            return(hits.Count > 0);
        }