BEPUphysicsDrawer.Models.DisplayWrappedBody.GetShapeMeshData C# (CSharp) Метод

GetShapeMeshData() публичный статический Метод

public static GetShapeMeshData ( EntityCollidable collidable, List vertices, List indices ) : void
collidable BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable
vertices List
indices List
Результат void
        public static void GetShapeMeshData(EntityCollidable collidable, List<VertexPositionNormalTexture> vertices, List<ushort> indices)
        {
            var wrappedShape = collidable.Shape as WrappedShape;
            if (wrappedShape == null)
                throw new ArgumentException("Wrong shape type");
            var points = new List<Vector3>();
            Vector3 max;
            var direction = new Vector3();
            float angleChange = MathHelper.TwoPi / NumSamples;

            for (int i = 1; i < NumSamples / 2 - 1; i++)
            {
                float phi = MathHelper.PiOver2 - i * angleChange;
                var sinPhi = (float)Math.Sin(phi);
                var cosPhi = (float)Math.Cos(phi);
                for (int j = 0; j < NumSamples; j++)
                {
                    float theta = j * angleChange;
                    direction.X = (float)Math.Cos(theta) * cosPhi;
                    direction.Y = sinPhi;
                    direction.Z = (float)Math.Sin(theta) * cosPhi;

                    wrappedShape.GetLocalExtremePoint(direction, out max);
                    points.Add(max);
                }
            }

            wrappedShape.GetLocalExtremePoint(Toolbox.UpVector, out max);
            points.Add(max);
            wrappedShape.GetLocalExtremePoint(Toolbox.DownVector, out max);
            points.Add(max);

            var hullTriangleVertices = new List<Vector3>();
            var hullTriangleIndices = new List<int>();
            ConvexHullHelper.GetConvexHull(points, hullTriangleIndices, hullTriangleVertices);
            //The hull triangle vertices are used as a dummy to get the unnecessary hull vertices, which are cleared afterwards.
            hullTriangleVertices.Clear();
            foreach (int i in hullTriangleIndices)
            {
                hullTriangleVertices.Add(points[i]);
            }

            for (ushort i = 0; i < hullTriangleVertices.Count; i += 3)
            {
                Vector3 normal = Vector3.Normalize(Vector3.Cross(hullTriangleVertices[i + 2] - hullTriangleVertices[i], hullTriangleVertices[i + 1] - hullTriangleVertices[i]));
                vertices.Add(new VertexPositionNormalTexture(hullTriangleVertices[i], normal, new Vector2(0, 0)));
                vertices.Add(new VertexPositionNormalTexture(hullTriangleVertices[i + 1], normal, new Vector2(1, 0)));
                vertices.Add(new VertexPositionNormalTexture(hullTriangleVertices[i + 2], normal, new Vector2(0, 1)));
                indices.Add(i);
                indices.Add((ushort)(i + 1));
                indices.Add((ushort)(i + 2));
            }
        }
    }
DisplayWrappedBody