DoogeJ / MonoGame.Primitives2D

Easy-to-use 2D primitives
https://www.nuget.org/packages/MonoGame.Primitives2D/
zlib License
54 stars 12 forks source link

Add a triangle method #2

Open DoogeJ opened 4 years ago

DoogeJ commented 4 years ago

Triangles are useful!

It would be nice to have a version with line thickness and a solid one.

https://en.wikipedia.org/wiki/Triangle

https://gamedev.stackexchange.com/questions/31047/how-do-i-draw-a-single-triangle-with-xna-and-fill-it-with-a-texture

http://rbwhitaker.wikidot.com/drawing-triangles

DoogeJ commented 4 years ago

Better: https://github.com/RudeySH/Shapes2D

DoogeJ commented 4 years ago

This draws a (secretly 3D) triangle:

VertexPositionColor[] _vertexPositionColors = new[]
{
    new VertexPositionColor(new Vector3(0, 1, 0), Color.Red),
    new VertexPositionColor(new Vector3(1, -1, 0), Color.Green),
    new VertexPositionColor(new Vector3(-1, -1, 0), Color.Blue)
};
BasicEffect effect = new BasicEffect(GraphicsDevice);
effect.World = Matrix.Identity;
effect.View = Matrix.CreateLookAt(new Vector3(0, 0, 5), Vector3.Zero, Vector3.Up);
float aspect = (float)Window.ClientBounds.Width / (float)Window.ClientBounds.Height;
effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspect, 1, 100);
effect.VertexColorEnabled = true;
effect.CurrentTechnique.Passes[0].Apply();
GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, _vertexPositionColors, 0, 1);