Esempio n. 1
0
 public void AddTriangle(TriangleData triangle)
 {
     if (!triangles.Contains(triangle))
     {
         triangles.Add(triangle);
     }
 }
Esempio n. 2
0
        public List<TriangleData> GetFaces()
        {
            Matrix rootTransform = sceneModel.Root.Transform;

            List<TriangleData> faceList = new List<TriangleData>();// new TriangleData[totalNumFaces];

            foreach (ModelMesh mesh in sceneModel.Meshes)
            {
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    VertexPositionColorTexture[] meshPartVertices = new VertexPositionColorTexture[meshPart.NumVertices];
                    meshPart.VertexBuffer.GetData<VertexPositionColorTexture>(meshPartVertices);

                    if (meshPart.IndexBuffer.IndexElementSize == IndexElementSize.SixteenBits)
                    {
                        short[] meshIndices = new short[meshPart.IndexBuffer.IndexCount];
                        meshPart.IndexBuffer.GetData<short>(meshIndices);

                        for (int cFaces = 0; cFaces < meshPart.PrimitiveCount; cFaces++)
                        {
                            Vector3[] vertices = new Vector3[3];
                            for (int cFaceVertice = 0; cFaceVertice < 3; cFaceVertice++)
                            {
                                vertices[cFaceVertice] = Vector3.Transform(meshPartVertices[meshIndices[meshPart.VertexOffset + (cFaces * 3) + cFaceVertice]].Position, rootTransform);
                            }
                            TriangleData triangleData = new TriangleData(ref vertices);
                            faceList.Add(triangleData);

                        }

                    }
                    else
                    {
                        int[] meshIndices = new int[meshPart.IndexBuffer.IndexCount];
                        meshPart.IndexBuffer.GetData<int>(meshIndices);

                        for (int cFaces = 0; cFaces < meshPart.PrimitiveCount; cFaces++)
                        {
                            Vector3[] vertices = new Vector3[3];
                            for (int cFaceVertice = 0; cFaceVertice < 3; cFaceVertice++)
                            {
                                vertices[cFaceVertice] = Vector3.Transform(meshPartVertices[meshIndices[meshPart.VertexOffset + (cFaces * 3) + cFaceVertice]].Position, rootTransform);
                            }
                            TriangleData triangleData = new TriangleData(ref vertices);
                            faceList.Add(triangleData);

                        }

                    }

                }
            }
            return faceList;
        }
Esempio n. 3
0
 public bool Intersects(TriangleData other)
 {
     foreach (OrientedBoundingBox obb in boundingBoxList)
     {
         obb.Transforms = Transform * obb.BoxTransform;
         if (obb.Intersects(other))
             return true;
     }
     return false;
 }
Esempio n. 4
0
        public bool Intersects(TriangleData other)
        {
            Matrix m = Transforms;
            Matrix otherM = Matrix.Identity;

            Vector3[] extentsOther = other.Edges;
            Vector3 myCenter = Vector3.Transform(center, m);
            Vector3 centerOther = Vector3.Transform(other.Center, otherM);

            Vector3 distance = centerOther - myCenter;

            /*
            box vs tri axes
            ---------------
            tri.normal
            box.dir0
            box.dir1
            box.dir2

            box.dir0 x tri.edge0
            box.dir0 x tri.edge1
            box.dir0 x tri.edge2

            box.dir1 x tri.edge0
            box.dir1 x tri.edge1
            box.dir1 x tri.edge2

            box.dir2 x tri.edge0
            box.dir2 x tri.edge1
            box.dir2 x tri.edge2
             */

            if (IsSeparationAxisTriBox(other.Normal, distance, extents, m, other.Edges, otherM))
                return false;

            if (IsSeparationAxisTriBox(m.Forward, distance, extents, m, other.Edges, otherM))
                return false;

            if (IsSeparationAxisTriBox(m.Left, distance, extents, m, other.Edges, otherM))
                return false;

            if (IsSeparationAxisTriBox(m.Up, distance, extents, m, other.Edges, otherM))
                return false;

            if (IsSeparationAxisTriBox(Vector3.Cross(m.Forward, other.Edges[0]), distance, extents, transforms, other.Edges, otherM))
                return false;
            if (IsSeparationAxisTriBox(Vector3.Cross(m.Forward, other.Edges[1]), distance, extents, transforms, other.Edges, otherM))
                return false;
            if (IsSeparationAxisTriBox(Vector3.Cross(m.Forward, other.Edges[2]), distance, extents, transforms, other.Edges, otherM))
                return false;

            if (IsSeparationAxisTriBox(Vector3.Cross(m.Left, other.Edges[0]), distance, extents, transforms, other.Edges, otherM))
                return false;
            if (IsSeparationAxisTriBox(Vector3.Cross(m.Left, other.Edges[1]), distance, extents, transforms, other.Edges, otherM))
                return false;
            if (IsSeparationAxisTriBox(Vector3.Cross(m.Left, other.Edges[2]), distance, extents, transforms, other.Edges, otherM))
                return false;

            if (IsSeparationAxisTriBox(Vector3.Cross(m.Up, other.Edges[0]), distance, extents, transforms, other.Edges, otherM))
                return false;
            if (IsSeparationAxisTriBox(Vector3.Cross(m.Up, other.Edges[1]), distance, extents, transforms, other.Edges, otherM))
                return false;
            if (IsSeparationAxisTriBox(Vector3.Cross(m.Up, other.Edges[2]), distance, extents, transforms, other.Edges, otherM))
                return false;

            /*
             * tri vs tri axes
            ---------------
            tri0.normal
            tri1.normal

            tri0.edge0 x tri1.edge0
            tri0.edge0 x tri1.edge1
            tri0.edge0 x tri1.edge2

            tri0.edge1 x tri1.edge0
            tri0.edge1 x tri1.edge1
            tri0.edge1 x tri1.edge2

            tri0.edge2 x tri1.edge0
            tri0.edge2 x tri1.edge1
            tri0.edge2 x tri1.edge2

             */
            return true;
        }