/// <summary> /// Returns the extra height added by the top and bottom borders extending before the 4:3 aspect. /// </summary> public float GetBorderHeightY(float actualAspect, float width) { if (actualAspect < AspectRatioLimit) { AspectConverter.WidthToResolution((int)width, actualAspect, out Resolution resolutionOurAspect); AspectConverter.WidthToResolution((int)width, AspectConverter.OriginalGameAspect, out Resolution resolutionGameAspect); return(resolutionOurAspect.Height - resolutionGameAspect.Height); } return(0); }
/// <summary> /// Used for shifting item locations of an orthographic projection (e.g. special stage HUD) /// that are relative to the top 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 ProjectFromOldToNewCanvasY(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.WidthToResolution((int)GameCanvasWidth, actualAspect, out Resolution resolution); // Get resolution with our aspect equal to the height. float borderHeight = resolution.Height - GameCanvasHeight; // Get the extra height (top and bottom border) float topBorderOnly = (borderHeight / 2); // We only want top border. float originalPlusTopBorder = topBorderOnly + originalPosition; // Our top border is in the aspect ratio it originated from, // we need to scale it to the new ratio. return(originalPlusTopBorder * relativeAspectRatio); } return(originalPosition); }