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

@ -0,0 +1,35 @@
using System.Collections.Generic;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL4;
using SM.Base.Objects;
using SM.OGL.Mesh;
namespace SM2D.Object
{
public enum PolyLineType
{
NotConnected = 1,
Connected = 3,
ConnectedLoop = 2
}
public class PolyLine : Polygon, ILineMesh
{
public float LineWidth { get; set; } = 1;
public PolyLine(ICollection<Vector2> vertices, PolyLineType lineType = PolyLineType.NotConnected) : base(vertices)
{
UVs.Active = false;
PrimitiveType = (PrimitiveType)lineType;
}
public PolyLine(ICollection<PolygonVertex> vertices, PolyLineType lineType = PolyLineType.NotConnected) : base(vertices)
{
UVs.Active = false;
PrimitiveType = (PrimitiveType)lineType;
}
}
}

View file

@ -16,13 +16,16 @@ namespace SM2D.Object
{
public Polygon(ICollection<Vector2> vertices) : base(PrimitiveType.TriangleFan)
{
Color.Active = false;
foreach (var vertex in vertices)
{
Color.Add(Color4.White);
AddVertex(vertex);
Vertex.Add(vertex, 0);
}
foreach (var vertex in vertices) AddUV(vertex);
UpdateBoundingBox();
if (UVs.Active) foreach (var vertex in vertices) AddUV(vertex);
}
public Polygon(ICollection<PolygonVertex> vertices) : base(PrimitiveType.TriangleFan)
@ -30,10 +33,12 @@ namespace SM2D.Object
foreach (var polygonVertex in vertices)
{
Color.Add(polygonVertex.Color);
AddVertex(polygonVertex.Vertex);
Vertex.Add(polygonVertex.Vertex, 0);
}
foreach (var vertex in vertices) AddUV(vertex.Vertex);
UpdateBoundingBox();
if (UVs.Active) foreach (var vertex in vertices) AddUV(vertex.Vertex);
}
public override VBO Vertex { get; protected set; } = new VBO();
@ -42,12 +47,6 @@ namespace SM2D.Object
public override PrimitiveType PrimitiveType { get; protected set; } = PrimitiveType.TriangleFan;
private void AddVertex(Vector2 vertex)
{
BoundingBox.Update(vertex);
Vertex.Add(vertex, 0);
}
private void AddUV(Vector2 vertex)
{
var uv = Vector2.Divide(vertex - BoundingBox.Min.Xy, BoundingBox.Max.Xy - BoundingBox.Min.Xy);