public Vector2i ToPixelPosition(Vector2f canvasPosition) { Vector2f v = Vector2f.ComponentDivision(canvasPosition, root.unitSize); v = Vector2f.ComponentMultiply(v, new Vector2f(root.viewport.Dimensions.X, root.viewport.Dimensions.Y)); return(new Vector2i((int)(v.X + 0.5f), (int)(v.Y + 0.5f))); }
/// <summary> /// Calculates width of border. /// </summary> /// <param name="canvas"></param> /// <returns></returns> public float CalculateWidth(ICanvasInfo canvas) { Vector2i ps = canvas.CanvasPixelSize; Vector2f t = Vector2f.ComponentDivision(canvas.CanvasUnitSize, new Vector2f(ps.X, ps.Y)); return(widthInCanvas + widthInPixels * (t.X > t.Y ? t.X : t.Y)); }
public SharpMedia.Math.Vector2f[] Generate(object shape, Vector2f[] positions) { // Maps positions. First find min and max (bounding box) Vector2f max = new Vector2f(float.NegativeInfinity, float.NegativeInfinity); Vector2f min = new Vector2f(float.PositiveInfinity, float.PositiveInfinity); for (int i = 0; i < positions.Length; i++) { Vector2f v = positions[i]; max.X = max.X > v.X ? max.X : v.X; max.Y = max.Y > v.Y ? max.Y : v.Y; min.X = min.X < v.X ? min.X : v.X; min.Y = min.Y < v.Y ? min.Y : v.Y; } // We now remap uniformy based on the box to range [0,1]x[0,1]. Vector2f diff = max - min; for (int i = 0; i < positions.Length; i++) { positions[i] = Vector2f.ComponentDivision(positions[i] - min, diff); } return(positions); }
/// <summary> /// Converts pixel coordinates to canvas coordinates. /// </summary> /// <param name="canvas"></param> /// <param name="pixel"></param> /// <returns></returns> public static Vector2f PixelToCanvas(ICanvas canvas, Vector2f pixel) { Vector2i ps = canvas.CanvasPixelSize; return(Vector2f.ComponentDivision( Vector2f.ComponentMultiply(pixel, canvas.CanvasUnitSize), new Vector2f(ps.X, ps.Y))); }
public Vector2i ToPixelPosition(Vector3f position) { // We first convert to [0,1] space. Vector2f uniformSpacePosition = Vector2f.ComponentDivision(position.Vec2, unitSize); return(new Vector2i((int)((float)pixelSize.X * uniformSpacePosition.X + 0.5f), (int)((float)pixelSize.Y * uniformSpacePosition.Y + 0.5f))); }
public Vector2f ToCanvasPosition(Vector2i pixelPosition) { Vector2f v = Vector2f.ComponentDivision( new Vector2f((float)pixelPosition.X, (float)pixelPosition.Y), new Vector2f((float)root.viewport.Width, (float)root.viewport.Height)); return(Vector2f.ComponentMultiply(v, root.unitSize)); }
/// <summary> /// Calculates mouse sensitivity. /// </summary> /// <param name="canvas"></param> /// <returns></returns> public Vector2f CalcMouseSensitivity(ICanvas canvas) { Vector2i ps = canvas.CanvasPixelSize; return(mouseSensitivity.CanvasCoordinates + Vector2f.ComponentDivision(Vector2f.ComponentMultiply(mouseSensitivity.PixelCoordinates, canvas.CanvasUnitSize), new Vector2f(ps.X, ps.Y))); }
public Vector2f[] Generate(object shape, Vector2f[] positions) { Vector2f dif = region.Dimensions; // We clamp at border. for (int i = 0; i < positions.Length; i++) { positions[i] = Vector2f.ComponentDivision(positions[i] - region.LeftBottom, dif); } // We return "transformed" positions as result. return(positions); }
/// <summary> /// The lines are perpBicular. /// </summary> /// <param name="other">The other line.</param> /// <returns>Are lines perpBicular.</returns> public bool IsPerpendicular([NotNull] Line2f other) { Vector2f special; //#ifdef 2D special = new Vector2f((float)-1, (float)-1); //#endif return(Vector2f.NearEqual(Direction, Vector2f.ComponentDivision( special, Direction))); }