예제 #1
0
        public AffineMesh ToTranslation(AffinePoint Translation)
        {
            var n = new AffineMesh();

            foreach (var p in this.Points)
            {
                n.Points.Add(p.Translation(Translation));
            }


            foreach (var k in this.Vertecies)
            {
                var kn = new AffineVertex
                {
                    Element       = k.Element,
                    ElementWidth  = k.ElementWidth,
                    ElementHeight = k.ElementHeight,
                    A             = k.A.Translation(Translation),
                    B             = k.B.Translation(Translation),
                    C             = k.C.Translation(Translation),
                    //Tag = k.Tag
                };

                n.Vertecies.Add(kn);
            }


            foreach (var p in this.Meshes)
            {
                n.Meshes.Add(p.ToTranslation(Translation));
            }


            return(n);
        }
예제 #2
0
 public static AffinePoint Zoom(this AffinePoint p, AffineZoom Zoom)
 {
     return(new AffinePoint
     {
         X = p.X * Zoom.X,
         Y = p.Y * Zoom.Y,
         Z = p.Z * Zoom.Z,
         Tag = p.Tag
     });
 }
 public static AffinePoint Translation(this AffinePoint p, AffinePoint Translation)
 {
     return(new AffinePoint
     {
         X = p.X + Translation.X,
         Y = p.Y + Translation.Y,
         Z = p.Z + Translation.Z,
         Tag = p.Tag
     });
 }
		public static AffinePoint RotateXZ(this AffinePoint p, double Rotation)
		{
			// X,Z
			var r = new AffinePoint { X = p.X, Y = p.Z }.GetRotation() + Rotation;
			var z = new AffinePoint { X = p.X, Y = p.Z }.GetLength();

			var Z = Math.Sin(r) * z;
			var X = Math.Cos(r) * z;
			var Y = p.Y;

			return new AffinePoint { X = X, Y = Y, Z = Z, Tag = p.Tag };
		}
예제 #5
0
        public static double GetYawn(this AffinePoint p)
        {
            var x = p.X;
            var y = p.Z;

            const double _180 = System.Math.PI;
            const double _90  = System.Math.PI / 2;
            const double _270 = System.Math.PI * 3 / 2;

            if (x == 0)
            {
                if (y < 0)
                {
                    return(_270);
                }
                else if (y == 0)
                {
                    return(0);
                }
                else
                {
                    return(_90);
                }
            }

            if (y == 0)
            {
                if (x < 0)
                {
                    return(_180);
                }
                else
                {
                    return(0);
                }
            }

            var a = System.Math.Atan(y / x);

            if (x < 0)
            {
                a += _180;
            }
            else if (y < 0)
            {
                a += System.Math.PI * 2;
            }


            return(a);
        }
예제 #6
0
        public static AffinePoint RotateXZ(this AffinePoint p, double Rotation)
        {
            // X,Z
            var r = new AffinePoint {
                X = p.X, Y = p.Z
            }.GetRotation() + Rotation;
            var z = new AffinePoint {
                X = p.X, Y = p.Z
            }.GetLength();

            var Z = Math.Sin(r) * z;
            var X = Math.Cos(r) * z;
            var Y = p.Y;

            return(new AffinePoint {
                X = X, Y = Y, Z = Z, Tag = p.Tag
            });
        }
예제 #7
0
		public AffineMesh ToTranslation(AffinePoint Translation)
		{
			var n = new AffineMesh();

			foreach (var p in this.Points)
			{
				n.Points.Add(p.Translation(Translation));
			}


			foreach (var k in this.Vertecies)
			{
				var kn = new AffineVertex
				{
					Element = k.Element,
					ElementWidth = k.ElementWidth,
					ElementHeight = k.ElementHeight,
					A = k.A.Translation(Translation),
					B = k.B.Translation(Translation),
					C = k.C.Translation(Translation),
					//Tag = k.Tag

				};

				n.Vertecies.Add(kn);
			}


			foreach (var p in this.Meshes)
			{
				n.Meshes.Add(p.ToTranslation(Translation));
			}


			return n;
		}
        private AffineMesh AddCube(AffineMesh context, ImageSource Source, ImageSource Source2, AffinePoint TopLocation)
        {
            var a = new AffineMesh();


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

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

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

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

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

            var _a = a.ToTranslation(new AffinePoint(TopLocation.X * 200, TopLocation.Z * 200, TopLocation.Y * 200));

            context.Meshes.Add(
                _a
            );

            return _a;
        }
        private void AddCubeFace(AffineMesh a, string t, AffinePoint A, AffinePoint B, AffinePoint C, AffinePoint D)
        {
            var v1 =
               new AffineVertex
               {
                   A = A,
                   B = B,
                   C = C,

                   Element = new Avalon.Images._17 {
                       Width = 100,
                       Height = 100,
                   
                   }.AttachTo(AffineContent),
                   ElementWidth = 100,
                   ElementHeight = 100
               };

            //var t1 = new TextBox { Text = t, Foreground = Brushes.Blue }.AttachTo(InfoContent);

            //v1.Tag = new Action<AffineVertex>(
            //    k =>
            //    {
            //        t1.Text = t + " " + Convert.ToInt32(k.Center.Z);
            //        t1.MoveTo(k.Center.X + DefaultWidth / 2, k.Center.Y + DefaultHeight / 2);

            //    }
            //);

            a.Add(v1);

            var v2 =
                new AffineVertex
                {
                    A = D,
                    B = C,
                    C = B,

                    Element = new Avalon.Images._19g
                        {
                            Width = 100,
                            Height = 100,
                        }
                    .AttachTo(AffineContent),
                    ElementWidth = 100,
                    ElementHeight = 100
                };

            //v2.Element.Opacity = 0.5;

            //var t2 = new TextBox { Text = t }.AttachTo(InfoContent);

            //v2.Tag = new Action<AffineVertex>(
            //    k =>
            //    {
            //        t2.Text = t + " " + Convert.ToInt32(k.Center.Z);
            //        t2.MoveTo(k.Center.X + DefaultWidth / 2, k.Center.Y + DefaultHeight / 2);

            //    }
            //);

            a.Add(v2);

        }
예제 #10
0
 public void Add(AffinePoint p)
 {
     Points.Add(p);
 }
예제 #11
0
 public static double GetLength(this AffinePoint p)
 {
     return(Math.Sqrt(p.X * p.X + p.Y * p.Y));
 }
예제 #12
0
 public static double GetYawnLength(this AffinePoint p)
 {
     return(Math.Sqrt(p.X * p.X + p.Z * p.Z));
 }
        void InitializeContent()
        {
            Colors.Blue.ToGradient(Colors.Red, Convert.ToInt32( Height) / 4).Select(
            (c, i) =>
                new Rectangle
                {
                    Fill = new SolidColorBrush(c),
                    Width = Width,
                    Height = 4,
                }.MoveTo(0, i * 4).AttachTo(this)
        ).ToArray();



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

            //help.Opacity = 0;

            var img = new Image
            {
                Source = new Avalon.Images.jsc().Source
            }.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);



            //help.Opacity = 1;
            img.Opacity = 0.5;








            // cursor position calculations are not ready
            // for transofrmed elements.
            // we will provide a floor for those events...
            var shadow = new Rectangle
            {
                Width = Width,
                Height = Height,

                Fill = Brushes.Black,
            }.AttachTo(this);

            var shadowa = shadow.ToAnimatedOpacity();

            shadowa.Opacity = 0;



            var a = new AffineMesh();

            Func<double, double, double, Brush, AffinePoint> a_Add =
                (X, Y, Z, Fill) =>
                {
                    var p = new AffinePoint { Z = Z, X = X, Y = Y };
                    var h = new Rectangle { Fill = Fill, Width = 4, Height = 4 }.AttachTo(this);
                    //var ht = new TextBox { }.AttachTo(this);

                    var historysize = 64;
                    var history = new Queue<Rectangle>();

                    Action<AffinePoint> p_Update =
                        pp =>
                        {
                            if (history.Count > historysize)
                            {
                                history.Dequeue();
                            }

                            // -100 == 0.5
                            // 0 == 1
                            // +100 == 2

                            //var zoom = (pp.Z) / 1000;

                            var zoom = 0.5;

                            var pp_X = Width / 2 - 4 + pp.X * zoom;
                            var pp_Y = Height / 2 - 4 + pp.Y * zoom;
                            // Z is ignored here
                            // but could be used for sorting

                            h.MoveTo(pp_X, pp_Y);

                            //var hh = new Rectangle { Fill = Fill, Width = 4, Height = 4, Opacity = 1 }.MoveTo(pp_X, pp_Y).AttachTo(this);
                            //history.Enqueue(hh);

                            //foreach (var k in history.Select((c, i) => new { c, i }))
                            //{
                            //    k.c.Opacity = ((double)k.i / historysize) * 0.6;
                            //}

                            //ht.MoveTo(
                            //    DefaultWidth / 2 + pp.X - 4,
                            //    DefaultHeight / 2 + pp.Y + 4
                            //);

                            //ht.Text = new { pp.X, pp.Y, pp.Z }.ToString();
                        };

                    p.Tag = p_Update;

                    a.Add(p);

                    p_Update(p);

                    return p;
                };


            Enumerable.Range(0, 10).Select(X => a_Add(X * 10, 0, 0, Brushes.Red)).ToArray();
            Enumerable.Range(0, 10).Select(Y => a_Add(0, Y * 10, 0, Brushes.Blue)).ToArray();
            Enumerable.Range(0, 10).Select(Z => a_Add(0, 0, Z * 10, Brushes.GreenYellow)).ToArray();

            Enumerable.Range(0, 10).Select(X => a_Add(X * 10 + 100, 0, 0, Brushes.Red)).ToArray();
            Enumerable.Range(0, 10).Select(Y => a_Add(100, Y * 10, 0, Brushes.Blue)).ToArray();
            Enumerable.Range(0, 10).Select(Z => a_Add(100, 0, Z * 10, Brushes.GreenYellow)).ToArray();


            Enumerable.Range(0, 100).Select(X => a_Add(X * 10 + 200, 0, 0, Brushes.Red)).ToArray();
            Enumerable.Range(0, 10).Select(Y => a_Add(200, Y * 10, 0, Brushes.Blue)).ToArray();
            Enumerable.Range(0, 10).Select(Z => a_Add(200, 0, Z * 10, Brushes.GreenYellow)).ToArray();

            {
                var radius = 100;
                foreach (var i in Enumerable.Range(0, 90).Select(aa => (aa * 4).DegreesToRadians()))
                {
                    a_Add(Math.Cos(i) * radius, Math.Sin(i) * radius, 0, Brushes.GreenYellow);
                    a_Add(Math.Cos(i) * radius, 0, Math.Sin(i) * radius, Brushes.BlueViolet);
                    a_Add(0, Math.Cos(i) * radius, Math.Sin(i) * radius, Brushes.Magenta);
                }
            }

            {
                var radius = 200;
                foreach (var i in Enumerable.Range(0, 90).Select(aa => (aa * 4).DegreesToRadians()))
                {
                    a_Add(Math.Cos(i) * radius, Math.Sin(i) * radius, 0, Brushes.GreenYellow);
                    a_Add(Math.Cos(i) * radius, 0, Math.Sin(i) * radius, Brushes.BlueViolet);
                    a_Add(0, Math.Cos(i) * radius, Math.Sin(i) * radius, Brushes.Magenta);
                }
            }

            {
                var radius = 500;
                foreach (var i in Enumerable.Range(0, 90).Select(aa => (aa * 4).DegreesToRadians()))
                {
                    a_Add(Math.Cos(i) * radius, Math.Sin(i) * radius, 0, Brushes.GreenYellow);
                    a_Add(Math.Cos(i) * radius, 0, Math.Sin(i) * radius, Brushes.BlueViolet);
                    a_Add(0, Math.Cos(i) * radius, Math.Sin(i) * radius, Brushes.Magenta);
                }
            }

            a_Add(200, 0, 0, Brushes.BlueViolet);
            a_Add(0, 200, 0, Brushes.Yellow);
            a_Add(0, 0, 200, Brushes.Red);

            (1000 / 50).AtIntervalWithCounter(
                c =>
                {
                    // rotate floor
                    var _a = a.ToRotation(
                        new AffineRotation
                        {
                            XY = 0.01,
                            YZ = 0.02,
                            XZ = 0.03
                        }
                    );

                    //var _a = a.ToRotation(0, 0.01);

                    a = _a;

                    //var _a = a.ToRotation(c * 0.01, c * 0.005);
                    //var _a = a.ToRotation(c * 0.01, 0);

                    foreach (var p in _a.Points)
                    {
                        ((Action<AffinePoint>)p.Tag)(p);
                    }
                }
            );
        }
예제 #14
0
		public void Add(AffinePoint p)
		{
			Points.Add(p);
		}
        private void AddCubeFace(AffineMesh a, ImageSource Source, ImageSource Source2, AffinePoint A, AffinePoint B, AffinePoint C, AffinePoint D)
        {
            var v1 =
               new AffineVertex
               {
                   A = A,
                   B = B,
                   C = C,

                   Element = new Image
                   {
                       Width = 100,
                       Height = 100,
                       Source = Source
                   }.AttachTo(AffineContent),
                   ElementWidth = 100,
                   ElementHeight = 100
               };



            a.Vertecies.Add(v1);

            var v2 =
                new AffineVertex
                {
                    A = D,
                    B = C,
                    C = B,

                    Element = new Image
                    {
                        Width = 100,
                        Height = 100,
                        Source = Source2
                    }.AttachTo(AffineContent),
                    ElementWidth = 100,
                    ElementHeight = 100
                };



            a.Vertecies.Add(v2);

        }
        private void AddCubeFace(AffineMesh a, string t, AffinePoint A, AffinePoint B, AffinePoint C, AffinePoint D)
        {
            var v1 =
               new AffineVertex
               {
                   A = A,
                   B = B,
                   C = C,

                   Element = new Avalon.Images._17
                   {
                       Width = 100,
                       Height = 100,
                   }.AttachTo(AffineContent),
                   ElementWidth = 100,
                   ElementHeight = 100
               };

            a.Vertecies.Add(v1);

            var v2 =
                new AffineVertex
                {
                    A = D,
                    B = C,
                    C = B,

                    Element = new Avalon.Images._17g
                    {
                        Width = 100,
                        Height = 100,
                    }.AttachTo(AffineContent),
                    ElementWidth = 100,
                    ElementHeight = 100
                };



            a.Vertecies.Add(v2);

        }
예제 #17
0
 public static AffinePoint Rotate(this AffinePoint p, AffineRotation Rotation)
 {
     return(p.RotateXY(Rotation.XY).RotateYZ(Rotation.XZ).RotateXZ(Rotation.XZ));
 }