Added Summeries
This commit is contained in:
parent
71a22df8bd
commit
8296d9b8a9
47 changed files with 812 additions and 177 deletions
|
|
@ -8,8 +8,14 @@ using SM2D.Types;
|
|||
|
||||
namespace SM2D.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains special methods for the mouse.
|
||||
/// </summary>
|
||||
public class Mouse2D
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the current position of the mouse inside the world.
|
||||
/// </summary>
|
||||
public static Vector2 InWorld(Vector2 worldScale)
|
||||
{
|
||||
var res = worldScale;
|
||||
|
|
@ -17,28 +23,63 @@ namespace SM2D.Controls
|
|||
return Mouse.InScreenNormalized * res - res / 2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current position of the mouse inside the world.
|
||||
/// </summary>
|
||||
public static Vector2 InWorld(Camera cam)
|
||||
{
|
||||
return InWorld(cam.WorldScale) + cam.Position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current position of the mouse inside the world.
|
||||
/// </summary>
|
||||
public static Vector2 InWorld(Vector2 worldScale, Vector2 position)
|
||||
{
|
||||
return InWorld(worldScale) + position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the mouse is over an object.
|
||||
/// </summary>
|
||||
/// <param name="mousePos">The position in the world. See <see cref="InWorld(Camera)"/></param>
|
||||
/// <param name="checkingObjects"></param>
|
||||
/// <typeparam name="TObject"></typeparam>
|
||||
public static bool MouseOver<TObject>(Vector2 mousePos, params TObject[] checkingObjects)
|
||||
where TObject : IModelItem, ITransformItem<Transformation>
|
||||
=> MouseOver(mousePos, out _, checkingObjects);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the mouse is over an object.
|
||||
/// </summary>
|
||||
/// <param name="mousePos">The position in the world. See <see cref="InWorld(Camera)"/></param>
|
||||
/// <param name="checkingObjects"></param>
|
||||
/// <typeparam name="TObject"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static bool MouseOver<TObject>(Vector2 mousePos, ICollection<TObject> checkingObjects)
|
||||
where TObject : IModelItem, ITransformItem<Transformation>
|
||||
=> MouseOver<TObject>(mousePos, out _, checkingObjects);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the mouse is over an object and returns the object that was clicked on.
|
||||
/// </summary>
|
||||
/// <param name="mousePos">The position in the world. See <see cref="InWorld(Camera)"/></param>
|
||||
/// <param name="clicked"></param>
|
||||
/// <param name="checkingObjects"></param>
|
||||
/// <typeparam name="TObject"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static bool MouseOver<TObject>(Vector2 mousePos, out TObject clicked, params TObject[] checkingObjects)
|
||||
where TObject : IModelItem, ITransformItem<Transformation>
|
||||
=> MouseOver<TObject>(mousePos, out clicked, (ICollection<TObject>)checkingObjects);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the mouse is over an object and returns the object that was clicked on.
|
||||
/// </summary>
|
||||
/// <param name="mousePos">The position in the world. See <see cref="InWorld(Camera)"/></param>
|
||||
/// <param name="clickedObj"></param>
|
||||
/// <param name="checkingObjects"></param>
|
||||
/// <typeparam name="TObject"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static bool MouseOver<TObject>(Vector2 mousePos, out TObject clickedObj, ICollection<TObject> checkingObjects)
|
||||
where TObject : IModelItem, ITransformItem<Transformation>
|
||||
{
|
||||
|
|
@ -70,6 +111,13 @@ namespace SM2D.Controls
|
|||
return success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the mouse is over an object and returns the object that was clicked on.
|
||||
/// </summary>
|
||||
/// <param name="mousePos">The position in the world. See <see cref="InWorld(Camera)"/></param>
|
||||
/// <param name="boundingBox"></param>
|
||||
/// <param name="transform"></param>
|
||||
/// <returns></returns>
|
||||
public static bool MouseOver(Vector2 mousePos, BoundingBox boundingBox, Transformation transform)
|
||||
{
|
||||
Matrix4 worldPos = transform.InWorldSpace;
|
||||
|
|
|
|||
|
|
@ -14,14 +14,23 @@ using SM2D.Scene;
|
|||
|
||||
namespace SM2D.Drawing
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows easy access to draw something on the background.
|
||||
/// </summary>
|
||||
public class DrawBackground : DrawingBasis, IBackgroundItem
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the color or tint (in case a texture is set).
|
||||
/// </summary>
|
||||
public Color4 Color
|
||||
{
|
||||
get => Material.Tint;
|
||||
set => Material.Tint = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the texture of the background.
|
||||
/// </summary>
|
||||
public TextureBase Texture
|
||||
{
|
||||
get => Material.Texture;
|
||||
|
|
@ -32,18 +41,34 @@ namespace SM2D.Drawing
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a black background.
|
||||
/// </summary>
|
||||
public DrawBackground() : this(Color4.Black) {}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a background with a color.
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
public DrawBackground(Color4 color)
|
||||
{
|
||||
Color = color;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a background with a texture.
|
||||
/// </summary>
|
||||
/// <param name="texture"></param>
|
||||
public DrawBackground(Bitmap texture)
|
||||
{
|
||||
Texture = (Texture) texture;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a background with a texture and a tint.
|
||||
/// </summary>
|
||||
/// <param name="texture"></param>
|
||||
/// <param name="tint"></param>
|
||||
public DrawBackground(Bitmap texture, Color4 tint)
|
||||
{
|
||||
Color = tint;
|
||||
|
|
@ -51,6 +76,7 @@ namespace SM2D.Drawing
|
|||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void DrawContext(ref DrawContext context)
|
||||
{
|
||||
base.DrawContext(ref context);
|
||||
|
|
|
|||
|
|
@ -10,46 +10,72 @@ using SM2D.Types;
|
|||
|
||||
namespace SM2D.Drawing
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public class DrawObject2D : DrawingBasis<Transformation>
|
||||
{
|
||||
/// <summary>
|
||||
/// The texture the object should use.
|
||||
/// </summary>
|
||||
public Texture Texture
|
||||
{
|
||||
get => (Texture) Material.Texture;
|
||||
set => Material.Texture = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The color or tint the object should use.
|
||||
/// </summary>
|
||||
public Color4 Color
|
||||
{
|
||||
get => Material.Tint;
|
||||
set => Material.Tint = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void DrawContext(ref DrawContext context)
|
||||
{
|
||||
base.DrawContext(ref context);
|
||||
context.Shader.Draw(context);
|
||||
}
|
||||
|
||||
public void SetShader(MaterialShader shader) => Material.CustomShader = shader;
|
||||
|
||||
public Polygon ApplyPolygon(ICollection<Vector2> vertices, bool centerUVs = false)
|
||||
/// <summary>
|
||||
/// Applies a polygon to the object.
|
||||
/// </summary>
|
||||
/// <param name="vertices"></param>
|
||||
/// <returns></returns>
|
||||
public Polygon ApplyPolygon(ICollection<Vector2> vertices)
|
||||
{
|
||||
Polygon polygon = new Polygon(vertices);
|
||||
Mesh = polygon;
|
||||
return polygon;
|
||||
}
|
||||
public Polygon ApplyPolygon(ICollection<PolygonVertex> vertices, bool centerUVs = false)
|
||||
|
||||
/// <summary>
|
||||
/// Applies a polygon to the object.
|
||||
/// </summary>
|
||||
/// <param name="vertices"></param>
|
||||
/// <returns></returns>
|
||||
public Polygon ApplyPolygon(ICollection<PolygonVertex> vertices)
|
||||
{
|
||||
Polygon polygon = new Polygon(vertices);
|
||||
Mesh = polygon;
|
||||
return polygon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies a polygon to the object.
|
||||
/// </summary>
|
||||
public void ApplyPolygon(Polygon polygon)
|
||||
{
|
||||
Mesh = polygon;
|
||||
}
|
||||
|
||||
public Polygon ApplyCircle(int segments = 32, bool centerUVs = false)
|
||||
/// <summary>
|
||||
/// This applies a circle.
|
||||
/// </summary>
|
||||
/// <param name="segments"></param>
|
||||
/// <returns></returns>
|
||||
public Polygon ApplyCircle(int segments = 32)
|
||||
{
|
||||
Polygon pol = Polygon.GenerateCircle(segments);
|
||||
Mesh = pol;
|
||||
|
|
|
|||
|
|
@ -6,14 +6,20 @@ using SM2D.Types;
|
|||
|
||||
namespace SM2D.Drawing
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates particles.
|
||||
/// </summary>
|
||||
public class DrawParticles : ParticleDrawingBasis<Transformation, Vector2>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override Func<Vector2, ParticleContext, Vector2> MovementCalculation { get; set; } = ParticleMovement.Default2D;
|
||||
|
||||
/// <inheritdoc />
|
||||
public DrawParticles(TimeSpan duration) : base(duration)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override ParticleStruct<Vector2> CreateObject(int index)
|
||||
{
|
||||
return new ParticleStruct<Vector2>()
|
||||
|
|
@ -24,6 +30,7 @@ namespace SM2D.Drawing
|
|||
};
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Matrix4 CreateMatrix(ParticleStruct<Vector2> Struct, Vector2 direction)
|
||||
{
|
||||
return Struct.Matrix * Matrix4.CreateTranslation(direction.X, direction.Y, 0);
|
||||
|
|
|
|||
|
|
@ -9,14 +9,21 @@ using SM2D.Types;
|
|||
|
||||
namespace SM2D.Drawing
|
||||
{
|
||||
/// <summary>
|
||||
/// Draws a text to the world.
|
||||
/// </summary>
|
||||
public class DrawText : TextDrawingBasis<Transformation>
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a text object.
|
||||
/// </summary>
|
||||
public DrawText(Font font, string text) : base(font)
|
||||
{
|
||||
_text = text;
|
||||
Transform.Size = new CVector2(1);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void DrawContext(ref DrawContext context)
|
||||
{
|
||||
base.DrawContext(ref context);
|
||||
|
|
|
|||
|
|
@ -5,15 +5,36 @@ using SM.OGL.Mesh;
|
|||
|
||||
namespace SM2D.Object
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows different type of lines.
|
||||
/// </summary>
|
||||
public enum PolyLineType
|
||||
{
|
||||
/// <summary>
|
||||
/// Those lines are not connected to each other.
|
||||
/// <para>Every two points starts a new line.</para>
|
||||
/// </summary>
|
||||
NotConnected = 1,
|
||||
/// <summary>
|
||||
/// Those lines are connected with each other, but don't connect the start and the end.
|
||||
/// </summary>
|
||||
Connected = 3,
|
||||
/// <summary>
|
||||
/// Those lines are connected and they connect start and end.
|
||||
/// </summary>
|
||||
ConnectedLoop = 2
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates new poly line.
|
||||
/// </summary>
|
||||
public class PolyLine : Polygon, ILineMesh
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new polyline by using <see cref="Vector2"/>.
|
||||
/// </summary>
|
||||
/// <param name="vertices"></param>
|
||||
/// <param name="lineType"></param>
|
||||
public PolyLine(ICollection<Vector2> vertices, PolyLineType lineType = PolyLineType.NotConnected) : base(vertices)
|
||||
{
|
||||
UVs.Active = false;
|
||||
|
|
@ -21,6 +42,11 @@ namespace SM2D.Object
|
|||
PrimitiveType = (PrimitiveType)lineType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new polyline by using <see cref="PolygonVertex"/>.
|
||||
/// </summary>
|
||||
/// <param name="vertices"></param>
|
||||
/// <param name="lineType"></param>
|
||||
public PolyLine(ICollection<PolygonVertex> vertices, PolyLineType lineType = PolyLineType.NotConnected) : base(vertices)
|
||||
{
|
||||
UVs.Active = false;
|
||||
|
|
|
|||
|
|
@ -11,8 +11,27 @@ using SM.OGL.Mesh;
|
|||
|
||||
namespace SM2D.Object
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a polygon.
|
||||
/// </summary>
|
||||
public class Polygon : Mesh
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override VBO Vertex { get; protected set; } = new VBO();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override VBO UVs { get; protected set; } = new VBO(pointerSize: 2);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override VBO Color { get; protected set; } = new VBO(pointerSize: 4);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override PrimitiveType PrimitiveType { get; protected set; } = PrimitiveType.TriangleFan;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a polygon with <see cref="Vector2"/>s.
|
||||
/// </summary>
|
||||
/// <param name="vertices"></param>
|
||||
public Polygon(ICollection<Vector2> vertices) : base(PrimitiveType.TriangleFan)
|
||||
{
|
||||
Color.Active = false;
|
||||
|
|
@ -27,25 +46,23 @@ namespace SM2D.Object
|
|||
if (UVs.Active) foreach (var vertex in vertices) AddUV(vertex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a polygon with <see cref="PolygonVertex"/>, what allows colors hard coded.
|
||||
/// </summary>
|
||||
/// <param name="vertices"></param>
|
||||
public Polygon(ICollection<PolygonVertex> vertices) : base(PrimitiveType.TriangleFan)
|
||||
{
|
||||
foreach (var polygonVertex in vertices)
|
||||
{
|
||||
Color.Add(polygonVertex.Color);
|
||||
Vertex.Add(polygonVertex.Vertex, 0);
|
||||
Vertex.Add(polygonVertex.Position, 0);
|
||||
}
|
||||
|
||||
UpdateBoundingBox();
|
||||
|
||||
if (UVs.Active) foreach (var vertex in vertices) AddUV(vertex.Vertex);
|
||||
if (UVs.Active) foreach (var vertex in vertices) AddUV(vertex.Position);
|
||||
}
|
||||
|
||||
public override VBO Vertex { get; protected set; } = new VBO();
|
||||
public override VBO UVs { get; protected set; } = new VBO(pointerSize: 2);
|
||||
public override VBO Color { get; protected set; } = new VBO(pointerSize: 4);
|
||||
|
||||
public override PrimitiveType PrimitiveType { get; protected set; } = PrimitiveType.TriangleFan;
|
||||
|
||||
private void AddUV(Vector2 vertex)
|
||||
{
|
||||
var uv = Vector2.Divide(vertex - BoundingBox.Min.Xy, BoundingBox.Max.Xy - BoundingBox.Min.Xy);
|
||||
|
|
@ -53,6 +70,11 @@ namespace SM2D.Object
|
|||
UVs.Add(uv);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a circle.
|
||||
/// </summary>
|
||||
/// <param name="secments"></param>
|
||||
/// <returns></returns>
|
||||
public static Polygon GenerateCircle(int secments = 32)
|
||||
{
|
||||
var vertices = new List<Vector2> {Vector2.Zero};
|
||||
|
|
|
|||
|
|
@ -7,17 +7,36 @@ using OpenTK.Graphics;
|
|||
|
||||
namespace SM2D.Object
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows storing more information inside a vertex.
|
||||
/// </summary>
|
||||
public struct PolygonVertex
|
||||
{
|
||||
public Vector2 Vertex;
|
||||
/// <summary>
|
||||
/// The position in the polygon.
|
||||
/// </summary>
|
||||
public Vector2 Position;
|
||||
/// <summary>
|
||||
/// The color of the vertex.
|
||||
/// </summary>
|
||||
public Color4 Color;
|
||||
|
||||
public PolygonVertex(Vector2 vertex = default, Color4 color = default)
|
||||
/// <summary>
|
||||
/// Creates a polygon vertex.
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <param name="color"></param>
|
||||
public PolygonVertex(Vector2 position = default, Color4 color = default)
|
||||
{
|
||||
Vertex = vertex;
|
||||
Position = position;
|
||||
Color = color;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Automaticly translates Vector2s to PolygonVertex
|
||||
/// </summary>
|
||||
/// <param name="vec"></param>
|
||||
/// <returns></returns>
|
||||
public static implicit operator PolygonVertex(Vector2 vec) => new PolygonVertex(vec, Color4.White);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,13 +4,22 @@ using SM2D.Shader;
|
|||
|
||||
namespace SM2D.Pipelines
|
||||
{
|
||||
/// <summary>
|
||||
/// This implements the most basic render pipeline.
|
||||
/// </summary>
|
||||
public class Basic2DPipeline : RenderPipeline
|
||||
{
|
||||
/// <summary>
|
||||
/// The access to the pipeline.
|
||||
/// </summary>
|
||||
public static Basic2DPipeline Pipeline = new Basic2DPipeline();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override MaterialShader DefaultShader { get; protected set; } = ShaderCollection.Instanced;
|
||||
|
||||
private Basic2DPipeline() {}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void RenderProcess(ref DrawContext context)
|
||||
{
|
||||
context.Scene?.Draw(context);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SM2D</RootNamespace>
|
||||
<AssemblyName>SM2D</AssemblyName>
|
||||
<AssemblyName>SMRenderer2D</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
|
|
@ -21,6 +21,7 @@
|
|||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Debug\SMRenderer2D.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
|
|
@ -47,13 +48,11 @@
|
|||
<Compile Include="Pipelines\Basic2DPipeline.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Scene\Camera.cs" />
|
||||
<Compile Include="Scene\I2DShowItem.cs" />
|
||||
<Compile Include="Scene\ItemCollection.cs" />
|
||||
<Compile Include="Scene\Scene.cs" />
|
||||
<Compile Include="Shader\ShaderCollection.cs" />
|
||||
<Compile Include="Types\Transformation.cs" />
|
||||
<Compile Include="Window\Window2DSetup.cs" />
|
||||
<Compile Include="Window\I2DSetup.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SM.Base\SM.Base.csproj">
|
||||
|
|
@ -69,9 +68,6 @@
|
|||
<PackageReference Include="OpenTK">
|
||||
<Version>3.3.1</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="OpenTK.GLWpfControl">
|
||||
<Version>3.2.3</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Shader\ShaderFiles\basic.glsl" />
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ using SM.Base.Window;
|
|||
|
||||
namespace SM2D.Scene
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public class Camera : GenericCamera
|
||||
{
|
||||
internal static int ResizeCounter = 0;
|
||||
|
|
@ -19,6 +20,14 @@ namespace SM2D.Scene
|
|||
private bool _updateWorldScale = false;
|
||||
private Vector2? _requestedWorldScale = null;
|
||||
|
||||
/// <summary>
|
||||
/// This vector allows to request a world scale.
|
||||
/// <para>Following cases are possible. ("not set" means 0)</para>
|
||||
/// <para>None is set: It takes the window size.</para>
|
||||
/// <para>X is set: Y get calculated by the aspect ratio of the window.</para>
|
||||
/// <para>Y is set: X get calculated by the aspect ratio of the window.</para>
|
||||
/// <para>Both are set: Now the system try to keep a (invisible) rectangle in view, by increasing the width or height of the view, if needed.</para>
|
||||
/// </summary>
|
||||
public Vector2? RequestedWorldScale
|
||||
{
|
||||
get => _requestedWorldScale;
|
||||
|
|
@ -29,18 +38,32 @@ namespace SM2D.Scene
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The world scale that got calculated.
|
||||
/// </summary>
|
||||
public Vector2 WorldScale { get; private set; } = Vector2.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// A event that gets triggered, when the world scale changed.
|
||||
/// <para>Possible causes: Window resizes, <see cref="RequestedWorldScale"/> changed</para>
|
||||
/// </summary>
|
||||
public event Action<Camera> WorldScaleChanged;
|
||||
|
||||
/// <summary>
|
||||
/// The position of the camera.
|
||||
/// </summary>
|
||||
public CVector2 Position = new CVector2(0);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Orthographic { get; } = true;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Matrix4 ViewCalculation(IGenericWindow window)
|
||||
{
|
||||
return Matrix4.LookAt(Position.X, Position.Y, Distance, Position.X, Position.Y, 0f, 0, 1, 0);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override bool WorldCalculation(IGenericWindow window, out Matrix4 world)
|
||||
{
|
||||
world = Matrix4.Identity;
|
||||
|
|
@ -57,6 +80,11 @@ namespace SM2D.Scene
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This calculates the world scale.
|
||||
/// <para>Usually gets called, by the camera itself, but if you need the world scale for additional calculations, you can execute it by yourself.</para>
|
||||
/// </summary>
|
||||
/// <param name="window"></param>
|
||||
public void CalculateWorldScale(IGenericWindow window)
|
||||
{
|
||||
if (RequestedWorldScale.HasValue)
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
#region usings
|
||||
|
||||
using SM.Base.Scene;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM2D.Scene
|
||||
{
|
||||
public interface I2DShowItem : IShowItem
|
||||
{
|
||||
int ZIndex { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -2,23 +2,19 @@
|
|||
|
||||
using SM.Base.Scene;
|
||||
using SM.Base.Types;
|
||||
using SM.Base.Window;
|
||||
using SM2D.Types;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM2D.Scene
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public class ItemCollection : GenericItemCollection<Transformation>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public ItemCollection()
|
||||
{
|
||||
Transform.Size = new CVector2(1);
|
||||
}
|
||||
|
||||
public override void Draw(DrawContext context)
|
||||
{
|
||||
base.Draw(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -11,17 +11,25 @@ using SM2D.Drawing;
|
|||
|
||||
namespace SM2D.Scene
|
||||
{
|
||||
/// <summary>
|
||||
/// The scene allows connecting different objects to render together.
|
||||
/// </summary>
|
||||
public class Scene : GenericScene<Camera, ItemCollection>
|
||||
{
|
||||
private static DrawObject2D _axisHelper;
|
||||
private static readonly DrawObject2D _axisHelper;
|
||||
|
||||
/// <summary>
|
||||
/// This determent how large the axishelper should be.
|
||||
/// </summary>
|
||||
public float AxisHelperSize = 100;
|
||||
static Scene()
|
||||
{
|
||||
_axisHelper = new DrawObject2D();
|
||||
_axisHelper.Mesh = AxisHelper.Object;
|
||||
_axisHelper = new DrawObject2D {Mesh = AxisHelper.Object};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This creates a new scene.
|
||||
/// </summary>
|
||||
public Scene()
|
||||
{
|
||||
_Background = new DrawBackground(Color4.Black);
|
||||
|
|
@ -32,12 +40,16 @@ namespace SM2D.Scene
|
|||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the background.
|
||||
/// </summary>
|
||||
public DrawBackground Background
|
||||
{
|
||||
get => (DrawBackground) _Background;
|
||||
set => _Background = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void DrawHUD(DrawContext context)
|
||||
{
|
||||
context.ModelMatrix *= Matrix4.CreateTranslation(0,0,1);
|
||||
|
|
@ -45,6 +57,7 @@ namespace SM2D.Scene
|
|||
base.DrawHUD(context);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void DrawDebug(DrawContext context)
|
||||
{
|
||||
if (ShowAxisHelper)
|
||||
|
|
|
|||
|
|
@ -5,9 +5,15 @@ using SM.OGL.Shaders;
|
|||
|
||||
namespace SM2D.Shader
|
||||
{
|
||||
public class ShaderCollection
|
||||
class ShaderCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// The most basic shader, that renders only one thing and only allows colors and one texture.
|
||||
/// </summary>
|
||||
public static SimpleShader Basic = new SimpleShader("basic", AssemblyUtility.ReadAssemblyFile("SM2D.Shader.ShaderFiles.basic.glsl"), SetUniforms);
|
||||
/// <summary>
|
||||
/// The same fragment shader as <see cref="Basic"/>, but allows to be instanced and used in (f.E.) text.
|
||||
/// </summary>
|
||||
public static SimpleShader Instanced = new SimpleShader("instanced", AssemblyUtility.ReadAssemblyFile("SM2D.Shader.ShaderFiles.basic.glsl"), SetUniforms);
|
||||
|
||||
static void SetUniforms(UniformCollection uniforms, DrawContext context)
|
||||
|
|
|
|||
|
|
@ -11,5 +11,4 @@ layout(location = 0) out vec4 color;
|
|||
void main() {
|
||||
color = v_Color * Tint;
|
||||
if (UseTexture) color *= texture(Texture, v_TexCoords);
|
||||
color *= 1.2;
|
||||
}
|
||||
|
|
@ -10,22 +10,46 @@ using SM.Base.Utility;
|
|||
|
||||
namespace SM2D.Types
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public class Transformation : GenericTransformation
|
||||
{
|
||||
public static int ZIndexPercision = 300;
|
||||
/// <summary>
|
||||
/// The precision of the Z-Index.
|
||||
/// <para>High values can result into "z-fighting" and cliping.</para>
|
||||
/// </summary>
|
||||
public static int ZIndexPercision = 100;
|
||||
|
||||
/// <summary>
|
||||
/// The transformations translation.
|
||||
/// </summary>
|
||||
public CVector2 Position { get; set; } = new CVector2(0);
|
||||
|
||||
/// <summary>
|
||||
/// The scaling.
|
||||
/// </summary>
|
||||
public CVector2 Size { get; set; } = new CVector2(50);
|
||||
|
||||
/// <summary>
|
||||
/// The rotation.
|
||||
/// </summary>
|
||||
public CVector1 Rotation { get; set; } = new CVector1(0);
|
||||
|
||||
/// <summary>
|
||||
/// If true, the object get rotated on the X-Axis by 180°.
|
||||
/// </summary>
|
||||
public bool HorizontalFlip { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// If true, the object get rotated on the Y-Axis by 180°.
|
||||
/// </summary>
|
||||
public bool VerticalFlip { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// The ZIndex.
|
||||
/// </summary>
|
||||
public CVector1 ZIndex { get; set; } = new CVector1(0);
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Matrix4 RequestMatrix()
|
||||
{
|
||||
float z = 1 / (float) ZIndexPercision * ZIndex;
|
||||
|
|
@ -37,11 +61,18 @@ namespace SM2D.Types
|
|||
Matrix4.CreateTranslation(Position.X, Position.Y, z);
|
||||
}
|
||||
|
||||
public void TurnTo(Vector2 v)
|
||||
/// <summary>
|
||||
/// Rotates the object, so it SHOULD turn toward the position.
|
||||
/// </summary>
|
||||
public void TurnTo(Vector2 turnposition)
|
||||
{
|
||||
Rotation.Set(RotationUtility.TurnTowards(Position, v));
|
||||
Rotation.Set(RotationUtility.TurnTowards(Position, turnposition));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the vector the object is looking.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Vector2 LookAtVector()
|
||||
{
|
||||
if (_modelMatrix.Determinant < 0.0001) return new Vector2(0);
|
||||
|
|
@ -51,11 +82,20 @@ namespace SM2D.Types
|
|||
return vec.Xy;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The object scale gets set to the same as the resolution of the texture.
|
||||
/// </summary>
|
||||
/// <param name="texture"></param>
|
||||
public void ApplyTextureSize(Texture texture)
|
||||
{
|
||||
Size.Set(texture.Width, texture.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The object scale gets set to the same aspect ratio as the texture and then it will set the width..
|
||||
/// </summary>
|
||||
/// <param name="texture"></param>
|
||||
/// <param name="width"></param>
|
||||
public void ApplyTextureSize(Texture texture, float width)
|
||||
{
|
||||
Size.Set(width, width / texture.Aspect);
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
using OpenTK;
|
||||
using SM.Base.Window;
|
||||
|
||||
namespace SM2D
|
||||
{
|
||||
public interface I2DSetup : ISetup
|
||||
{
|
||||
Vector2? WorldScale { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -7,10 +7,12 @@ using SM2D.Shader;
|
|||
|
||||
namespace SM2D
|
||||
{
|
||||
public struct Window2DSetup : I2DSetup
|
||||
/// <summary>
|
||||
/// Sets up a 2D window.
|
||||
/// </summary>
|
||||
public struct Window2DSetup : ISetup
|
||||
{
|
||||
public Vector2? WorldScale { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Applied(IGenericWindow window)
|
||||
{
|
||||
window.ViewportCamera = new Camera();
|
||||
|
|
@ -18,16 +20,18 @@ namespace SM2D
|
|||
SMRenderer.DefaultMaterialShader = ShaderCollection.Instanced;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Load(IGenericWindow window)
|
||||
{
|
||||
(window.ViewportCamera as Camera).RequestedWorldScale = WorldScale;
|
||||
GL.Enable(EnableCap.DepthTest);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Loaded(IGenericWindow window)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Resize(IGenericWindow window)
|
||||
{
|
||||
Camera.ResizeCounter++;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue