/// <summary> /// Returns the extra width added by the left and right borders extending beyond the 4:3 aspect. /// </summary> public float GetBorderWidthX(float actualAspect, float height) { if (actualAspect > AspectRatioLimit) { AspectConverter.HeightToResolution((int)height, actualAspect, out Resolution resolutionOurAspect); AspectConverter.HeightToResolution((int)height, AspectConverter.OriginalGameAspect, out Resolution resolutionGameAspect); return(resolutionOurAspect.Width - resolutionGameAspect.Width); } return(0); }
/// <summary> /// Used for shifting item locations of an orthographic projection (e.g. special stage HUD) /// that are relative to the left edge of the screen. /// Note: Assumes resolution is 640x480. /// </summary> /// <param name="originalPosition">Original position of the object.</param> /// <param name="relativeAspectRatio">Relative aspect ratio of the desired aspect compared to game's aspect.</param> /// <param name="actualAspect">The desired aspect ratio.</param> public float ProjectFromOldToNewCanvasX(float originalPosition, float relativeAspectRatio, float actualAspect) { if (actualAspect > AspectRatioLimit) { // Now the projection is the right size, however it is not centered to our screen. AspectConverter.HeightToResolution((int)GameCanvasHeight, actualAspect, out Resolution resolution); // Get resolution with our aspect equal to the height. float borderWidth = resolution.Width - GameCanvasWidth; // Get the extra width (left and right border) float leftBorderOnly = (borderWidth / 2); // We only want left border. float originalPlusLeftBorder = leftBorderOnly + originalPosition; return(originalPlusLeftBorder / relativeAspectRatio); } return(originalPosition); }