Exemple #1
0
        public static bool Intersect(Ray a, Software.Mesh b, out object intersection)
        {
            var r = new Common.RayIntersection();

            intersection = r;
            Software.Triangle t;
            Vector2           uv;
            bool hit = b.Intersect(a, false, out t, out r.Distance, out uv);

            r.Userdata = uv;
            return(hit);
        }
        private Graphics.Software.Mesh MeshFromCoordinates(List<Common.Tuple<Vector3, Vector3>> coordinates)
        {
            List<Position3Normal3Texcoord3> vertices = new List<Position3Normal3Texcoord3>();
            List<int> indices = new List<int>();

            for (int i = 0; i < coordinates.Count; i++)
            {
                float texturecoord = 1 - ((float)i / (float)coordinates.Count) + offset;

                if (texturecoord > 0.99f)
                    texturecoord = 0.99f;

                vertices.Add(new Position3Normal3Texcoord3(coordinates[i].First, Vector3.Zero, new Vector3(texturecoord, 1, 0)));
                vertices.Add(new Position3Normal3Texcoord3(coordinates[i].Second, Vector3.Zero, new Vector3(texturecoord, 0, 0)));
            }

            for (int i = 0; i < coordinates.Count - 1; i++)
            {
                indices.Add(i * 2);
                indices.Add(i * 2 + 2);
                indices.Add(i * 2 + 1);

                indices.Add(i * 2 + 1);
                indices.Add(i * 2 + 2);
                indices.Add(i * 2 + 3);

                indices.Add(i * 2 + 0);
                indices.Add(i * 2 + 1);
                indices.Add(i * 2 + 3);

                indices.Add(i * 2 + 0);
                indices.Add(i * 2 + 3);
                indices.Add(i * 2 + 2);
            }

            Graphics.Software.Mesh mesh = new Graphics.Software.Mesh
            {
                NVertices = this.coordinates.Count * 2,
                NFaces = this.coordinates.Count * 4 - 4,
                MeshType = MeshType.Indexed,
                VertexBuffer = new VertexBuffer<Position3Normal3Texcoord3>(vertices.ToArray()),
                IndexBuffer = new IndexBuffer(indices.ToArray()),
                VertexStreamLayout = global::Graphics.Software.Vertex.Position3Normal3Texcoord3.Instance,
            };

            return mesh;
        }