07.10.2020

+ Parent, Name and Flags to objects.

~ Improved Matrix calculations
This commit is contained in:
Michel Fedde 2020-10-08 12:25:20 +02:00
parent f865496414
commit 2c00dbd31a
21 changed files with 383 additions and 42 deletions

View file

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using OpenTK;
using SM.Base.Contexts;
@ -9,10 +10,29 @@ namespace SM.Base.Scene
/// </summary>
public abstract class GenericScene
{
private IBackgroundItem _background;
/// <summary>
/// This contains the background.
/// </summary>
protected IBackgroundItem _background;
protected IBackgroundItem _Background
{
get => _background;
set
{
value.Parent = this;
_background = value;
}
}
/// <summary>
/// Updates this scene.
/// </summary>
/// <param name="context"></param>
public virtual void Update(UpdateContext context)
{
}
/// <summary>
/// Draws this scene.
@ -48,6 +68,9 @@ namespace SM.Base.Scene
where TCollection : GenericItemCollection<TItem>, new()
where TItem : IShowItem
{
private TCollection _objectCollection = new TCollection();
private TCollection _hud = new TCollection();
/// <summary>
/// The active camera, that is used if the context doesn't force the viewport camera.
/// <para>If none set, it automaticly uses the viewport camera.</para>
@ -65,16 +88,42 @@ namespace SM.Base.Scene
/// <summary>
/// Objects inside the scene.
/// </summary>
public TCollection Objects { get; set; } = new TCollection();
public TCollection Objects
{
get => _objectCollection;
set
{
value.Parent = this;
_objectCollection = value;
}
}
/// <summary>
/// This defines the HUD objects.
/// </summary>
public TCollection HUD { get; } = new TCollection();
public TCollection HUD
{
get => _hud;
set
{
value.Parent = this;
_hud = value;
}
}
/// <summary>
/// A collection for cameras to switch easier to different cameras.
/// </summary>
public Dictionary<string, TCamera> Cameras = new Dictionary<string, TCamera>();
/// <inheritdoc />
public override void Update(UpdateContext context)
{
_Background?.Update(context);
_objectCollection.Update(context);
_hud.Update(context);
}
/// <inheritdoc />
public override void Draw(DrawContext context)
{
@ -82,12 +131,12 @@ namespace SM.Base.Scene
DrawContext backgroundDrawContext = context;
backgroundDrawContext.View = BackgroundCamera.CalculateViewMatrix();
_background?.Draw(backgroundDrawContext);
_Background?.Draw(backgroundDrawContext);
Objects.Draw(context);
_objectCollection.Draw(context);
context.View = HUDCamera.CalculateViewMatrix();
HUD.Draw(context);
_hud.Draw(context);
}
}
}