public void InitializeContent()
        {
            var DefaultWidth  = Convert.ToInt32(Width);
            var DefaultHeight = Convert.ToInt32(Height);

            this.ClipToBounds = true;

            new[] {
                Colors.Black,
                Colors.Blue,
                Colors.Black
            }.ToGradient(DefaultHeight / 2).Select(
                (c, i) =>
                new Rectangle
            {
                Fill   = new SolidColorBrush(c),
                Width  = DefaultWidth,
                Height = 3,
            }.MoveTo(0, i * 2).AttachTo(this)
                ).ToArray();

            var logo = new Avalon.Images.white_jsc().AttachTo(this);

            logo.MoveTo(
                DefaultWidth - Avalon.Images.white_jsc.ImageDefaultWidth,
                DefaultHeight - Avalon.Images.white_jsc.ImageDefaultHeight
                );

            this.SizeChanged +=
                delegate
            {
                logo.MoveTo(
                    this.Width - Avalon.Images.white_jsc.ImageDefaultWidth,
                    this.Height - Avalon.Images.white_jsc.ImageDefaultHeight
                    );
            };

            var t = new TextBox
            {
                FontSize        = 10,
                Text            = "powered by jsc",
                BorderThickness = new Thickness(0),
                Foreground      = 0xffffffff.ToSolidColorBrush(),
                Background      = Brushes.Transparent,
                IsReadOnly      = true,
                Width           = DefaultWidth
            }.MoveTo(8, 8).AttachTo(this);

            #region Initialize
            AffineContent = new Canvas
            {
            }.AttachTo(this);



            InfoContent = new Canvas
            {
            }.AttachTo(this);



            var a = new AffineMesh();



            for (int i = -5; i <= 5; i++)
            {
                if (Math.Abs(i) > 1)
                {
                    AddCube(a, new AffinePoint(210 * i, 0, 0));
                    AddCube(a, new AffinePoint(0, 210 * i, 0));
                    AddCube(a, new AffinePoint(0, 0, 210 * i));
                }
            }

            // AddCubeFace(a, "back",
            //    new AffinePoint(-100, -100, -100),
            //    new AffinePoint(100, -100, -100),
            //    new AffinePoint(-100, 100, -100),
            //    new AffinePoint(100, 100, -100)
            //);


            //a = a.ToZoom(new AffineZoom { X = 2 });


            //a = a.ToZoom(0.8);
            //a = a.ToZoom(1.2);

            var pp = new Point();

            // while jsc initializes local structs it does not do that for fields
            pp = new Point(0, 0);

            var pp_XZ = 0.0;

            Action Update =
                delegate
            {
                var Rotation = new AffineRotation
                {
                    XY = 0.01 * pp.X * 0.5,
                    YZ = 0.02 * pp.X * 0.5,
                    XZ = 0.03 * pp.X * 0.5 + pp_XZ
                };

                t.Text = new
                {
                    XY = Rotation.XZ.RadiansToDegrees(),
                    YZ = Rotation.YZ.RadiansToDegrees(),
                    XZ = Rotation.XZ.RadiansToDegrees()
                }.ToString();

                // rotate floor
                var _a = a.ToZoom(0.2 * (DefaultHeight / 2 + pp.Y) / (DefaultHeight)).ToRotation(Rotation);



                foreach (var k in _a.Vertecies)
                {
                    k.Element.Orphanize();
                    k.Element.AttachTo(AffineContent);
                    k.Element.RenderTransform = new AffineTransform
                    {
                        Left   = 0,
                        Top    = 0,
                        Width  = k.ElementWidth,
                        Height = k.ElementHeight,

                        X1 = k.B.X + DefaultWidth / 2,
                        Y1 = k.B.Y + DefaultHeight / 2,

                        X2 = k.C.X + DefaultWidth / 2,
                        Y2 = k.C.Y + DefaultHeight / 2,

                        X3 = k.A.X + DefaultWidth / 2,
                        Y3 = k.A.Y + DefaultHeight / 2,
                    };

                    //((Action<AffineVertex>)k.Tag)(k);
                }
            };

            this.MouseMove +=
                (sender, args) =>
            {
                pp = args.GetPosition(this);

                Update();
            }
            ;
            #endregion


            var tt = new DispatcherTimer();

            tt.Tick +=
                delegate
            {
                pp_XZ += 0.02;
                Update();
            };

            tt.Interval = TimeSpan.FromMilliseconds(1000 / 30);

            tt.Start();
        }
示例#2
0
        private void CreateContent(int sandcount, int cubecount, bool rotor)
        {
            var t = new TextBox
            {
                FontSize        = 10,
                Text            = "powered by jsc",
                BorderThickness = new Thickness(0),
                Foreground      = 0xffffffff.ToSolidColorBrush(),
                Background      = Brushes.Transparent,
                IsReadOnly      = true,
                Width           = Width
            }.MoveTo(8, 8).AttachTo(InfoContent);

            if (rotor)
            {
                t.MoveTo(8, 32);
            }

            var a = new AffineMesh();


            var _17  = new Avalon.Images._17().Source;
            var _17g = new Avalon.Images._17g().Source;
            var _18  = new Avalon.Images._18().Source;
            var _18g = new Avalon.Images._18g().Source;



            for (int cubex = -cubecount; cubex < cubecount; cubex++)
            {
                AddCube(a, _18, _18g, new AffinePoint(-1 + cubex * 4, -1, 0));
                AddCube(a, _18, _18g, new AffinePoint(-1 + cubex * 4, 1, 0));

                AddCube(a, _18, _18g, new AffinePoint(1 + cubex * 4, -1, 0));
                AddCube(a, _18, _18g, new AffinePoint(1 + cubex * 4, 1, 0));

                AddCube(a, _17, _17g, new AffinePoint(-1 + cubex * 4, -1, 1));
                AddCube(a, _17, _17g, new AffinePoint(-1 + cubex * 4, 1, 1));

                AddCube(a, _17, _17g, new AffinePoint(1 + cubex * 4, -1, 1));
                AddCube(a, _17, _17g, new AffinePoint(1 + cubex * 4, 1, 1));
            }


            var top = default(AffineMesh);

            if (rotor)
            {
                top = AddCube(a, _18, _18g, new AffinePoint(0, 0, 2));
            }

            var topdef = top;

            if (!rotor)
            {
                for (int ix = -sandcount; ix <= sandcount; ix++)
                {
                    for (int iy = -sandcount; iy <= sandcount; iy++)
                    {
                        AddCubeFace(a,
                                    new Avalon.Images.sandv().Source,
                                    new Avalon.Images.sandv().Source,
                                    new AffinePoint(-100 + ix * 200, -100, -100 + iy * 200),
                                    new AffinePoint(100 + ix * 200, -100, -100 + iy * 200),
                                    new AffinePoint(-100 + ix * 200, -100, 100 + iy * 200),
                                    new AffinePoint(100 + ix * 200, -100, 100 + iy * 200)
                                    );
                    }
                }
            }



            //z			a = a.ToZoom(0.5);


            //a = a.ToZoom(0.8);
            //a = a.ToZoom(1.2);

            var _a       = a;
            var Rotation = new AffineRotation
            {
                XY = (180 + 22).DegreesToRadians(),
                YZ = -22.DegreesToRadians(),
                XZ = 45.DegreesToRadians()
            };

            var MouseOffset0 = 0.0;
            var MouseOffset1 = 0.0;
            var MouseOffset2 = 0.0;

            var MouseMode = 0;

            this.MouseLeftButtonUp +=
                delegate
            {
                MouseMode++;
            };

            this.MouseMove +=
                (sender, args) =>
            {
                var pp = args.GetPosition(this);

                if ((MouseMode % 4) == 1)
                {
                    MouseOffset1 = pp.X;
                    Rotation     = new AffineRotation
                    {
                        XZ = Rotation.XZ,
                        YZ = Rotation.YZ,

                        XY = 0.01 * (pp.X - MouseOffset0) * 2,
                    };
                }

                if ((MouseMode % 4) == 2)
                {
                    MouseOffset2 = pp.X;
                    Rotation     = new AffineRotation
                    {
                        XY = Rotation.XY,
                        YZ = Rotation.YZ,


                        XZ = 0.01 * (pp.X - MouseOffset1) * 2,
                    };
                }

                if ((MouseMode % 4) == 3)
                {
                    MouseOffset0 = pp.X;
                    Rotation     = new AffineRotation
                    {
                        XY = Rotation.XY,
                        XZ = Rotation.XZ,

                        YZ = 0.01 * (pp.X - MouseOffset2) * 2,
                    };
                }
            };


            Action <int> nextframe = null;

            var sw2 = new Stopwatch();

            sw2.Start();

            nextframe =
                c =>
            {
                sw2.Stop();

                var sw = new Stopwatch();

                sw.Start();

                if (top != null)
                {
                    a.Meshes.Remove(top);

                    top = topdef.ToTranslation(
                        new AffinePoint(0, -200 * 3, 0)
                        ).ToRotation(
                        new AffineRotation {
                        XZ = 0.01 * c
                    }
                        ).ToTranslation(
                        new AffinePoint(0, 200 * 3, 0)
                        );

                    a.Meshes.Add(top);
                }



                // rotate floor

                if (rotor)
                {
                    _a = a.ToZoom(0.5).ToRotation(Rotation);
                    Show(_a);
                }
                else
                if (c == 1)
                {
                    _a = a.ToZoom(0.5).ToRotation(Rotation);
                    Show(_a);
                }

                sw.Stop();

                t.Text = new
                {
                    rotor,
                    ShowCounter,
                    XY       = Rotation.XY.RadiansToDegrees() % 360,
                    YZ       = Rotation.YZ.RadiansToDegrees() % 360,
                    XZ       = Rotation.XZ.RadiansToDegrees() % 360,
                    Renderer = sw.ElapsedMilliseconds + "ms",
                    Other    = sw2.ElapsedMilliseconds + "ms"
                }.ToString();

                sw2 = new Stopwatch();
                //sw2.Reset();
                sw2.Start();
                1.AtDelay(() => nextframe(c + 1));

                //this.UpdateLayout();
            }
            ;

            1.AtDelay(() => nextframe(0));
        }
        void InitializeContent()
        {
            //new[] {
            //    Colors.Black,
            //    Colors.Blue,
            //    Colors.Black
            //}.ToGradient(Convert.ToInt32( Height) / 2).Select(
            //    (c, i) =>
            //        new Rectangle
            //        {
            //            Fill = new SolidColorBrush(c),
            //            Width = Width,
            //            Height = 3,
            //        }.MoveTo(0, i * 2).AttachTo(this)
            //).ToArray();



            //var help = new Image
            //{
            //    Source = (KnownAssets.Path.Assets + "/help.png").ToSource()
            //}.AttachTo(this);

            //help.Opacity = 0;

            var img = new Avalon.Images.jsc().MoveTo(Width - 128, Height - 128).AttachTo(this);

            var t = new TextBox
            {
                FontSize        = 10,
                Text            = "powered by jsc",
                BorderThickness = new Thickness(0),
                Foreground      = 0xffffffff.ToSolidColorBrush(),
                Background      = Brushes.Transparent,
                IsReadOnly      = true,
                Width           = Width
            }.MoveTo(8, 8).AttachTo(this);



            AffineContent = new Canvas
            {
            }.AttachTo(this);



            InfoContent = new Canvas
            {
            }.AttachTo(this);



            var a = new AffineMesh();



            // front
            AddCubeFace(a, "front",
                        new AffinePoint(-100, -100, 100),
                        new AffinePoint(100, -100, 100),
                        new AffinePoint(-100, 100, 100),
                        new AffinePoint(100, 100, 100)
                        );

            // right
            AddCubeFace(a, "right",
                        new AffinePoint(100, -100, 100),
                        new AffinePoint(100, -100, -100),
                        new AffinePoint(100, 100, 100),
                        new AffinePoint(100, 100, -100)
                        );

            // left
            AddCubeFace(a, "left",
                        new AffinePoint(-100, -100, 100),
                        new AffinePoint(-100, -100, -100),
                        new AffinePoint(-100, 100, 100),
                        new AffinePoint(-100, 100, -100)
                        );

            // back
            AddCubeFace(a, "back",
                        new AffinePoint(-100, -100, -100),
                        new AffinePoint(100, -100, -100),
                        new AffinePoint(-100, 100, -100),
                        new AffinePoint(100, 100, -100)
                        );

            // top
            AddCubeFace(a, "top",
                        new AffinePoint(-100, 100, -100),
                        new AffinePoint(100, 100, -100),
                        new AffinePoint(-100, 100, 100),
                        new AffinePoint(100, 100, 100)
                        );

            // bottom
            AddCubeFace(a, "bottom",
                        new AffinePoint(-100, -100, -100),
                        new AffinePoint(100, -100, -100),
                        new AffinePoint(-100, -100, 100),
                        new AffinePoint(100, -100, 100)
                        );

            // AddCubeFace(a, "back",
            //    new AffinePoint(-100, -100, -100),
            //    new AffinePoint(100, -100, -100),
            //    new AffinePoint(-100, 100, -100),
            //    new AffinePoint(100, 100, -100)
            //);


            //a = a.ToZoom(new AffineZoom { X = 2 });


            //a = a.ToZoom(0.8);
            //a = a.ToZoom(1.2);

            var    pp_X   = 0.0;
            var    pp     = new Point(Width / 2, Height / 2);
            Action Update =
                () =>
            {
                var Rotation = new AffineRotation
                {
                    XY = 0.01 * pp.X * 0.5,
                    YZ = 0.02 * pp.X * 0.5,
                    XZ = 0.03 * pp.X * 0.5 + pp_X
                };

                t.Text = new
                {
                    XY = Rotation.XZ.RadiansToDegrees(),
                    YZ = Rotation.YZ.RadiansToDegrees(),
                    XZ = Rotation.XZ.RadiansToDegrees()
                }.ToString();

                // rotate floor
                var _a = a.ToZoom((Height / 2 + pp.Y) / (Height)).ToRotation(Rotation);



                foreach (var k in _a.Vertecies)
                {
                    k.Element.Orphanize();
                    k.Element.AttachTo(AffineContent);
                    k.Element.RenderTransform = new AffineTransform
                    {
                        Left   = 0,
                        Top    = 0,
                        Width  = k.ElementWidth,
                        Height = k.ElementHeight,

                        X1 = k.B.X + Width / 2,
                        Y1 = k.B.Y + Height / 2,

                        X2 = k.C.X + Width / 2,
                        Y2 = k.C.Y + Height / 2,

                        X3 = k.A.X + Width / 2,
                        Y3 = k.A.Y + Height / 2,
                    };

                    //((Action<AffineVertex>)k.Tag)(k);
                }
            };

            this.MouseMove +=
                (sender, args) =>
            {
                pp = args.GetPosition(this);

                Update();
            };

            var tt = new DispatcherTimer();

            tt.Tick +=
                delegate
            {
                pp_X += 0.02;
                Update();
            };

            tt.Interval = TimeSpan.FromMilliseconds(1000 / 30);
            tt.Start();
        }