// * // * Sets the texture rectangle // public MeshGenerator <T> setTextureRectangle(RealRect textureRectangle) { mUVOrigin = new Vector2(textureRectangle.top, textureRectangle.left); mUTile = textureRectangle.right - textureRectangle.left; mVTile = textureRectangle.bottom - textureRectangle.top; //return (T)this; return(this); }
/// <summary> /// Calculates all the required offset and scale. The real world rect will /// always all be shown but may have to occupy a sub section of the computer /// screen. /// </summary> public void Calculate() { RealWindowsRect.Set(RealRect); float fWinRatio = (float)WindowsRect.Width / (float)WindowsRect.Height; float fRealRatio = (float)RealRect.Width() / (float)RealRect.Height(); bool bFillX = fRealRatio >= fWinRatio; if (bFillX) { Scale.x = (float)WindowsRect.Width / (float)RealRect.Width(); Scale.y = Scale.x; RealWindowsRect.GrowHeight(fRealRatio / fWinRatio); } else { Scale.y = (float)WindowsRect.Height / (float)RealRect.Height(); Scale.x = Scale.y; RealWindowsRect.GrowWidth(fWinRatio / fRealRatio); } if (FlipX) { Scale.x = -Scale.x; } if (FlipY) { Scale.y = -Scale.y; } // Now find 2 points to map onto each other and the rest is easy. C2DPoint ptRealCen = RealRect.GetCentre(); Point ptWinCen = new Point(WindowsRect.X + WindowsRect.Width / 2, WindowsRect.Y + WindowsRect.Height / 2); Offset.x = ptRealCen.x - (float)ptWinCen.X / Scale.x; Offset.y = ptRealCen.y - (float)ptWinCen.Y / Scale.y; }
/// Transforms an input vector expressed in the 0,0->1,1 rect towards another rect public static Vector2 reframe(RealRect rect, Vector2 input) { return new Vector2(rect.left + input.x * rect.Width, rect.top + input.y * rect.Height); }
// //ORIGINAL LINE: Blit& setOutputRect(RealRect rect, bool relative = true) public Blit setOutputRect(RealRect rect, bool relative) { if (relative) { mOutputRect.left = (int)((float)mBuffer.getWidth() * System.Math.Min(rect.left, 1.0f)); mOutputRect.top = (int)((float)mBuffer.getHeight() * System.Math.Min(rect.top, 1.0f)); mOutputRect.right = (int)((float)mBuffer.getWidth() * System.Math.Min(rect.right, 1.0f)); mOutputRect.bottom = (int)((float)mBuffer.getHeight() * System.Math.Min(rect.bottom, 1.0f)); } else { mOutputRect.left = (int)System.Math.Min((int)rect.left, mBuffer.getWidth()); mOutputRect.top = (int)System.Math.Min((int)rect.top, mBuffer.getHeight()); mOutputRect.right = (int)System.Math.Min((int)rect.right, mBuffer.getWidth()); mOutputRect.bottom = (int)System.Math.Min((int)rect.bottom, mBuffer.getHeight()); } return this; }
// * // Set the full rectangle coordinates of the output buffer where the input is copied to. // \param rect Full rectangle description (default: left=0.0, top=0.0, right=1.0, bottom=1.0) // \param relative If this is set to true (default) the rectangle data are relative [0.0, 1.0]; else absolut [px] // public Blit setOutputRect(RealRect rect) { return setOutputRect(rect, true); }
// //ORIGINAL LINE: RectangleTexture& setRectangle(RealRect rect, bool relative = true) public RectangleTexture setRectangle(RealRect rect, bool relative) { if (relative) { mX1 = (int)((float)mBuffer.getWidth() * System.Math.Min(rect.left, 1.0f)); mY1 = (int)((float)mBuffer.getHeight() * System.Math.Min(rect.top, 1.0f)); mX2 = (int)((float)mBuffer.getWidth() * System.Math.Min(rect.right, 1.0f)); mY2 = (int)((float)mBuffer.getHeight() * System.Math.Min(rect.bottom, 1.0f)); } else { mX1 = System.Math.Min((int)rect.left, mBuffer.getWidth()); mY1 = System.Math.Min((int)rect.top, mBuffer.getHeight()); mX2 = System.Math.Min((int)rect.right, mBuffer.getWidth()); mY2 = System.Math.Min((int)rect.bottom, mBuffer.getHeight()); } return this; }
// * // Set the full rectangle coordinates. // \param rect Full rectangle description (default: left=0.0, top=0.0, right=1.0, bottom=1.0) // \param relative If this is set to true (default) the rectangle data are relative [0.0, 1.0]; else absolut [px] // public RectangleTexture setRectangle(RealRect rect) { return setRectangle(rect, true); }
/// <summary> /// This simply moves the real world rectangle but by a scaled, screen based /// value e.g. 10 pixels to the right. The image is shown in the same place on /// the screen but the image scrolls. /// </summary> /// <param name="Vector">Vector to scroll / move by.</param> public void ScrollScreen(C2DVector Vector) { RealRect.Move(new C2DVector(Vector.i / Scale.x, Vector.j / Scale.y)); }
/// <summary> /// This simply moves the real world rectangle. /// </summary> /// <param name="Vector">Vector to move / scroll by</param> public void ScrollReal(C2DVector Vector) { RealRect.Move(Vector); }
/// <summary> /// This simply grows the real world rectangle. /// </summary> /// <param name="dFactor">Factor to zoom out by.</param> public void ZoomOut(double dFactor) { RealRect.Grow(dFactor); }
/// Transforms an input vector expressed in the 0,0->1,1 rect towards another rect public static Vector2 reframe(RealRect rect, Vector2 input) { return(new Vector2(rect.left + input.x * rect.Width, rect.top + input.y * rect.Height)); }