Loads and loads of small improvements I added while developing on my game

This commit is contained in:
Michel Fedde 2021-03-02 19:54:19 +01:00
parent 41421b1df9
commit a7c71e7ea1
107 changed files with 2278 additions and 1023 deletions

View file

@ -2,6 +2,7 @@
using System;
using OpenTK;
using OpenTK.Graphics.OpenGL;
#endregion
@ -47,9 +48,35 @@ namespace SM.OGL.Mesh
/// <param name="y">If true, it takes the Y-value of maximum, otherwise the minimum.</param>
/// <param name="z">If true, it takes the Z-value of maximum, otherwise the minimum.</param>
/// <returns></returns>
public Vector3 this[bool x, bool y, bool z] =>
new Vector3(x ? Max.X : Min.X, y ? Max.Y : Min.Y, z ? Max.Z : Min.Z);
public Vector3 this[bool x, bool y, bool z] => Get(x,y,z);
public Vector3 Get(bool x, bool y, bool z)
{
return new Vector3(x ? Max.X : Min.X, y ? Max.Y : Min.Y, z ? Max.Z : Min.Z);
}
public Vector3 Get(bool xyz) => Get(xyz, xyz, xyz);
public Vector3 Get(Matrix4 transformation, bool x, bool y, bool z)
{
Vector3 get = Get(x, y, z);
return (new Vector4(get, 1) * transformation).Xyz;
}
public Vector3 Get(Matrix4 transformation, bool xyz) => Get(transformation, xyz, xyz, xyz);
public void Update(GenericMesh mesh)
{
int pos = 0;
foreach (float f in mesh.Vertex)
{
Min[pos] = Math.Min(Min[pos], f);
Max[pos] = Math.Max(Max[pos], f);
pos++;
pos %= mesh.Vertex.PointerSize;
}
}
/// <summary>
/// Updates the bounding box.
/// </summary>

View file

@ -13,6 +13,9 @@ namespace SM.OGL.Mesh
/// </summary>
public abstract class GenericMesh : GLObject
{
private bool _boundingBoxUpdated = false;
public static int LastID { get; internal set; } = -1;
/// <summary>
/// Generates the AttribDataIndex
@ -69,14 +72,28 @@ namespace SM.OGL.Mesh
/// </summary>
public virtual int[] Indices { get; set; }
public void UpdateBoundingBox()
{
BoundingBox.Update(this);
_boundingBoxUpdated = true;
}
public void Activate()
{
GL.BindVertexArray(ID);
}
/// <inheritdoc />
public override void Compile()
{
_id = GL.GenVertexArray();
GL.BindVertexArray(_id);
if (Attributes == null || Attributes.Count == 0) throw new Exception("[Critical] The model requires attributes.");
if (!_boundingBoxUpdated)
UpdateBoundingBox();
foreach (var kvp in Attributes)
kvp.ConnectedVBO?.BindBuffer(kvp.Index);

View file

@ -0,0 +1,7 @@
namespace SM.OGL.Mesh
{
public interface ILineMesh
{
float LineWidth { get; set; }
}
}

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using OpenTK.Graphics.OpenGL;
namespace SM.OGL.Mesh
{
@ -50,5 +51,11 @@ namespace SM.OGL.Mesh
//if (vbo == null) return;
Add(new MeshAttribute(id, name, vbo));
}
public bool Has(string name)
{
VBO attribute = this[name];
return attribute != null && attribute.Active;
}
}
}

View file

@ -40,6 +40,8 @@ namespace SM.OGL.Mesh
/// </summary>
public int PointerStride;
public bool Active = true;
/// <summary>
/// Specifies the data type of each component in the array.
/// </summary>
@ -133,6 +135,14 @@ namespace SM.OGL.Mesh
Add(vector.X, vector.Y, z, w);
}
public void Add(params Vector2[] vectors)
{
foreach (Vector2 vector in vectors)
{
Add(vector);
}
}
/// <summary>
/// Adds a Vector3.
/// </summary>
@ -149,6 +159,13 @@ namespace SM.OGL.Mesh
Add(vector.X, vector.Y, vector.Z, w);
}
public void Add(params Vector3[] vectors)
{
foreach (Vector3 vector in vectors)
{
Add(vector);
}
}
/// <summary>
/// Adds a vector4.
/// </summary>
@ -172,6 +189,8 @@ namespace SM.OGL.Mesh
/// <param name="attribID">The id for the attribute.</param>
internal void BindBuffer(int attribID)
{
if (!Active) return;
var data = ToArray();
var buffer = GL.GenBuffer();