public async Task RotateMaintainsCorrectAabb()
        {
            {
                // create a simple cube with translation
                var root = new Object3D();
                var cube = await CubeObject3D.Create(20, 20, 20);

                cube.Matrix = Matrix4X4.CreateTranslation(50, 60, 10);
                root.Children.Add(cube);
                Assert.AreEqual(2, root.DescendantsAndSelf().Count());
                var preRotateAabb = root.GetAxisAlignedBoundingBox();

                // add a rotate to it (that is not rotated)
                var rotateObject = new RotateObject3D_2(cube);

                // ensure that the object did not move
                Assert.IsTrue(rotateObject.RotateAbout.Origin.Equals(new Vector3(50, 60, 10)));
                Assert.AreEqual(4, root.DescendantsAndSelf().Count());
                var postRotateAabb = root.GetAxisAlignedBoundingBox();

                Assert.IsTrue(preRotateAabb.Equals(postRotateAabb, .001));

                Assert.AreEqual(cube, rotateObject.UntransformedChildren.First(), "There is no undo buffer, there should not have been a clone");
            }
        }
        public void ScaleAndRotateMantainsCorrectAabb()
        {
            {
                // create a simple cube with translation
                var root = new Object3D();
                var cube = CubeObject3D.Create(20, 20, 20);
                cube.Matrix = Matrix4X4.CreateTranslation(50, 60, 10);
                root.Children.Add(cube);
                Assert.AreEqual(2, root.DescendantsAndSelf().Count());
                var preScaleAabb = root.GetAxisAlignedBoundingBox();

                // add a scale to it (that is not scaled)
                var scaleObject = new ScaleObject3D(cube);

                // ensure that the object did not move
                Assert.IsTrue(scaleObject.ScaleAbout.Equals(Vector3.Zero), "The objects have been moved to be scalling about 0.");
                Assert.AreEqual(4, root.DescendantsAndSelf().Count());
                var postScaleAabb = root.GetAxisAlignedBoundingBox();

                Assert.IsTrue(preScaleAabb.Equals(postScaleAabb, .001));

                Assert.AreEqual(cube, scaleObject.UntransformedChildren.First(), "There is no undo buffer, there should not have been a clone");

                var rotateScaleObject = new RotateObject3D_2(cube);
                // ensure that the object did not move
                Assert.AreEqual(6, root.DescendantsAndSelf().Count());
                var postRotateScaleAabb = root.GetAxisAlignedBoundingBox();

                Assert.IsTrue(preScaleAabb.Equals(postRotateScaleAabb, .001));

                Assert.AreEqual(cube, rotateScaleObject.UntransformedChildren.First(), "There is no undo buffer, there should not have been a clone");
            }
        }
Example #3
0
        public override async Task Rebuild()
        {
            using (RebuildLock())
            {
                using (new CenterAndHeightMantainer(this))
                {
                    this.Children.Modify(list =>
                    {
                        list.Clear();
                    });

                    var brailleLetter = new BrailleObject3D()
                    {
                        TextToEncode = Letter.ToString(),
                        BaseHeight   = BaseHeight,
                    };
                    await brailleLetter.Rebuild();

                    this.Children.Add(brailleLetter);

                    var textObject = new TextObject3D()
                    {
                        PointSize   = 46,
                        Color       = Color.LightBlue,
                        NameToWrite = Letter.ToString(),
                        Height      = BaseHeight
                    };

                    await textObject.Rebuild();

                    IObject3D letterObject = new RotateObject3D_2(textObject, Vector3.UnitX, -90);
                    await letterObject.Rebuild();

                    var scaleRatio = Math.Max(letterObject.XSize() / 17, letterObject.ZSize() / 17);
                    if (scaleRatio > 1)
                    {
                        letterObject = new ScaleObject3D(letterObject, 1.0 / scaleRatio, 1, 1.0 / scaleRatio);
                    }
                    letterObject = new AlignObject3D(letterObject, FaceAlign.Bottom | FaceAlign.Front, brailleLetter, FaceAlign.Top | FaceAlign.Front, 0, 0, 3.5);
                    letterObject = new SetCenterObject3D(letterObject, brailleLetter.GetCenter(), true, false, false);
                    this.Children.Add(letterObject);

                    var basePath = new RoundedRect(0, 0, 22, 34, 3)
                    {
                        ResolutionScale = 10
                    };

                    IObject3D basePlate = new Object3D()
                    {
                        Mesh   = VertexSourceToMesh.Extrude(basePath, BaseHeight),
                        Matrix = Matrix4X4.CreateRotationX(MathHelper.Tau / 4)
                    };

                    basePlate = new AlignObject3D(basePlate, FaceAlign.Bottom | FaceAlign.Back, brailleLetter, FaceAlign.Bottom | FaceAlign.Back);
                    basePlate = new SetCenterObject3D(basePlate, brailleLetter.GetCenter(), true, false, false);
                    this.Children.Add(basePlate);

                    IObject3D underline = await CubeObject3D.Create(basePlate.XSize(), .2, 1);

                    underline = new AlignObject3D(underline, FaceAlign.Bottom, brailleLetter, FaceAlign.Top);
                    underline = new AlignObject3D(underline, FaceAlign.Back | FaceAlign.Left, basePlate, FaceAlign.Front | FaceAlign.Left, 0, .01);
                    this.Children.Add(underline);
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
        }