01.10.2020
+ Time controls (Stopwatch, Timers, Intervals) + Added smmeries to everything in SM.Base ~ Renamed Vectors to CVectors.
This commit is contained in:
parent
7acdba92f8
commit
97e638d9d9
44 changed files with 1092 additions and 289 deletions
|
|
@ -2,25 +2,62 @@
|
|||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
/// <summary>
|
||||
/// Controller for a camera
|
||||
/// </summary>
|
||||
public abstract class GenericCamera
|
||||
{
|
||||
/// <summary>
|
||||
/// The matrix for the orthographic world.
|
||||
/// </summary>
|
||||
public static Matrix4 OrthographicWorld { get; protected set; }
|
||||
/// <summary>
|
||||
/// The matrix for the perspective world.
|
||||
/// </summary>
|
||||
public static Matrix4 PerspectiveWorld { get; protected set; }
|
||||
/// <summary>
|
||||
/// This defines what is up. (Normalized)
|
||||
/// <para>Default: <see cref="Vector3.UnitY"/></para>
|
||||
/// </summary>
|
||||
public static Vector3 UpVector { get; set; } = Vector3.UnitY;
|
||||
|
||||
public Matrix4 ViewMatrix { get; protected set; }
|
||||
/// <summary>
|
||||
/// Contains the view matrix of this camera.
|
||||
/// <para>Default: <see cref="Matrix4.Identity"/></para>
|
||||
/// </summary>
|
||||
public Matrix4 ViewMatrix { get; protected set; } = Matrix4.Identity;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the world matrix that is connected to this camera.
|
||||
/// </summary>
|
||||
public Matrix4 World => Orthographic ? OrthographicWorld : PerspectiveWorld;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the view matrix.
|
||||
/// </summary>
|
||||
/// <returns>The calculated view matrix. Same as <see cref="ViewMatrix"/></returns>
|
||||
internal Matrix4 CalculateViewMatrix()
|
||||
{
|
||||
ViewMatrix = ViewCalculation();
|
||||
return ViewMatrix;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This calculates the view matrix.
|
||||
/// </summary>
|
||||
/// <returns>The new view matrix. This is the returns for <see cref="CalculateViewMatrix"/> and the next value for <see cref="ViewMatrix"/>. </returns>
|
||||
protected abstract Matrix4 ViewCalculation();
|
||||
|
||||
/// <summary>
|
||||
/// Represents if the camera is orthographic.
|
||||
/// </summary>
|
||||
public abstract bool Orthographic { get; }
|
||||
/// <summary>
|
||||
/// This will calculate the world.
|
||||
/// <para>This is called on <see cref="GenericWindow{TScene,TItem,TCamera}.ViewportCamera"/> to calculate the world.</para>
|
||||
/// </summary>
|
||||
/// <param name="world">The world scale</param>
|
||||
/// <param name="aspect">The aspect ratio from the window.</param>
|
||||
public abstract void RecalculateWorld(Vector2 world, float aspect);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,23 +3,50 @@ using SM.Base.Contexts;
|
|||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
public abstract class GenericItemCollection<TItem, TTransformation> : IShowItem, IShowCollection<TItem>
|
||||
/// <summary>
|
||||
/// Contains a list of show items.
|
||||
/// </summary>
|
||||
/// <typeparam name="TItem">The type of show items.</typeparam>
|
||||
public abstract class GenericItemCollection<TItem> : IShowItem, IShowCollection<TItem>
|
||||
where TItem : IShowItem
|
||||
where TTransformation : GenericTransformation, new()
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public List<TItem> Objects { get; } = new List<TItem>();
|
||||
public TTransformation Transform = new TTransformation();
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Update(UpdateContext context)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IShowCollection{TItem}.Draw" />
|
||||
public virtual void Draw(DrawContext context)
|
||||
{
|
||||
context.View = Transform.GetMatrix() * context.View;
|
||||
|
||||
for (int i = 0; i < Objects.Count; i++)
|
||||
Objects[i].Draw(context);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains a list of show items with transformation.
|
||||
/// </summary>
|
||||
/// <typeparam name="TItem">The type of show items.</typeparam>
|
||||
/// <typeparam name="TTransformation">The type of transformation.</typeparam>
|
||||
public abstract class GenericItemCollection<TItem, TTransformation> : GenericItemCollection<TItem>
|
||||
where TItem : IShowItem
|
||||
where TTransformation : GenericTransformation, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// Transformation of the collection
|
||||
/// </summary>
|
||||
public TTransformation Transform = new TTransformation();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Draw(DrawContext context)
|
||||
{
|
||||
context.View = Transform.GetMatrix() * context.View;
|
||||
|
||||
base.Draw(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,20 +4,44 @@ using SM.Base.Contexts;
|
|||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
public abstract class GenericScene<TCamera, TItem> : IShowCollection<TItem>
|
||||
/// <summary>
|
||||
/// A generic scene that imports different functions.
|
||||
/// </summary>
|
||||
/// <typeparam name="TCamera">The type of cameras.</typeparam>
|
||||
/// <typeparam name="TItem">The type of show items.</typeparam>
|
||||
public abstract class GenericScene<TCamera, TItem> : GenericItemCollection<TItem>
|
||||
where TCamera : GenericCamera, new()
|
||||
where TItem : IShowItem
|
||||
{
|
||||
|
||||
protected IBackgroundItem _background;
|
||||
public List<TItem> HUD { get; } = new List<TItem>();
|
||||
public List<TItem> Objects { get; } = new List<TItem>();
|
||||
/// <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>
|
||||
/// </summary>
|
||||
public TCamera Camera { get; set; }
|
||||
/// <summary>
|
||||
/// A camera to control the background.
|
||||
/// </summary>
|
||||
public TCamera BackgroundCamera { get; set; } = new TCamera();
|
||||
/// <summary>
|
||||
/// A camera to control the HUD.
|
||||
/// </summary>
|
||||
public TCamera HUDCamera { get; set; } = new TCamera();
|
||||
|
||||
/// <summary>
|
||||
/// This contains the background.
|
||||
/// </summary>
|
||||
protected IBackgroundItem _background;
|
||||
/// <summary>
|
||||
/// This defines the HUD objects.
|
||||
/// </summary>
|
||||
public List<TItem> HUD { get; } = new List<TItem>();
|
||||
/// <summary>
|
||||
/// A collection for cameras to switch easier to different cameras.
|
||||
/// </summary>
|
||||
public Dictionary<string, TCamera> Cameras = new Dictionary<string, TCamera>();
|
||||
|
||||
public virtual void Draw(DrawContext context)
|
||||
/// <inheritdoc />
|
||||
public override void Draw(DrawContext context)
|
||||
{
|
||||
if (!context.ForceViewport && Camera != null) context.View = Camera.CalculateViewMatrix();
|
||||
|
||||
|
|
@ -25,19 +49,24 @@ namespace SM.Base.Scene
|
|||
backgroundDrawContext.View = BackgroundCamera.CalculateViewMatrix();
|
||||
_background?.Draw(backgroundDrawContext);
|
||||
|
||||
for(int i = 0; i < Objects.Count; i++)
|
||||
Objects[i].Draw(context);
|
||||
base.Draw(context);
|
||||
|
||||
context.View = HUDCamera.CalculateViewMatrix();
|
||||
for (int i = 0; i < HUD.Count; i++)
|
||||
HUD[i].Draw(context);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called, when the user activates the scene.
|
||||
/// </summary>
|
||||
internal void Activate()
|
||||
{
|
||||
OnActivating();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called, when the user activates the scene.
|
||||
/// </summary>
|
||||
protected virtual void OnActivating()
|
||||
{ }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
namespace SM.Base.Scene
|
||||
{
|
||||
/// <summary>
|
||||
/// A iteration of <see cref="IShowItem"/> to reduce clutter.
|
||||
/// </summary>
|
||||
public interface IBackgroundItem : IShowItem
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,21 @@ using SM.Base.Contexts;
|
|||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds functions, that is required for a collection.
|
||||
/// </summary>
|
||||
/// <typeparam name="TItem">The type of show item.</typeparam>
|
||||
public interface IShowCollection<TItem> where TItem : IShowItem
|
||||
{
|
||||
/// <summary>
|
||||
/// The object collection.
|
||||
/// </summary>
|
||||
List<TItem> Objects { get; }
|
||||
|
||||
/// <summary>
|
||||
/// This draws the objects in the <see cref="Objects"/> list.
|
||||
/// </summary>
|
||||
/// <param name="context">The context how the objects need to be drawn.</param>
|
||||
void Draw(DrawContext context);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,9 +2,20 @@
|
|||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds requirements to object, to be properly used as a update and/or draw item.
|
||||
/// </summary>
|
||||
public interface IShowItem
|
||||
{
|
||||
/// <summary>
|
||||
/// Tells the object to update own systems.
|
||||
/// </summary>
|
||||
/// <param name="context">The update context</param>
|
||||
void Update(UpdateContext context);
|
||||
/// <summary>
|
||||
/// Tells the object to draw its object.
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
void Draw(DrawContext context);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue