07.10.2020
+ Parent, Name and Flags to objects. ~ Improved Matrix calculations
This commit is contained in:
parent
f865496414
commit
2c00dbd31a
21 changed files with 383 additions and 42 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using SM.Base.Contexts;
|
||||
using System.Collections.Generic;
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base.Objects.Static;
|
||||
using SM.OGL.Mesh;
|
||||
|
||||
|
|
@ -16,7 +17,16 @@ namespace SM.Base.Scene
|
|||
/// <summary>
|
||||
/// The mesh it should use.
|
||||
/// </summary>
|
||||
protected GenericMesh _mesh = Defaults.DefaultMesh;
|
||||
protected GenericMesh _mesh = SMRenderer.DefaultMesh;
|
||||
|
||||
/// <inheritdoc />
|
||||
public object Parent { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Name { get; set; } = "Unnamed draw object";
|
||||
|
||||
/// <inheritdoc />
|
||||
public ICollection<string> Flags { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Update(UpdateContext context)
|
||||
|
|
@ -33,6 +43,18 @@ namespace SM.Base.Scene
|
|||
DrawContext(ref context);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void OnAdded(object sender)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void OnRemoved(object sender)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws the context, that was given to them.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -7,10 +7,34 @@ namespace SM.Base.Scene
|
|||
/// </summary>
|
||||
public abstract class GenericTransformation
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains the current model matrix.
|
||||
/// </summary>
|
||||
protected Matrix4 _modelMatrix { get; private set; }
|
||||
/// <summary>
|
||||
/// Contains the last frame the matrix was calculated.
|
||||
/// </summary>
|
||||
protected ulong _lastFrame { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current model matrix.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Matrix4 GetMatrix()
|
||||
{
|
||||
if (_lastFrame != SMRenderer.CurrentFrame)
|
||||
{
|
||||
_lastFrame = SMRenderer.CurrentFrame;
|
||||
_modelMatrix = RequestMatrix();
|
||||
}
|
||||
|
||||
return _modelMatrix;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the current matrix.
|
||||
/// </summary>
|
||||
/// <returns>The current matrix.</returns>
|
||||
public abstract Matrix4 GetMatrix();
|
||||
protected abstract Matrix4 RequestMatrix();
|
||||
}
|
||||
}
|
||||
16
SMCode/SM.Base/PostProcessing/PostProcessingEffect.cs
Normal file
16
SMCode/SM.Base/PostProcessing/PostProcessingEffect.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using System.Collections.Generic;
|
||||
using SM.OGL.Framebuffer;
|
||||
|
||||
namespace SM.Base.PostProcessing
|
||||
{
|
||||
public abstract class PostProcessingEffect
|
||||
{
|
||||
public virtual Dictionary<string, int> AdditionalFramebufferOutputs { get; }
|
||||
public virtual ICollection<Framebuffer> AdditionalFramebuffers { get; }
|
||||
|
||||
public void ApplyOutputs(Framebuffer mainbuffer)
|
||||
{
|
||||
mainbuffer.Append();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -52,18 +52,19 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Controls\Mouse.cs" />
|
||||
<Compile Include="Defaults.cs" />
|
||||
<Compile Include="Drawing\DrawingBasis.cs" />
|
||||
<Compile Include="Drawing\GenericTransformation.cs" />
|
||||
<Compile Include="Drawing\Instance.cs" />
|
||||
<Compile Include="Drawing\IShader.cs" />
|
||||
<Compile Include="Log.cs" />
|
||||
<Compile Include="Objects\Mesh.cs" />
|
||||
<Compile Include="PostProcessing\PostProcessingEffect.cs" />
|
||||
<Compile Include="Scene\IShowCollection.cs" />
|
||||
<Compile Include="Scene\IShowItem.cs" />
|
||||
<Compile Include="Drawing\Material.cs" />
|
||||
<Compile Include="Scene\IBackgroundItem.cs" />
|
||||
<Compile Include="Scene\GenericItemCollection.cs" />
|
||||
<Compile Include="SMRenderer.cs" />
|
||||
<Compile Include="Textures\Texture.cs" />
|
||||
<Compile Include="Text\CharParameter.cs" />
|
||||
<Compile Include="Text\Font.cs" />
|
||||
|
|
@ -79,6 +80,7 @@
|
|||
<Compile Include="Utility\Assembly.cs" />
|
||||
<Compile Include="Utility\Deltatime.cs" />
|
||||
<Compile Include="Utility\Randomize.cs" />
|
||||
<Compile Include="Utility\RotationUtility.cs" />
|
||||
<Compile Include="Window\Contexts\DrawContext.cs" />
|
||||
<Compile Include="Window\Contexts\UpdateContext.cs" />
|
||||
<Compile Include="Window\GenericWindow.cs" />
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
using SM.Base.Objects;
|
||||
using SM.Base.Objects.Static;
|
||||
using SM.Base.Scene;
|
||||
using SM.Base.Objects.Static;
|
||||
using SM.Base.Text;
|
||||
using SM.OGL.Mesh;
|
||||
using SM.Utility;
|
||||
|
|
@ -8,9 +6,9 @@ using SM.Utility;
|
|||
namespace SM.Base
|
||||
{
|
||||
/// <summary>
|
||||
/// The default options.
|
||||
/// Contains different information about this renderer.
|
||||
/// </summary>
|
||||
public class Defaults
|
||||
public class SMRenderer
|
||||
{
|
||||
/// <summary>
|
||||
/// The default mesh.
|
||||
|
|
@ -26,5 +24,10 @@ namespace SM.Base
|
|||
/// The default deltatime helper.
|
||||
/// </summary>
|
||||
public static Deltatime DefaultDeltatime = new Deltatime();
|
||||
|
||||
/// <summary>
|
||||
/// Current Frame
|
||||
/// </summary>
|
||||
public static ulong CurrentFrame { get; internal set; } = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -14,7 +14,37 @@ namespace SM.Base.Scene
|
|||
public List<TItem> Objects => this;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Update(UpdateContext context)
|
||||
public object Parent { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Name { get; set; } = "Unnamed Item Collection";
|
||||
|
||||
/// <inheritdoc />
|
||||
public ICollection<string> Flags { get; set; } = new[] {"collection"};
|
||||
|
||||
/// <summary>
|
||||
/// Adds a item.
|
||||
/// </summary>
|
||||
public new void Add(TItem item)
|
||||
{
|
||||
base.Add(item);
|
||||
item.Parent = this;
|
||||
item.OnAdded(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a item.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
public new void Remove(TItem item)
|
||||
{
|
||||
base.Remove(item);
|
||||
item.Parent = null;
|
||||
item.OnRemoved(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Update(UpdateContext context)
|
||||
{
|
||||
for(int i = 0; i < Objects.Count; i++)
|
||||
this[i].Update(context);
|
||||
|
|
@ -26,6 +56,64 @@ namespace SM.Base.Scene
|
|||
for (int i = 0; i < Objects.Count; i++)
|
||||
this[i].Draw(context);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void OnAdded(object sender)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void OnRemoved(object sender)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Returns a object with this name or the default, if not available.
|
||||
/// <para>Not reclusive.</para>
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public TItem GetItemByName(string name)
|
||||
{
|
||||
TItem obj = default;
|
||||
for (var i = 0; i < this.Count; i++)
|
||||
{
|
||||
if (this[i].Name == name)
|
||||
{
|
||||
obj = this[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a object with this name or the default if not available.
|
||||
/// <para>Not reclusive.</para>
|
||||
/// </summary>
|
||||
/// <typeparam name="TGetItem">Type of return</typeparam>
|
||||
public TGetItem GetItemByName<TGetItem>(string name)
|
||||
where TGetItem : TItem
|
||||
{
|
||||
return (TGetItem)GetItemByName(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all object that have this flag.
|
||||
/// <para>Only in this list.</para>
|
||||
/// </summary>
|
||||
public ICollection<TItem> GetItemsWithFlag(string flag)
|
||||
{
|
||||
List<TItem> list = new List<TItem>();
|
||||
for (var i = 0; i < this.Count; i++)
|
||||
{
|
||||
TItem obj = this[i];
|
||||
if (obj.Flags.Contains(flag)) list.Add(obj);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -45,7 +133,7 @@ namespace SM.Base.Scene
|
|||
/// <inheritdoc />
|
||||
public override void Draw(DrawContext context)
|
||||
{
|
||||
context.View = Transform.GetMatrix() * context.View;
|
||||
context.ModelMaster = Transform.GetMatrix() * context.ModelMaster;
|
||||
|
||||
base.Draw(context);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using SM.Base.Contexts;
|
||||
using System.Collections.Generic;
|
||||
using SM.Base.Contexts;
|
||||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
|
|
@ -7,6 +8,21 @@ namespace SM.Base.Scene
|
|||
/// </summary>
|
||||
public interface IShowItem
|
||||
{
|
||||
/// <summary>
|
||||
/// Parent of the object.
|
||||
/// </summary>
|
||||
object Parent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Contains the name for the object.
|
||||
/// </summary>
|
||||
string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Contains specific flags for the object.
|
||||
/// </summary>
|
||||
ICollection<string> Flags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Tells the object to update own systems.
|
||||
/// </summary>
|
||||
|
|
@ -17,5 +33,14 @@ namespace SM.Base.Scene
|
|||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
void Draw(DrawContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Action, that is called, when the object was added to a GenericItemCollection.
|
||||
/// </summary>
|
||||
void OnAdded(object sender);
|
||||
/// <summary>
|
||||
/// Action, that is called, when the object was removed from a GenericItemCollection.
|
||||
/// </summary>
|
||||
void OnRemoved(object sender);
|
||||
}
|
||||
}
|
||||
20
SMCode/SM.Base/Utility/RotationUtility.cs
Normal file
20
SMCode/SM.Base/Utility/RotationUtility.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using OpenTK;
|
||||
|
||||
namespace SM.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Utilitys for rotations
|
||||
/// </summary>
|
||||
public class RotationUtility
|
||||
{
|
||||
/// <summary>
|
||||
/// Angle towards an coordinate.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static float TurnTowards(Vector2 origin, Vector2 target)
|
||||
{
|
||||
return MathHelper.RadiansToDegrees((float)Math.Atan2(target.Y - origin.Y, target.X - origin.X));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -24,6 +24,10 @@ namespace SM.Base.Contexts
|
|||
/// </summary>
|
||||
public Matrix4 View;
|
||||
/// <summary>
|
||||
/// The master model matrix.
|
||||
/// </summary>
|
||||
public Matrix4 ModelMaster;
|
||||
/// <summary>
|
||||
/// The drawing instances.
|
||||
/// <para>If there is only one, it's index 0</para>
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace SM.Base.Contexts
|
|||
/// <summary>
|
||||
/// The delta time.
|
||||
/// </summary>
|
||||
public float Deltatime => Defaults.DefaultDeltatime.DeltaTime;
|
||||
public float Deltatime => SMRenderer.DefaultDeltatime.DeltaTime;
|
||||
|
||||
/// <summary>
|
||||
/// The current keyboard state.
|
||||
|
|
|
|||
|
|
@ -95,6 +95,16 @@ namespace SM.Base
|
|||
MouseState = Mouse.GetState()
|
||||
};
|
||||
|
||||
Update(e, ref context);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the system.
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
/// <param name="context"></param>
|
||||
protected virtual void Update(FrameEventArgs e, ref UpdateContext context)
|
||||
{
|
||||
Stopwatch.PerformTicks(context);
|
||||
}
|
||||
|
||||
|
|
@ -152,14 +162,24 @@ namespace SM.Base
|
|||
ViewportCamera = new TCamera();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(FrameEventArgs e, ref UpdateContext context)
|
||||
{
|
||||
base.Update(e, ref context);
|
||||
CurrentScene?.Update(context);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnRenderFrame(FrameEventArgs e)
|
||||
{
|
||||
SMRenderer.CurrentFrame++;
|
||||
|
||||
Deltatime.RenderDelta = (float)e.Time;
|
||||
DrawContext drawContext = new DrawContext()
|
||||
{
|
||||
World = ViewportCamera.World,
|
||||
View = ViewportCamera.CalculateViewMatrix(),
|
||||
ModelMaster = Matrix4.Identity,
|
||||
Instances = new[] { new Instance {ModelMatrix = Matrix4.Identity, TexturePosition = Vector2.Zero, TextureScale = Vector2.One } },
|
||||
Mesh = Plate.Object,
|
||||
ForceViewport = ForceViewportCamera,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
7
SMCode/SM2D/Pipelines/Adv2DPipeline.cs
Normal file
7
SMCode/SM2D/Pipelines/Adv2DPipeline.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
namespace SM2D.Pipelines
|
||||
{
|
||||
public class Adv2DPipeline
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ namespace SM2D.Pipelines
|
|||
|
||||
Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
|
||||
scene.Draw(context);
|
||||
scene?.Draw(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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" />
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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++)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Authentication.ExtendedProtection.Configuration;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using SM.Base;
|
||||
|
|
@ -41,7 +42,11 @@ namespace SM_TEST
|
|||
|
||||
private static void WindowOnUpdateFrame(object sender, FrameEventArgs e)
|
||||
{
|
||||
polyogn.Transform.Position.Set(window.Mouse.InWorld(window.ViewportCamera));
|
||||
Vector2 mousepos = window.Mouse.InWorld();
|
||||
//polyogn.Transform.Position.Set(mousepos);
|
||||
polyogn.Transform.TurnTo(mousepos);
|
||||
|
||||
Log.Write(LogType.Info, polyogn.Transform.LookAtVector());
|
||||
}
|
||||
|
||||
private static void WindowOnLoad(object sender, EventArgs e)
|
||||
|
|
@ -52,7 +57,7 @@ namespace SM_TEST
|
|||
|
||||
col = new ItemCollection()
|
||||
{
|
||||
Transform = { Position = new SM.Base.Types.CVector2(0, -400) },
|
||||
Transform = { Position = new SM.Base.Types.CVector2(0, 400) },
|
||||
ZIndex = 1
|
||||
};
|
||||
|
||||
|
|
@ -69,12 +74,12 @@ namespace SM_TEST
|
|||
scene.Objects.Add(col);
|
||||
scene.Objects.Add(new DrawText(font, "Testing...")
|
||||
{
|
||||
Transform = { Position = new SM.Base.Types.CVector2(0, -400)},
|
||||
Transform = { Position = new SM.Base.Types.CVector2(0, 400)},
|
||||
Color = Color4.Black
|
||||
});
|
||||
|
||||
scene.Objects.Add(polyogn = new DrawPolygon(Polygon.GenerateCircle(),Color4.Blue));
|
||||
scene.Objects.Add(new DrawPolygon(new Polygon(new[]
|
||||
scene.Objects.Add(new DrawPolygon(Polygon.GenerateCircle(),Color4.Blue));
|
||||
scene.Objects.Add(polyogn = new DrawPolygon(new Polygon(new[]
|
||||
{
|
||||
new PolygonVertex(new Vector2(.25f, 0), Color4.White),
|
||||
new PolygonVertex(new Vector2(.75f, 0), Color4.White),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue