Exemple #1
0
        private void AdjustChildSize(object sender, EventArgs e)
        {
            if (Children.Count > 0)
            {
                var aabb = SourceItem.GetAxisAlignedBoundingBox();
                TransformItem.Matrix = Matrix4X4.Identity;
                var scale = Vector3.One;
                if (StretchX)
                {
                    scale.X = SizeX / aabb.XSize;
                }
                if (StretchY)
                {
                    scale.Y = SizeY / aabb.YSize;
                }
                if (StretchZ)
                {
                    scale.Z = SizeZ / aabb.ZSize;
                }

                switch (MaintainRatio)
                {
                case MaintainRatio.None:
                    break;

                case MaintainRatio.X_Y:
                    var minXy = Math.Min(scale.X, scale.Y);
                    scale.X = minXy;
                    scale.Y = minXy;
                    break;

                case MaintainRatio.X_Y_Z:
                    var minXyz = Math.Min(Math.Min(scale.X, scale.Y), scale.Z);
                    scale.X = minXyz;
                    scale.Y = minXyz;
                    scale.Z = minXyz;
                    break;
                }

                TransformItem.Matrix = Object3DExtensions.ApplyAtPosition(TransformItem.Matrix, aabb.Center, Matrix4X4.CreateScale(scale));
            }
        }
        public void DrawEditor(object sender, DrawEventArgs e)
        {
            if (sender is InteractionLayer layer &&
                layer.Scene.SelectedItem != null &&
                layer.Scene.SelectedItem.DescendantsAndSelf().Where((i) => i == this).Any())
            {
                var aabb = SourceItem.GetAxisAlignedBoundingBox();

                var center      = aabb.Center;
                var worldMatrix = this.WorldMatrix();

                var minXyz = center - new Vector3(SizeX / 2, SizeY / 2, SizeZ / 2);
                var maxXyz = center + new Vector3(SizeX / 2, SizeY / 2, SizeZ / 2);
                var bounds = new AxisAlignedBoundingBox(minXyz, maxXyz);
                //var leftW = Vector3.Transform(, worldMatrix);
                var right = Vector3.Transform(center + new Vector3(SizeX / 2, 0, 0), worldMatrix);
                // layer.World.Render3DLine(left, right, Agg.Color.Red);
                layer.World.RenderAabb(bounds, worldMatrix, Agg.Color.Red, 1, 1);
            }
        }