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

@ -13,10 +13,20 @@ namespace SM2D.Controls
internal new void MouseMoveEvent(MouseMoveEventArgs mmea) => base.MouseMoveEvent(mmea);
public Vector2 InWorld(Camera cam)
public Vector2 InWorld()
{
Vector2 res = _window.WorldScale;
return InScreenNormalized * res - res / 2;
}
public Vector2 InWorld(Camera cam)
{
return InWorld() + cam.Position;
}
public Vector2 InWorld(Vector2 position)
{
return InWorld() + position;
}
}
}

View file

@ -1,4 +1,5 @@
using System.Drawing;
using System.Collections.Generic;
using System.Drawing;
using OpenTK;
using OpenTK.Graphics;
using SM.Base;
@ -43,10 +44,12 @@ namespace SM2D.Drawing
Texture = (Texture) texture;
}
public object Parent { get; set; }
public string Name { get; set; } = "Background";
public ICollection<string> Flags { get; set; } = new string[0];
public void Update(UpdateContext context)
{
throw new System.NotImplementedException();
}
{ }
public void Draw(DrawContext context)
{
@ -56,5 +59,13 @@ namespace SM2D.Drawing
context.Instances[0].ModelMatrix = Matrix4.CreateScale(context.WorldScale.X, context.WorldScale.Y, 1);
context.Shader.Draw(context);
}
public void OnAdded(object sender)
{
}
public void OnRemoved(object sender)
{
}
}
}

View file

@ -0,0 +1,7 @@
namespace SM2D.Pipelines
{
public class Adv2DPipeline
{
}
}

View file

@ -17,7 +17,7 @@ namespace SM2D.Pipelines
Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
scene.Draw(context);
scene?.Draw(context);
}
}
}

View file

@ -55,6 +55,7 @@
<Compile Include="GLWindow2D.cs" />
<Compile Include="Object\Polygon.cs" />
<Compile Include="Object\PolygonVertex.cs" />
<Compile Include="Pipelines\Adv2DPipeline.cs" />
<Compile Include="Pipelines\Basic2DPipeline.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Scene\Camera.cs" />

View file

@ -7,11 +7,11 @@ namespace SM2D.Scene
{
public class Scene : GenericScene<Camera, ItemCollection, I2DShowItem>
{
public DrawBackground Background => (DrawBackground)_background;
public DrawBackground Background => (DrawBackground)_Background;
public Scene()
{
_background = new DrawBackground(Color4.Black);
_Background = new DrawBackground(Color4.Black);
}
}
}

View file

@ -25,7 +25,7 @@ namespace SM2D.Shader
GL.BindVertexArray(context.Mesh);
// Vertex Uniforms
Uniforms["MVP"].SetMatrix4(context.View * context.World);
Uniforms["MVP"].SetMatrix4(context.ModelMaster * context.View * context.World);
Uniforms["HasVColor"].SetUniform1(context.Mesh.AttribDataIndex.ContainsKey(3) && context.Mesh.AttribDataIndex[3] != null);
for (int i = 0; i < context.Instances.Length; i++)

View file

@ -1,20 +1,54 @@
using OpenTK;
using System;
using System.Configuration.Assemblies;
using OpenTK;
using SM.Base.Scene;
using SM.Base.Types;
using SM.Utility;
namespace SM2D.Types
{
public class Transformation : GenericTransformation
{
public CVector2 Position = new CVector2(0);
public CVector2 Size = new CVector2(50);
public float Rotation;
private float _eulerRotation = 0;
private CVector2 _position = new CVector2(0);
private CVector2 _scale = new CVector2(50);
public override Matrix4 GetMatrix()
public CVector2 Position
{
return Matrix4.CreateScale(Size.X, Size.Y, 1) *
Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(Rotation)) *
Matrix4.CreateTranslation(Position.X, Position.Y, 0);
get => _position;
set => _position = value;
}
public CVector2 Size
{
get => _scale;
set => _scale = value;
}
public float Rotation
{
get => _eulerRotation;
set => _eulerRotation = value;
}
protected override Matrix4 RequestMatrix()
{
return Matrix4.CreateScale(_scale.X, _scale.Y, 1) *
Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(_eulerRotation)) *
Matrix4.CreateTranslation(_position.X, _position.Y, 0);
}
public void TurnTo(Vector2 v)
{
_eulerRotation = RotationUtility.TurnTowards(Position, v);
}
public Vector2 LookAtVector()
{
if (_modelMatrix.Determinant < 0.0001) return new Vector2(0);
Vector3 vec = Vector3.TransformNormal(Vector3.UnitX, _modelMatrix);
vec.Normalize();
return vec.Xy;
}
}
}