Holidays 12.10. -> 25.10.2020
~ Moved code around in files. SM.Base: + PostProcessing-system + OnInitialization() for Scenes. + Shader-Extensions + Added option to not react while unfocused to the window. + Added Screenshots to the window. + Connected the log system to the SM.OGL-action system. ~ Replaced IShader with abstract MaterialShader. ~ When a log compression folder doesn't exist, it will create one. SM.OGL: + Added support for UniformArrays + Added ShaderPreProcessing + Added Shader Extensions. + Added Debug actions. + SM.OGL settings ~ Framebuffer Size is automaticly changed, when the window and scale is set. SM2D: + Added easy shader drawing.
This commit is contained in:
parent
2c00dbd31a
commit
03b3942732
102 changed files with 2683 additions and 1398 deletions
|
|
@ -1,32 +1,26 @@
|
|||
using System;
|
||||
#region usings
|
||||
|
||||
using OpenTK;
|
||||
using OpenTK.Input;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Mouse controller
|
||||
/// Mouse controller
|
||||
/// </summary>
|
||||
/// <typeparam name="TWindow">The type of window this controller is connected to.</typeparam>
|
||||
public class Mouse<TWindow>
|
||||
where TWindow : GenericWindow
|
||||
where TWindow : GenericWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// The window it is connected to.
|
||||
/// The window it is connected to.
|
||||
/// </summary>
|
||||
protected TWindow _window;
|
||||
|
||||
/// <summary>
|
||||
/// The current position of the mouse in the screen.
|
||||
/// </summary>
|
||||
public Vector2 InScreen { get; private set; }
|
||||
/// <summary>
|
||||
/// The current position of the mouse in the screen from 0..1.
|
||||
/// </summary>
|
||||
public Vector2 InScreenNormalized { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The constructor
|
||||
/// The constructor
|
||||
/// </summary>
|
||||
/// <param name="window">The window, its listen to.</param>
|
||||
protected internal Mouse(TWindow window)
|
||||
|
|
@ -35,13 +29,23 @@ namespace SM.Base.Controls
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// The event to update the values.
|
||||
/// The current position of the mouse in the screen.
|
||||
/// </summary>
|
||||
public Vector2 InScreen { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The current position of the mouse in the screen from 0..1.
|
||||
/// </summary>
|
||||
public Vector2 InScreenNormalized { get; private set; }
|
||||
|
||||
/// <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);
|
||||
InScreenNormalized = new Vector2(mmea.X / (float)_window.Width, mmea.Y / (float)_window.Height);
|
||||
InScreenNormalized = new Vector2(mmea.X / (float) _window.Width, mmea.Y / (float) _window.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +1,25 @@
|
|||
using System.Collections.Generic;
|
||||
#region usings
|
||||
|
||||
using System.Collections.Generic;
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base.Objects.Static;
|
||||
using SM.OGL.Mesh;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains general basis systems for drawing objects.
|
||||
/// Contains general basis systems for drawing objects.
|
||||
/// </summary>
|
||||
public abstract class DrawingBasis : IShowItem
|
||||
{
|
||||
/// <summary>
|
||||
/// The material it should use.
|
||||
/// The material it should use.
|
||||
/// </summary>
|
||||
protected Material _material = new Material();
|
||||
|
||||
/// <summary>
|
||||
/// The mesh it should use.
|
||||
/// The mesh it should use.
|
||||
/// </summary>
|
||||
protected GenericMesh _mesh = SMRenderer.DefaultMesh;
|
||||
|
||||
|
|
@ -31,7 +35,6 @@ namespace SM.Base.Scene
|
|||
/// <inheritdoc />
|
||||
public virtual void Update(UpdateContext context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
@ -46,33 +49,31 @@ namespace SM.Base.Scene
|
|||
/// <inheritdoc />
|
||||
public virtual void OnAdded(object sender)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void OnRemoved(object sender)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws the context, that was given to them.
|
||||
/// Draws the context, that was given to them.
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected virtual void DrawContext(ref DrawContext context)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains general basis systems for drawing objects.
|
||||
/// Contains general basis systems for drawing objects.
|
||||
/// </summary>
|
||||
/// <typeparam name="TTransformation">The transformation type</typeparam>
|
||||
public abstract class DrawingBasis<TTransformation> : DrawingBasis
|
||||
where TTransformation : GenericTransformation, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// The current transformation.
|
||||
/// The current transformation.
|
||||
/// </summary>
|
||||
public TTransformation Transform = new TTransformation();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,28 @@
|
|||
using OpenTK;
|
||||
#region usings
|
||||
|
||||
using OpenTK;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains methods for using transformations right.
|
||||
/// Contains methods for using transformations right.
|
||||
/// </summary>
|
||||
public abstract class GenericTransformation
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains the current model matrix.
|
||||
/// Contains the current model matrix.
|
||||
/// </summary>
|
||||
protected Matrix4 _modelMatrix { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Contains the last frame the matrix was calculated.
|
||||
/// Contains the last frame the matrix was calculated.
|
||||
/// </summary>
|
||||
protected ulong _lastFrame { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current model matrix.
|
||||
/// Returns the current model matrix.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Matrix4 GetMatrix()
|
||||
|
|
@ -32,7 +37,7 @@ namespace SM.Base.Scene
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the current matrix.
|
||||
/// Calculates the current matrix.
|
||||
/// </summary>
|
||||
/// <returns>The current matrix.</returns>
|
||||
protected abstract Matrix4 RequestMatrix();
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using OpenTK;
|
||||
using SM.Base.Contexts;
|
||||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
/// <summary>
|
||||
/// A general interface to work with material shaders properly.
|
||||
/// </summary>
|
||||
public interface IShader
|
||||
{
|
||||
/// <summary>
|
||||
/// Draws the context.
|
||||
/// </summary>
|
||||
/// <param name="context">The context</param>
|
||||
void Draw(DrawContext context);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +1,28 @@
|
|||
using OpenTK;
|
||||
#region usings
|
||||
|
||||
using OpenTK;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
/// <summary>
|
||||
/// This represens a drawing instance.
|
||||
/// This represens a drawing instance.
|
||||
/// </summary>
|
||||
public struct Instance
|
||||
{
|
||||
/// <summary>
|
||||
/// The model matrix.
|
||||
/// The model matrix.
|
||||
/// </summary>
|
||||
public Matrix4 ModelMatrix;
|
||||
|
||||
/// <summary>
|
||||
/// The texture offset.
|
||||
/// The texture offset.
|
||||
/// </summary>
|
||||
public Vector2 TexturePosition;
|
||||
|
||||
/// <summary>
|
||||
/// The texture scale.
|
||||
/// The texture scale.
|
||||
/// </summary>
|
||||
public Vector2 TextureScale;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,30 @@
|
|||
using OpenTK.Graphics;
|
||||
#region usings
|
||||
|
||||
using OpenTK.Graphics;
|
||||
using SM.OGL.Texture;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a material.
|
||||
/// Represents a material.
|
||||
/// </summary>
|
||||
public class Material
|
||||
{
|
||||
/// <summary>
|
||||
/// The base texture. (aka. Diffuse Texture)
|
||||
/// A custom shader, that is used to draw this material.
|
||||
/// </summary>
|
||||
public TextureBase Texture;
|
||||
/// <summary>
|
||||
/// The tint or color.
|
||||
/// </summary>
|
||||
public Color4 Tint = Color4.White;
|
||||
public MaterialShader CustomShader;
|
||||
|
||||
/// <summary>
|
||||
/// A custom shader, that is used to draw this material.
|
||||
/// The base texture. (aka. Diffuse Texture)
|
||||
/// </summary>
|
||||
public IShader CustomShader;
|
||||
public TextureBase Texture;
|
||||
|
||||
/// <summary>
|
||||
/// The tint or color.
|
||||
/// </summary>
|
||||
public Color4 Tint = Color4.White;
|
||||
}
|
||||
}
|
||||
47
SMCode/SM.Base/Drawing/MaterialShader.cs
Normal file
47
SMCode/SM.Base/Drawing/MaterialShader.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#region usings
|
||||
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.Base.Contexts;
|
||||
using SM.OGL.Shaders;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
/// <summary>
|
||||
/// A general class to work with material shaders properly.
|
||||
/// </summary>
|
||||
public abstract class MaterialShader : GenericShader
|
||||
{
|
||||
|
||||
protected MaterialShader(string vertex, string fragment) : base(vertex, fragment)
|
||||
{
|
||||
}
|
||||
|
||||
protected MaterialShader(ShaderFileCollection shaderFileFiles) : base(shaderFileFiles)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws the context.
|
||||
/// </summary>
|
||||
/// <param name="context">The context</param>
|
||||
public virtual void Draw(DrawContext context)
|
||||
{
|
||||
GL.UseProgram(this);
|
||||
|
||||
GL.BindVertexArray(context.Mesh);
|
||||
|
||||
DrawProcess(context);
|
||||
|
||||
CleanUp();
|
||||
|
||||
GL.UseProgram(0);
|
||||
}
|
||||
|
||||
protected virtual void DrawProcess(DrawContext context)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,98 +1,108 @@
|
|||
using System;
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Net.Http;
|
||||
using System.Windows.Forms;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.OGL;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies the target.
|
||||
/// Specifies the target.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum LogTarget
|
||||
{
|
||||
/// <summary>
|
||||
/// No target, will not draw.
|
||||
/// No target, will not draw.
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Takes the <see cref="Log.DefaultTarget"/>.
|
||||
/// Takes the <see cref="Log.DefaultTarget" />.
|
||||
/// </summary>
|
||||
Default = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Writes the log to the console.
|
||||
/// Writes the log to the console.
|
||||
/// </summary>
|
||||
Console = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Writes the log to the debugger at <see cref="Debug"/>.
|
||||
/// Writes the log to the debugger at <see cref="Debug" />.
|
||||
/// </summary>
|
||||
Debugger = 4,
|
||||
|
||||
/// <summary>
|
||||
/// Writes the log to the specific file.
|
||||
/// Writes the log to the specific file.
|
||||
/// </summary>
|
||||
File = 8,
|
||||
|
||||
/// <summary>
|
||||
/// Writes the log to every target.
|
||||
/// Writes the log to every target.
|
||||
/// </summary>
|
||||
All = Console | Debugger | File
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Preset log types.
|
||||
/// Preset log types.
|
||||
/// </summary>
|
||||
public enum LogType
|
||||
{
|
||||
/// <summary>
|
||||
/// Informations. Console Color: Green
|
||||
/// Informations. Console Color: Green
|
||||
/// </summary>
|
||||
Info,
|
||||
|
||||
/// <summary>
|
||||
/// Warnings. Console Color: Yellow
|
||||
/// Warnings. Console Color: Yellow
|
||||
/// </summary>
|
||||
Warning,
|
||||
|
||||
/// <summary>
|
||||
/// Error. Console Color: Red
|
||||
/// Error. Console Color: Red
|
||||
/// </summary>
|
||||
Error
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains the system for logging.
|
||||
/// Contains the system for logging.
|
||||
/// </summary>
|
||||
public class Log
|
||||
{
|
||||
private static StreamWriter _logStream;
|
||||
private static bool _init = false;
|
||||
private static bool _init;
|
||||
|
||||
/// <summary>
|
||||
/// Presets for the log targets.
|
||||
/// Presets for the log targets.
|
||||
/// </summary>
|
||||
public static Dictionary<LogTarget, string> Preset = new Dictionary<LogTarget, string>()
|
||||
public static Dictionary<LogTarget, string> Preset = new Dictionary<LogTarget, string>
|
||||
{
|
||||
{LogTarget.Console, "[%type%] %msg%"},
|
||||
{LogTarget.Debugger, "[%type%] %msg%"},
|
||||
{LogTarget.File, "<%date%, %time%> [%type%] %msg%"}
|
||||
};
|
||||
|
||||
private static readonly Dictionary<LogType, ConsoleColor> Colors = new Dictionary<LogType, ConsoleColor>()
|
||||
private static readonly Dictionary<LogType, ConsoleColor> Colors = new Dictionary<LogType, ConsoleColor>
|
||||
{
|
||||
{LogType.Info, ConsoleColor.Green},
|
||||
{LogType.Warning, ConsoleColor.Yellow},
|
||||
{LogType.Error, ConsoleColor.Red},
|
||||
{LogType.Error, ConsoleColor.Red}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Specified the default target.
|
||||
/// Specified the default target.
|
||||
/// </summary>
|
||||
public static LogTarget DefaultTarget = LogTarget.All;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the log file. At wish compresses the old file to a zip file.
|
||||
/// Sets the log file. At wish compresses the old file to a zip file.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the log file.</param>
|
||||
/// <param name="compressionFolder">Path for the compression, if desired.</param>
|
||||
|
|
@ -106,10 +116,12 @@ namespace SM.Base
|
|||
{
|
||||
if (compressionFolder != "")
|
||||
{
|
||||
DateTime creation = File.GetLastWriteTime(path);
|
||||
if (!Directory.Exists(compressionFolder)) Directory.CreateDirectory(compressionFolder);
|
||||
|
||||
var creation = File.GetLastWriteTime(path);
|
||||
try
|
||||
{
|
||||
using ZipArchive archive =
|
||||
using var archive =
|
||||
ZipFile.Open(
|
||||
$"{compressionFolder}{Path.DirectorySeparatorChar}{Path.GetFileName(path)}_{creation.Year.ToString() + creation.Month + creation.Day}_{creation.Hour.ToString() + creation.Minute + creation.Second + creation.Millisecond}.zip",
|
||||
ZipArchiveMode.Create);
|
||||
|
|
@ -127,11 +139,12 @@ namespace SM.Base
|
|||
_logStream = new StreamWriter(path) {AutoFlush = true};
|
||||
|
||||
Write(LogType.Info, $"Activated new log file. ['{path}']");
|
||||
|
||||
}
|
||||
|
||||
static void Init()
|
||||
internal static void Init()
|
||||
{
|
||||
if (_init) return;
|
||||
|
||||
AppDomain.CurrentDomain.UnhandledException += ExceptionHandler;
|
||||
AppDomain.CurrentDomain.DomainUnload += (sender, args) =>
|
||||
{
|
||||
|
|
@ -139,27 +152,25 @@ namespace SM.Base
|
|||
_logStream.Close();
|
||||
};
|
||||
|
||||
GLDebugging.DebugAction = GLDebugAction;
|
||||
GLDebugging.GlErrorAction = code =>
|
||||
{
|
||||
Write(LogType.Warning, $"A '{code}' GL error occured.");
|
||||
};
|
||||
GLCustomActions.AtKHRDebug = GLDebugAction;
|
||||
GLCustomActions.AtError = err => Write(LogType.Error, err);
|
||||
GLCustomActions.AtWarning = warning => Write(LogType.Warning, warning);
|
||||
GLCustomActions.AtInfo = info => Write(LogType.Info, info);
|
||||
|
||||
_init = true;
|
||||
}
|
||||
|
||||
private static void GLDebugAction(DebugSource source, DebugType type, DebugSeverity severity, string msg)
|
||||
{
|
||||
if (type.HasFlag(DebugType.DebugTypeError))
|
||||
{
|
||||
throw new Exception("[GLError] "+msg);
|
||||
}
|
||||
if (type.HasFlag(DebugType.DebugTypeError)) throw new Exception("[GLError] " + msg);
|
||||
Write(type != DebugType.DontCare ? type.ToString().Substring(9) : "DontCare", ConsoleColor.Gray, msg);
|
||||
}
|
||||
|
||||
[DebuggerStepThrough]
|
||||
private static void ExceptionHandler(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
Write(e.IsTerminating ? "Terminating Error" : LogType.Error.ToString(), e.IsTerminating ? ConsoleColor.DarkRed : ConsoleColor.Red, e.ExceptionObject);
|
||||
Write(e.IsTerminating ? "Terminating Error" : LogType.Error.ToString(),
|
||||
e.IsTerminating ? ConsoleColor.DarkRed : ConsoleColor.Red, e.ExceptionObject);
|
||||
|
||||
if (e.IsTerminating)
|
||||
{
|
||||
|
|
@ -170,30 +181,31 @@ namespace SM.Base
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes multiple lines of the same type to the log.
|
||||
/// Writes multiple lines of the same type to the log.
|
||||
/// </summary>
|
||||
public static void Write<T>(LogType type, params T[] values) => Write<T>(type.ToString(), Colors[type], values);
|
||||
|
||||
/// <summary>
|
||||
/// Writes multiple lines of the same type to the log.
|
||||
/// </summary>
|
||||
public static void Write<T>(string type, ConsoleColor color, params T[] values)
|
||||
public static void Write<T>(LogType type, params T[] values)
|
||||
{
|
||||
for (var i = 0; i < values.Length; i++)
|
||||
{
|
||||
Write(type, color, values[i], DefaultTarget);
|
||||
}
|
||||
Write(type.ToString(), Colors[type], values);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes one line to the log.
|
||||
/// Writes multiple lines of the same type to the log.
|
||||
/// </summary>
|
||||
public static void Write<T>(LogType type, T value, LogTarget target = LogTarget.Default) =>
|
||||
Write<T>(type.ToString(), Colors[type], value, target);
|
||||
public static void Write<T>(string type, ConsoleColor color, params T[] values)
|
||||
{
|
||||
for (var i = 0; i < values.Length; i++) Write(type, color, values[i], DefaultTarget);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes one line to the log.
|
||||
///
|
||||
/// Writes one line to the log.
|
||||
/// </summary>
|
||||
public static void Write<T>(LogType type, T value, LogTarget target = LogTarget.Default)
|
||||
{
|
||||
Write(type.ToString(), Colors[type], value, target);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes one line to the log.
|
||||
/// </summary>
|
||||
public static void Write<T>(string type, ConsoleColor color, T value, LogTarget target = LogTarget.Default)
|
||||
{
|
||||
|
|
@ -209,23 +221,23 @@ namespace SM.Base
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a text with a different color.
|
||||
/// Writes a text with a different color.
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <param name="value"></param>
|
||||
public static void ColorfulWriteLine(ConsoleColor color, string value)
|
||||
{
|
||||
ConsoleColor before = Console.ForegroundColor;
|
||||
var before = Console.ForegroundColor;
|
||||
|
||||
Console.ForegroundColor = color;
|
||||
Console.WriteLine(value);
|
||||
Console.ForegroundColor = before;
|
||||
}
|
||||
|
||||
static string ProcessPreset(LogTarget target, string type, string msg)
|
||||
private static string ProcessPreset(LogTarget target, string type, string msg)
|
||||
{
|
||||
string preset = Preset[target];
|
||||
DateTime now = DateTime.Now;
|
||||
var preset = Preset[target];
|
||||
var now = DateTime.Now;
|
||||
|
||||
return preset.Replace("%date%", now.ToShortDateString())
|
||||
.Replace("%time%", now.ToShortTimeString())
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
using SM.OGL.Mesh;
|
||||
#region usings
|
||||
|
||||
using SM.OGL.Mesh;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Objects
|
||||
{
|
||||
|
|
@ -6,16 +10,16 @@ namespace SM.Base.Objects
|
|||
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.
|
||||
/// While initializing, it will add the <see cref="Color" /> to the data index.
|
||||
/// </summary>
|
||||
protected Mesh()
|
||||
{
|
||||
AttribDataIndex.Add(3, Color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains vertex colors
|
||||
/// </summary>
|
||||
public virtual VBO Color { get; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +1,36 @@
|
|||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
#region usings
|
||||
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.OGL.Mesh;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Objects.Static
|
||||
{
|
||||
/// <summary>
|
||||
/// A basic plate
|
||||
/// A basic plate
|
||||
/// </summary>
|
||||
public class Plate : GenericMesh
|
||||
{
|
||||
/// <summary>
|
||||
/// The object.
|
||||
/// The object.
|
||||
/// </summary>
|
||||
public static Plate Object = new Plate();
|
||||
|
||||
//public override int[] Indices { get; set; } = new[] {0, 1, 2, 3};
|
||||
|
||||
private Plate()
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override VBO Vertex { get; } = new VBO()
|
||||
public override VBO Vertex { get; } = new VBO
|
||||
{
|
||||
{-.5f, -.5f, 0},
|
||||
{-.5f, .5f, 0},
|
||||
{.5f, .5f, 0},
|
||||
{.5f, -.5f, 0},
|
||||
{.5f, -.5f, 0}
|
||||
};
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
@ -30,17 +39,14 @@ namespace SM.Base.Objects.Static
|
|||
{0, 0},
|
||||
{0, 1},
|
||||
{1, 1},
|
||||
{1, 0},
|
||||
{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};
|
||||
|
||||
private Plate() {}
|
||||
public override BoundingBox BoundingBox { get; } =
|
||||
new BoundingBox(new Vector3(-.5f, -.5f, 0), new Vector3(.5f, .5f, 0));
|
||||
}
|
||||
}
|
||||
9
SMCode/SM.Base/PostProcess/DefaultFiles/extensions.frag
Normal file
9
SMCode/SM.Base/PostProcess/DefaultFiles/extensions.frag
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#version 330
|
||||
|
||||
in vec2 vTexture;
|
||||
|
||||
uniform sampler2D renderedTexture;
|
||||
|
||||
vec4 GetRenderColor() {
|
||||
return texture(renderedTexture, vTexture);
|
||||
}
|
||||
14
SMCode/SM.Base/PostProcess/DefaultFiles/vertexFile.vert
Normal file
14
SMCode/SM.Base/PostProcess/DefaultFiles/vertexFile.vert
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#version 330
|
||||
|
||||
layout(location = 0) in vec3 aPos;
|
||||
layout(location = 1) in vec2 aTex;
|
||||
|
||||
uniform mat4 MVP;
|
||||
|
||||
out vec2 vTexture;
|
||||
|
||||
void main() {
|
||||
vTexture = aTex;
|
||||
|
||||
gl_Position = MVP * vec4(aPos, 1);
|
||||
}
|
||||
18
SMCode/SM.Base/PostProcess/DefaultFiles/vertexWithExt.vert
Normal file
18
SMCode/SM.Base/PostProcess/DefaultFiles/vertexWithExt.vert
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#version 330
|
||||
|
||||
layout(location = 0) in vec3 aPos;
|
||||
layout(location = 1) in vec2 aTex;
|
||||
|
||||
uniform mat4 MVP;
|
||||
|
||||
out vec2 vTexture;
|
||||
|
||||
void vertex();
|
||||
|
||||
void main() {
|
||||
vTexture = aTex;
|
||||
|
||||
gl_Position = MVP * vec4(aPos, 1);
|
||||
|
||||
vertex();
|
||||
}
|
||||
30
SMCode/SM.Base/PostProcess/PostProcessEffect.cs
Normal file
30
SMCode/SM.Base/PostProcess/PostProcessEffect.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.Base.Objects.Static;
|
||||
using SM.OGL.Framebuffer;
|
||||
using SM.OGL.Shaders;
|
||||
|
||||
namespace SM.Base.PostProcess
|
||||
{
|
||||
public abstract class PostProcessEffect
|
||||
{
|
||||
internal static Matrix4 Mvp;
|
||||
|
||||
public virtual ICollection<Framebuffer> RequiredFramebuffers { get; }
|
||||
|
||||
public virtual void Init() {}
|
||||
|
||||
public virtual void Init(Framebuffer main)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
public virtual void Draw(Framebuffer main)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
64
SMCode/SM.Base/PostProcess/PostProcessShader.cs
Normal file
64
SMCode/SM.Base/PostProcess/PostProcessShader.cs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.Base.Objects.Static;
|
||||
using SM.OGL.Framebuffer;
|
||||
using SM.OGL.Shaders;
|
||||
using SM.Utility;
|
||||
|
||||
namespace SM.Base.PostProcess
|
||||
{
|
||||
public class PostProcessShader : GenericShader
|
||||
{
|
||||
private static ShaderFile _fragExtensions = new ShaderFile(AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.extensions.frag"));
|
||||
private static ShaderFile _normalVertex = new ShaderFile(AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.vertexFile.vert"));
|
||||
private static string _normalVertexWithExt =
|
||||
AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.vertexWithExt.vert");
|
||||
|
||||
public PostProcessShader(string fragment) : this(_normalVertex,
|
||||
new ShaderFile(fragment)) { }
|
||||
|
||||
public PostProcessShader(string vertexExt, string fragment) : this(new ShaderFile(_normalVertexWithExt)
|
||||
{
|
||||
GLSLExtensions = new List<ShaderFile>() { new ShaderFile(vertexExt) }
|
||||
}, new ShaderFile(fragment)) { }
|
||||
|
||||
private PostProcessShader(ShaderFile vertex, ShaderFile fragment) : base(
|
||||
new ShaderFileCollection(vertex, fragment))
|
||||
{
|
||||
fragment.GLSLExtensions.Add(_fragExtensions);
|
||||
}
|
||||
|
||||
public void Draw(ColorAttachment color)
|
||||
{
|
||||
GL.UseProgram(this);
|
||||
GL.BindVertexArray(Plate.Object);
|
||||
|
||||
Uniforms["MVP"].SetMatrix4(PostProcessEffect.Mvp);
|
||||
Uniforms["renderedTexture"].SetTexture(color, 0);
|
||||
|
||||
GL.DrawArrays(PrimitiveType.Quads, 0, 4);
|
||||
|
||||
GL.BindTexture(TextureTarget.Texture2D, 0);
|
||||
GL.BindVertexArray(0);
|
||||
GL.UseProgram(0);
|
||||
}
|
||||
|
||||
public void Draw(ColorAttachment color, Action<UniformCollection> setUniformAction)
|
||||
{
|
||||
GL.UseProgram(this);
|
||||
GL.BindVertexArray(Plate.Object);
|
||||
|
||||
Uniforms["MVP"].SetMatrix4(PostProcessEffect.Mvp);
|
||||
Uniforms["renderedTexture"].SetTexture(color, 0);
|
||||
|
||||
setUniformAction(Uniforms);
|
||||
|
||||
GL.DrawArrays(PrimitiveType.Quads, 0, 4);
|
||||
|
||||
GL.BindTexture(TextureTarget.Texture2D, 0);
|
||||
GL.BindVertexArray(0);
|
||||
GL.UseProgram(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +1,19 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
#region usings
|
||||
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#endregion
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("SM.Base")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyTitle("Basis for every SMRenderer")]
|
||||
[assembly: AssemblyDescription("SMRenderer-Basis functions")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyCompany("iedSoftworks")]
|
||||
[assembly: AssemblyProduct("SM.Base")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2020")]
|
||||
[assembly: AssemblyCopyright("Copyright © iedSoftworks 2020")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
|
|
@ -33,4 +36,4 @@ using System.Runtime.InteropServices;
|
|||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
|
|
@ -34,8 +34,8 @@
|
|||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="OpenTK, Version=3.2.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OpenTK.3.2\lib\net20\OpenTK.dll</HintPath>
|
||||
<Reference Include="OpenTK, Version=3.2.1.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\OpenTK.3.2.1\lib\net20\OpenTK.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
|
|
@ -43,27 +43,23 @@
|
|||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.IO.Compression.FileSystem" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Controls\Mouse.cs" />
|
||||
<Compile Include="Drawing\DrawingBasis.cs" />
|
||||
<Compile Include="Drawing\GenericTransformation.cs" />
|
||||
<Compile Include="Drawing\Instance.cs" />
|
||||
<Compile Include="Drawing\IShader.cs" />
|
||||
<Compile Include="Drawing\MaterialShader.cs" />
|
||||
<Compile Include="Log.cs" />
|
||||
<Compile Include="Objects\Mesh.cs" />
|
||||
<Compile Include="PostProcessing\PostProcessingEffect.cs" />
|
||||
<Compile Include="PostProcess\PostProcessEffect.cs" />
|
||||
<Compile Include="PostProcess\PostProcessShader.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="ShaderExtension\ExtensionManager.cs" />
|
||||
<Compile Include="SMRenderer.cs" />
|
||||
<Compile Include="Textures\Texture.cs" />
|
||||
<Compile Include="Text\CharParameter.cs" />
|
||||
|
|
@ -81,6 +77,7 @@
|
|||
<Compile Include="Utility\Deltatime.cs" />
|
||||
<Compile Include="Utility\Randomize.cs" />
|
||||
<Compile Include="Utility\RotationUtility.cs" />
|
||||
<Compile Include="Utility\ShaderUtility.cs" />
|
||||
<Compile Include="Window\Contexts\DrawContext.cs" />
|
||||
<Compile Include="Window\Contexts\UpdateContext.cs" />
|
||||
<Compile Include="Window\GenericWindow.cs" />
|
||||
|
|
@ -91,8 +88,9 @@
|
|||
<Compile Include="Window\RenderPipeline.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="OpenTK.dll.config" />
|
||||
<None Include="packages.config" />
|
||||
<EmbeddedResource Include="ShaderExtension\vertex\basic.vert" />
|
||||
<EmbeddedResource Include="PostProcess\DefaultFiles\vertexFile.vert" />
|
||||
<EmbeddedResource Include="PostProcess\DefaultFiles\extensions.frag" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SM.OGL\SM.OGL.csproj">
|
||||
|
|
@ -100,6 +98,15 @@
|
|||
<Name>SM.OGL</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<Folder Include="ShaderExtension\fragment\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="PostProcess\DefaultFiles\vertexWithExt.vert" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="OpenTK.dll.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
|
|
@ -1,33 +1,54 @@
|
|||
using SM.Base.Objects.Static;
|
||||
#region usings
|
||||
|
||||
using SM.Base.Objects.Static;
|
||||
using SM.Base.Scene;
|
||||
using SM.Base.Text;
|
||||
using SM.OGL.Mesh;
|
||||
using SM.OGL.Shaders;
|
||||
using SM.Utility;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains different information about this renderer.
|
||||
/// Contains different information about this renderer.
|
||||
/// </summary>
|
||||
public class SMRenderer
|
||||
{
|
||||
/// <summary>
|
||||
/// The default mesh.
|
||||
/// Defines, how many instances the 'SM_base_vertex_basic'-extension can handle.
|
||||
/// </summary>
|
||||
public const int MaxInstances = 32;
|
||||
|
||||
/// <summary>
|
||||
/// The default mesh.
|
||||
/// </summary>
|
||||
public static GenericMesh DefaultMesh = Plate.Object;
|
||||
|
||||
/// <summary>
|
||||
/// The default font.
|
||||
/// The default font.
|
||||
/// </summary>
|
||||
public static Font DefaultFont;
|
||||
|
||||
/// <summary>
|
||||
/// The default deltatime helper.
|
||||
/// The default deltatime helper.
|
||||
/// </summary>
|
||||
public static Deltatime DefaultDeltatime = new Deltatime();
|
||||
|
||||
public static MaterialShader DefaultMaterialShader;
|
||||
|
||||
/// <summary>
|
||||
/// Current Frame
|
||||
/// Shows more information onto the log system.
|
||||
/// </summary>
|
||||
public static bool AdvancedDebugging = false;
|
||||
|
||||
/// <summary>
|
||||
/// Current Frame
|
||||
/// </summary>
|
||||
public static ulong CurrentFrame { get; internal set; } = 0;
|
||||
|
||||
public static GenericWindow CurrentWindow;
|
||||
public static GenericScene CurrentScene;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,41 +1,52 @@
|
|||
using OpenTK;
|
||||
#region usings
|
||||
|
||||
using OpenTK;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
/// <summary>
|
||||
/// Controller for a camera
|
||||
/// Controller for a camera
|
||||
/// </summary>
|
||||
public abstract class GenericCamera
|
||||
{
|
||||
/// <summary>
|
||||
/// The matrix for the orthographic world.
|
||||
/// The matrix for the orthographic world.
|
||||
/// </summary>
|
||||
public static Matrix4 OrthographicWorld { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// The matrix for the perspective world.
|
||||
/// 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>
|
||||
/// This defines what is up. (Normalized)
|
||||
/// <para>Default: <see cref="Vector3.UnitY" /></para>
|
||||
/// </summary>
|
||||
public static Vector3 UpVector { get; set; } = Vector3.UnitY;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Contains the view matrix of this camera.
|
||||
/// <para>Default: <see cref="Matrix4.Identity"/></para>
|
||||
/// 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.
|
||||
/// Returns the world matrix that is connected to this camera.
|
||||
/// </summary>
|
||||
public Matrix4 World => Orthographic ? OrthographicWorld : PerspectiveWorld;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the view matrix.
|
||||
/// Represents if the camera is orthographic.
|
||||
/// </summary>
|
||||
/// <returns>The calculated view matrix. Same as <see cref="ViewMatrix"/></returns>
|
||||
public abstract bool Orthographic { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the view matrix.
|
||||
/// </summary>
|
||||
/// <returns>The calculated view matrix. Same as <see cref="ViewMatrix" /></returns>
|
||||
internal Matrix4 CalculateViewMatrix()
|
||||
{
|
||||
ViewMatrix = ViewCalculation();
|
||||
|
|
@ -43,18 +54,17 @@ namespace SM.Base.Scene
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// This calculates the view matrix.
|
||||
/// 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>
|
||||
/// <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,TCamera}.ViewportCamera"/> to calculate the world.</para>
|
||||
/// This will calculate the world.
|
||||
/// <para>This is called on <see cref="GenericWindow{TScene,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>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
using System.Collections.Generic;
|
||||
#region usings
|
||||
|
||||
using System.Collections.Generic;
|
||||
using SM.Base.Contexts;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains a list of show items.
|
||||
/// Contains a list of show items.
|
||||
/// </summary>
|
||||
/// <typeparam name="TItem">The type of show items.</typeparam>
|
||||
public abstract class GenericItemCollection<TItem> : List<TItem>, IShowItem, IShowCollection<TItem>
|
||||
|
|
@ -22,8 +26,32 @@ namespace SM.Base.Scene
|
|||
/// <inheritdoc />
|
||||
public ICollection<string> Flags { get; set; } = new[] {"collection"};
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Update(UpdateContext context)
|
||||
{
|
||||
for (var i = 0; i < Objects.Count; i++)
|
||||
this[i].Update(context);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IShowCollection{TItem}.Draw" />
|
||||
public virtual void Draw(DrawContext context)
|
||||
{
|
||||
for (var 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>
|
||||
/// Adds a item.
|
||||
/// Adds a item.
|
||||
/// </summary>
|
||||
public new void Add(TItem item)
|
||||
{
|
||||
|
|
@ -33,7 +61,7 @@ namespace SM.Base.Scene
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a item.
|
||||
/// Removes a item.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
public new void Remove(TItem item)
|
||||
|
|
@ -43,72 +71,46 @@ namespace SM.Base.Scene
|
|||
item.OnRemoved(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Update(UpdateContext context)
|
||||
{
|
||||
for(int i = 0; i < Objects.Count; i++)
|
||||
this[i].Update(context);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IShowCollection{TItem}.Draw" />
|
||||
public virtual void Draw(DrawContext context)
|
||||
{
|
||||
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>
|
||||
/// 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++)
|
||||
{
|
||||
for (var i = 0; i < 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>
|
||||
/// 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);
|
||||
return (TGetItem) GetItemByName(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all object that have this flag.
|
||||
/// <para>Only in this list.</para>
|
||||
/// 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++)
|
||||
var list = new List<TItem>();
|
||||
for (var i = 0; i < Count; i++)
|
||||
{
|
||||
TItem obj = this[i];
|
||||
var obj = this[i];
|
||||
if (obj.Flags.Contains(flag)) list.Add(obj);
|
||||
}
|
||||
|
||||
|
|
@ -117,7 +119,7 @@ namespace SM.Base.Scene
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains a list of show items with transformation.
|
||||
/// 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>
|
||||
|
|
@ -126,7 +128,7 @@ namespace SM.Base.Scene
|
|||
where TTransformation : GenericTransformation, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// Transformation of the collection
|
||||
/// Transformation of the collection
|
||||
/// </summary>
|
||||
public TTransformation Transform = new TTransformation();
|
||||
|
||||
|
|
@ -134,7 +136,7 @@ namespace SM.Base.Scene
|
|||
public override void Draw(DrawContext context)
|
||||
{
|
||||
context.ModelMaster = Transform.GetMatrix() * context.ModelMaster;
|
||||
|
||||
|
||||
base.Draw(context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,22 @@
|
|||
using System;
|
||||
#region usings
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenTK;
|
||||
using System.Dynamic;
|
||||
using SM.Base.Contexts;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
/// <summary>
|
||||
/// A generic scene, that imports functions for scene control.
|
||||
/// A generic scene, that imports functions for scene control.
|
||||
/// </summary>
|
||||
public abstract class GenericScene
|
||||
{
|
||||
private IBackgroundItem _background;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This contains the background.
|
||||
/// This contains the background.
|
||||
/// </summary>
|
||||
protected IBackgroundItem _Background
|
||||
{
|
||||
|
|
@ -24,41 +27,53 @@ namespace SM.Base.Scene
|
|||
_background = value;
|
||||
}
|
||||
}
|
||||
public bool IsInitialized { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Updates this scene.
|
||||
/// Updates this scene.
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
public virtual void Update(UpdateContext context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws this scene.
|
||||
/// Draws this scene.
|
||||
/// </summary>
|
||||
public virtual void Draw(DrawContext context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called, when the user activates the scene.
|
||||
/// Called, when the user activates the scene.
|
||||
/// </summary>
|
||||
internal void Activate()
|
||||
{
|
||||
if (!IsInitialized)
|
||||
{
|
||||
OnInitialization();
|
||||
IsInitialized = true;
|
||||
}
|
||||
|
||||
OnActivating();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called, when the user activates the scene.
|
||||
/// Called, when the user activates the scene for the first time.
|
||||
/// </summary>
|
||||
protected virtual void OnInitialization()
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Called, when the user activates the scene.
|
||||
/// </summary>
|
||||
protected virtual void OnActivating()
|
||||
{ }
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A generic scene that imports different functions.
|
||||
/// 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>
|
||||
|
|
@ -68,25 +83,32 @@ namespace SM.Base.Scene
|
|||
where TCollection : GenericItemCollection<TItem>, new()
|
||||
where TItem : IShowItem
|
||||
{
|
||||
private TCollection _objectCollection = new TCollection();
|
||||
private TCollection _hud = new TCollection();
|
||||
private TCollection _objectCollection = 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>
|
||||
/// A collection for cameras to switch easier to different cameras.
|
||||
/// </summary>
|
||||
public Dictionary<string, TCamera> Cameras = new Dictionary<string, TCamera>();
|
||||
|
||||
/// <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.
|
||||
/// A camera to control the background.
|
||||
/// </summary>
|
||||
public TCamera BackgroundCamera { get; set; } = new TCamera();
|
||||
|
||||
/// <summary>
|
||||
/// A camera to control the HUD.
|
||||
/// A camera to control the HUD.
|
||||
/// </summary>
|
||||
public TCamera HUDCamera { get; set; } = new TCamera();
|
||||
|
||||
/// <summary>
|
||||
/// Objects inside the scene.
|
||||
/// Objects inside the scene.
|
||||
/// </summary>
|
||||
public TCollection Objects
|
||||
{
|
||||
|
|
@ -99,7 +121,7 @@ namespace SM.Base.Scene
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// This defines the HUD objects.
|
||||
/// This defines the HUD objects.
|
||||
/// </summary>
|
||||
public TCollection HUD
|
||||
{
|
||||
|
|
@ -110,10 +132,6 @@ namespace SM.Base.Scene
|
|||
_hud = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// A collection for cameras to switch easier to different cameras.
|
||||
/// </summary>
|
||||
public Dictionary<string, TCamera> Cameras = new Dictionary<string, TCamera>();
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
@ -127,14 +145,28 @@ namespace SM.Base.Scene
|
|||
/// <inheritdoc />
|
||||
public override void Draw(DrawContext context)
|
||||
{
|
||||
if (!context.ForceViewport && Camera != null) context.View = Camera.CalculateViewMatrix();
|
||||
DrawBackground(context);
|
||||
|
||||
DrawContext backgroundDrawContext = context;
|
||||
DrawMainObjects(context);
|
||||
|
||||
DrawHUD(context);
|
||||
}
|
||||
|
||||
public void DrawBackground(DrawContext context)
|
||||
{
|
||||
var backgroundDrawContext = context;
|
||||
backgroundDrawContext.View = BackgroundCamera.CalculateViewMatrix();
|
||||
_Background?.Draw(backgroundDrawContext);
|
||||
}
|
||||
|
||||
public void DrawMainObjects(DrawContext context)
|
||||
{
|
||||
if (!context.ForceViewport && Camera != null) context.View = Camera.CalculateViewMatrix();
|
||||
_objectCollection.Draw(context);
|
||||
}
|
||||
|
||||
public void DrawHUD(DrawContext context)
|
||||
{
|
||||
context.View = HUDCamera.CalculateViewMatrix();
|
||||
_hud.Draw(context);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
namespace SM.Base.Scene
|
||||
{
|
||||
/// <summary>
|
||||
/// A iteration of <see cref="IShowItem"/> to reduce clutter.
|
||||
/// A iteration of <see cref="IShowItem" /> to reduce clutter.
|
||||
/// </summary>
|
||||
public interface IBackgroundItem : IShowItem
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +1,25 @@
|
|||
using System.Collections.Generic;
|
||||
#region usings
|
||||
|
||||
using System.Collections.Generic;
|
||||
using SM.Base.Contexts;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds functions, that is required for a collection.
|
||||
/// 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.
|
||||
/// The object collection.
|
||||
/// </summary>
|
||||
List<TItem> Objects { get; }
|
||||
|
||||
/// <summary>
|
||||
/// This draws the objects in the <see cref="Objects"/> list.
|
||||
/// 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);
|
||||
|
|
|
|||
|
|
@ -1,45 +1,51 @@
|
|||
using System.Collections.Generic;
|
||||
#region usings
|
||||
|
||||
using System.Collections.Generic;
|
||||
using SM.Base.Contexts;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Scene
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds requirements to object, to be properly used as a update and/or draw item.
|
||||
/// Adds requirements to object, to be properly used as a update and/or draw item.
|
||||
/// </summary>
|
||||
public interface IShowItem
|
||||
{
|
||||
/// <summary>
|
||||
/// Parent of the object.
|
||||
/// Parent of the object.
|
||||
/// </summary>
|
||||
object Parent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Contains the name for the object.
|
||||
/// Contains the name for the object.
|
||||
/// </summary>
|
||||
string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Contains specific flags for the object.
|
||||
/// Contains specific flags for the object.
|
||||
/// </summary>
|
||||
ICollection<string> Flags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Tells the object to update own systems.
|
||||
/// 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.
|
||||
/// Tells the object to draw its object.
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
void Draw(DrawContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Action, that is called, when the object was added to a GenericItemCollection.
|
||||
/// 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.
|
||||
/// Action, that is called, when the object was removed from a GenericItemCollection.
|
||||
/// </summary>
|
||||
void OnRemoved(object sender);
|
||||
}
|
||||
|
|
|
|||
19
SMCode/SM.Base/ShaderExtension/ExtensionManager.cs
Normal file
19
SMCode/SM.Base/ShaderExtension/ExtensionManager.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#region usings
|
||||
|
||||
using SM.OGL.Shaders;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.ShaderExtension
|
||||
{
|
||||
internal class ExtensionManager
|
||||
{
|
||||
internal static void InitExtensions()
|
||||
{
|
||||
ShaderExtensions.AddAssemblyExtensions("SM_base", "SM.Base.ShaderExtension");
|
||||
|
||||
ShaderExtensions.Extensions["SM_base_vertex_basic"].StringOverrides["instanceMax"] =
|
||||
SMRenderer.MaxInstances.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
35
SMCode/SM.Base/ShaderExtension/vertex/basic.vert
Normal file
35
SMCode/SM.Base/ShaderExtension/vertex/basic.vert
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#version 330
|
||||
#define maxInstances //!instanceMax
|
||||
|
||||
struct Instance {
|
||||
mat4 ModelMatrix;
|
||||
vec2 TextureOffset;
|
||||
vec2 TextureScale;
|
||||
};
|
||||
|
||||
layout(location = 0) in vec3 aPos;
|
||||
layout(location = 1) in vec2 aTex;
|
||||
layout(location = 3) in vec4 aColor;
|
||||
|
||||
uniform mat4 MVP;
|
||||
uniform bool HasVColor;
|
||||
uniform Instance[maxInstances] Instances;
|
||||
|
||||
out vec2 vTexture;
|
||||
out vec4 vColor;
|
||||
out vec3 FragPos;
|
||||
|
||||
void ApplyTexModifier() {
|
||||
vTexture = aTex * Instances[gl_InstanceID].TextureScale + Instances[gl_InstanceID].TextureOffset;
|
||||
}
|
||||
|
||||
void CheckVertexColor() {
|
||||
if (HasVColor) vColor = aColor;
|
||||
else vColor = vec4(1);
|
||||
}
|
||||
|
||||
void ApplyModelTransformation() {
|
||||
gl_Position = MVP * Instances[gl_InstanceID].ModelMatrix * vec4(aPos, 1);
|
||||
|
||||
FragPos = vec3(Instances[gl_InstanceID].ModelMatrix * vec4(aPos, 1));
|
||||
}
|
||||
|
|
@ -1,28 +1,34 @@
|
|||
using System;
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Text
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains information for a font character.
|
||||
/// Contains information for a font character.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public struct CharParameter
|
||||
{
|
||||
/// <summary>
|
||||
/// The position on the X-axis.
|
||||
/// The position on the X-axis.
|
||||
/// </summary>
|
||||
public int X;
|
||||
|
||||
/// <summary>
|
||||
/// The width of the character.
|
||||
/// The width of the character.
|
||||
/// </summary>
|
||||
public float Width;
|
||||
|
||||
/// <summary>
|
||||
/// The normalized position inside the texture.
|
||||
/// The normalized position inside the texture.
|
||||
/// </summary>
|
||||
public float NormalizedX;
|
||||
|
||||
/// <summary>
|
||||
/// The normalized width inside the texture.
|
||||
/// The normalized width inside the texture.
|
||||
/// </summary>
|
||||
public float NormalizedWidth;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,71 +1,74 @@
|
|||
using System.Collections.Generic;
|
||||
#region usings
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Text;
|
||||
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;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Text
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a font.
|
||||
/// Represents a font.
|
||||
/// </summary>
|
||||
public class Font : Texture
|
||||
{
|
||||
/// <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>
|
||||
/// The char set for the font.
|
||||
/// <para>Default: <see cref="FontCharStorage.SimpleUTF8" /></para>
|
||||
/// </summary>
|
||||
public ICollection<char> CharSet = FontCharStorage.SimpleUTF8;
|
||||
|
||||
/// <summary>
|
||||
/// This contains all information for the different font character.
|
||||
/// The font family, that is used to find the right font.
|
||||
/// </summary>
|
||||
public FontFamily FontFamily;
|
||||
|
||||
/// <summary>
|
||||
/// The font size.
|
||||
/// <para>Default: 12</para>
|
||||
/// </summary>
|
||||
public float FontSize = 12;
|
||||
|
||||
/// <summary>
|
||||
/// The font style.
|
||||
/// <para>Default: <see cref="System.Drawing.FontStyle.Regular" /></para>
|
||||
/// </summary>
|
||||
public FontStyle FontStyle = FontStyle.Regular;
|
||||
|
||||
/// <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.
|
||||
/// 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();
|
||||
var pfc = new PrivateFontCollection();
|
||||
pfc.AddFontFile(path);
|
||||
FontFamily = pfc.Families[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a font from a specified font family.
|
||||
/// Generates a font from a specified font family.
|
||||
/// </summary>
|
||||
/// <param name="font">Font-Family</param>
|
||||
public Font(FontFamily font)
|
||||
{
|
||||
FontFamily = font;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override TextureWrapMode WrapMode { get; set; } = TextureWrapMode.ClampToEdge;
|
||||
|
||||
/// <summary>
|
||||
/// Regenerates the texture.
|
||||
/// Regenerates the texture.
|
||||
/// </summary>
|
||||
public void RegenerateTexture()
|
||||
{
|
||||
|
|
@ -74,47 +77,47 @@ namespace SM.Base.Text
|
|||
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))
|
||||
var map = new Bitmap(1000, 20);
|
||||
var charParams = new Dictionary<char, float[]>();
|
||||
using (var f = new System.Drawing.Font(FontFamily, FontSize, FontStyle))
|
||||
{
|
||||
using (Graphics g = Graphics.FromImage(map))
|
||||
using (var g = Graphics.FromImage(map))
|
||||
{
|
||||
g.Clear(Color.Transparent);
|
||||
|
||||
foreach (char c in CharSet)
|
||||
foreach (var c in CharSet)
|
||||
{
|
||||
string s = c.ToString();
|
||||
SizeF size = g.MeasureString(s, f);
|
||||
var s = c.ToString();
|
||||
var size = g.MeasureString(s, f);
|
||||
try
|
||||
{
|
||||
charParams.Add(c, new[] {size.Width, Width });
|
||||
charParams.Add(c, new[] {size.Width, Width});
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
|
||||
if (Height < size.Height) Height = (int)size.Height;
|
||||
Width += (int)size.Width;
|
||||
if (Height < size.Height) Height = (int) size.Height;
|
||||
Width += (int) size.Width;
|
||||
}
|
||||
}
|
||||
|
||||
map = new Bitmap(Width, Height);
|
||||
using (Graphics g = Graphics.FromImage(map))
|
||||
using (var g = Graphics.FromImage(map))
|
||||
{
|
||||
foreach (KeyValuePair<char, float[]> keyValuePair in charParams)
|
||||
foreach (var keyValuePair in charParams)
|
||||
{
|
||||
float normalizedX = (keyValuePair.Value[1] + 0.00001f) / Width;
|
||||
float normalizedWidth = (keyValuePair.Value[0]) / Width;
|
||||
var normalizedX = (keyValuePair.Value[1] + 0.00001f) / Width;
|
||||
var normalizedWidth = keyValuePair.Value[0] / Width;
|
||||
|
||||
CharParameter parameter;
|
||||
Positions.Add(keyValuePair.Key, parameter = new CharParameter()
|
||||
Positions.Add(keyValuePair.Key, parameter = new CharParameter
|
||||
{
|
||||
NormalizedWidth = normalizedWidth,
|
||||
NormalizedX = normalizedX,
|
||||
Width = keyValuePair.Value[0],
|
||||
X = (int)keyValuePair.Value[1]
|
||||
X = (int) keyValuePair.Value[1]
|
||||
});
|
||||
|
||||
g.DrawString(keyValuePair.Key.ToString(), f, Brushes.White, parameter.X, 0);
|
||||
|
|
|
|||
|
|
@ -1,28 +1,29 @@
|
|||
namespace SM.Data.Fonts
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains default char sets.
|
||||
/// Contains default char sets.
|
||||
/// </summary>
|
||||
public class FontCharStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains the english alphabet and the common special character.
|
||||
/// Contains the english alphabet and the common special character.
|
||||
/// </summary>
|
||||
public static readonly char[] SimpleUTF8 = new char[]
|
||||
public static readonly char[] SimpleUTF8 =
|
||||
{
|
||||
'!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6',
|
||||
'!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5',
|
||||
'6',
|
||||
'7', '8', '9', ':', ';', '<', '=', '>', '?', '@', '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', '[', '\\', ']', '^', '_', '`',
|
||||
'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.
|
||||
/// Contains only numbers.
|
||||
/// </summary>
|
||||
public static readonly char[] Numbers = new[]
|
||||
public static readonly char[] Numbers =
|
||||
{
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +1,49 @@
|
|||
using System;
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base.Scene;
|
||||
using SM.Data.Fonts;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Text
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a basis for text drawing.
|
||||
/// Defines a basis for text drawing.
|
||||
/// </summary>
|
||||
/// <typeparam name="TTransform">Transformation type</typeparam>
|
||||
public abstract class TextDrawingBasis<TTransform> : DrawingBasis<TTransform>
|
||||
where TTransform : GenericTransformation, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// The different instances for drawing.
|
||||
/// The different instances for drawing.
|
||||
/// </summary>
|
||||
protected Instance[] _instances;
|
||||
|
||||
/// <summary>
|
||||
/// The text, that is drawn.
|
||||
/// The text, that is drawn.
|
||||
/// </summary>
|
||||
protected string _text;
|
||||
|
||||
/// <summary>
|
||||
/// The font.
|
||||
/// 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The font.
|
||||
/// </summary>
|
||||
public Font Font
|
||||
{
|
||||
|
|
@ -37,7 +56,7 @@ namespace SM.Base.Text
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// The text, that is drawn.
|
||||
/// The text, that is drawn.
|
||||
/// </summary>
|
||||
public string Text
|
||||
{
|
||||
|
|
@ -50,7 +69,7 @@ namespace SM.Base.Text
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// The font color.
|
||||
/// The font color.
|
||||
/// </summary>
|
||||
public Color4 Color
|
||||
{
|
||||
|
|
@ -58,21 +77,6 @@ namespace SM.Base.Text
|
|||
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 />
|
||||
protected override void DrawContext(ref DrawContext context)
|
||||
|
|
@ -81,7 +85,7 @@ namespace SM.Base.Text
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// This generates the instances.
|
||||
/// 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()
|
||||
|
|
@ -91,7 +95,7 @@ namespace SM.Base.Text
|
|||
_instances = new Instance[_text.Length];
|
||||
|
||||
float x = 0;
|
||||
CharParameter _last = new CharParameter();
|
||||
var _last = new CharParameter();
|
||||
for (var i = 0; i < _text.Length; i++)
|
||||
{
|
||||
if (_text[i] == 32)
|
||||
|
|
@ -99,7 +103,7 @@ namespace SM.Base.Text
|
|||
x += _last.Width * Spacing;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
CharParameter parameter;
|
||||
try
|
||||
{
|
||||
|
|
@ -110,15 +114,15 @@ namespace SM.Base.Text
|
|||
throw new Exception("Font doesn't contain '" + _text[i] + "'");
|
||||
}
|
||||
|
||||
Matrix4 matrix = Matrix4.CreateScale(parameter.Width, Font.Height, 1) *
|
||||
Matrix4.CreateTranslation(x, 0, 0);
|
||||
var matrix = Matrix4.CreateScale(parameter.Width, Font.Height, 1) *
|
||||
Matrix4.CreateTranslation(x, 0, 0);
|
||||
_instances[i] = new Instance
|
||||
{
|
||||
ModelMatrix = matrix,
|
||||
TexturePosition = new Vector2(parameter.NormalizedX, 0),
|
||||
TextureScale = new Vector2(parameter.NormalizedWidth, 1)
|
||||
};
|
||||
|
||||
|
||||
x += parameter.Width * Spacing;
|
||||
_last = parameter;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,38 +1,48 @@
|
|||
using System.Drawing;
|
||||
#region usings
|
||||
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.OGL.Texture;
|
||||
using PixelFormat = System.Drawing.Imaging.PixelFormat;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Textures
|
||||
{
|
||||
/// <summary>
|
||||
/// Texture that can be drawn to an object.
|
||||
/// 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.
|
||||
/// Decides if the bitmap will automatically dispose itself.
|
||||
/// </summary>
|
||||
public bool AutoDispose = false;
|
||||
|
||||
/// <summary>
|
||||
/// Empty constructor
|
||||
/// The texture as bitmap.
|
||||
/// </summary>
|
||||
protected Texture() {}
|
||||
public Bitmap Map;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a texture with only the map.
|
||||
/// <para>Sets the filter to Linear and WrapMode to Repeat.</para>
|
||||
/// 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) {}
|
||||
public Texture(Bitmap map) : this(map, TextureMinFilter.Linear, TextureWrapMode.Repeat)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the texture.
|
||||
/// Creates the texture.
|
||||
/// </summary>
|
||||
/// <param name="map">The texture map</param>
|
||||
/// <param name="filter">The filter</param>
|
||||
|
|
@ -62,22 +72,23 @@ namespace SM.Base.Textures
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a OpenGL-texture.
|
||||
/// 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)
|
||||
public static int GenerateTexture(Bitmap map, TextureMinFilter filter, TextureWrapMode wrapMode,
|
||||
bool dispose = false)
|
||||
{
|
||||
int id = GL.GenTexture();
|
||||
var id = GL.GenTexture();
|
||||
GL.BindTexture(TextureTarget.Texture2D, id);
|
||||
|
||||
BitmapData data = map.LockBits(new Rectangle(0, 0, map.Width, map.Height), ImageLockMode.ReadOnly,
|
||||
var data = map.LockBits(new Rectangle(0, 0, map.Width, map.Height), ImageLockMode.ReadOnly,
|
||||
map.PixelFormat);
|
||||
|
||||
bool transparenz = map.PixelFormat == PixelFormat.Format32bppArgb;
|
||||
var transparenz = map.PixelFormat == PixelFormat.Format32bppArgb;
|
||||
|
||||
GL.TexImage2D(TextureTarget.Texture2D, 0,
|
||||
transparenz ? PixelInternalFormat.Rgba : PixelInternalFormat.Rgb,
|
||||
|
|
@ -85,10 +96,10 @@ namespace SM.Base.Textures
|
|||
transparenz ? OpenTK.Graphics.OpenGL4.PixelFormat.Bgra : OpenTK.Graphics.OpenGL4.PixelFormat.Bgr,
|
||||
PixelType.UnsignedByte, data.Scan0);
|
||||
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)filter);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)filter);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)wrapMode);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)wrapMode);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) filter);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) filter);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int) wrapMode);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int) wrapMode);
|
||||
|
||||
GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
|
||||
|
||||
|
|
@ -101,8 +112,11 @@ namespace SM.Base.Textures
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a bitmap to a texture.
|
||||
/// Converts a bitmap to a texture.
|
||||
/// </summary>
|
||||
public static implicit operator Texture(Bitmap map) => new Texture(map);
|
||||
public static implicit operator Texture(Bitmap map)
|
||||
{
|
||||
return new Texture(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,14 @@
|
|||
using System;
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
using SM.Base.Contexts;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Time
|
||||
{
|
||||
/// <summary>
|
||||
/// Performs intervals.
|
||||
/// Performs intervals.
|
||||
/// </summary>
|
||||
public class Interval : Timer
|
||||
{
|
||||
|
|
@ -24,13 +28,14 @@ namespace SM.Base.Time
|
|||
protected override void Stopping(UpdateContext context)
|
||||
{
|
||||
TriggerEndAction(context);
|
||||
if (_stop){base.Stop();}
|
||||
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>
|
||||
/// 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()
|
||||
{
|
||||
|
|
@ -38,7 +43,7 @@ namespace SM.Base.Time
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will stop the interval immediately.
|
||||
/// This will stop the interval immediately.
|
||||
/// </summary>
|
||||
public void Cancel()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,22 +1,26 @@
|
|||
using System.Collections.Generic;
|
||||
#region usings
|
||||
|
||||
using System.Collections.Generic;
|
||||
using SM.Base.Contexts;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Time
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a stopwatch.
|
||||
/// 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)
|
||||
/// Contains how much time already has passed. (in seconds)
|
||||
/// </summary>
|
||||
public float Elapsed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Starts the stopwatch.
|
||||
/// Starts the stopwatch.
|
||||
/// </summary>
|
||||
public virtual void Start()
|
||||
{
|
||||
|
|
@ -24,7 +28,7 @@ namespace SM.Base.Time
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs a tick.
|
||||
/// Performs a tick.
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
private protected virtual void Tick(UpdateContext context)
|
||||
|
|
@ -33,7 +37,7 @@ namespace SM.Base.Time
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the stopwatch.
|
||||
/// Stops the stopwatch.
|
||||
/// </summary>
|
||||
public virtual void Stop()
|
||||
{
|
||||
|
|
@ -41,7 +45,7 @@ namespace SM.Base.Time
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the stopwatch.
|
||||
/// Resets the stopwatch.
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
|
|
@ -50,10 +54,7 @@ namespace SM.Base.Time
|
|||
|
||||
internal static void PerformTicks(UpdateContext context)
|
||||
{
|
||||
for (var i = 0; i < _activeStopwatches.Count; i++)
|
||||
{
|
||||
_activeStopwatches[i].Tick(context);
|
||||
}
|
||||
for (var i = 0; i < _activeStopwatches.Count; i++) _activeStopwatches[i].Tick(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
using SM.Base.Contexts;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Time
|
||||
{
|
||||
/// <summary>
|
||||
/// Timer-System
|
||||
/// 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.
|
||||
/// Creates a timer with specified seconds.
|
||||
/// </summary>
|
||||
/// <param name="seconds"></param>
|
||||
public Timer(float seconds)
|
||||
|
|
@ -34,14 +22,29 @@ namespace SM.Base.Time
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a timer with a time span.
|
||||
/// Creates a timer with a time span.
|
||||
/// </summary>
|
||||
/// <param name="timeSpan"></param>
|
||||
public Timer(TimeSpan timeSpan)
|
||||
{
|
||||
Target = (float)timeSpan.TotalSeconds;
|
||||
Target = (float) timeSpan.TotalSeconds;
|
||||
}
|
||||
|
||||
/// <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;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Start()
|
||||
{
|
||||
|
|
@ -58,15 +61,16 @@ namespace SM.Base.Time
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs, when the timer tries to stop.
|
||||
/// 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"/>
|
||||
/// This will trigger <see cref="EndAction" />
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
protected void TriggerEndAction(UpdateContext context)
|
||||
|
|
|
|||
|
|
@ -1,146 +1,145 @@
|
|||
using System;
|
||||
using System.Configuration.Assemblies;
|
||||
#region usings
|
||||
|
||||
using System.Diagnostics;
|
||||
using OpenTK;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a base vector-class
|
||||
/// 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.
|
||||
/// 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.
|
||||
/// 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;
|
||||
_X = x;
|
||||
_Y = y;
|
||||
_Z = z;
|
||||
_W = w;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The X-component.
|
||||
/// </summary>
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||
protected float _X { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The Y-component
|
||||
/// </summary>
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||
protected float _Y { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The Z-component.
|
||||
/// </summary>
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||
protected float _Z { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The W-component.
|
||||
/// </summary>
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||
protected float _W { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Transforms a <see cref="CVector" /> to a <see cref="OpenTK.Vector2" />
|
||||
/// </summary>
|
||||
public static implicit operator Vector2(CVector v) => new Vector2(v._X, v._Y);
|
||||
|
||||
/// <summary>
|
||||
/// Transforms a <see cref="CVector" /> to a <see cref="OpenTK.Vector3" />
|
||||
/// </summary>
|
||||
public static implicit operator Vector3(CVector v) => new Vector3(v._X, v._Y, v._Z);
|
||||
|
||||
/// <summary>
|
||||
/// Transforms a <see cref="CVector" /> to a <see cref="OpenTK.Vector4" />
|
||||
/// </summary>
|
||||
public static implicit operator Vector4(CVector v) => new Vector4(v._X, v._Y, v._Z, v._W);
|
||||
|
||||
#region Set
|
||||
|
||||
/// <summary>
|
||||
/// Sets the X and Y-component.
|
||||
/// 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"/>
|
||||
/// Sets the X and Y-component from a <see cref="OpenTK.Vector2" />
|
||||
/// </summary>
|
||||
protected void Set(OpenTK.Vector2 vector)
|
||||
protected void Set(Vector2 vector)
|
||||
{
|
||||
Set(vector.X, vector.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the X, Y and Z-component.
|
||||
/// Sets the X, Y and Z-component.
|
||||
/// </summary>
|
||||
protected void Set(float x, float y, float z)
|
||||
{
|
||||
Set(x,y);
|
||||
Set(x, y);
|
||||
_Z = z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the X, Y and Z-component from a <see cref="OpenTK.Vector3"/>.
|
||||
/// Sets the X, Y and Z-component from a <see cref="OpenTK.Vector3" />.
|
||||
/// </summary>
|
||||
/// <param name="vector"></param>
|
||||
protected void Set(OpenTK.Vector3 vector)
|
||||
protected void Set(Vector3 vector)
|
||||
{
|
||||
Set(vector.X, vector.Y, vector.Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the X, Y, Z and W-component.
|
||||
/// Sets the X, Y, Z and W-component.
|
||||
/// </summary>
|
||||
protected void Set(float x, float y, float z, float w)
|
||||
{
|
||||
Set(x,y,z);
|
||||
Set(x, y, z);
|
||||
_W = w;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the X, Y, Z and W-component from a <see cref="OpenTK.Vector4"/>.
|
||||
/// Sets the X, Y, Z and W-component from a <see cref="OpenTK.Vector4" />.
|
||||
/// </summary>
|
||||
protected void Set(OpenTK.Vector4 vector)
|
||||
protected void Set(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.
|
||||
/// Adds a <see cref="OpenTK.Vector2" /> to the X and Y-component.
|
||||
/// </summary>
|
||||
protected void Add(OpenTK.Vector2 vector)
|
||||
protected void Add(Vector2 vector)
|
||||
{
|
||||
_X += vector.X;
|
||||
_Y += vector.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref="OpenTK.Vector3"/> to the X, Y and Z-component.
|
||||
/// Adds a <see cref="OpenTK.Vector3" /> to the X, Y and Z-component.
|
||||
/// </summary>
|
||||
protected void Add(OpenTK.Vector3 vector)
|
||||
protected void Add(Vector3 vector)
|
||||
{
|
||||
_X += vector.X;
|
||||
_Y += vector.Y;
|
||||
|
|
@ -148,9 +147,9 @@ namespace SM.Base.Types
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref="OpenTK.Vector4"/> to the X, Y, Z and W-component.
|
||||
/// Adds a <see cref="OpenTK.Vector4" /> to the X, Y, Z and W-component.
|
||||
/// </summary>
|
||||
protected void Add(OpenTK.Vector4 vector)
|
||||
protected void Add(Vector4 vector)
|
||||
{
|
||||
_X += vector.X;
|
||||
_Y += vector.Y;
|
||||
|
|
@ -159,18 +158,5 @@ namespace SM.Base.Types
|
|||
}
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +1,47 @@
|
|||
namespace SM.Base.Types
|
||||
#region usings
|
||||
|
||||
using OpenTK;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a vector of two floats.
|
||||
/// Represents a vector of two floats.
|
||||
/// </summary>
|
||||
public class CVector2 : CVector
|
||||
{
|
||||
/// <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>
|
||||
/// X-component
|
||||
/// X-component
|
||||
/// </summary>
|
||||
public float X
|
||||
{
|
||||
get => _X;
|
||||
set => _X = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Y-component
|
||||
/// Y-component
|
||||
/// </summary>
|
||||
public float Y
|
||||
{
|
||||
|
|
@ -22,35 +49,30 @@
|
|||
set => _Y = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public CVector2() : this(0)
|
||||
{}
|
||||
|
||||
/// <inheritdoc />
|
||||
public CVector2(float uniform) : base(uniform)
|
||||
/// <summary>
|
||||
/// Sets the X and Y-component.
|
||||
/// </summary>
|
||||
public new void Set(float x, float y)
|
||||
{
|
||||
|
||||
base.Set(x, y);
|
||||
}
|
||||
|
||||
/// <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 from a <see cref="OpenTK.Vector2" />
|
||||
/// </summary>
|
||||
public new void Set(Vector2 vector)
|
||||
{
|
||||
base.Set(vector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the X and Y-component.
|
||||
/// Adds a <see cref="OpenTK.Vector2" /> to the X and Y-component.
|
||||
/// </summary>
|
||||
public new void Set(float x, float y) => base.Set(x, y);
|
||||
public new void Add(Vector2 vector)
|
||||
{
|
||||
base.Add(vector);
|
||||
}
|
||||
|
||||
/// <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);
|
||||
public static implicit operator CVector2(Vector2 v) => new CVector2(v.X,v.Y);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +1,33 @@
|
|||
using System.Drawing.Design;
|
||||
using System.Runtime.InteropServices;
|
||||
#region usings
|
||||
|
||||
using OpenTK;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a Vector of three floats.
|
||||
/// Represents a Vector of three floats.
|
||||
/// </summary>
|
||||
public class CVector3 : CVector2
|
||||
{
|
||||
/// <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>
|
||||
/// Z-component
|
||||
/// Z-component
|
||||
/// </summary>
|
||||
public float Z
|
||||
{
|
||||
|
|
@ -18,29 +35,28 @@ namespace SM.Base.Types
|
|||
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.
|
||||
/// 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);
|
||||
public new void Set(float x, float y, float z)
|
||||
{
|
||||
base.Set(x, y, z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref="OpenTK.Vector3"/> to the X, Y and Z-component.
|
||||
/// Sets the X, Y and Z-component from a <see cref="OpenTK.Vector3" />.
|
||||
/// </summary>
|
||||
public new void Add(Vector3 vector) => base.Add(vector);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +1,16 @@
|
|||
using OpenTK;
|
||||
#region usings
|
||||
|
||||
using OpenTK;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a vector of four floats.
|
||||
/// 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)
|
||||
{
|
||||
|
|
@ -27,16 +22,36 @@ namespace SM.Base.Types
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the X, Y, Z and W-component.
|
||||
/// W-component
|
||||
/// </summary>
|
||||
public new void Set(float x, float y, float z, float w) => base.Set(x, y, z, w);
|
||||
public float W
|
||||
{
|
||||
get => _W;
|
||||
set => _W = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the X, Y, Z and W-component from a <see cref="OpenTK.Vector4"/>.
|
||||
/// Sets the X, Y, Z and W-component.
|
||||
/// </summary>
|
||||
public new void Set(Vector4 vector) => base.Set(vector);
|
||||
public new void Set(float x, float y, float z, float w)
|
||||
{
|
||||
base.Set(x, y, z, w);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref="OpenTK.Vector4"/> to the X, Y, Z and W-component.
|
||||
/// Sets the X, Y, Z and W-component from a <see cref="OpenTK.Vector4" />.
|
||||
/// </summary>
|
||||
public new void Add(Vector4 vector) => base.Add(vector);
|
||||
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,43 +1,60 @@
|
|||
using System;
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains utility functions for handling with assemblies.
|
||||
/// Contains utility functions for handling with assemblies.
|
||||
/// </summary>
|
||||
public class AssemblyUtility
|
||||
{
|
||||
/// <summary>
|
||||
/// Read a file that is saved in a assembly
|
||||
/// Read a file that is saved in a assembly
|
||||
/// </summary>
|
||||
/// <param name="ass">The assembly that contains the file</param>
|
||||
/// <param name="path">The path to the file inside the assembly</param>
|
||||
/// <returns></returns>
|
||||
public static string ReadAssemblyFile(Assembly ass, string path) { return new StreamReader(GetAssemblyStream(ass, path)).ReadToEnd(); }
|
||||
public static string ReadAssemblyFile(Assembly ass, string path)
|
||||
{
|
||||
return new StreamReader(GetAssemblyStream(ass, path)).ReadToEnd();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a file that is saved in the calling assembly
|
||||
/// Read a file that is saved in the calling assembly
|
||||
/// </summary>
|
||||
/// <param name="path">The path to the file inside the assembly</param>
|
||||
/// <returns></returns>
|
||||
public static string ReadAssemblyFile(string path) { return ReadAssemblyFile(Assembly.GetCallingAssembly(), path); }
|
||||
public static string ReadAssemblyFile(string path)
|
||||
{
|
||||
return ReadAssemblyFile(Assembly.GetCallingAssembly(), path);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns a stream of a requested resource.
|
||||
/// 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 + "'."); }
|
||||
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.
|
||||
/// 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); }
|
||||
public static Stream GetAssemblyStream(string path)
|
||||
{
|
||||
return GetAssemblyStream(Assembly.GetCallingAssembly(), path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,46 +1,49 @@
|
|||
namespace SM.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// A assistant to control the delta time.
|
||||
/// 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>
|
||||
/// Scaling of the delta time.
|
||||
/// <para>Default: 1</para>
|
||||
/// </summary>
|
||||
public float Scale;
|
||||
|
||||
/// <summary>
|
||||
/// The calculated delta time.
|
||||
/// If true, it uses <see cref="RenderDelta" />, otherwise <see cref="UpdateDelta" />.
|
||||
/// <para>Default: false</para>
|
||||
/// </summary>
|
||||
public float DeltaTime => (UseRender ? RenderDelta : UpdateDelta) * Scale;
|
||||
public bool UseRender;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a delta time assistant.
|
||||
/// 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)
|
||||
/// <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;
|
||||
Scale = scale;
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// The calculated delta time.
|
||||
/// </summary>
|
||||
public float DeltaTime => (UseRender ? RenderDelta : UpdateDelta) * Scale;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,53 +1,84 @@
|
|||
using System;
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// A global helper class for randomization.
|
||||
/// A global helper class for randomization.
|
||||
/// </summary>
|
||||
public class Randomize
|
||||
{
|
||||
/// <summary>
|
||||
/// The randomizer.
|
||||
/// The randomizer.
|
||||
/// </summary>
|
||||
public static Random Randomizer = new Random();
|
||||
|
||||
/// <summary>
|
||||
/// Sets the seed for the randomizer.
|
||||
/// 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 void SetSeed(int seed)
|
||||
{
|
||||
Randomizer = new Random(seed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a double and checks if its under the tolerance.
|
||||
/// Generates a double and checks if its under the tolerance.
|
||||
/// </summary>
|
||||
public static bool GetBool(float tolerance) { return Randomizer.NextDouble() < tolerance; }
|
||||
public static bool GetBool(float tolerance)
|
||||
{
|
||||
return Randomizer.NextDouble() < tolerance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a integer.
|
||||
/// 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); }
|
||||
public static int GetInt()
|
||||
{
|
||||
return Randomizer.Next();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a float between 0 and 1.
|
||||
/// Generates a integer with a maximum.
|
||||
/// </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; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +1,24 @@
|
|||
using System;
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
using OpenTK;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Utilitys for rotations
|
||||
/// Utilitys for rotations
|
||||
/// </summary>
|
||||
public class RotationUtility
|
||||
{
|
||||
/// <summary>
|
||||
/// Angle towards an coordinate.
|
||||
/// 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));
|
||||
return MathHelper.RadiansToDegrees((float) Math.Atan2(target.Y - origin.Y, target.X - origin.X));
|
||||
}
|
||||
}
|
||||
}
|
||||
7
SMCode/SM.Base/Utility/ShaderUtility.cs
Normal file
7
SMCode/SM.Base/Utility/ShaderUtility.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
namespace SM.Utility
|
||||
{
|
||||
public class ShaderUtility
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,61 +1,71 @@
|
|||
using System.Collections.Generic;
|
||||
#region usings
|
||||
|
||||
using OpenTK;
|
||||
using SM.Base.Scene;
|
||||
using SM.OGL.Mesh;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Contexts
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains important information for drawing.
|
||||
/// Contains important information for drawing.
|
||||
/// </summary>
|
||||
public struct DrawContext
|
||||
{
|
||||
/// <summary>
|
||||
/// This says if it was forced to use the viewport camera.
|
||||
/// This says if it was forced to use the viewport camera.
|
||||
/// </summary>
|
||||
public bool ForceViewport;
|
||||
|
||||
/// <summary>
|
||||
/// The current world matrix.
|
||||
/// The current world matrix.
|
||||
/// </summary>
|
||||
public Matrix4 World;
|
||||
|
||||
/// <summary>
|
||||
/// The current view matrix.
|
||||
/// The current view matrix.
|
||||
/// </summary>
|
||||
public Matrix4 View;
|
||||
|
||||
/// <summary>
|
||||
/// The master model matrix.
|
||||
/// The master model matrix.
|
||||
/// </summary>
|
||||
public Matrix4 ModelMaster;
|
||||
|
||||
/// <summary>
|
||||
/// The drawing instances.
|
||||
/// <para>If there is only one, it's index 0</para>
|
||||
/// The drawing instances.
|
||||
/// <para>If there is only one, it's index 0</para>
|
||||
/// </summary>
|
||||
public Instance[] Instances;
|
||||
|
||||
/// <summary>
|
||||
/// The mesh.
|
||||
/// The mesh.
|
||||
/// </summary>
|
||||
public GenericMesh Mesh;
|
||||
|
||||
/// <summary>
|
||||
/// The material.
|
||||
/// The material.
|
||||
/// </summary>
|
||||
public Material Material;
|
||||
|
||||
/// <summary>
|
||||
/// Contains the currently used render pipeline.
|
||||
/// Contains the currently used render pipeline.
|
||||
/// </summary>
|
||||
public RenderPipeline ActivePipeline;
|
||||
|
||||
/// <summary>
|
||||
/// The current world scale.
|
||||
/// The current world scale.
|
||||
/// </summary>
|
||||
public Vector2 WorldScale;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the appropriate shader.
|
||||
/// <para>Returns the material shader, if available, otherwise it will take the default shader from the render pipeline.</para>
|
||||
/// Returns the appropriate shader.
|
||||
/// <para>
|
||||
/// Returns the material shader, if available, otherwise it will take the default shader from the render
|
||||
/// pipeline.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public IShader Shader => Material.CustomShader ?? ActivePipeline._defaultShader;
|
||||
public MaterialShader Shader => Material.CustomShader ?? ActivePipeline._defaultShader;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +1,28 @@
|
|||
using OpenTK.Input;
|
||||
using SM.Utility;
|
||||
#region usings
|
||||
|
||||
using OpenTK.Input;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base.Contexts
|
||||
{
|
||||
/// <summary>
|
||||
/// The update context.
|
||||
/// The update context.
|
||||
/// </summary>
|
||||
public struct UpdateContext
|
||||
{
|
||||
/// <summary>
|
||||
/// The delta time.
|
||||
/// The delta time.
|
||||
/// </summary>
|
||||
public float Deltatime => SMRenderer.DefaultDeltatime.DeltaTime;
|
||||
|
||||
/// <summary>
|
||||
/// The current keyboard state.
|
||||
/// The current keyboard state.
|
||||
/// </summary>
|
||||
public KeyboardState KeyboardState;
|
||||
|
||||
/// <summary>
|
||||
/// The current mouse state.
|
||||
/// The current mouse state.
|
||||
/// </summary>
|
||||
public MouseState MouseState;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,53 +1,86 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using OpenTK.Input;
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base.Objects.Static;
|
||||
using SM.Base.PostProcess;
|
||||
using SM.Base.Scene;
|
||||
using SM.Base.ShaderExtension;
|
||||
using SM.Base.Time;
|
||||
using SM.OGL;
|
||||
using SM.OGL.Shaders;
|
||||
using SM.OGL.Framebuffer;
|
||||
using SM.Utility;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base
|
||||
{
|
||||
/// <summary>
|
||||
/// The base window.
|
||||
/// The base window.
|
||||
/// </summary>
|
||||
public abstract class GenericWindow : GameWindow
|
||||
{
|
||||
private bool _loading = false;
|
||||
|
||||
private bool _loading;
|
||||
|
||||
/// <summary>
|
||||
/// This tells you the current world scale.
|
||||
/// This tells you the current world scale.
|
||||
/// </summary>
|
||||
protected Vector2 _worldScale = Vector2.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// This tells you the current aspect ratio of this window.
|
||||
/// This tells you the current aspect ratio of this window.
|
||||
/// </summary>
|
||||
public float Aspect { get; private set; } = 0f;
|
||||
public float Aspect { get; private set; }
|
||||
|
||||
public bool ReactWhileUnfocused = false;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected GenericWindow() : base(1280, 720, GraphicsMode.Default, "Generic OGL Title", GameWindowFlags.Default,
|
||||
DisplayDevice.Default, 0, 0, GraphicsContextFlags.Default, null, true)
|
||||
{ }
|
||||
protected GenericWindow() : this(1280, 720, "Generic OGL Title", GameWindowFlags.Default)
|
||||
{
|
||||
}
|
||||
|
||||
protected GenericWindow(int width, int height, string title, GameWindowFlags flags, bool vSync = true) : base(width, height,
|
||||
GraphicsMode.Default, title, flags, DisplayDevice.Default, GLSettings.ForcedVersion.MajorVersion,
|
||||
GLSettings.ForcedVersion.MinorVersion, GraphicsContextFlags.Default)
|
||||
{
|
||||
VSync = vSync ? VSyncMode.On : VSyncMode.Off;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
GLSystem.INIT_SYSTEM();
|
||||
GLSettings.ShaderPreProcessing = true;
|
||||
|
||||
var args = Environment.GetCommandLineArgs();
|
||||
if (args.Contains("--advDebugging"))
|
||||
{
|
||||
SMRenderer.AdvancedDebugging = true;
|
||||
GLSettings.InfoEveryUniform = true;
|
||||
}
|
||||
|
||||
Log.Init();
|
||||
|
||||
Log.Write("#", ConsoleColor.Cyan, "----------------------",
|
||||
"--- OpenGL Loading ---",
|
||||
"----------------------------------",
|
||||
$"--- {"DeviceVersion",14}: {GLSystem.DeviceVersion,-10} ---",
|
||||
$"--- {"ForcedVersion",14}: {GLSystem.ForcedVersion,-10} ---",
|
||||
$"--- {"ForcedVersion",14}: {GLSettings.ForcedVersion,-10} ---",
|
||||
$"--- {"ShadingVersion",14}: {GLSystem.ShadingVersion,-10} ---",
|
||||
$"--- {"Debugging",14}: {GLSystem.Debugging,-10} ---",
|
||||
$"----------------------------------");
|
||||
$"--- {"AdvDebugging",14}: {SMRenderer.AdvancedDebugging,-10} ---",
|
||||
"----------------------------------");
|
||||
|
||||
if (SMRenderer.AdvancedDebugging) Log.Write("Extension", ConsoleColor.DarkCyan, GLSystem.Extensions);
|
||||
|
||||
ExtensionManager.InitExtensions();
|
||||
|
||||
base.OnLoad(e);
|
||||
_loading = true;
|
||||
|
|
@ -58,7 +91,7 @@ namespace SM.Base
|
|||
{
|
||||
base.OnResize(e);
|
||||
|
||||
Aspect = (float)Width / Height;
|
||||
Aspect = (float) Width / Height;
|
||||
_worldScale = new Vector2(Width, Height);
|
||||
SetWorldScale();
|
||||
GL.Viewport(ClientRectangle);
|
||||
|
|
@ -71,25 +104,28 @@ namespace SM.Base
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is triggered after all the window-loading has been done.
|
||||
/// This is triggered after all the window-loading has been done.
|
||||
/// </summary>
|
||||
protected virtual void OnLoaded()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the world scale.
|
||||
/// Sets the world scale.
|
||||
/// </summary>
|
||||
protected virtual void SetWorldScale() { }
|
||||
protected virtual void SetWorldScale()
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnUpdateFrame(FrameEventArgs e)
|
||||
{
|
||||
if (!ReactWhileUnfocused && !Focused) return;
|
||||
|
||||
base.OnUpdateFrame(e);
|
||||
|
||||
Deltatime.UpdateDelta = (float)e.Time;
|
||||
UpdateContext context = new UpdateContext()
|
||||
|
||||
Deltatime.UpdateDelta = (float) e.Time;
|
||||
var context = new UpdateContext
|
||||
{
|
||||
KeyboardState = Keyboard.GetState(),
|
||||
MouseState = Mouse.GetState()
|
||||
|
|
@ -99,7 +135,7 @@ namespace SM.Base
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the system.
|
||||
/// Updates the system.
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
/// <param name="context"></param>
|
||||
|
|
@ -109,7 +145,7 @@ namespace SM.Base
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grabs the cursor and make sure it doesn't leave the window.
|
||||
/// 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)
|
||||
|
|
@ -119,17 +155,42 @@ namespace SM.Base
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ungrabs the cursor.
|
||||
/// Ungrabs the cursor.
|
||||
/// </summary>
|
||||
public void UngrabCursor()
|
||||
{
|
||||
CursorGrabbed = false;
|
||||
if (!CursorVisible) CursorVisible = true;
|
||||
}
|
||||
|
||||
public Bitmap TakeScreenshot(Framebuffer framebuffer, ReadBufferMode readBuffer, int x, int y, int width, int height)
|
||||
{
|
||||
GL.GetInteger(GetPName.FramebufferBinding, out int prevFBId);
|
||||
GL.GetInteger(GetPName.DrawFramebufferBinding, out int prevFBDrawId);
|
||||
GL.GetInteger(GetPName.ReadFramebufferBinding, out int prevFBReadId);
|
||||
|
||||
Bitmap b = new Bitmap(width, height);
|
||||
System.Drawing.Imaging.BitmapData bits = b.LockBits(new Rectangle(0, 0, width, height),
|
||||
System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
|
||||
GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, framebuffer);
|
||||
GL.ReadBuffer(readBuffer);
|
||||
GL.ReadPixels(x, y, width, height, OpenTK.Graphics.OpenGL4.PixelFormat.Bgra, PixelType.UnsignedByte,
|
||||
bits.Scan0);
|
||||
|
||||
b.UnlockBits(bits);
|
||||
b.RotateFlip(RotateFlipType.RotateNoneFlipY);
|
||||
|
||||
GL.BindFramebuffer(FramebufferTarget.Framebuffer, prevFBId);
|
||||
GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, prevFBDrawId);
|
||||
GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, prevFBReadId);
|
||||
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The base window.
|
||||
/// The base window.
|
||||
/// </summary>
|
||||
/// <typeparam name="TScene">The scene type</typeparam>
|
||||
/// <typeparam name="TCamera">The camera type</typeparam>
|
||||
|
|
@ -137,31 +198,32 @@ namespace SM.Base
|
|||
where TScene : GenericScene, new()
|
||||
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; }
|
||||
|
||||
/// <summary>
|
||||
/// Controls how a scene is rendered.
|
||||
/// </summary>
|
||||
public RenderPipeline<TScene> RenderPipeline { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected GenericWindow()
|
||||
{
|
||||
ViewportCamera = new TCamera();
|
||||
}
|
||||
|
||||
/// <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; }
|
||||
|
||||
/// <summary>
|
||||
/// Controls how a scene is rendered.
|
||||
/// </summary>
|
||||
public RenderPipeline<TScene> RenderPipeline { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(FrameEventArgs e, ref UpdateContext context)
|
||||
{
|
||||
|
|
@ -172,15 +234,21 @@ namespace SM.Base
|
|||
/// <inheritdoc />
|
||||
protected override void OnRenderFrame(FrameEventArgs e)
|
||||
{
|
||||
if (!ReactWhileUnfocused && !Focused) return;
|
||||
|
||||
SMRenderer.CurrentFrame++;
|
||||
|
||||
Deltatime.RenderDelta = (float)e.Time;
|
||||
DrawContext drawContext = new DrawContext()
|
||||
Deltatime.RenderDelta = (float) e.Time;
|
||||
var 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 } },
|
||||
Instances = new[]
|
||||
{
|
||||
new Instance
|
||||
{ModelMatrix = Matrix4.Identity, TexturePosition = Vector2.Zero, TextureScale = Vector2.One}
|
||||
},
|
||||
Mesh = Plate.Object,
|
||||
ForceViewport = ForceViewportCamera,
|
||||
WorldScale = _worldScale
|
||||
|
|
@ -202,10 +270,14 @@ namespace SM.Base
|
|||
|
||||
ViewportCamera.RecalculateWorld(_worldScale, Aspect);
|
||||
RenderPipeline.Resize();
|
||||
|
||||
PostProcessEffect.Mvp = Matrix4.CreateScale(_worldScale.X, -_worldScale.Y, 1) *
|
||||
Matrix4.LookAt(0, 0, 1, 0, 0, 0, 0, 1, 0) *
|
||||
GenericCamera.OrthographicWorld;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the scene.
|
||||
/// Sets the scene.
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
public virtual void SetScene(TScene scene)
|
||||
|
|
@ -215,7 +287,7 @@ namespace SM.Base
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines the render pipeline.
|
||||
/// Defines the render pipeline.
|
||||
/// </summary>
|
||||
/// <param name="pipeline"></param>
|
||||
public void SetRenderPipeline(RenderPipeline<TScene> pipeline)
|
||||
|
|
|
|||
|
|
@ -1,70 +1,79 @@
|
|||
using System.Collections.Generic;
|
||||
#region usings
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base.Scene;
|
||||
using SM.OGL.Framebuffer;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace SM.Base
|
||||
{
|
||||
/// <summary>
|
||||
/// Definition of specific render options.
|
||||
/// Definition of specific render options.
|
||||
/// </summary>
|
||||
public abstract class RenderPipeline
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The framebuffers, that are used in this Pipeline.
|
||||
/// The framebuffers, that are used in this Pipeline.
|
||||
/// </summary>
|
||||
protected virtual List<Framebuffer> _framebuffers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The default shader for the pipeline.
|
||||
/// </summary>
|
||||
protected internal virtual IShader _defaultShader { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Occurs, when the window is loading.
|
||||
/// The default shader for the pipeline.
|
||||
/// </summary>
|
||||
protected internal virtual MaterialShader _defaultShader { get; } = SMRenderer.DefaultMaterialShader;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs, when the window is loading.
|
||||
/// </summary>
|
||||
protected internal virtual void Load()
|
||||
{
|
||||
foreach (Framebuffer framebuffer in _framebuffers)
|
||||
framebuffer.Compile();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs, when the window is resizing.
|
||||
/// Occurs, when the window is resizing.
|
||||
/// </summary>
|
||||
protected internal virtual void Resize()
|
||||
{ }
|
||||
{
|
||||
if (_framebuffers == null) return;
|
||||
|
||||
foreach (var framebuffer in _framebuffers)
|
||||
framebuffer.Dispose();
|
||||
|
||||
Thread.Sleep(50);
|
||||
|
||||
foreach (Framebuffer framebuffer in _framebuffers)
|
||||
{
|
||||
framebuffer.Compile();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs, when the pipeline was connected to a window.
|
||||
/// Occurs, when the pipeline was connected to a window.
|
||||
/// </summary>
|
||||
protected internal virtual void Activate(GenericWindow window)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs, when the window is unloading.
|
||||
/// Occurs, when the window is unloading.
|
||||
/// </summary>
|
||||
protected internal virtual void Unload()
|
||||
{
|
||||
foreach (Framebuffer framebuffer in _framebuffers)
|
||||
{
|
||||
framebuffer.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a render pipeline.
|
||||
/// Represents a render pipeline.
|
||||
/// </summary>
|
||||
/// <typeparam name="TScene">The scene type</typeparam>
|
||||
public abstract class RenderPipeline<TScene> : RenderPipeline
|
||||
where TScene : GenericScene
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The system to render stuff.
|
||||
/// The system to render stuff.
|
||||
/// </summary>
|
||||
protected internal virtual void Render(ref DrawContext context, TScene scene)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="OpenTK" version="3.2" targetFramework="net452" />
|
||||
<package id="OpenTK" version="3.2.1" targetFramework="net452" />
|
||||
</packages>
|
||||
Loading…
Add table
Add a link
Reference in a new issue