Loads and loads of small improvements I added while developing on my game
This commit is contained in:
parent
41421b1df9
commit
a7c71e7ea1
107 changed files with 2278 additions and 1023 deletions
|
|
@ -1,8 +1,11 @@
|
|||
#region usings
|
||||
|
||||
using System;
|
||||
using OpenTK;
|
||||
using SM.Base;
|
||||
using SM.Base.Scene;
|
||||
using SM.Base.Types;
|
||||
using SM.Base.Windows;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -10,18 +13,73 @@ namespace SM2D.Scene
|
|||
{
|
||||
public class Camera : GenericCamera
|
||||
{
|
||||
internal static int ResizeCounter = 0;
|
||||
|
||||
private int _resizeCounter = 0;
|
||||
private bool _updateWorldScale = false;
|
||||
private Vector2? _requestedWorldScale = null;
|
||||
|
||||
public Vector2? RequestedWorldScale
|
||||
{
|
||||
get => _requestedWorldScale;
|
||||
set
|
||||
{
|
||||
_requestedWorldScale = value;
|
||||
_updateWorldScale = true;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 WorldScale { get; private set; } = Vector2.Zero;
|
||||
|
||||
public event Action<Camera> WorldScaleChanged;
|
||||
|
||||
public CVector2 Position = new CVector2(0);
|
||||
public override bool Orthographic { get; } = true;
|
||||
|
||||
protected override Matrix4 ViewCalculation()
|
||||
protected override Matrix4 ViewCalculation(IGenericWindow window)
|
||||
{
|
||||
return Matrix4.LookAt(Position.X, Position.Y, 2, Position.X, Position.Y, 0, 0, 1, 0);
|
||||
return Matrix4.LookAt(Position.X, Position.Y, 1, Position.X, Position.Y, 0, 0, 1, 0);
|
||||
}
|
||||
|
||||
public override void RecalculateWorld(Vector2 world, float aspect)
|
||||
protected override bool WorldCalculation(IGenericWindow window, out Matrix4 world)
|
||||
{
|
||||
OrthographicWorld =
|
||||
Matrix4.CreateOrthographic(world.X, world.Y, 0.1f, 100f);
|
||||
world = Matrix4.Identity;
|
||||
if (ResizeCounter != _resizeCounter || _updateWorldScale)
|
||||
{
|
||||
_updateWorldScale = false;
|
||||
_resizeCounter = ResizeCounter;
|
||||
CalculateWorldScale(window);
|
||||
|
||||
world = Matrix4.CreateOrthographic(WorldScale.X, WorldScale.Y, .0001f, 1.5f);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void CalculateWorldScale(IGenericWindow window)
|
||||
{
|
||||
if (RequestedWorldScale.HasValue)
|
||||
{
|
||||
float aspect = window.Width > window.Height ? window.AspectRatio : window.AspectRatioReverse;
|
||||
Vector2 requested = RequestedWorldScale.Value;
|
||||
|
||||
if (requested.X > 0 && requested.Y > 0)
|
||||
{
|
||||
float requestRatio = requested.X / requested.Y;
|
||||
|
||||
if (requestRatio > aspect) WorldScale = new Vector2(requested.X, requested.X / aspect);
|
||||
else WorldScale = new Vector2(aspect * requested.Y, requested.Y);
|
||||
}
|
||||
else if (requested.X > 0) WorldScale = new Vector2(requested.X, requested.X / aspect);
|
||||
else if (requested.Y > 0) WorldScale = new Vector2(aspect * requested.Y, requested.Y);
|
||||
}
|
||||
else
|
||||
{
|
||||
WorldScale = window.WindowSize;
|
||||
}
|
||||
|
||||
WorldScaleChanged?.Invoke(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +1,16 @@
|
|||
#region usings
|
||||
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base;
|
||||
using SM.Base.Scene;
|
||||
using SM.Base.Types;
|
||||
using SM.Base.Windows;
|
||||
using SM2D.Types;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM2D.Scene
|
||||
{
|
||||
public class ItemCollection : GenericItemCollection<I2DShowItem, Transformation>, I2DShowItem
|
||||
public class ItemCollection : GenericItemCollection<Transformation>
|
||||
{
|
||||
public ItemCollection()
|
||||
{
|
||||
|
|
@ -18,11 +19,7 @@ namespace SM2D.Scene
|
|||
|
||||
public override void Draw(DrawContext context)
|
||||
{
|
||||
Sort((x, y) => x.ZIndex - y.ZIndex);
|
||||
|
||||
base.Draw(context);
|
||||
}
|
||||
|
||||
public int ZIndex { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -2,16 +2,17 @@
|
|||
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base;
|
||||
using SM.Base.Objects.Static;
|
||||
using SM.Base.Scene;
|
||||
using SM.Base.Windows;
|
||||
using SM2D.Drawing;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM2D.Scene
|
||||
{
|
||||
public class Scene : GenericScene<Camera, ItemCollection, I2DShowItem>
|
||||
public class Scene : GenericScene<Camera, ItemCollection>
|
||||
{
|
||||
private static DrawObject2D _axisHelper;
|
||||
|
||||
|
|
@ -19,16 +20,24 @@ namespace SM2D.Scene
|
|||
static Scene()
|
||||
{
|
||||
_axisHelper = new DrawObject2D();
|
||||
_axisHelper.ApplyMesh(AxisHelper.Object);
|
||||
_axisHelper.Mesh = AxisHelper.Object;
|
||||
}
|
||||
|
||||
public Scene()
|
||||
{
|
||||
_Background = new DrawBackground(Color4.Black);
|
||||
Objects = new ItemCollection();
|
||||
|
||||
BackgroundCamera = new Camera();
|
||||
HUDCamera = new Camera();
|
||||
}
|
||||
|
||||
|
||||
public DrawBackground Background => (DrawBackground) _Background;
|
||||
public DrawBackground Background
|
||||
{
|
||||
get => (DrawBackground) _Background;
|
||||
set => _Background = value;
|
||||
}
|
||||
|
||||
public override void DrawDebug(DrawContext context)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue