17.09.2020
+ Generic Scene + Generic Camera + Generic Window + Contexts for drawing and updateing + very basic 2D-implermention
This commit is contained in:
parent
9889366317
commit
589d131246
25 changed files with 383 additions and 78 deletions
26
SMCode/SM.Base/Scene/GenericCamera.cs
Normal file
26
SMCode/SM.Base/Scene/GenericCamera.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
using OpenTK;
|
||||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
public abstract class GenericCamera
|
||||
{
|
||||
public static Matrix4 OrthographicWorld { get; protected set; }
|
||||
public static Matrix4 PerspectiveWorld { get; protected set; }
|
||||
public static Vector3 UpVector { get; set; } = Vector3.UnitY;
|
||||
|
||||
public Matrix4 ViewMatrix { get; protected set; }
|
||||
|
||||
public Matrix4 World => Orthographic ? OrthographicWorld : PerspectiveWorld;
|
||||
|
||||
internal Matrix4 CalculateViewMatrix()
|
||||
{
|
||||
ViewMatrix = ViewCalculation();
|
||||
return ViewMatrix;
|
||||
}
|
||||
|
||||
public abstract Matrix4 ViewCalculation();
|
||||
|
||||
public abstract bool Orthographic { get; }
|
||||
public abstract void RecalculateWorld(float width, float height);
|
||||
}
|
||||
}
|
||||
23
SMCode/SM.Base/Scene/GenericScene.cs
Normal file
23
SMCode/SM.Base/Scene/GenericScene.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using System.Collections.Generic;
|
||||
using SM.Base.Contexts;
|
||||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
public abstract class GenericScene<TCamera> : IShowCollection
|
||||
where TCamera : GenericCamera
|
||||
{
|
||||
|
||||
public List<IShowItem> Objects { get; } = new List<IShowItem>();
|
||||
public TCamera Camera { get; set; }
|
||||
public Dictionary<string, TCamera> Cameras = new Dictionary<string, TCamera>();
|
||||
|
||||
public void Draw(DrawContext context)
|
||||
{
|
||||
if (!context.ForceViewport && Camera != null) context.View = Camera.ViewMatrix;
|
||||
|
||||
for(int i = 0; i < Objects.Count; i++)
|
||||
Objects[i].Draw(context);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
9
SMCode/SM.Base/Scene/IShowCollection.cs
Normal file
9
SMCode/SM.Base/Scene/IShowCollection.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
public interface IShowCollection
|
||||
{
|
||||
List<IShowItem> Objects { get; }
|
||||
}
|
||||
}
|
||||
10
SMCode/SM.Base/Scene/IShowItem.cs
Normal file
10
SMCode/SM.Base/Scene/IShowItem.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using SM.Base.Contexts;
|
||||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
public interface IShowItem
|
||||
{
|
||||
void Update(UpdateContext context);
|
||||
void Draw(DrawContext context);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue