private void ApplyResolutionSettings() { #if XBOX360 _fullscreen = true; #endif // If we aren't using a full screen mode, the height and width of the window can // be set to anything equal to or smaller than the actual screen size. if (!_fullscreen) { if (_width > DisplayWidth || _height > DisplayHeight) { Assert.Fail("We should not reach this point."); } ApplyResolutionToGraphicsDevice(); _dirtyMatrix = true; _width = _graphicsDevice.PreferredBackBufferWidth; _height = _graphicsDevice.PreferredBackBufferHeight; return; } // Fullscreen float ratio = _width / (float)_height; DisplayMode fitDisplayMode = ChooseBestFitDisplayMode(out float dmScale); if (fitDisplayMode != null) { _width = FeMath.FloorToInt(_width * dmScale); _height = FeMath.FloorToInt(_height * dmScale); } else { float wScale = DisplayWidth / (float)_width; float hScale = DisplayHeight / (float)_height; if (wScale < hScale) { _width = FeMath.FloorToInt(_width * wScale); _height = FeMath.FloorToInt(_height * wScale); } else { _width = FeMath.FloorToInt(_width * hScale); _height = FeMath.FloorToInt(_height * hScale); } } ApplyResolutionToGraphicsDevice(); _dirtyMatrix = true; _width = _graphicsDevice.PreferredBackBufferWidth; _height = _graphicsDevice.PreferredBackBufferHeight; }
public static bool BoxWithCircle(BoxCollider collider, CircleCollider other) { float closestX = FeMath.Clamp(other.Position.X, collider.Left, collider.Right); float closestY = FeMath.Clamp(other.Position.Y, collider.Top, collider.Bottom); // Calculate the distance between the circle's center and this closest point float distanceX = other.Position.X - closestX; float distanceY = other.Position.Y - closestY; // If the distance is less than the circle's radius, an intersection occurs float distanceSquared = (distanceX * distanceX) + (distanceY * distanceY); return(distanceSquared < (other.Radius * other.Radius)); }
private DisplayMode ChooseBestFitDisplayMode(out float scale) { DisplayMode fitDisplayMode = null; scale = 0f; foreach (DisplayMode dm in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes) { if (_width > dm.Width || _height > dm.Height) { continue; } int wScale = FeMath.FloorToInt(dm.Width / (float)_width); int hScale = FeMath.FloorToInt(dm.Width / (float)_height); // Check the width and height of each mode against the passed values if (dm.Width == _width * wScale && dm.Height >= _height * wScale) { if (wScale > scale) { scale = wScale; fitDisplayMode = dm; } } else if (dm.Width >= _width * hScale && dm.Height == _height * hScale) { if (hScale > scale) { scale = hScale; fitDisplayMode = dm; } } } return(fitDisplayMode); }
private void SetResolutionImpl(int width, int height, bool fullScreen) { _width = width; _height = height; _fullscreen = fullScreen; if (_width > DisplayWidth || _height > DisplayHeight) { if (_width > DisplayWidth) { float scale = (float)DisplayWidth / (float)_width; SetResolutionImpl(DisplayWidth, FeMath.FloorToInt(scale * _height), _fullscreen); return; } if (_height > DisplayHeight) { float scale = (float)DisplayHeight / (float)_height; SetResolutionImpl(FeMath.FloorToInt(scale * _width), DisplayHeight, _fullscreen); return; } } ApplyResolutionSettings(); }
public static bool CircleWithPoint(CircleCollider collider, PointCollider other) { return(FeMath.Distance(collider.Position, other.Position) <= collider.Radius); }