Exemplo n.º 1
0
        public Cloth()
        {
            const int gridSize = 10; // size in points per side of the cloth

            Vertices  = new List <Vertex>();
            Normals   = new List <Vector>();
            Triangles = new List <Triangle>();
            var material = new SalmonViewer.Material {
                Diffuse = new[] { 1f, 0.5f, 1f }
            };

            Normals.Add(new Vector(0, 1, 0));
            var normalIndex = 0;

            for (int row = 0; row < gridSize; row++)
            {
                for (int col = 0; col < gridSize; col++)
                {
                    Vertices.Add(new Vertex((double)row / gridSize, 0, (double)col / gridSize));

                    if (row < gridSize - 1 && col < gridSize - 1)
                    {
                        var vertIndex = row * gridSize + col;
                        Triangles.Add(new Triangle(vertIndex, vertIndex + 1, vertIndex + gridSize, normalIndex, normalIndex, normalIndex, material));
                        Triangles.Add(new Triangle(vertIndex + 1, vertIndex + gridSize + 1, vertIndex + gridSize, normalIndex, normalIndex, normalIndex, material));
                    }
                }
            }

            CalcExtent();
            PostProcessGeometry();
            LoadingComplete = true;
            LoadingError    = false;

            Logger.Log("Cloth has {0} vertices, {1} normals and {2} triangles", Vertices.Count, Normals.Count, Triangles.Count);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Construct with valid normal indices.
        /// </summary>
        /// <param name="index1"></param>
        /// <param name="index2"></param>
        /// <param name="index3"></param>
        /// <param name="normalIndex1"></param>
        /// <param name="normalIndex2"></param>
        /// <param name="normalIndex3"></param>
        /// <param name="material"></param>
        public Triangle(int index1, int index2, int index3, int normalIndex1, int normalIndex2, int normalIndex3, SalmonViewer.Material material)
        {
            Contract.Requires(material != null);
            Contract.Requires(material.Ambient.Length == 3);
            Contract.Requires(material.Diffuse.Length == 3);
            Contract.Requires(material.Specular.Length == 3);

            vertexIndex1       = index1;
            vertexIndex2       = index2;
            vertexIndex3       = index3;
            vertexNormalIndex1 = normalIndex1;
            vertexNormalIndex2 = normalIndex2;
            vertexNormalIndex3 = normalIndex3;
            centre             = new Vector();

            // Copy colors from SalmonViewer.Material object.
            ambientMaterial          = new Color(material.Ambient[0], material.Ambient[1], material.Ambient[2]);
            diffuseMaterial          = new Color(material.Diffuse[0], material.Diffuse[1], material.Diffuse[2]);
            specularMaterial         = new Color(material.Specular[0], material.Specular[1], material.Specular[2]);
            specularMaterialExponent = material.Shininess;
            //this.material = material;
        }
Exemplo n.º 3
0
        //public uint color;
        //public SalmonViewer.Material material;

        /// <summary>
        /// Construct with sentinel normal indices.
        /// </summary>
        /// <param name="index1"></param>
        /// <param name="index2"></param>
        /// <param name="index3"></param>
        /// <param name="material"></param>
        public Triangle(int index1, int index2, int index3, SalmonViewer.Material material)
            : this(index1, index2, index3, -1, -1, -1, material)
        {
            Contract.Requires(material != null);
        }