public static void GetShapeMeshData(EntityCollidable collidable, List <VertexPositionNormalTexture> vertices, List <ushort> indices)
        {
            var convexHullShape = collidable.Shape as ConvexHullShape;

            if (convexHullShape == null)
            {
                throw new ArgumentException("Wrong shape type.");
            }

            var hullTriangleVertices = new List <Vector3>();
            var hullTriangleIndices  = new List <int>();

            ConvexHullHelper.GetConvexHull(convexHullShape.Vertices, 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(convexHullShape.Vertices[i]);
            }

            var     toReturn = new VertexPositionNormalTexture[hullTriangleVertices.Count];
            Vector3 normal;

            for (ushort i = 0; i < hullTriangleVertices.Count; i += 3)
            {
                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));
            }
        }
示例#2
0
        /// <summary>
        /// Solve A * x = b, where b is a column vector. This is more efficient
        /// than computing the inverse in one-shot cases.
        /// </summary>
        /// <param name="b">The b.</param>
        /// <returns></returns>
        public Vector3 Solve33(Vector3 b)
        {
            float det = Vector3.Dot(ex, Vector3.Cross(ey, ez));

            if (det != 0.0f)
            {
                det = 1.0f / det;
            }

            return(new Vector3(det * Vector3.Dot(b, Vector3.Cross(ey, ez)), det * Vector3.Dot(ex, Vector3.Cross(b, ez)), det * Vector3.Dot(ex, Vector3.Cross(ey, b))));
        }
示例#3
0
 public static Vector3 Cross(Vector3 a, Vector3 b)
 {
     return(new Vector3(MonoGameVector3.Cross(a.MonoGameVector, b.MonoGameVector)));
 }
 public static Vector3 Cross(Vector3 v1, Vector3 v2)
 {
     return(new Vector3(Vector.Cross(v1, v2)));
 }