+ comments to the SM.Base

+ Length, Normalize methods for CVectors
This commit is contained in:
Michel Fedde 2020-12-19 20:49:16 +01:00
parent 5d4b360b05
commit 9b917ac181
18 changed files with 248 additions and 33 deletions

View file

@ -11,6 +11,9 @@ namespace SM.Base.Drawing
/// </summary>
public abstract class GenericTransformation
{
/// <summary>
/// If true, ignores the transformation and sends <see cref="Matrix4.Identity"/>, when requested.
/// </summary>
public bool Ignore = false;
/// <summary>

View file

@ -54,6 +54,10 @@ namespace SM.Base.Drawing.Particles
/// </summary>
public abstract Func<TDirection, ParticleContext, TDirection> MovementCalculation { get; set; }
/// <summary>
/// Sets up the timer.
/// </summary>
/// <param name="duration">Duration how long the particles should live</param>
protected ParticleDrawingBasis(TimeSpan duration)
{
timer = new Timer(duration);

View file

@ -1,5 +1,6 @@
#region usings
using OpenTK.Graphics.OpenGL4;
using SM.OGL.Mesh;
#endregion
@ -12,14 +13,15 @@ namespace SM.Base.Objects
/// <summary>
/// While initializing, it will add the <see cref="Color" /> to the data index.
/// </summary>
public Mesh()
public Mesh(PrimitiveType type)
{
PrimitiveType = type;
Attributes.Add(3, "color", Color);
}
/// <summary>
/// Contains vertex colors
/// </summary>
public virtual VBO Color { get; }
public virtual VBO Color { get; protected set; }
}
}

View file

@ -4,13 +4,24 @@ using SM.OGL.Mesh;
namespace SM.Base.Objects.Static
{
/// <summary>
/// An AxisHelper-Model
/// <para>White: -X, -Y, -Z</para>
/// <para>Red: +X </para>
/// <para>Green: +Y </para>
/// <para>Blue: +Z </para>
/// </summary>
public class AxisHelper : Mesh
{
/// <summary>
/// Object
/// </summary>
public static AxisHelper Object = new AxisHelper();
private AxisHelper() {}
private AxisHelper() : base(PrimitiveType.Lines) {}
public override VBO Vertex { get; } = new VBO()
/// <inheritdoc />
public override VBO Vertex { get; protected set; } = new VBO()
{
{0, 0, 0},
{.5f, 0, 0},
@ -20,7 +31,8 @@ namespace SM.Base.Objects.Static
{0, 0, .5f},
};
public override VBO Color { get; } = new VBO(pointerSize:4)
/// <inheritdoc />
public override VBO Color { get; protected set; } = new VBO(pointerSize:4)
{
{Color4.White},
{Color4.Red},
@ -29,7 +41,5 @@ namespace SM.Base.Objects.Static
{Color4.White},
{Color4.DarkBlue},
};
public override PrimitiveType PrimitiveType { get; } = PrimitiveType.Lines;
}
}

View file

@ -25,7 +25,7 @@ namespace SM.Base.Objects.Static
}
/// <inheritdoc />
public override VBO Vertex { get; } = new VBO
public override VBO Vertex { get; protected set; } = new VBO
{
{-.5f, -.5f, 0},
{-.5f, .5f, 0},
@ -34,7 +34,7 @@ namespace SM.Base.Objects.Static
};
/// <inheritdoc />
public override VBO UVs { get; } = new VBO(pointerSize: 2)
public override VBO UVs { get; protected set; } = new VBO(pointerSize: 2)
{
{0, 1},
{0, 0},
@ -43,7 +43,7 @@ namespace SM.Base.Objects.Static
};
/// <inheritdoc />
public override PrimitiveType PrimitiveType { get; } = PrimitiveType.Quads;
public override PrimitiveType PrimitiveType { get; protected set; } = PrimitiveType.Quads;
/// <inheritdoc />
public override BoundingBox BoundingBox { get; } =

View file

@ -10,25 +10,39 @@ using SM.OGL.Shaders;
namespace SM.Base.PostProcess
{
/// <summary>
/// Basis for a post process effect
/// </summary>
public abstract class PostProcessEffect
{
internal static Matrix4 Mvp;
internal static Matrix4 Model;
public virtual ICollection<Framebuffer> RequiredFramebuffers { get; }
/// <summary>
/// Method, to initialize the shader.
/// </summary>
public virtual void Init() {}
/// <summary>
/// Method, to initialize the shader.
/// </summary>
public virtual void Init(Framebuffer main)
{
Init();
}
public virtual void Draw(Framebuffer main, Framebuffer target)
{
}
/// <summary>
/// Method to draw the actual effect.
/// </summary>
/// <param name="main">The framebuffer, that was used.</param>
/// <param name="target">The framebuffer, the system should draw to.</param>
public abstract void Draw(Framebuffer main, Framebuffer target);
/// <summary>
/// Event, when the scene changed.
/// </summary>
public virtual void SceneChanged(GenericScene scene)
{

View file

@ -41,6 +41,9 @@ namespace SM.Base.Textures
get => _height ?? Map.Height;
protected set => _height = value;
}
/// <summary>
/// Aspect ratio of Width and Height of the texture
/// </summary>
public float Aspect { get; private set; }
/// <summary>

View file

@ -12,8 +12,6 @@ namespace SM.Base.Time
/// </summary>
public class Interval : Timer
{
private bool _stop;
/// <inheritdoc />
public Interval(float seconds) : base(seconds)
{

View file

@ -16,8 +16,15 @@ namespace SM.Base.Time
private static List<Stopwatch> _activeStopwatches = new List<Stopwatch>();
private bool _paused = false;
/// <summary>
/// If true, the stopwatch was started.
/// <para>This doesn't changed when paused.</para>
/// </summary>
public bool Active { get; private set; } = false;
/// <summary>
/// Gets/Sets if the stopwatch is paused.
/// </summary>
public bool Paused
{
get => _paused;
@ -30,6 +37,9 @@ namespace SM.Base.Time
}
}
/// <summary>
/// If true, the stopwatch is active and not paused... (who would have guessed...)
/// </summary>
public bool Running => Active && !Paused;
/// <summary>

View file

@ -1,20 +1,90 @@
namespace SM.Base.Types
using System;
using OpenTK;
namespace SM.Base.Types
{
/// <summary>
/// A One-dimensional Vector (also known as <see cref="float"/>), in a class.
/// </summary>
public class CVector1
{
/// <summary>
/// X - Component
/// </summary>
public float X { get; set; }
/// <summary>
/// The length/magnitute of the vector.
/// </summary>
public float Length => GetLength();
/// <summary>
/// Gets the square of the vector length (magnitude).
/// </summary>
/// <remarks>
/// This property avoids the costly square root operation required by the Length property. This makes it more suitable
/// for comparisons.
/// </remarks>
public float LengthSquared => GetLength(true);
/// <summary>
/// Creates a class vector
/// </summary>
/// <param name="x">X-Component</param>
public CVector1(float x)
{
X = x;
}
/// <summary>
/// Sets the X-Component.
/// </summary>
/// <param name="x">X-Component</param>
public virtual void Set(float x)
{
X = x;
}
/// <summary>
/// Get the length of the vector.
/// </summary>
/// <param name="squared">If true, it will return the squared product.</param>
/// <returns></returns>
public float GetLength(bool squared = false)
{
float length = GetLengthProcess();
if (squared) return length;
return (float) Math.Sqrt(length);
}
/// <summary>
/// Normalizes the vector.
/// </summary>
public void Normalize()
{
float length = GetLength();
NormalizationProcess(length);
}
/// <summary>
/// Conversion into <see cref="float"/>
/// </summary>
public static implicit operator float(CVector1 vector1) => vector1.X;
/// <summary>
/// Conversion from <see cref="float"/> to One-dimensional Vector.
/// </summary>
/// <param name="f"></param>
/// <returns></returns>
public static implicit operator CVector1(float f) => new CVector1(f);
private protected virtual float GetLengthProcess()
{
return X * X;
}
private protected virtual void NormalizationProcess(float length)
{
X *= length;
}
}
}

View file

@ -2,38 +2,81 @@
namespace SM.Base.Types
{
/// <summary>
/// A two-dimensional vector.
/// </summary>
public class CVector2 : CVector1
{
/// <summary>
/// Y-component
/// </summary>
public float Y { get; set; }
/// <summary>
/// Creates a vector, where each component is the same value.
/// </summary>
/// <param name="uniform">The Value</param>
public CVector2(float uniform) : base(uniform)
{
Y = uniform;
}
/// <summary>
/// Creates a vector
/// </summary>
public CVector2(float x, float y) : base(x)
{
Y = y;
}
public virtual void Set(float uniform)
private protected override float GetLengthProcess()
{
return base.GetLengthProcess() + Y * Y;
}
private protected override void NormalizationProcess(float length)
{
base.NormalizationProcess(length);
Y *= length;
}
/// <summary>
/// Sets each component to the same value
/// </summary>
/// <param name="uniform"></param>
public override void Set(float uniform)
{
base.Set(uniform);
Y = uniform;
}
/// <summary>
/// Sets each component to the <see cref="Vector2"/> counter-part.
/// </summary>
/// <param name="vector"></param>
public void Set(Vector2 vector)
{
Set(vector.X, vector.Y);
}
/// <summary>
/// Sets the a own value to each component.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
public void Set(float x, float y)
{
base.Set(x);
Y = y;
}
/// <summary>
/// Converts to <see cref="Vector2"/>
/// </summary>
public static implicit operator Vector2(CVector2 vector2) => new Vector2(vector2.X, vector2.Y);
/// <summary>
/// Converts from <see cref="Vector2"/> to <see cref="CVector2"/>.
/// </summary>
public static implicit operator CVector2(Vector2 vector2) => new CVector2(vector2.X, vector2.Y);
}
}

View file

@ -2,38 +2,74 @@
namespace SM.Base.Types
{
/// <summary>
/// A three-dimensional vector.
/// </summary>
public class CVector3 : CVector2
{
/// <summary>
/// Z-component
/// </summary>
public float Z { get; set; }
/// <summary>
/// Creates a vector, where each component is the same value.
/// </summary>
/// <param name="uniform">The Value</param>
public CVector3(float uniform) : base(uniform)
{
Z = uniform;
}
/// <summary>
/// Creates a vector
/// </summary>
public CVector3(float x, float y, float z) : base(x, y)
{
Z = z;
}
private protected override float GetLengthProcess()
{
return base.GetLengthProcess() + Z * Z;
}
private protected override void NormalizationProcess(float length)
{
base.NormalizationProcess(length);
Z *= length;
}
/// <inheritdoc />
public override void Set(float uniform)
{
base.Set(uniform);
Z = uniform;
}
/// <summary>
/// Sets the a own value to each component.
/// </summary>
public void Set(float x, float y, float z)
{
base.Set(x,y);
Z = z;
}
/// <summary>
/// Sets each component to the <see cref="Vector3"/> counter-part.
/// </summary>
/// <param name="vector"></param>
public void Set(Vector3 vector)
{
Set(vector.X, vector.Y, vector.Z);
}
/// <summary>
/// Converts to <see cref="Vector3"/>
/// </summary>
public static implicit operator Vector3(CVector3 vector) => new Vector3(vector.X, vector.Y, vector.Z);
/// <summary>
/// Converts from <see cref="Vector3"/> to <see cref="CVector3"/>.
/// </summary>
public static implicit operator CVector3(Vector3 vector) => new CVector3(vector.X, vector.Y, vector.Z);
}
}

View file

@ -84,6 +84,9 @@ namespace SM.Utility
return (float) Randomizer.NextDouble() * (max - min) + min;
}
/// <summary>
/// Gets a random item from the provided list.
/// </summary>
public static TSource GetRandomItem<TSource>(this IList<TSource> list)
{
return list[GetInt(0, list.Count - 1)];

View file

@ -182,6 +182,9 @@ namespace SM.Base
if (!CursorVisible) CursorVisible = true;
}
/// <summary>
/// Create a bitmap from the framebuffer.
/// </summary>
public Bitmap TakeScreenshot(Framebuffer framebuffer, ReadBufferMode readBuffer, int x, int y, int width, int height)
{
GL.GetInteger(GetPName.FramebufferBinding, out int prevFBId);

View file

@ -16,8 +16,14 @@ namespace SM.Base
/// </summary>
public abstract class RenderPipeline
{
/// <summary>
/// If true, this pipeline was already once activated.
/// </summary>
public bool IsInitialized { get; private set; } = false;
/// <summary>
/// The window the pipeline is connected to.
/// </summary>
protected GenericWindow _window { get; private set; }
/// <summary>
@ -76,6 +82,10 @@ namespace SM.Base
}
/// <summary>
/// Occurs, when the pipeline was connected to a window the first time.
/// </summary>
/// <param name="window"></param>
protected internal virtual void Initialization(GenericWindow window)
{
@ -88,6 +98,10 @@ namespace SM.Base
{
}
/// <summary>
/// Creates a framebuffer, that has specific (often) required settings already applied.
/// </summary>
/// <returns></returns>
public static Framebuffer CreateWindowFramebuffer()
{
Framebuffer framebuffer = new Framebuffer(window: SMRenderer.CurrentWindow);
@ -112,6 +126,10 @@ namespace SM.Base
context.ActivePipeline = this;
}
/// <summary>
/// Event, that triggers, when the scene in the current window changes.
/// </summary>
/// <param name="scene"></param>
protected internal virtual void SceneChanged(TScene scene)
{