public void CreateContainingBoxSquareTest() { var width = 10f; var height = 10f; var aspect = width / height; var fitBox = Box2DExtensions.CreateContainingBox(width, height, aspect); Assert.AreEqual(new Box2D(0, 0, width, height), fitBox); }
private static void LandscapeTest(float width, float height, float aspect) { var fitBox = Box2DExtensions.CreateContainingBox(width, height, aspect); var delta = .0001f; Assert.AreEqual(0f, fitBox.MinX, delta); Assert.AreEqual(-.5f * (aspect * width - height), fitBox.MinY, delta); Assert.AreEqual(width, fitBox.SizeX, delta); Assert.AreEqual(width / aspect, fitBox.SizeY, delta); }
private static void PortraitTest(float width, float height, float aspect) { var fitBox = Box2DExtensions.CreateContainingBox(width, height, aspect); var delta = .0001f; Assert.AreEqual(-.5f * (aspect * height - width), fitBox.MinX, delta); Assert.AreEqual(0f, fitBox.MinY, delta); Assert.AreEqual(height * aspect, fitBox.SizeX, delta); Assert.AreEqual(height, fitBox.SizeY, delta); }
public void Render(IReadOnlyBox2D bounds) { GL.Clear(ClearBufferMask.ColorBufferBit); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); var fitBox = Box2DExtensions.CreateContainingBox(bounds.SizeX, bounds.SizeY, aspect); GL.Ortho(fitBox.MinX, fitBox.MaxX, fitBox.MinY, fitBox.MaxY, 0, 1); GL.MatrixMode(MatrixMode.Modelview); foreach (var layer in layers) { layer.Value.Draw(); } }
internal void DrawLevelState(ILevelGrid levelState, Color tint) { UpdateLevelGeometry(levelState); shdTexColor.Activate(); texArray.Activate(); var fitBox = Box2DExtensions.CreateContainingBox(levelState.Width, levelState.Height, windowAspect); var camera = Matrix4x4.CreateOrthographicOffCenter(fitBox.MinX, fitBox.MaxX, fitBox.MinY, fitBox.MaxY, 0, 1); shdTexColor.Uniform(nameof(tint), tint.ToVector4()); shdTexColor.Uniform(nameof(camera), camera, true); vaoLevelGeometry.Draw(levelState.Width * levelState.Height); texArray.Deactivate(); shdTexColor.Deactivate(); }
public void DrawLevelState(ILevelGrid level, Color tint) { GL.Color3(tint); GL.LoadIdentity(); var fitBox = Box2DExtensions.CreateContainingBox(level.Width, level.Height, windowAspect); GL.Ortho(fitBox.MinX, fitBox.MaxX, fitBox.MinY, fitBox.MaxY, 0.0, 1.0); for (int x = 0; x < level.Width; ++x) { for (int y = 0; y < level.Height; ++y) { var tile = new Box2D(x, y, 1.0f, 1.0f); var element = level.GetElement(x, y); var tex = tileSet[element]; tex.Activate(); tile.DrawTexturedRect(Box2D.BOX01); tex.Deactivate(); } } }
public void Resize(IGameState gameState, int width, int height) { var fitBox = Box2DExtensions.CreateContainingBox(gameState.GridWidth, gameState.GridHeight, width / (float)height); toClipSpace = Matrix4.CreateOrthographicOffCenter(fitBox.MinX, fitBox.MaxX, fitBox.MinY, fitBox.MaxY, 0f, 1f); }