Esempio n. 1
0
        private void ReadObjFile(string pathObjFile)
        {
            using (var myStream = new FileStream(pathObjFile, FileMode.Open))
            {
                var myReader = new StreamReader(myStream);
                var coord    = new double[3];
                var tri      = new int[3];
                var tex      = new int[4];
                var quad     = new int[4];

                string line;
                while ((line = myReader.ReadLine()) != null)
                {
                    if (line != "")
                    {
                        line = line.Trim(' ');

                        string[] array;
                        switch (line[0])
                        {
                        case 'v':
                        {
                            if (line[1] != 't' && line[1] != 'n')
                            {
                                line  = line.Trim('v', ' ');
                                array = line.Split(' ');
                                for (var i = 0; i < 3; i++)
                                {
                                    coord[i] = double.Parse(array[i], CultureInfo.InvariantCulture);
                                }

                                var v = new Vertex(coord[0], coord[1], coord[2]);
                                Vertices.Add(v);
                            }
                            else
                            {
                                if (line[1] == 't')
                                {
                                    line  = line.Trim('t', 'v', ' ');
                                    array = line.Split(' ');
                                    for (var i = 0; i < 2; i++)
                                    {
                                        coord[i] = double.Parse(array[i], CultureInfo.InvariantCulture);
                                    }

                                    var v = new Vertex2D(coord[0], coord[1]);
                                    TextureCoordinates.Add(v);
                                }
                            }

                            break;
                        }

                        case 'f':
                        {
                            line  = line.Trim('f', ' ');
                            array = line.Split(new[] { ' ', '/' },
                                               StringSplitOptions.RemoveEmptyEntries);
                            if (array.Length == 9)
                            {
                                for (int i = 0, j = 0; i < 3 && j < array.Length; i++, j += 3)
                                {
                                    tri[i] = int.Parse(array[j]);
                                    tex[i] = int.Parse(array[j + 1]);
                                }

                                var t = new Triangle(Vertices[tri[0] - 1], Vertices[tri[1] - 1],
                                                     Vertices[tri[2] - 1], TextureCoordinates[tex[0] - 1],
                                                     TextureCoordinates[tex[1] - 1], TextureCoordinates[tex[2] - 1]);
                                Triangles.Add(t);
                            }

                            if (array.Length == 12)
                            {
                                for (int i = 0, j = 0; i < 4 && j < array.Length; i++, j += 3)
                                {
                                    quad[i] = int.Parse(array[j]);
                                    tex[i]  = int.Parse(array[j + 1]);
                                }

                                var q = new Quad(Vertices[quad[0] - 1], Vertices[quad[1] - 1],
                                                 Vertices[quad[2] - 1],
                                                 Vertices[quad[3] - 1], TextureCoordinates[tex[0] - 1],
                                                 TextureCoordinates[tex[1] - 1], TextureCoordinates[tex[2] - 1],
                                                 TextureCoordinates[tex[3] - 1]);
                                Quads.Add(q);
                            }
                        }
                        break;
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 //Add quad to the list
 public void AddQuad(Quad quad)
 {
     Quads.Add(quad);
 }
Esempio n. 3
0
    public HinhChop(float a, float height)
    {
        VertexList[] quads = new VertexList[5];
        for (int i = 0; i < 5; i++)
        {
            quads[i] = new VertexList();
        }
        float half_a      = a / 2;
        float half_height = height / 2;

        Vertex        vertex1, vertex2, vertex3, vertex4;
        List <Vertex> vertices;

        // trái
        vertex1 = new Vertex {
            X = 0.0f, Y = half_height, Z = 0.0f
        };
        vertex2 = new Vertex {
            X = -half_a, Y = -half_height, Z = -half_a
        };
        vertex3 = new Vertex {
            X = half_a, Y = -half_height, Z = -half_a
        };

        vertices = new List <Vertex> {
            vertex1, vertex2, vertex3
        };

        quads[0].Vertices = vertices;
        Quads.Add(quads[0]);

        // sau
        vertex1 = new Vertex {
            X = 0.0f, Y = half_height, Z = 0.0f
        };
        vertex2 = new Vertex {
            X = -half_a, Y = -half_height, Z = half_a
        };
        vertex3 = new Vertex {
            X = -half_a, Y = -half_height, Z = -half_a
        };

        vertices = new List <Vertex> {
            vertex1, vertex2, vertex3
        };

        quads[1].Vertices = vertices;
        Quads.Add(quads[1]);

        // phải
        vertex1 = new Vertex {
            X = 0.0f, Y = half_height, Z = 0.0f
        };
        vertex2 = new Vertex {
            X = half_a, Y = -half_height, Z = half_a
        };
        vertex3 = new Vertex {
            X = -half_a, Y = -half_height, Z = half_a
        };

        vertices = new List <Vertex> {
            vertex1, vertex2, vertex3
        };

        quads[2].Vertices = vertices;
        Quads.Add(quads[2]);

        // trước
        vertex1 = new Vertex {
            X = 0.0f, Y = half_height, Z = 0.0f
        };
        vertex2 = new Vertex {
            X = half_a, Y = -half_height, Z = -half_a
        };
        vertex3 = new Vertex {
            X = half_a, Y = -half_height, Z = half_a
        };

        vertices = new List <Vertex> {
            vertex1, vertex2, vertex3
        };

        quads[3].Vertices = vertices;
        Quads.Add(quads[3]);

        // dưới
        vertex1 = new Vertex {
            X = -half_a, Y = -half_height, Z = -half_a
        };
        vertex2 = new Vertex {
            X = half_a, Y = -half_height, Z = -half_a
        };
        vertex3 = new Vertex {
            X = half_a, Y = -half_height, Z = half_a
        };
        vertex4 = new Vertex {
            X = -half_a, Y = -half_height, Z = half_a
        };
        vertices = new List <Vertex> {
            vertex1, vertex2, vertex3, vertex4
        };

        quads[4].Vertices = vertices;
        Quads.Add(quads[4]);
    }
Esempio n. 4
0
    public LangTru(float size, float height)
    {
        VertexList[] quads = new VertexList[5];
        for (int i = 0; i < 5; i++)
        {
            quads[i] = new VertexList();
        }

        float a, b, c;

        a = size * (float)Math.Sqrt(6) / 6;
        b = size * (float)(-Math.Sqrt(6) + 3 * Math.Sqrt(2)) / 12;
        c = size * (float)(-Math.Sqrt(6) - 3 * Math.Sqrt(2)) / 12;
        float half_height = height / 2;


        Vertex        vertex1, vertex2, vertex3, vertex4;
        List <Vertex> vertices;



        // vẽ các mặt của hình lăng trụ


        vertex1 = new Vertex {
            X = b, Y = -half_height, Z = c
        };
        vertex2 = new Vertex {
            X = a, Y = -half_height, Z = a
        };
        vertex3 = new Vertex {
            X = a, Y = half_height, Z = a
        };
        vertex4 = new Vertex {
            X = b, Y = half_height, Z = c
        };

        vertices = new List <Vertex> {
            vertex1, vertex2, vertex3, vertex4
        };

        quads[0].Vertices = vertices;
        Quads.Add(quads[0]);

        vertex1 = new Vertex {
            X = a, Y = -half_height, Z = a
        };
        vertex2 = new Vertex {
            X = c, Y = -half_height, Z = b
        };
        vertex3 = new Vertex {
            X = c, Y = half_height, Z = b
        };
        vertex4 = new Vertex {
            X = a, Y = half_height, Z = a
        };

        vertices = new List <Vertex> {
            vertex1, vertex2, vertex3, vertex4
        };

        quads[1].Vertices = vertices;
        Quads.Add(quads[1]);


        vertex1 = new Vertex {
            X = b, Y = -half_height, Z = c
        };
        vertex2 = new Vertex {
            X = c, Y = -half_height, Z = b
        };
        vertex3 = new Vertex {
            X = c, Y = half_height, Z = b
        };
        vertex4 = new Vertex {
            X = b, Y = half_height, Z = c
        };

        vertices = new List <Vertex> {
            vertex1, vertex2, vertex3, vertex4
        };

        quads[2].Vertices = vertices;
        Quads.Add(quads[2]);


        vertex1 = new Vertex {
            X = b, Y = -half_height, Z = c
        };
        vertex2 = new Vertex {
            X = a, Y = -half_height, Z = a
        };
        vertex3 = new Vertex {
            X = c, Y = -half_height, Z = b
        };

        vertices = new List <Vertex> {
            vertex1, vertex2, vertex3
        };

        quads[3].Vertices = vertices;
        Quads.Add(quads[3]);


        vertex1 = new Vertex {
            X = b, Y = half_height, Z = c
        };
        vertex2 = new Vertex {
            X = a, Y = half_height, Z = a
        };
        vertex3 = new Vertex {
            X = c, Y = half_height, Z = b
        };

        vertices = new List <Vertex> {
            vertex1, vertex2, vertex3
        };

        quads[4].Vertices = vertices;
        Quads.Add(quads[4]);
    }
Esempio n. 5
0
    public LapPhuong(float a)
    {
        VertexList[] quads = new VertexList[6];
        for (int i = 0; i < 6; i++)
        {
            quads[i] = new VertexList();
        }
        float half_a = a / 2;

        // dưới
        Vertex vertex1 = new Vertex {
            X = -half_a, Y = -half_a, Z = -half_a
        };
        Vertex vertex2 = new Vertex {
            X = half_a, Y = -half_a, Z = -half_a
        };
        Vertex vertex3 = new Vertex {
            X = half_a, Y = -half_a, Z = half_a
        };
        Vertex vertex4 = new Vertex {
            X = -half_a, Y = -half_a, Z = half_a
        };
        List <Vertex> vertices = new List <Vertex> {
            vertex1, vertex2, vertex3, vertex4
        };

        quads[0].Vertices = vertices;
        Quads.Add(quads[0]);

        // trái
        vertex1 = new Vertex {
            X = -half_a, Y = -half_a, Z = -half_a
        };
        vertex2 = new Vertex {
            X = -half_a, Y = half_a, Z = -half_a
        };
        vertex3 = new Vertex {
            X = half_a, Y = half_a, Z = -half_a
        };
        vertex4 = new Vertex {
            X = half_a, Y = -half_a, Z = -half_a
        };
        vertices = new List <Vertex> {
            vertex1, vertex2, vertex3, vertex4
        };

        quads[1].Vertices = vertices;
        Quads.Add(quads[1]);

        // phía sau
        vertex1 = new Vertex {
            X = -half_a, Y = -half_a, Z = -half_a
        };
        vertex2 = new Vertex {
            X = -half_a, Y = half_a, Z = -half_a
        };
        vertex3 = new Vertex {
            X = -half_a, Y = half_a, Z = half_a
        };
        vertex4 = new Vertex {
            X = -half_a, Y = -half_a, Z = half_a
        };
        vertices = new List <Vertex> {
            vertex1, vertex2, vertex3, vertex4
        };

        quads[2].Vertices = vertices;
        Quads.Add(quads[2]);

        // phải
        vertex1 = new Vertex {
            X = -half_a, Y = half_a, Z = half_a
        };
        vertex2 = new Vertex {
            X = half_a, Y = half_a, Z = half_a
        };
        vertex3 = new Vertex {
            X = half_a, Y = -half_a, Z = half_a
        };
        vertex4 = new Vertex {
            X = -half_a, Y = -half_a, Z = half_a
        };
        vertices = new List <Vertex> {
            vertex1, vertex2, vertex3, vertex4
        };

        quads[3].Vertices = vertices;
        Quads.Add(quads[3]);

        // phía trước
        vertex1 = new Vertex {
            X = half_a, Y = half_a, Z = half_a
        };
        vertex2 = new Vertex {
            X = half_a, Y = half_a, Z = -half_a
        };
        vertex3 = new Vertex {
            X = half_a, Y = -half_a, Z = -half_a
        };
        vertex4 = new Vertex {
            X = half_a, Y = -half_a, Z = half_a
        };
        vertices = new List <Vertex> {
            vertex1, vertex2, vertex3, vertex4
        };

        quads[4].Vertices = vertices;
        Quads.Add(quads[4]);

        // đằng trên
        vertex1 = new Vertex {
            X = -half_a, Y = half_a, Z = -half_a
        };
        vertex2 = new Vertex {
            X = half_a, Y = half_a, Z = -half_a
        };
        vertex3 = new Vertex {
            X = half_a, Y = half_a, Z = half_a
        };
        vertex4 = new Vertex {
            X = -half_a, Y = half_a, Z = half_a
        };
        vertices = new List <Vertex> {
            vertex1, vertex2, vertex3, vertex4
        };

        quads[5].Vertices = vertices;
        Quads.Add(quads[5]);
    }