30.09.2020
+ Mouse support + Started to add summaries to SM.Base
This commit is contained in:
parent
16366fa015
commit
7acdba92f8
21 changed files with 325 additions and 58 deletions
22
SMCode/SM2D/Controls/Mouse2D.cs
Normal file
22
SMCode/SM2D/Controls/Mouse2D.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using OpenTK;
|
||||
using OpenTK.Input;
|
||||
using SM.Base;
|
||||
using SM.Base.Controls;
|
||||
using SM2D.Scene;
|
||||
|
||||
namespace SM2D.Controls
|
||||
{
|
||||
public class Mouse2D : Mouse<GLWindow2D>
|
||||
{
|
||||
protected internal Mouse2D(GLWindow2D window) : base(window)
|
||||
{ }
|
||||
|
||||
internal new void MouseMoveEvent(MouseMoveEventArgs mmea) => base.MouseMoveEvent(mmea);
|
||||
|
||||
public Vector2 InWorld(Camera cam)
|
||||
{
|
||||
Vector2 res = _window.WorldScale;
|
||||
return InScreenNormalized * res - res / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using OpenTK.Graphics;
|
||||
using SM.Base;
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base.Scene;
|
||||
using SM2D.Scene;
|
||||
|
|
|
|||
|
|
@ -1,15 +1,27 @@
|
|||
using System;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using OpenTK.Input;
|
||||
using SM.Base;
|
||||
using SM.Base.Controls;
|
||||
using SM2D.Controls;
|
||||
using SM2D.Scene;
|
||||
using SM2D.Shader;
|
||||
using Vector2 = OpenTK.Vector2;
|
||||
|
||||
namespace SM2D
|
||||
{
|
||||
public class GLWindow2D : GenericWindow<Scene.Scene, I2DShowItem, Camera>
|
||||
{
|
||||
public Vector2? Scaling { get; set; }
|
||||
public Vector2 WorldScale => _worldScale;
|
||||
|
||||
public Mouse2D Mouse { get; }
|
||||
|
||||
public GLWindow2D()
|
||||
{
|
||||
Mouse = new Mouse2D(this);
|
||||
}
|
||||
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
|
|
@ -25,5 +37,21 @@ namespace SM2D
|
|||
GL.Disable(EnableCap.DepthTest);
|
||||
base.OnRenderFrame(e);
|
||||
}
|
||||
|
||||
protected override void SetWorldScale()
|
||||
{
|
||||
if (Scaling.HasValue)
|
||||
{
|
||||
if (Scaling.Value.X > 0 && Scaling.Value.Y > 0) _worldScale = Scaling.Value;
|
||||
else if (Scaling.Value.X > 0) _worldScale = new Vector2(Scaling.Value.X, Scaling.Value.X / Aspect);
|
||||
else if (Scaling.Value.Y > 0) _worldScale = new Vector2(Aspect * Scaling.Value.Y, Scaling.Value.Y);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseMoveEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
Mouse.MouseMoveEvent(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -58,5 +58,19 @@ namespace SM2D.Object
|
|||
Vector2 uv = Vector2.Divide(vertex, BoundingBox.Max.Xy) + BoundingBox.Min.Xy;
|
||||
UVs.Add(uv);
|
||||
}
|
||||
|
||||
public static Polygon GenerateCircle(int secments = 32)
|
||||
{
|
||||
List<Vector2> vertices = new List<Vector2>() {Vector2.Zero};
|
||||
|
||||
float step = 360f / secments;
|
||||
for (int i = 0; i < secments + 1; i++)
|
||||
{
|
||||
Vector2 vertex = new Vector2( 0.5f * (float)Math.Cos(step * i * Math.PI / 180f), 0.5f * (float)Math.Sin(step * i * Math.PI / 180f));
|
||||
vertices.Add(vertex);
|
||||
}
|
||||
|
||||
return new Polygon(vertices);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -45,6 +45,7 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Controls\Mouse2D.cs" />
|
||||
<Compile Include="Drawing\DrawBackground.cs" />
|
||||
<Compile Include="Drawing\DrawColor.cs" />
|
||||
<Compile Include="Drawing\DrawComplex.cs" />
|
||||
|
|
|
|||
|
|
@ -9,13 +9,12 @@ namespace SM2D.Types
|
|||
public Vector2 Position = new Vector2(0);
|
||||
public Vector2 Size = new Vector2(50);
|
||||
public float Rotation;
|
||||
public int ZIndex = 0;
|
||||
|
||||
public override Matrix4 GetMatrix()
|
||||
{
|
||||
return Matrix4.CreateScale(Size.X, Size.Y, 1) *
|
||||
Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(Rotation)) *
|
||||
Matrix4.CreateTranslation(Position.X, Position.Y, ZIndex);
|
||||
Matrix4.CreateTranslation(Position.X, Position.Y, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue