Exemplo n.º 1
0
        public void GroupManipulations()
        {
            var s1 = new SphereFigure(Matrix4x4.Identity, MaterialConstants.Default);
            var s2 = new CubeFigure(Matrix4x4.Identity, MaterialConstants.Default);
            var s3 = new PlaneFigure(Matrix4x4.Identity, MaterialConstants.Default);

            var g  = new GroupFigure();
            var g2 = new GroupFigure();

            s1.Parent = g;
            s2.Parent = g;
            g.Add(s3);

            Assert.Equal(g, s1.Parent);
            Assert.Equal(g, s2.Parent);
            Assert.Equal(g, s3.Parent);

            Assert.Contains(s1, g.Figures);
            Assert.Contains(s2, g.Figures);
            Assert.Contains(s3, g.Figures);

            g.Remove(s1);
            s3.Parent = null;

            Assert.Null(s1.Parent);
            Assert.Equal(g, s2.Parent);
            Assert.Null(s3.Parent);

            Assert.DoesNotContain(s1, g.Figures);
            Assert.Contains(s2, g.Figures);
            Assert.DoesNotContain(s3, g.Figures);

            s2.Parent = g2;

            Assert.DoesNotContain(s2, g.Figures);
            Assert.Equal(g2, s2.Parent);
            Assert.Contains(s2, g2.Figures);
        }
Exemplo n.º 2
0
        private void And_figure(string id, string figureType, DataTable dataTable)
        {
            IMatrix transformation  = Matrix4x4.Identity;
            var     defaultMaterial = MaterialConstants.Default;

            Tuple4 color           = defaultMaterial.GetColor(Tuple4.ZeroPoint);
            double ambient         = defaultMaterial.Ambient;
            double diffuse         = defaultMaterial.Diffuse;
            double specular        = defaultMaterial.Specular;
            double reflective      = defaultMaterial.Reflective;
            double refractiveIndex = defaultMaterial.RefractiveIndex;
            double transparency    = defaultMaterial.Transparency;

            foreach (var row in dataTable.Rows)
            {
                var cells = row.Cells.ToArray();
                switch (cells[0].Value)
                {
                case "material.color":
                {
                    var entries = cells[1].Value
                                  .Split(new char[] { ',', '(', ')', ' ' }, System.StringSplitOptions.RemoveEmptyEntries)
                                  .ToArray();

                    color = new Tuple4(double.Parse(entries[0]), double.Parse(entries[1]), double.Parse(entries[2]), TupleFlavour.Vector);
                    break;
                }

                case "material.ambient":
                    ambient = double.Parse(cells[1].Value);
                    break;

                case "material.diffuse":
                    diffuse = double.Parse(cells[1].Value);
                    break;

                case "material.specular":
                    specular = double.Parse(cells[1].Value);
                    break;

                case "material.reflective":
                    reflective = double.Parse(cells[1].Value);
                    break;

                case "material.transparency":
                    transparency = double.Parse(cells[1].Value);
                    break;

                case "material.refractive_index":
                    refractiveIndex = double.Parse(cells[1].Value);
                    break;

                case "transform":
                {
                    var entries = cells[1].Value
                                  .Split(new char[] { ',', ')', '(', ' ' }, System.StringSplitOptions.RemoveEmptyEntries)
                                  .ToArray();

                    switch (entries[0])
                    {
                    case "scaling":
                        transformation = MatrixOperations.Multiply(transformation,
                                                                   MatrixOperations.Geometry3D.Scale(
                                                                       double.Parse(entries[1]),
                                                                       double.Parse(entries[2]),
                                                                       double.Parse(entries[3])));
                        break;

                    case "translation":
                        transformation = MatrixOperations.Multiply(transformation,
                                                                   MatrixOperations.Geometry3D.Translation(
                                                                       double.Parse(entries[1]),
                                                                       double.Parse(entries[2]),
                                                                       double.Parse(entries[3])));
                        break;

                    default:
                        throw new NotImplementedException();
                    }

                    break;
                }

                default:
                    throw new NotImplementedException(cells[0].Value);
                }
            }

            var material = new SolidColorMaterial(color,
                                                  ambient,
                                                  diffuse,
                                                  specular,
                                                  defaultMaterial.Shininess,
                                                  reflective,
                                                  refractiveIndex,
                                                  transparency);

            switch (figureType)
            {
            case "sphere":
                figure[id] = new SphereFigure(transformation, material);
                break;

            case "plane":
                figure[id] = new PlaneFigure(transformation, material);
                break;

            default:
                throw new NotImplementedException(figureType);
            }
        }
Exemplo n.º 3
0
 public void Given_sphere(string id)
 {
     figure[id] = new PlaneFigure(MatrixOperations.Identity(4), MaterialConstants.Default);
 }