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); }
public static double Multiply(Vector vector1, Vector vector2) { return (vector1.X * vector2.X) + (vector1.Y * vector2.Y); }
/// <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); }
/// <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); }
/// <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); }
public static Point Add(Point point, Vector vector) { return new Point(point.X + vector.X, point.Y + vector.Y); }
public bool Equals(Vector value) { return this.x == value.X && this.y == value.Y; }
/// <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; }
public static Rect Offset(Rect rect, Vector offsetVector) { Rect result = rect; result.Offset(offsetVector); return result; }
public static double Determinant(Vector vector1, Vector vector2) { return (vector1.X * vector2.Y) - (vector1.Y * vector2.X); }
public static Vector Divide(Vector vector, double scalar) { return new Vector(vector.X / scalar, vector.Y / scalar); }
public static double CrossProduct(Vector vector1, Vector vector2) { return (vector1.X * vector2.Y) - (vector1.Y * vector2.X); }
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; }
public static Vector Add(Vector vector1, Vector vector2) { return new Vector(vector1.X + vector2.X, vector1.Y + vector2.Y); }
public static Point Add(Vector vector, Point point) { return new Point(vector.X + point.X, vector.Y + point.Y); }
public static bool Equals(Vector vector1, Vector vector2) { return vector1.Equals(vector2); }
public Rect(Point point, Vector vector) : this(point, Point.Add(point, vector)) { }
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)); }
public void Offset(Vector offsetVector) { this.x += offsetVector.X; this.y += offsetVector.Y; }
public static Vector Multiply(double scalar, Vector vector) { return new Vector(scalar * vector.X, scalar * vector.Y); }
public static Point Subtract(Point point, Vector vector) { return new Point(point.X - vector.X, point.Y - vector.Y); }
public static Vector Subtract(Vector vector1, Vector vector2) { return new Vector(vector1.X - vector2.X, vector1.Y - vector2.Y); }