Ejemplo n.º 1
0
        /// <summary>
        ///     Crear Collider a partir de TgcMesh.
        ///     Los triangulos se calculan CounterClock-Wise.
        ///     Crea el BoundingSphere del Collider.
        /// </summary>
        /// <param name="mesh">TgcMesh</param>
        /// <returns>Collider creado</returns>
        public static TriangleMeshCollider fromMesh(TgcMesh mesh)
        {
            var collider = new TriangleMeshCollider();

            //Cargar triangulos
            var vertices      = mesh.getVertexPositions();
            var triangleCount = vertices.Length / 3;

            collider.Triangles = new Triangle[triangleCount];
            for (var i = 0; i < triangleCount; i++)
            {
                //Invertir orden de vertices para que la normal quede CounterClock-Wise
                collider.Triangles[i] = new Triangle(
                    vertices[i * 3 + 2],
                    vertices[i * 3 + 1],
                    vertices[i * 3]
                    );
            }

            //Crear BoundingSphere
            collider.BoundingSphere = TgcBoundingSphere.computeFromMesh(mesh);

            return(collider);
        }
 public SphereCollider(TgcMesh mesh)
     : this(TgcBoundingSphere.computeFromMesh(mesh))
 {
 }