Beispiel #1
0
        public DevRender(Enviroment enviroment, int winWidth, int winHeight, params Camera[] cameras)
        {
            Width  = winHeight;
            Height = winHeight;
            Avalonia.Vector dpi         = new Avalonia.Vector(96, 96);
            PixelSize       wbitmapSize = new PixelSize(Width, Height);
            WriteableBitmap wbitmap     = new WriteableBitmap(wbitmapSize, dpi, PixelFormat.Bgra8888);

            Enviroment = enviroment;
            Cameras    = cameras.ToList();
            foreach (var cam in Cameras)
            {
                cam.ScreenWidth  = winWidth;
                cam.ScreenHeight = winHeight;
            }
            Preparer = new BufferPreparer(Cameras, enviroment);
            // RenderForm = new Form1()
            //  {
            //      BackColor = Color.Black,
            //     Width = winWidth,
            //     Height = winHeight
            //  };
            Controller = new Controller(this);


            //RenderForm.KeyDown += (args, e) => Controller.KeyDown(e);
            //  RenderForm.KeyUp += (args, e) => Controller.KeyUp(e);
            //  RenderForm.MouseMove += (args, e) => Controller.HanleMouse(e);
            Timer          = new DispatcherTimer();
            Timer.Interval = new System.TimeSpan(0, 0, 0, 0, 100);
            Timer.Tick    += (args, e) =>
            {
                Controller.ComputeKeys();
                Preparer.PrepareNewBuffer();
                var buffer = Preparer.GetBuffer();
                if (buffer.Width != 1)
                {
                    for (int row = 0; row < Height; row++)
                    {
                        for (int col = 0; col < Width; col++)
                        {
                            System.Drawing.Color colr  = buffer.GetPixel(col, row);
                            Avalonia.Media.Color color = Avalonia.Media.Color.FromArgb(colr.A, colr.R, colr.G, colr.B);
                            wbitmap.SetPixel(col, row, color);
                        }
                    }
                    //RenderForm.BackgroundImage = new Bitmap(buffer , RenderForm.Size);
                }
            };
        }
        /// <summary>
        /// Gets the root of the control's visual tree and the position of the control 
        /// in the root's coordinate space.
        /// </summary>
        /// <param name="v">The visual.</param>
        /// <returns>A tuple containing the root and the position of the control.</returns>
        private static Tuple<IRenderRoot, Vector> GetRootAndPosition(IVisual v)
        {
            var result = new Vector();

            while (!(v is IRenderRoot))
            {
                result = new Vector(result.X + v.Bounds.X, result.Y + v.Bounds.Y);
                v = v.VisualParent;

                if (v == null)
                {
                    throw new InvalidOperationException("Control is not attached to visual tree.");
                }
            }

            return Tuple.Create((IRenderRoot)v, result);
        }
Beispiel #3
0
 public static double Multiply(Vector vector1, Vector vector2)
 {
     return (vector1.X * vector2.X) + (vector1.Y * vector2.Y);
 }
Beispiel #4
0
 /// <summary>
 /// Translates the rectangle by an offset.
 /// </summary>
 /// <param name="offset">The offset.</param>
 /// <returns>The translated rectangle.</returns>
 public Rect Translate(Vector offset)
 {
     return new Rect(Position + offset, Size);
 }
 private static Matrix Rotation(double angle, Vector center)
 {
     return Translate(-center.X, -center.Y) * Rotation(angle) * Translate(center.X, center.Y);
 }
Beispiel #6
0
 /// <summary>
 /// Creates a scale matrix from the given vector scale.
 /// </summary>
 /// <param name="scales">The scale to use.</param>
 /// <returns>A scaling matrix.</returns>
 public static Matrix CreateScale(Vector scales)
 {
     return new Matrix(scales.X, 0, 0, scales.Y, 0, 0);
 }
Beispiel #7
0
 /// <summary>
 /// Creates a translation matrix from the given vector.
 /// </summary>
 /// <param name="position">The translation position.</param>
 /// <returns>A translation matrix.</returns>
 public static Matrix CreateTranslation(Vector position)
 {
     return CreateTranslation(position.X, position.Y);
 }
Beispiel #8
0
 public static Point Add(Point point, Vector vector)
 {
     return new Point(point.X + vector.X, point.Y + vector.Y);
 }
Beispiel #9
0
 public bool Equals(Vector value)
 {
     return this.x == value.X && this.y == value.Y;
 }
Beispiel #10
0
        /// <summary>
        /// Gets the visual offset from the specified ancestor.
        /// </summary>
        /// <param name="ancestor">The ancestor visual.</param>
        /// <param name="visual">The visual.</param>
        /// <returns>The visual offset.</returns>
        private static Vector GetOffsetFrom(IVisual ancestor, IVisual visual)
        {
            var result = new Vector();

            while (visual != ancestor)
            {
                result = new Vector(result.X + visual.Bounds.X, result.Y + visual.Bounds.Y);
                visual = visual.VisualParent;

                if (visual == null)
                {
                    throw new ArgumentException("'visual' is not a descendent of 'ancestor'.");
                }
            }

            return result;
        }
Beispiel #11
0
 public static Rect Offset(Rect rect, Vector offsetVector)
 {
     Rect result = rect;
     result.Offset(offsetVector);
     return result;
 }
Beispiel #12
0
 public static double Determinant(Vector vector1, Vector vector2)
 {
     return (vector1.X * vector2.Y) - (vector1.Y * vector2.X);
 }
Beispiel #13
0
 public static Vector Divide(Vector vector, double scalar)
 {
     return new Vector(vector.X / scalar, vector.Y / scalar);
 }
Beispiel #14
0
 public static double CrossProduct(Vector vector1, Vector vector2)
 {
     return (vector1.X * vector2.Y) - (vector1.Y * vector2.X);
 }
Beispiel #15
0
        public static double AngleBetween(Vector vector1, Vector vector2)
        {
            double cos_theta = ((vector1.X * vector2.X) + (vector1.Y * vector2.Y)) / (vector1.Length * vector2.Length);

            return Math.Acos(cos_theta) / Math.PI * 180;
        }
Beispiel #16
0
 public static Vector Add(Vector vector1, Vector vector2)
 {
     return new Vector(vector1.X + vector2.X, vector1.Y + vector2.Y);
 }
Beispiel #17
0
 public static Point Add(Vector vector, Point point)
 {
     return new Point(vector.X + point.X, vector.Y + point.Y);
 }
Beispiel #18
0
 public static bool Equals(Vector vector1, Vector vector2)
 {
     return vector1.Equals(vector2);
 }
Beispiel #19
0
 public Rect(Point point, Vector vector)
             : this(point, Point.Add(point, vector))
 {
 }
Beispiel #20
0
 public static Vector Multiply(Vector vector, Matrix matrix)
 {
     return new Vector(
         (vector.X * matrix.M11) + (vector.Y * matrix.M21),
         (vector.X * matrix.M12) + (vector.Y * matrix.M22));
 }
Beispiel #21
0
 public void Offset(Vector offsetVector)
 {
     this.x += offsetVector.X;
     this.y += offsetVector.Y;
 }
Beispiel #22
0
 public static Vector Multiply(double scalar, Vector vector)
 {
     return new Vector(scalar * vector.X, scalar * vector.Y);
 }
Beispiel #23
0
 public static Point Subtract(Point point, Vector vector)
 {
     return new Point(point.X - vector.X, point.Y - vector.Y);
 }
Beispiel #24
0
 public static Vector Subtract(Vector vector1, Vector vector2)
 {
     return new Vector(vector1.X - vector2.X, vector1.Y - vector2.Y);
 }