01.10.2020

+ Time controls (Stopwatch, Timers, Intervals)
+ Added smmeries to everything in SM.Base

~ Renamed Vectors to CVectors.
This commit is contained in:
Michel Fedde 2020-10-01 15:39:03 +02:00
parent 7acdba92f8
commit 97e638d9d9
44 changed files with 1092 additions and 289 deletions

View 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);
}
}

View 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);
}
}

View 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);
}
}

View 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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}