30 lines
		
	
	
		
			979 B
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			979 B
		
	
	
	
		
			C#
		
	
	
	
	
	
using System.Collections.Generic;
 | 
						|
 | 
						|
using Engine.Core;
 | 
						|
 | 
						|
namespace Engine.Integration.MonoGame;
 | 
						|
 | 
						|
public class DrawableShape : Behaviour2D, IDrawableTriangle, IPreDraw
 | 
						|
{
 | 
						|
    private readonly Shape2D shape = new([]);
 | 
						|
    private readonly List<Triangle> worldTriangles = [];
 | 
						|
    private readonly Shape2D worldShape = new([]);
 | 
						|
    protected ColorRGB color = new(255, 255, 255);
 | 
						|
 | 
						|
    public void PreDraw() => UpdateWorldShape();
 | 
						|
 | 
						|
    public void Draw(ITriangleBatch triangleBatch)
 | 
						|
    {
 | 
						|
        worldShape.ToTrianglesConvex(worldTriangles);
 | 
						|
 | 
						|
        foreach (Triangle triangle in worldTriangles)
 | 
						|
            triangleBatch.Draw(new(triangle.C, triangle.B, triangle.A), color);
 | 
						|
    }
 | 
						|
 | 
						|
    protected void UpdateWorldShape() => shape.Transform(Transform, worldShape);
 | 
						|
 | 
						|
    public DrawableShape() => shape = Shape2D.Triangle;
 | 
						|
    public DrawableShape(Shape2D shape) => this.shape = shape;
 | 
						|
    public DrawableShape(Shape2D shape, ColorRGB color) { this.shape = shape; this.color = color; }
 | 
						|
}
 |