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
|
|
@ -25,11 +25,19 @@ namespace SM.Base.Controls
|
|||
/// </summary>
|
||||
public Vector2 InScreenNormalized { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The constructor
|
||||
/// </summary>
|
||||
/// <param name="window">The window, its listen to.</param>
|
||||
protected internal Mouse(TWindow window)
|
||||
{
|
||||
_window = window;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The event to update the values.
|
||||
/// </summary>
|
||||
/// <param name="mmea">The event args.</param>
|
||||
protected void MouseMoveEvent(MouseMoveEventArgs mmea)
|
||||
{
|
||||
InScreen = new Vector2(mmea.X, mmea.Y);
|
||||
|
|
|
|||
|
|
@ -2,12 +2,27 @@
|
|||
using SM.Base.Objects.Static;
|
||||
using SM.Base.Scene;
|
||||
using SM.OGL.Mesh;
|
||||
using SM.Utility;
|
||||
|
||||
namespace SM.Base
|
||||
{
|
||||
/// <summary>
|
||||
/// The default options.
|
||||
/// </summary>
|
||||
public class Defaults
|
||||
{
|
||||
/// <summary>
|
||||
/// The default shader.
|
||||
/// </summary>
|
||||
public static IShader DefaultShader;
|
||||
/// <summary>
|
||||
/// The default mesh.
|
||||
/// </summary>
|
||||
public static GenericMesh DefaultMesh = Plate.Object;
|
||||
|
||||
/// <summary>
|
||||
/// The default deltatime helper.
|
||||
/// </summary>
|
||||
public static Deltatime DefaultDeltatime = new Deltatime();
|
||||
}
|
||||
}
|
||||
|
|
@ -17,11 +17,14 @@ namespace SM.Base.Scene
|
|||
/// The mesh it should use.
|
||||
/// </summary>
|
||||
protected GenericMesh _mesh = Defaults.DefaultMesh;
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Update(UpdateContext context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Draw(DrawContext context)
|
||||
{
|
||||
}
|
||||
|
|
@ -45,6 +48,9 @@ namespace SM.Base.Scene
|
|||
public abstract class DrawingBasis<TTransformation> : DrawingBasis
|
||||
where TTransformation : GenericTransformation, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// The current transformation.
|
||||
/// </summary>
|
||||
public TTransformation Transform = new TTransformation();
|
||||
}
|
||||
}
|
||||
|
|
@ -2,10 +2,17 @@
|
|||
|
||||
namespace SM.Base.Objects
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public class Mesh : GenericMesh
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains vertex colors
|
||||
/// </summary>
|
||||
public virtual VBO Color { get; }
|
||||
|
||||
/// <summary>
|
||||
/// While initializing, it will add the <see cref="Color"/> to the data index.
|
||||
/// </summary>
|
||||
protected Mesh()
|
||||
{
|
||||
AttribDataIndex.Add(3, Color);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ namespace SM.Base.Objects.Static
|
|||
/// </summary>
|
||||
public static Plate Object = new Plate();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override VBO Vertex { get; } = new VBO()
|
||||
{
|
||||
{-.5f, -.5f, 0},
|
||||
|
|
@ -23,6 +24,7 @@ namespace SM.Base.Objects.Static
|
|||
{.5f, -.5f, 0},
|
||||
};
|
||||
|
||||
/// <inheritdoc />
|
||||
public override VBO UVs { get; } = new VBO(pointerSize: 2)
|
||||
{
|
||||
{0, 0},
|
||||
|
|
@ -31,8 +33,10 @@ namespace SM.Base.Objects.Static
|
|||
{1, 0},
|
||||
};
|
||||
|
||||
/// <inheritdoc />
|
||||
public override PrimitiveType PrimitiveType { get; } = PrimitiveType.Quads;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override BoundingBox BoundingBox { get; } = new BoundingBox(new Vector3(-.5f, -.5f, 0), new Vector3(.5f, .5f, 0));
|
||||
|
||||
//public override int[] Indices { get; set; } = new[] {0, 1, 2, 3};
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<DocumentationFile>bin\Debug\SM.Base.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
|
|
@ -64,12 +65,14 @@
|
|||
<Compile Include="Text\Font.cs" />
|
||||
<Compile Include="Text\FontCharStorage.cs" />
|
||||
<Compile Include="Text\TextDrawingBasis.cs" />
|
||||
<Compile Include="Types\Vector.cs" />
|
||||
<Compile Include="Types\Vector2.cs" />
|
||||
<Compile Include="Types\Vector3.cs" />
|
||||
<Compile Include="Types\Vector4.cs" />
|
||||
<Compile Include="Time\Interval.cs" />
|
||||
<Compile Include="Time\Stopwatch.cs" />
|
||||
<Compile Include="Time\Timer.cs" />
|
||||
<Compile Include="Types\CVector.cs" />
|
||||
<Compile Include="Types\CVector2.cs" />
|
||||
<Compile Include="Types\CVector3.cs" />
|
||||
<Compile Include="Types\CVector4.cs" />
|
||||
<Compile Include="Utility\Assembly.cs" />
|
||||
<Compile Include="Utility\BezierCurve.cs" />
|
||||
<Compile Include="Utility\Deltatime.cs" />
|
||||
<Compile Include="Utility\Randomize.cs" />
|
||||
<Compile Include="Window\Contexts\DrawContext.cs" />
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +1,29 @@
|
|||
using System;
|
||||
using System.Configuration.Assemblies;
|
||||
using OpenTK;
|
||||
|
||||
namespace SM.Data.Fonts
|
||||
namespace SM.Base.Text
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains information for a font character.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class CharParameter
|
||||
public struct CharParameter
|
||||
{
|
||||
/// <summary>
|
||||
/// The position on the X-axis.
|
||||
/// </summary>
|
||||
public int X;
|
||||
/// <summary>
|
||||
/// The width of the character.
|
||||
/// </summary>
|
||||
public float Width;
|
||||
|
||||
public float RelativeX;
|
||||
public float RelativeWidth;
|
||||
/// <summary>
|
||||
/// The normalized position inside the texture.
|
||||
/// </summary>
|
||||
public float NormalizedX;
|
||||
/// <summary>
|
||||
/// The normalized width inside the texture.
|
||||
/// </summary>
|
||||
public float NormalizedWidth;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,28 +5,50 @@ using System.Security.Policy;
|
|||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using OpenTK.Input;
|
||||
using SM.Base.Textures;
|
||||
using SM.Data.Fonts;
|
||||
using SM.OGL.Texture;
|
||||
|
||||
namespace SM.Base.Text
|
||||
{
|
||||
public class Font : TextureBase
|
||||
/// <summary>
|
||||
/// Represents a font.
|
||||
/// </summary>
|
||||
public class Font : Texture
|
||||
{
|
||||
public Dictionary<char, CharParameter> Positions = new Dictionary<char, CharParameter>();
|
||||
|
||||
public override TextureMinFilter Filter { get; set; } = TextureMinFilter.Linear;
|
||||
/// <inheritdoc />
|
||||
public override TextureWrapMode WrapMode { get; set; } = TextureWrapMode.ClampToEdge;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The font family, that is used to find the right font.
|
||||
/// </summary>
|
||||
public FontFamily FontFamily;
|
||||
|
||||
/// <summary>
|
||||
/// The font style.
|
||||
/// <para>Default: <see cref="System.Drawing.FontStyle.Regular"/></para>
|
||||
/// </summary>
|
||||
public FontStyle FontStyle = FontStyle.Regular;
|
||||
/// <summary>
|
||||
/// The font size.
|
||||
/// <para>Default: 12</para>
|
||||
/// </summary>
|
||||
public float FontSize = 12;
|
||||
/// <summary>
|
||||
/// The char set for the font.
|
||||
/// <para>Default: <see cref="FontCharStorage.SimpleUTF8"/></para>
|
||||
/// </summary>
|
||||
public ICollection<char> CharSet = FontCharStorage.SimpleUTF8;
|
||||
|
||||
public int Width { get; private set; }
|
||||
public int Height { get; private set; }
|
||||
public Bitmap Texture { get; private set; }
|
||||
/// <summary>
|
||||
/// This contains all information for the different font character.
|
||||
/// </summary>
|
||||
public Dictionary<char, CharParameter> Positions = new Dictionary<char, CharParameter>();
|
||||
|
||||
/// <summary>
|
||||
/// Generates a font from a font family from the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The specified path</param>
|
||||
public Font(string path)
|
||||
{
|
||||
PrivateFontCollection pfc = new PrivateFontCollection();
|
||||
|
|
@ -34,16 +56,26 @@ namespace SM.Base.Text
|
|||
FontFamily = pfc.Families[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a font from a specified font family.
|
||||
/// </summary>
|
||||
/// <param name="font">Font-Family</param>
|
||||
public Font(FontFamily font)
|
||||
{
|
||||
FontFamily = font;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Regenerates the texture.
|
||||
/// </summary>
|
||||
public void RegenerateTexture()
|
||||
{
|
||||
Bitmap map = new Bitmap(1000,20);
|
||||
Width = 0;
|
||||
Height = 0;
|
||||
Positions = new Dictionary<char, CharParameter>();
|
||||
|
||||
|
||||
Bitmap map = new Bitmap(1000, 20);
|
||||
Dictionary<char, float[]> charParams = new Dictionary<char, float[]>();
|
||||
using (System.Drawing.Font f = new System.Drawing.Font(FontFamily, FontSize, FontStyle))
|
||||
{
|
||||
using (Graphics g = Graphics.FromImage(map))
|
||||
|
|
@ -56,7 +88,7 @@ namespace SM.Base.Text
|
|||
SizeF size = g.MeasureString(s, f);
|
||||
try
|
||||
{
|
||||
Positions.Add(c, new CharParameter() { Width = size.Width, X = Width });
|
||||
charParams.Add(c, new[] {size.Width, Width });
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -71,25 +103,34 @@ namespace SM.Base.Text
|
|||
map = new Bitmap(Width, Height);
|
||||
using (Graphics g = Graphics.FromImage(map))
|
||||
{
|
||||
foreach (KeyValuePair<char, CharParameter> keyValuePair in Positions)
|
||||
foreach (KeyValuePair<char, float[]> keyValuePair in charParams)
|
||||
{
|
||||
keyValuePair.Value.RelativeX = (keyValuePair.Value.X + 0.00001f) / Width;
|
||||
keyValuePair.Value.RelativeWidth = (keyValuePair.Value.Width) / Width;
|
||||
float normalizedX = (keyValuePair.Value[1] + 0.00001f) / Width;
|
||||
float normalizedWidth = (keyValuePair.Value[0]) / Width;
|
||||
|
||||
g.DrawString(keyValuePair.Key.ToString(), f, Brushes.White, keyValuePair.Value.X, 0);
|
||||
CharParameter parameter;
|
||||
Positions.Add(keyValuePair.Key, parameter = new CharParameter()
|
||||
{
|
||||
NormalizedWidth = normalizedWidth,
|
||||
NormalizedX = normalizedX,
|
||||
Width = keyValuePair.Value[0],
|
||||
X = (int)keyValuePair.Value[1]
|
||||
});
|
||||
|
||||
g.DrawString(keyValuePair.Key.ToString(), f, Brushes.White, parameter.X, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Texture = map;
|
||||
|
||||
_id = SM.Base.Textures.Texture.GenerateTexture(map, Filter, WrapMode);
|
||||
Map = map;
|
||||
Recompile();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Compile()
|
||||
{
|
||||
base.Compile();
|
||||
RegenerateTexture();
|
||||
base.Compile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,13 @@
|
|||
namespace SM.Data.Fonts
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains default char sets.
|
||||
/// </summary>
|
||||
public class FontCharStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains the english alphabet and the common special character.
|
||||
/// </summary>
|
||||
public static readonly char[] SimpleUTF8 = new char[]
|
||||
{
|
||||
'!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6',
|
||||
|
|
@ -10,5 +16,13 @@
|
|||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
|
||||
'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~'
|
||||
};
|
||||
/// <summary>
|
||||
/// Contains only numbers.
|
||||
/// </summary>
|
||||
public static readonly char[] Numbers = new[]
|
||||
{
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -7,12 +7,25 @@ using SM.Data.Fonts;
|
|||
|
||||
namespace SM.Base.Text
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a basis for text drawing.
|
||||
/// </summary>
|
||||
/// <typeparam name="TTransform">Transformation type</typeparam>
|
||||
public abstract class TextDrawingBasis<TTransform> : DrawingBasis<TTransform>
|
||||
where TTransform : GenericTransformation, new()
|
||||
{
|
||||
protected Instance[] _modelMatrixs;
|
||||
/// <summary>
|
||||
/// The different instances for drawing.
|
||||
/// </summary>
|
||||
protected Instance[] _instances;
|
||||
/// <summary>
|
||||
/// The text, that is drawn.
|
||||
/// </summary>
|
||||
protected string _text;
|
||||
|
||||
/// <summary>
|
||||
/// The font.
|
||||
/// </summary>
|
||||
public Font Font
|
||||
{
|
||||
get => (Font) _material.Texture;
|
||||
|
|
@ -23,6 +36,9 @@ namespace SM.Base.Text
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The text, that is drawn.
|
||||
/// </summary>
|
||||
public string Text
|
||||
{
|
||||
get => _text;
|
||||
|
|
@ -33,30 +49,47 @@ namespace SM.Base.Text
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The font color.
|
||||
/// </summary>
|
||||
public Color4 Color
|
||||
{
|
||||
get => _material.Tint;
|
||||
set => _material.Tint = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The spacing between numbers.
|
||||
/// <para>Default: 1</para>
|
||||
/// </summary>
|
||||
public float Spacing = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a text object with a font.
|
||||
/// </summary>
|
||||
/// <param name="font">The font.</param>
|
||||
protected TextDrawingBasis(Font font)
|
||||
{
|
||||
_material.Texture = font;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Draw(DrawContext context)
|
||||
{
|
||||
base.Draw(context);
|
||||
if (_modelMatrixs == null) GenerateMatrixes();
|
||||
if (_instances == null) GenerateMatrixes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This generates the instances.
|
||||
/// </summary>
|
||||
/// <exception cref="Exception">The font doesn't contain a character that is needed for the text.</exception>
|
||||
public void GenerateMatrixes()
|
||||
{
|
||||
if (!Font.WasCompiled) Font.RegenerateTexture();
|
||||
|
||||
_modelMatrixs = new Instance[_text.Length];
|
||||
_instances = new Instance[_text.Length];
|
||||
|
||||
float x = 0;
|
||||
CharParameter _last = new CharParameter();
|
||||
|
|
@ -80,11 +113,11 @@ namespace SM.Base.Text
|
|||
|
||||
Matrix4 matrix = Matrix4.CreateScale(parameter.Width, Font.Height, 1) *
|
||||
Matrix4.CreateTranslation(x, 0, 0);
|
||||
_modelMatrixs[i] = new Instance
|
||||
_instances[i] = new Instance
|
||||
{
|
||||
ModelMatrix = matrix,
|
||||
TexturePosition = new Vector2(parameter.RelativeX, 0),
|
||||
TextureScale = new Vector2(parameter.RelativeWidth, 1)
|
||||
TexturePosition = new Vector2(parameter.NormalizedX, 0),
|
||||
TextureScale = new Vector2(parameter.NormalizedWidth, 1)
|
||||
};
|
||||
|
||||
x += parameter.Width * Spacing;
|
||||
|
|
|
|||
|
|
@ -6,13 +6,37 @@ using PixelFormat = System.Drawing.Imaging.PixelFormat;
|
|||
|
||||
namespace SM.Base.Textures
|
||||
{
|
||||
/// <summary>
|
||||
/// Texture that can be drawn to an object.
|
||||
/// </summary>
|
||||
public class Texture : TextureBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The texture as bitmap.
|
||||
/// </summary>
|
||||
public Bitmap Map;
|
||||
/// <summary>
|
||||
/// Decides if the bitmap will automatically dispose itself.
|
||||
/// </summary>
|
||||
public bool AutoDispose = false;
|
||||
|
||||
public Texture(Bitmap map) : this(map, TextureMinFilter.Linear, TextureWrapMode.Repeat) {}
|
||||
/// <summary>
|
||||
/// Empty constructor
|
||||
/// </summary>
|
||||
protected Texture() {}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a texture with only the map.
|
||||
/// <para>Sets the filter to Linear and WrapMode to Repeat.</para>
|
||||
/// </summary>
|
||||
/// <param name="map">The map</param>
|
||||
public Texture(Bitmap map) : this(map, TextureMinFilter.Linear, TextureWrapMode.Repeat) {}
|
||||
/// <summary>
|
||||
/// Creates the texture.
|
||||
/// </summary>
|
||||
/// <param name="map">The texture map</param>
|
||||
/// <param name="filter">The filter</param>
|
||||
/// <param name="wrapMode">The wrap mode</param>
|
||||
public Texture(Bitmap map, TextureMinFilter filter, TextureWrapMode wrapMode)
|
||||
{
|
||||
Map = map;
|
||||
|
|
@ -20,6 +44,8 @@ namespace SM.Base.Textures
|
|||
WrapMode = wrapMode;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Compile()
|
||||
{
|
||||
base.Compile();
|
||||
|
|
@ -27,6 +53,22 @@ namespace SM.Base.Textures
|
|||
_id = GenerateTexture(Map, Filter, WrapMode, AutoDispose);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Dispose()
|
||||
{
|
||||
base.Dispose();
|
||||
|
||||
GL.DeleteTexture(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a OpenGL-texture.
|
||||
/// </summary>
|
||||
/// <param name="map">The texture as bitmap</param>
|
||||
/// <param name="filter">The filter</param>
|
||||
/// <param name="wrapMode">The wrap mode</param>
|
||||
/// <param name="dispose">Auto dispose of the bitmap? Default: false</param>
|
||||
/// <returns></returns>
|
||||
public static int GenerateTexture(Bitmap map, TextureMinFilter filter, TextureWrapMode wrapMode, bool dispose = false)
|
||||
{
|
||||
int id = GL.GenTexture();
|
||||
|
|
@ -58,8 +100,9 @@ namespace SM.Base.Textures
|
|||
return id;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a bitmap to a texture.
|
||||
/// </summary>
|
||||
public static implicit operator Texture(Bitmap map) => new Texture(map);
|
||||
public override TextureMinFilter Filter { get; set; }
|
||||
public override TextureWrapMode WrapMode { get; set; }
|
||||
}
|
||||
}
|
||||
48
SMCode/SM.Base/Time/Interval.cs
Normal file
48
SMCode/SM.Base/Time/Interval.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using System;
|
||||
using SM.Base.Contexts;
|
||||
|
||||
namespace SM.Base.Time
|
||||
{
|
||||
/// <summary>
|
||||
/// Performs intervals.
|
||||
/// </summary>
|
||||
public class Interval : Timer
|
||||
{
|
||||
private bool _stop;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Interval(float seconds) : base(seconds)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Interval(TimeSpan timeSpan) : base(timeSpan)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Stopping(UpdateContext context)
|
||||
{
|
||||
TriggerEndAction(context);
|
||||
if (_stop){base.Stop();}
|
||||
else Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will tell the interval to stop after the next iteration.
|
||||
/// <para>To stop immediately use <see cref="Cancel"/></para>
|
||||
/// </summary>
|
||||
public override void Stop()
|
||||
{
|
||||
_stop = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will stop the interval immediately.
|
||||
/// </summary>
|
||||
public void Cancel()
|
||||
{
|
||||
base.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
59
SMCode/SM.Base/Time/Stopwatch.cs
Normal file
59
SMCode/SM.Base/Time/Stopwatch.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
using System.Collections.Generic;
|
||||
using SM.Base.Contexts;
|
||||
|
||||
namespace SM.Base.Time
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a stopwatch.
|
||||
/// </summary>
|
||||
public class Stopwatch
|
||||
{
|
||||
private static List<Stopwatch> _activeStopwatches = new List<Stopwatch>();
|
||||
|
||||
/// <summary>
|
||||
/// Contains how much time already has passed. (in seconds)
|
||||
/// </summary>
|
||||
public float Elapsed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Starts the stopwatch.
|
||||
/// </summary>
|
||||
public virtual void Start()
|
||||
{
|
||||
_activeStopwatches.Add(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs a tick.
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
private protected virtual void Tick(UpdateContext context)
|
||||
{
|
||||
Elapsed += context.Deltatime;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the stopwatch.
|
||||
/// </summary>
|
||||
public virtual void Stop()
|
||||
{
|
||||
_activeStopwatches.Remove(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the stopwatch.
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
Elapsed = 0;
|
||||
}
|
||||
|
||||
internal static void PerformTicks(UpdateContext context)
|
||||
{
|
||||
for (var i = 0; i < _activeStopwatches.Count; i++)
|
||||
{
|
||||
_activeStopwatches[i].Tick(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
77
SMCode/SM.Base/Time/Timer.cs
Normal file
77
SMCode/SM.Base/Time/Timer.cs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SM.Base.Contexts;
|
||||
|
||||
namespace SM.Base.Time
|
||||
{
|
||||
/// <summary>
|
||||
/// Timer-System
|
||||
/// </summary>
|
||||
public class Timer : Stopwatch
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The target time in seconds.
|
||||
/// </summary>
|
||||
public float Target { get; private set; }
|
||||
/// <summary>
|
||||
/// The already elapsed time but normalized to the target.
|
||||
/// </summary>
|
||||
public float ElapsedNormalized { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The event, that is triggered when the timer stops.
|
||||
/// </summary>
|
||||
public event Action<Timer, UpdateContext> EndAction;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a timer with specified seconds.
|
||||
/// </summary>
|
||||
/// <param name="seconds"></param>
|
||||
public Timer(float seconds)
|
||||
{
|
||||
Target = seconds;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a timer with a time span.
|
||||
/// </summary>
|
||||
/// <param name="timeSpan"></param>
|
||||
public Timer(TimeSpan timeSpan)
|
||||
{
|
||||
Target = (float)timeSpan.TotalSeconds;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Start()
|
||||
{
|
||||
base.Start();
|
||||
Reset();
|
||||
}
|
||||
|
||||
private protected override void Tick(UpdateContext context)
|
||||
{
|
||||
base.Tick(context);
|
||||
|
||||
ElapsedNormalized = Elapsed / Target;
|
||||
if (ElapsedNormalized >= 1) Stopping(context);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs, when the timer tries to stop.
|
||||
/// </summary>
|
||||
protected virtual void Stopping(UpdateContext context)
|
||||
{
|
||||
EndAction?.Invoke(this, context);
|
||||
Stop();
|
||||
}
|
||||
/// <summary>
|
||||
/// This will trigger <see cref="EndAction"/>
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected void TriggerEndAction(UpdateContext context)
|
||||
{
|
||||
EndAction?.Invoke(this, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
176
SMCode/SM.Base/Types/CVector.cs
Normal file
176
SMCode/SM.Base/Types/CVector.cs
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
using System;
|
||||
using System.Configuration.Assemblies;
|
||||
using System.Diagnostics;
|
||||
using OpenTK;
|
||||
|
||||
namespace SM.Base.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a base vector-class
|
||||
/// </summary>
|
||||
public abstract class CVector
|
||||
{
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||
private float _x = default;
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||
private float _y = default;
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||
private float _z = default;
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||
private float _w = default;
|
||||
|
||||
/// <summary>
|
||||
/// The X-component.
|
||||
/// </summary>
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||
protected float _X
|
||||
{
|
||||
get => _x;
|
||||
set => _x = value;
|
||||
}
|
||||
/// <summary>
|
||||
/// The Y-component
|
||||
/// </summary>
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||
protected float _Y
|
||||
{
|
||||
get => _y;
|
||||
set => _y = value;
|
||||
}
|
||||
/// <summary>
|
||||
/// The Z-component.
|
||||
/// </summary>
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||
protected float _Z
|
||||
{
|
||||
get => _z;
|
||||
set => _z = value;
|
||||
}
|
||||
/// <summary>
|
||||
/// The W-component.
|
||||
/// </summary>
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||
protected float _W
|
||||
{
|
||||
get => _w;
|
||||
set => _w = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a vector by setting every component to the same value.
|
||||
/// </summary>
|
||||
protected CVector(float uniform) : this(uniform, uniform, uniform, uniform)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a vector by setting values for each component.
|
||||
/// </summary>
|
||||
protected CVector(float x, float y, float z, float w)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_z = z;
|
||||
_w = w;
|
||||
}
|
||||
|
||||
#region Set
|
||||
/// <summary>
|
||||
/// Sets the X and Y-component.
|
||||
/// </summary>
|
||||
protected void Set(float x, float y)
|
||||
{
|
||||
_X = x;
|
||||
_Y = y;
|
||||
}
|
||||
/// <summary>
|
||||
/// Sets the X and Y-component from a <see cref="OpenTK.Vector2"/>
|
||||
/// </summary>
|
||||
protected void Set(OpenTK.Vector2 vector)
|
||||
{
|
||||
Set(vector.X, vector.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the X, Y and Z-component.
|
||||
/// </summary>
|
||||
protected void Set(float x, float y, float z)
|
||||
{
|
||||
Set(x,y);
|
||||
_Z = z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the X, Y and Z-component from a <see cref="OpenTK.Vector3"/>.
|
||||
/// </summary>
|
||||
/// <param name="vector"></param>
|
||||
protected void Set(OpenTK.Vector3 vector)
|
||||
{
|
||||
Set(vector.X, vector.Y, vector.Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the X, Y, Z and W-component.
|
||||
/// </summary>
|
||||
protected void Set(float x, float y, float z, float w)
|
||||
{
|
||||
Set(x,y,z);
|
||||
_W = w;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the X, Y, Z and W-component from a <see cref="OpenTK.Vector4"/>.
|
||||
/// </summary>
|
||||
protected void Set(OpenTK.Vector4 vector)
|
||||
{
|
||||
Set(vector.X, vector.Y, vector.Z, vector.W);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Add
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref="OpenTK.Vector2"/> to the X and Y-component.
|
||||
/// </summary>
|
||||
protected void Add(OpenTK.Vector2 vector)
|
||||
{
|
||||
_X += vector.X;
|
||||
_Y += vector.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref="OpenTK.Vector3"/> to the X, Y and Z-component.
|
||||
/// </summary>
|
||||
protected void Add(OpenTK.Vector3 vector)
|
||||
{
|
||||
_X += vector.X;
|
||||
_Y += vector.Y;
|
||||
_Z += vector.Z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref="OpenTK.Vector4"/> to the X, Y, Z and W-component.
|
||||
/// </summary>
|
||||
protected void Add(OpenTK.Vector4 vector)
|
||||
{
|
||||
_X += vector.X;
|
||||
_Y += vector.Y;
|
||||
_Z += vector.Z;
|
||||
_W += vector.W;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Transforms a <see cref="CVector"/> to a <see cref="OpenTK.Vector2"/>
|
||||
/// </summary>
|
||||
public static implicit operator OpenTK.Vector2(CVector v) => new OpenTK.Vector2(v._x, v._y);
|
||||
/// <summary>
|
||||
/// Transforms a <see cref="CVector"/> to a <see cref="OpenTK.Vector3"/>
|
||||
/// </summary>
|
||||
public static implicit operator OpenTK.Vector3(CVector v) => new OpenTK.Vector3(v._x, v._y, v._z);
|
||||
/// <summary>
|
||||
/// Transforms a <see cref="CVector"/> to a <see cref="OpenTK.Vector4"/>
|
||||
/// </summary>
|
||||
public static implicit operator OpenTK.Vector4(CVector v) => new OpenTK.Vector4(v._x, v._y, v._z, v._w);
|
||||
}
|
||||
}
|
||||
56
SMCode/SM.Base/Types/CVector2.cs
Normal file
56
SMCode/SM.Base/Types/CVector2.cs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
namespace SM.Base.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a vector of two floats.
|
||||
/// </summary>
|
||||
public class CVector2 : CVector
|
||||
{
|
||||
/// <summary>
|
||||
/// X-component
|
||||
/// </summary>
|
||||
public float X
|
||||
{
|
||||
get => _X;
|
||||
set => _X = value;
|
||||
}
|
||||
/// <summary>
|
||||
/// Y-component
|
||||
/// </summary>
|
||||
public float Y
|
||||
{
|
||||
get => _Y;
|
||||
set => _Y = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public CVector2() : this(0)
|
||||
{}
|
||||
|
||||
/// <inheritdoc />
|
||||
public CVector2(float uniform) : base(uniform)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public CVector2(float x, float y) : base(x,y, default, default) {}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected CVector2(float x, float y, float z, float w) : base(x, y, z, w) {}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the X and Y-component.
|
||||
/// </summary>
|
||||
public new void Set(float x, float y) => base.Set(x, y);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the X and Y-component from a <see cref="OpenTK.Vector2"/>
|
||||
/// </summary>
|
||||
public new void Set(OpenTK.Vector2 vector) => base.Set(vector);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref="OpenTK.Vector2"/> to the X and Y-component.
|
||||
/// </summary>
|
||||
public new void Add(OpenTK.Vector2 vector) => base.Add(vector);
|
||||
}
|
||||
}
|
||||
46
SMCode/SM.Base/Types/CVector3.cs
Normal file
46
SMCode/SM.Base/Types/CVector3.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using System.Drawing.Design;
|
||||
using System.Runtime.InteropServices;
|
||||
using OpenTK;
|
||||
|
||||
namespace SM.Base.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a Vector of three floats.
|
||||
/// </summary>
|
||||
public class CVector3 : CVector2
|
||||
{
|
||||
/// <summary>
|
||||
/// Z-component
|
||||
/// </summary>
|
||||
public float Z
|
||||
{
|
||||
get => _Z;
|
||||
set => _Z = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public CVector3(float uniform) : base(uniform)
|
||||
{ }
|
||||
|
||||
/// <inheritdoc />
|
||||
public CVector3(float x, float y, float z) : base(x, y, z, default)
|
||||
{ }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected CVector3(float x, float y, float z, float w) : base(x, y, z, w) { }
|
||||
|
||||
/// <summary>
|
||||
/// Sets the X, Y and Z-component.
|
||||
/// </summary>
|
||||
public new void Set(float x, float y, float z) => base.Set(x, y, z);
|
||||
/// <summary>
|
||||
/// Sets the X, Y and Z-component from a <see cref="OpenTK.Vector3"/>.
|
||||
/// </summary>
|
||||
public new void Set(Vector3 vector) => base.Set(vector);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref="OpenTK.Vector3"/> to the X, Y and Z-component.
|
||||
/// </summary>
|
||||
public new void Add(Vector3 vector) => base.Add(vector);
|
||||
}
|
||||
}
|
||||
42
SMCode/SM.Base/Types/CVector4.cs
Normal file
42
SMCode/SM.Base/Types/CVector4.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using OpenTK;
|
||||
|
||||
namespace SM.Base.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a vector of four floats.
|
||||
/// </summary>
|
||||
public class CVector4 : CVector3
|
||||
{
|
||||
/// <summary>
|
||||
/// W-component
|
||||
/// </summary>
|
||||
public float W
|
||||
{
|
||||
get => _W;
|
||||
set => _W = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public CVector4(float uniform) : base(uniform)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public CVector4(float x, float y, float z, float w) : base(x, y, z, w)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the X, Y, Z and W-component.
|
||||
/// </summary>
|
||||
public new void Set(float x, float y, float z, float w) => base.Set(x, y, z, w);
|
||||
/// <summary>
|
||||
/// Sets the X, Y, Z and W-component from a <see cref="OpenTK.Vector4"/>.
|
||||
/// </summary>
|
||||
public new void Set(Vector4 vector) => base.Set(vector);
|
||||
/// <summary>
|
||||
/// Adds a <see cref="OpenTK.Vector4"/> to the X, Y, Z and W-component.
|
||||
/// </summary>
|
||||
public new void Add(Vector4 vector) => base.Add(vector);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,110 +0,0 @@
|
|||
using System;
|
||||
using System.Configuration.Assemblies;
|
||||
using OpenTK;
|
||||
|
||||
namespace SM.Base.Types
|
||||
{
|
||||
public abstract class Vector
|
||||
{
|
||||
private float _x = default;
|
||||
private float _y = default;
|
||||
private float _z = default;
|
||||
private float _w = default;
|
||||
|
||||
protected float _X
|
||||
{
|
||||
get => _x;
|
||||
set => _x = value;
|
||||
}
|
||||
protected float _Y
|
||||
{
|
||||
get => _y;
|
||||
set => _y = value;
|
||||
}
|
||||
protected float _Z
|
||||
{
|
||||
get => _z;
|
||||
set => _z = value;
|
||||
}
|
||||
protected float _W
|
||||
{
|
||||
get => _w;
|
||||
set => _w = value;
|
||||
}
|
||||
|
||||
protected Vector(float uniform) : this(uniform, uniform, uniform, uniform)
|
||||
{ }
|
||||
|
||||
protected Vector(float x, float y, float z, float w)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_z = z;
|
||||
_w = w;
|
||||
}
|
||||
|
||||
#region Set
|
||||
protected void Set(float x, float y)
|
||||
{
|
||||
_X = x;
|
||||
_Y = y;
|
||||
}
|
||||
|
||||
protected void Set(OpenTK.Vector2 vector)
|
||||
{
|
||||
Set(vector.X, vector.Y);
|
||||
}
|
||||
|
||||
protected void Set(float x, float y, float z)
|
||||
{
|
||||
Set(x,y);
|
||||
_Z = z;
|
||||
}
|
||||
|
||||
protected void Set(OpenTK.Vector3 vector)
|
||||
{
|
||||
Set(vector.X, vector.Y, vector.Z);
|
||||
}
|
||||
|
||||
protected void Set(float x, float y, float z, float w)
|
||||
{
|
||||
Set(x,y,z);
|
||||
_W = w;
|
||||
}
|
||||
|
||||
protected void Set(OpenTK.Vector4 vector)
|
||||
{
|
||||
Set(vector.X, vector.Y, vector.Z, vector.W);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Add
|
||||
|
||||
protected void Add(OpenTK.Vector2 vector)
|
||||
{
|
||||
_X += vector.X;
|
||||
_Y += vector.Y;
|
||||
}
|
||||
protected void Add(OpenTK.Vector3 vector)
|
||||
{
|
||||
_X += vector.X;
|
||||
_Y += vector.Y;
|
||||
_Z += vector.Z;
|
||||
}
|
||||
protected void Add(OpenTK.Vector4 vector)
|
||||
{
|
||||
_X += vector.X;
|
||||
_Y += vector.Y;
|
||||
_Z += vector.Z;
|
||||
_W += vector.W;
|
||||
}
|
||||
|
||||
#endregion
|
||||
public static implicit operator OpenTK.Vector2(Vector v) => new OpenTK.Vector2(v._x, v._y);
|
||||
public static implicit operator OpenTK.Vector3(Vector v) => new OpenTK.Vector3(v._x, v._y, v._z);
|
||||
public static implicit operator OpenTK.Vector4(Vector v) => new OpenTK.Vector4(v._x, v._y, v._z, v._w);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
namespace SM.Base.Types
|
||||
{
|
||||
public class Vector2 : Vector
|
||||
{
|
||||
public float X
|
||||
{
|
||||
get => _X;
|
||||
set => _X = value;
|
||||
}
|
||||
public float Y
|
||||
{
|
||||
get => _Y;
|
||||
set => _Y = value;
|
||||
}
|
||||
|
||||
public Vector2() : this(0)
|
||||
{}
|
||||
|
||||
public Vector2(float uniform) : base(uniform)
|
||||
{
|
||||
|
||||
}
|
||||
public Vector2(float x, float y) : base(x,y, default, default) {}
|
||||
protected Vector2(float x, float y, float z, float w) : base(x, y, z, w) {}
|
||||
|
||||
public new void Set(float x, float y) => base.Set(x, y);
|
||||
public new void Set(OpenTK.Vector2 vector) => base.Set(vector);
|
||||
|
||||
public new void Add(OpenTK.Vector2 vector) => base.Add(vector);
|
||||
|
||||
public static implicit operator Vector2(OpenTK.Vector2 v) => new Vector2(v.X, v.Y);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SM.Base.Types
|
||||
{
|
||||
public class Vector3 : Vector2
|
||||
{
|
||||
public float Z
|
||||
{
|
||||
get => _Z;
|
||||
set => _Z = value;
|
||||
}
|
||||
|
||||
public Vector3(float uniform) : base(uniform)
|
||||
{ }
|
||||
|
||||
public Vector3(float x, float y, float z) : base(x, y, z, default)
|
||||
{ }
|
||||
|
||||
protected Vector3(float x, float y, float z, float w) : base(x, y, z, w) { }
|
||||
|
||||
public static implicit operator Vector3(OpenTK.Vector3 v) => new Vector3(v.X, v.Y, v.Z);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
namespace SM.Base.Types
|
||||
{
|
||||
public class Vector4 : Vector3
|
||||
{
|
||||
public float W
|
||||
{
|
||||
get => _W;
|
||||
set => _W = value;
|
||||
}
|
||||
|
||||
public Vector4(float uniform) : base(uniform)
|
||||
{
|
||||
}
|
||||
|
||||
public Vector4(float x, float y, float z, float w) : base(x, y, z, w)
|
||||
{
|
||||
}
|
||||
|
||||
public static implicit operator Vector4(OpenTK.Vector4 v) => new Vector4(v.X, v.Y, v.Z, v.W);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,9 @@ using System.Reflection;
|
|||
|
||||
namespace SM.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains utility functions for handling with assemblies.
|
||||
/// </summary>
|
||||
public class AssemblyUtility
|
||||
{
|
||||
/// <summary>
|
||||
|
|
@ -22,8 +25,19 @@ namespace SM.Utility
|
|||
public static string ReadAssemblyFile(string path) { return ReadAssemblyFile(Assembly.GetCallingAssembly(), path); }
|
||||
|
||||
|
||||
public static Stream GetAssemblyStream(Assembly ass, string path) { return ass.GetManifestResourceStream(ass.GetName().Name + "." + path) ?? throw new InvalidOperationException("Assembly couldn't find resource at path '" + path + "'."); }
|
||||
/// <summary>
|
||||
/// Returns a stream of a requested resource.
|
||||
/// </summary>
|
||||
/// <param name="ass">The assembly the resource is in.</param>
|
||||
/// <param name="path">The path to the resource.</param>
|
||||
/// <returns>The stream</returns>
|
||||
public static Stream GetAssemblyStream(Assembly ass, string path) { return ass.GetManifestResourceStream(path) ?? throw new InvalidOperationException("Assembly couldn't find resource at path '" + path + "'."); }
|
||||
|
||||
/// <summary>
|
||||
/// Returns a stream of a requested resource in the calling assembly.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the resource</param>
|
||||
/// <returns>The stream</returns>
|
||||
public static Stream GetAssemblyStream(string path) { return GetAssemblyStream(Assembly.GetCallingAssembly(), path); }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace SM.Utility
|
||||
{
|
||||
public class BezierCurve
|
||||
{
|
||||
public static float Calculate(float t, params float[] points)
|
||||
{
|
||||
int pointAmount = points.Length;
|
||||
int itterations = pointAmount - 1;
|
||||
|
||||
double x = Math.Pow(1 - t, itterations) * points[0];
|
||||
for (int i = 1; i < itterations; i++)
|
||||
{
|
||||
if (i % 2 == 0) x += itterations * (1 - t) * Math.Pow(t, itterations - 1) * points[i];
|
||||
else x += itterations * Math.Pow(1 - t, itterations - 1) * t * points[i];
|
||||
}
|
||||
|
||||
x += Math.Pow(t, itterations) * points[pointAmount - 1];
|
||||
return (float)x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +1,40 @@
|
|||
namespace SM.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// A assistant to control the delta time.
|
||||
/// </summary>
|
||||
public class Deltatime
|
||||
{
|
||||
/// <summary>
|
||||
/// The current update delta time.
|
||||
/// </summary>
|
||||
public static float UpdateDelta { get; internal set; }
|
||||
/// <summary>
|
||||
/// The current render delta time.
|
||||
/// </summary>
|
||||
public static float RenderDelta { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// If true, it uses <see cref="RenderDelta"/>, otherwise <see cref="UpdateDelta"/>.
|
||||
/// <para>Default: false</para>
|
||||
/// </summary>
|
||||
public bool UseRender;
|
||||
/// <summary>
|
||||
/// Scaling of the delta time.
|
||||
/// <para>Default: 1</para>
|
||||
/// </summary>
|
||||
public float Scale;
|
||||
|
||||
/// <summary>
|
||||
/// The calculated delta time.
|
||||
/// </summary>
|
||||
public float DeltaTime => (UseRender ? RenderDelta : UpdateDelta) * Scale;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a delta time assistant.
|
||||
/// </summary>
|
||||
/// <param name="scale">The start scale for the delta time. Default: 1</param>
|
||||
/// <param name="useRender">If true, it uses <see cref="RenderDelta"/>, otherwise <see cref="UpdateDelta"/>. Default: false</param>
|
||||
public Deltatime(float scale = 1, bool useRender = false)
|
||||
{
|
||||
UseRender = useRender;
|
||||
|
|
|
|||
|
|
@ -2,20 +2,51 @@
|
|||
|
||||
namespace SM.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// A global helper class for randomization.
|
||||
/// </summary>
|
||||
public class Randomize
|
||||
{
|
||||
/// <summary>
|
||||
/// The randomizer.
|
||||
/// </summary>
|
||||
public static Random Randomizer = new Random();
|
||||
|
||||
/// <summary>
|
||||
/// Sets the seed for the randomizer.
|
||||
/// </summary>
|
||||
/// <param name="seed">The specified seed.</param>
|
||||
public static void SetSeed(int seed) { Randomizer = new Random(seed); }
|
||||
|
||||
public static bool GetBool(float tolerance) { return Randomizer.NextDouble() > tolerance; }
|
||||
/// <summary>
|
||||
/// Generates a double and checks if its under the tolerance.
|
||||
/// </summary>
|
||||
public static bool GetBool(float tolerance) { return Randomizer.NextDouble() < tolerance; }
|
||||
|
||||
/// <summary>
|
||||
/// Generates a integer.
|
||||
/// </summary>
|
||||
public static int GetInt() { return Randomizer.Next(); }
|
||||
/// <summary>
|
||||
/// Generates a integer with a maximum.
|
||||
/// </summary>
|
||||
public static int GetInt(int max) { return Randomizer.Next(max); }
|
||||
/// <summary>
|
||||
/// Generates a integer with a minimum and maximum
|
||||
/// </summary>
|
||||
public static int GetInt(int min, int max) { return Randomizer.Next(min, max); }
|
||||
|
||||
/// <summary>
|
||||
/// Generates a float between 0 and 1.
|
||||
/// </summary>
|
||||
public static float GetFloat() { return (float)Randomizer.NextDouble(); }
|
||||
/// <summary>
|
||||
/// Generates a float between 0 and the specified maximum.
|
||||
/// </summary>
|
||||
public static float GetFloat(float max) { return (float)Randomizer.NextDouble() * max; }
|
||||
/// <summary>
|
||||
/// Generates a float between the specified minimum and the specified maximum.
|
||||
/// </summary>
|
||||
public static float GetFloat(float min, float max) { return (float)Randomizer.NextDouble() * max + min; }
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,18 +5,42 @@ using SM.OGL.Mesh;
|
|||
|
||||
namespace SM.Base.Contexts
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains important information for drawing.
|
||||
/// </summary>
|
||||
public struct DrawContext
|
||||
{
|
||||
/// <summary>
|
||||
/// This says if it was forced to use the viewport camera.
|
||||
/// </summary>
|
||||
public bool ForceViewport;
|
||||
public bool Instancing;
|
||||
|
||||
/// <summary>
|
||||
/// The current world matrix.
|
||||
/// </summary>
|
||||
public Matrix4 World;
|
||||
/// <summary>
|
||||
/// The current view matrix.
|
||||
/// </summary>
|
||||
public Matrix4 View;
|
||||
/// <summary>
|
||||
/// The drawing instances.
|
||||
/// <para>If there is only one, it's index 0</para>
|
||||
/// </summary>
|
||||
public Instance[] Instances;
|
||||
|
||||
/// <summary>
|
||||
/// The mesh.
|
||||
/// </summary>
|
||||
public GenericMesh Mesh;
|
||||
/// <summary>
|
||||
/// The material.
|
||||
/// </summary>
|
||||
public Material Material;
|
||||
|
||||
/// <summary>
|
||||
/// The current world scale.
|
||||
/// </summary>
|
||||
public Vector2 WorldScale;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,26 @@
|
|||
namespace SM.Base.Contexts
|
||||
using OpenTK.Input;
|
||||
using SM.Utility;
|
||||
|
||||
namespace SM.Base.Contexts
|
||||
{
|
||||
/// <summary>
|
||||
/// The update context.
|
||||
/// </summary>
|
||||
public struct UpdateContext
|
||||
{
|
||||
public double Deltatime;
|
||||
/// <summary>
|
||||
/// The delta time.
|
||||
/// </summary>
|
||||
public float Deltatime => Defaults.DefaultDeltatime.DeltaTime;
|
||||
|
||||
/// <summary>
|
||||
/// The current keyboard state.
|
||||
/// </summary>
|
||||
public KeyboardState KeyboardState;
|
||||
|
||||
/// <summary>
|
||||
/// The current mouse state.
|
||||
/// </summary>
|
||||
public MouseState MouseState;
|
||||
}
|
||||
}
|
||||
|
|
@ -7,25 +7,36 @@ using OpenTK.Input;
|
|||
using SM.Base.Contexts;
|
||||
using SM.Base.Objects.Static;
|
||||
using SM.Base.Scene;
|
||||
using SM.Base.Time;
|
||||
using SM.OGL;
|
||||
using SM.OGL.Shaders;
|
||||
using SM.Utility;
|
||||
|
||||
namespace SM.Base
|
||||
{
|
||||
/// <summary>
|
||||
/// The base window.
|
||||
/// </summary>
|
||||
public abstract class GenericWindow : GameWindow
|
||||
{
|
||||
private bool _loading = false;
|
||||
|
||||
public bool ForceViewportCamera { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This tells you the current world scale.
|
||||
/// </summary>
|
||||
protected Vector2 _worldScale = Vector2.Zero;
|
||||
/// <summary>
|
||||
/// This tells you the current aspect ratio of this window.
|
||||
/// </summary>
|
||||
public float Aspect { get; private set; } = 0f;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected GenericWindow() : base(1280, 720, GraphicsMode.Default, "Generic OGL Title", GameWindowFlags.Default,
|
||||
DisplayDevice.Default, 0, 0, GraphicsContextFlags.Default, null, true)
|
||||
{ }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
GLSystem.INIT_SYSTEM();
|
||||
|
|
@ -42,6 +53,8 @@ namespace SM.Base
|
|||
base.OnLoad(e);
|
||||
_loading = true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
|
|
@ -58,25 +71,47 @@ namespace SM.Base
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is triggered after all the window-loading has been done.
|
||||
/// </summary>
|
||||
protected virtual void OnLoaded()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the world scale.
|
||||
/// </summary>
|
||||
protected virtual void SetWorldScale() { }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnUpdateFrame(FrameEventArgs e)
|
||||
{
|
||||
base.OnUpdateFrame(e);
|
||||
|
||||
Deltatime.UpdateDelta = (float)e.Time;
|
||||
UpdateContext context = new UpdateContext()
|
||||
{
|
||||
KeyboardState = Keyboard.GetState(),
|
||||
MouseState = Mouse.GetState()
|
||||
};
|
||||
|
||||
Stopwatch.PerformTicks(context);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grabs the cursor and make sure it doesn't leave the window.
|
||||
/// </summary>
|
||||
/// <param name="makeItInvisible">If true, it makes the cursor invisible.</param>
|
||||
public void GrabCursor(bool makeItInvisible = true)
|
||||
{
|
||||
CursorGrabbed = true;
|
||||
CursorVisible = !makeItInvisible;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ungrabs the cursor.
|
||||
/// </summary>
|
||||
public void UngrabCursor()
|
||||
{
|
||||
CursorGrabbed = false;
|
||||
|
|
@ -84,20 +119,38 @@ namespace SM.Base
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The base window.
|
||||
/// </summary>
|
||||
/// <typeparam name="TScene">The scene type</typeparam>
|
||||
/// <typeparam name="TItem">The base item type</typeparam>
|
||||
/// <typeparam name="TCamera">The camera type</typeparam>
|
||||
public abstract class GenericWindow<TScene, TItem, TCamera> : GenericWindow
|
||||
where TScene : GenericScene<TCamera, TItem>, new()
|
||||
where TItem : IShowItem
|
||||
where TCamera : GenericCamera, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// The viewport camera.
|
||||
/// </summary>
|
||||
public TCamera ViewportCamera { get; }
|
||||
/// <summary>
|
||||
/// This forces the render to use the viewport camera.
|
||||
/// </summary>
|
||||
public bool ForceViewportCamera { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// The current scene.
|
||||
/// </summary>
|
||||
public TScene CurrentScene { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected GenericWindow()
|
||||
{
|
||||
ViewportCamera = new TCamera();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnRenderFrame(FrameEventArgs e)
|
||||
{
|
||||
DrawContext drawContext = new DrawContext()
|
||||
|
|
@ -119,6 +172,7 @@ namespace SM.Base
|
|||
SwapBuffers();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
|
|
@ -126,6 +180,10 @@ namespace SM.Base
|
|||
ViewportCamera.RecalculateWorld(_worldScale, Aspect);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the scene.
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
public virtual void SetScene(TScene scene)
|
||||
{
|
||||
CurrentScene = scene;
|
||||
|
|
|
|||
|
|
@ -47,6 +47,22 @@ namespace SM.OGL
|
|||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is triggered, when something want to dispose this object.
|
||||
/// </summary>
|
||||
protected virtual void Dispose() {}
|
||||
|
||||
/// <summary>
|
||||
/// Re-compiles the object.
|
||||
/// </summary>
|
||||
public void Recompile()
|
||||
{
|
||||
if (!WasCompiled) return;
|
||||
|
||||
Dispose();
|
||||
Compile();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Names the object for debugging.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -15,11 +15,23 @@ namespace SM.OGL.Texture
|
|||
|
||||
/// <summary>
|
||||
/// The texture filter.
|
||||
/// <para>Default: <see cref="TextureMinFilter.Linear"/></para>
|
||||
/// </summary>
|
||||
public abstract TextureMinFilter Filter { get; set; }
|
||||
public virtual TextureMinFilter Filter { get; set; } = TextureMinFilter.Linear;
|
||||
|
||||
/// <summary>
|
||||
/// The wrap mode.
|
||||
/// <para>Default: <see cref="TextureWrapMode.Repeat"/></para>
|
||||
/// </summary>
|
||||
public abstract TextureWrapMode WrapMode { get; set; }
|
||||
public virtual TextureWrapMode WrapMode { get; set; } = TextureWrapMode.Repeat;
|
||||
|
||||
/// <summary>
|
||||
/// The Width of the texture
|
||||
/// </summary>
|
||||
public int Width { get; protected set; }
|
||||
/// <summary>
|
||||
/// The height of the texture
|
||||
/// </summary>
|
||||
public int Height { get; protected set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -11,13 +11,13 @@ namespace SM2D.Drawing
|
|||
public DrawText(Font font, string text) : base(font)
|
||||
{
|
||||
_text = text;
|
||||
Transform.Size = new Vector2(1);
|
||||
Transform.Size = new CVector2(1);
|
||||
}
|
||||
|
||||
public override void Draw(DrawContext context)
|
||||
{
|
||||
base.Draw(context);
|
||||
context.Instances = _modelMatrixs;
|
||||
context.Instances = _instances;
|
||||
ApplyContext(ref context);
|
||||
|
||||
context.View = Transform.GetMatrix() * context.View;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ using SM.Base.Textures;
|
|||
using SM.Base.Types;
|
||||
using SM2D.Scene;
|
||||
using SM2D.Types;
|
||||
using Vector2 = SM.Base.Types.Vector2;
|
||||
|
||||
namespace SM2D.Drawing
|
||||
{
|
||||
|
|
@ -37,7 +36,7 @@ namespace SM2D.Drawing
|
|||
|
||||
public override void Draw(DrawContext context)
|
||||
{
|
||||
Transform.Size = new Vector2(Texture.Map.Width * MasterScale * Scale, Texture.Map.Height * MasterScale * Scale);
|
||||
Transform.Size = new CVector2(Texture.Map.Width * MasterScale * Scale, Texture.Map.Height * MasterScale * Scale);
|
||||
base.Draw(context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
using OpenTK;
|
||||
using SM.Base.Scene;
|
||||
using Vector2 = SM.Base.Types.Vector2;
|
||||
using SM.Base.Types;
|
||||
|
||||
namespace SM2D.Scene
|
||||
{
|
||||
|
|
@ -8,7 +8,7 @@ namespace SM2D.Scene
|
|||
{
|
||||
public override bool Orthographic { get; } = true;
|
||||
|
||||
public Vector2 Position = new Vector2(0);
|
||||
public CVector2 Position = new CVector2(0);
|
||||
|
||||
protected override Matrix4 ViewCalculation()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace SM2D.Scene
|
|||
{
|
||||
public ItemCollection()
|
||||
{
|
||||
Transform.Size = new Vector2(1);
|
||||
Transform.Size = new CVector2(1);
|
||||
}
|
||||
|
||||
public override void Draw(DrawContext context)
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ namespace SM2D.Shader
|
|||
protected override bool AutoCompile { get; } = true;
|
||||
|
||||
public Default2DShader() : base(new ShaderFileCollection(
|
||||
AssemblyUtility.ReadAssemblyFile("Shader.ShaderFiles.default.vert"),
|
||||
AssemblyUtility.ReadAssemblyFile("Shader.ShaderFiles.default.frag")))
|
||||
AssemblyUtility.ReadAssemblyFile("SM2D.Shader.ShaderFiles.default.vert"),
|
||||
AssemblyUtility.ReadAssemblyFile("SM2D.Shader.ShaderFiles.default.frag")))
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
using OpenTK;
|
||||
using SM.Base.Scene;
|
||||
using Vector2 = SM.Base.Types.Vector2;
|
||||
using SM.Base.Types;
|
||||
|
||||
namespace SM2D.Types
|
||||
{
|
||||
public class Transformation : GenericTransformation
|
||||
{
|
||||
public Vector2 Position = new Vector2(0);
|
||||
public Vector2 Size = new Vector2(50);
|
||||
public CVector2 Position = new CVector2(0);
|
||||
public CVector2 Size = new CVector2(50);
|
||||
public float Rotation;
|
||||
|
||||
public override Matrix4 GetMatrix()
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using SM.Base.Time;
|
||||
using SM2D;
|
||||
using SM2D.Drawing;
|
||||
using SM2D.Object;
|
||||
|
|
@ -27,7 +29,7 @@ namespace SM_TEST
|
|||
};
|
||||
|
||||
window = new GLWindow2D {Scaling = new Vector2(0, 1000)};
|
||||
window.GrabCursor();
|
||||
//window.GrabCursor();
|
||||
window.SetScene(scene = new Scene());
|
||||
window.Load += WindowOnLoad;
|
||||
window.RenderFrame += WindowOnUpdateFrame;
|
||||
|
|
@ -41,9 +43,13 @@ namespace SM_TEST
|
|||
|
||||
private static void WindowOnLoad(object sender, EventArgs e)
|
||||
{
|
||||
Interval timer = new Interval(5);
|
||||
timer.EndAction += (timer1, context) => Console.WriteLine("Interval...");
|
||||
timer.Start();
|
||||
|
||||
col = new ItemCollection()
|
||||
{
|
||||
Transform = { Position = new SM.Base.Types.Vector2(0, -400) },
|
||||
Transform = { Position = new SM.Base.Types.CVector2(0, -400) },
|
||||
ZIndex = 1
|
||||
};
|
||||
|
||||
|
|
@ -53,14 +59,14 @@ namespace SM_TEST
|
|||
});
|
||||
col.Objects.Add(new DrawColor(Color4.Black)
|
||||
{
|
||||
Transform = { Rotation = 45, Position = new SM.Base.Types.Vector2(0, 25) },
|
||||
Transform = { Rotation = 45, Position = new SM.Base.Types.CVector2(0, 25) },
|
||||
ZIndex = 2
|
||||
});
|
||||
|
||||
scene.Objects.Add(col);
|
||||
scene.Objects.Add(new DrawText(font, "Testing...")
|
||||
{
|
||||
Transform = { Position = new SM.Base.Types.Vector2(0, -400)},
|
||||
Transform = { Position = new SM.Base.Types.CVector2(0, -400)},
|
||||
Color = Color4.Black
|
||||
});
|
||||
|
||||
|
|
@ -77,7 +83,7 @@ namespace SM_TEST
|
|||
new PolygonVertex(new Vector2(0, .25f), new Color4(10,10,10,255))
|
||||
}), Color4.LawnGreen)
|
||||
{
|
||||
Transform = {Position = new SM.Base.Types.Vector2(50,0)}
|
||||
Transform = {Position = new SM.Base.Types.CVector2(50,0)}
|
||||
});
|
||||
scene.Objects.Add(new DrawPolygon(new Polygon(new[]
|
||||
{
|
||||
|
|
@ -91,7 +97,7 @@ namespace SM_TEST
|
|||
new PolygonVertex(new Vector2(0, .25f), new Color4(10,10,10,255))
|
||||
}), new Bitmap("soldier_logo.png"))
|
||||
{
|
||||
Transform = {Position = new SM.Base.Types.Vector2(-50,0)}
|
||||
Transform = {Position = new SM.Base.Types.CVector2(-50,0)}
|
||||
});
|
||||
|
||||
scene.Background.Color = Color4.Beige;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue