public void lineRenderTeapot() { var lines = new List <List <(Vector2, Vector2, Color)> >(); var verts = ObjFileLoader.LoadVertsFromObjAtPath(new System.IO.FileInfo("../../../../../geometry_models/teapot.obj")) .Select(x => Vector4.Add(x, new Vector4(5, 5, 0, 0))).ToArray(); var tris = ObjFileLoader.LoadTrisFromObjAtPath(new System.IO.FileInfo("../../../../../geometry_models/teapot.obj")); var trilines = tris.SelectMany(x => new List <(Vector2, Vector2, Color)>() { (new Vector2(verts[x.vertIndexList[0] - 1].X * 50, verts[x.vertIndexList[0] - 1].Y * 50), new Vector2(verts[x.vertIndexList[1] - 1].X * 50, verts[x.vertIndexList[1] - 1].Y * 50), Color.White), (new Vector2(verts[x.vertIndexList[1] - 1].X * 50, verts[x.vertIndexList[1] - 1].Y * 50), new Vector2(verts[x.vertIndexList[2] - 1].X * 50, verts[x.vertIndexList[2] - 1].Y * 50), Color.White), (new Vector2(verts[x.vertIndexList[2] - 1].X * 50, verts[x.vertIndexList[2] - 1].Y * 50), new Vector2(verts[x.vertIndexList[0] - 1].X * 50, verts[x.vertIndexList[0] - 1].Y * 50), Color.White), } ); lines.Add(trilines.ToList()); var renderer = new LineRenderer2d(640, 480, lines); var image = new ppmImage(640, 480, 255); image.Colors = renderer.Render(); Assert.AreEqual(18702, image.Colors.Where(x => x == Color.White).Count()); System.IO.File.WriteAllBytes("../../../linetest_teapot.ppm", image.toByteArray()); }
public void lineRender2dsimpleLines() { var lines = new List <List <(Vector2, Vector2, Color)> >() { new List <(Vector2, Vector2, Color)> { (new Vector2(13, 20), new Vector2(80, 40), Color.White), (new Vector2(20, 13), new Vector2(40, 80), Color.White), (new Vector2(80, 40), new Vector2(80, 480), Color.White), (new Vector2(0, 0), new Vector2(320, 240), Color.White) } }; var renderer = new LineRenderer2d(640, 480, lines); var image = new ppmImage(640, 480, 255); image.Colors = renderer.Render(); Assert.AreEqual(930, image.Colors.Where(x => x == Color.White).Count()); System.IO.File.WriteAllBytes("../../../linetest.ppm", image.toByteArray()); }
public void LoadComplexOBJTestAsMesh2() { //scale and offset all verts. //flip verts since image top is 0,0 var mesh = ObjFileLoader.LoadMeshFromObjAtPath(new System.IO.FileInfo("../../../../../geometry_models/knot3/knot3.obj")); var tris = mesh.Triangles; mesh.VertexData = mesh.VertexData.Select(x => Vector4.Multiply(x, new Vector4(1.0f, 1.0f, 1.0f, 1.0f))) //scale and offset. .Select(x => Vector4.Multiply(Vector4.Add(x, new Vector4(5, 5, 0, 0)), 120)).ToArray(); var verts = mesh.VertexData; var lines = new List <List <(Vector2, Vector2, Color)> >(); var trilines = tris.SelectMany(x => new List <(Vector2, Vector2, Color)>() { (new Vector2(verts[x.vertIndexList[0] - 1].X, verts[x.vertIndexList[0] - 1].Y), new Vector2(verts[x.vertIndexList[1] - 1].X, verts[x.vertIndexList[1] - 1].Y), Color.White), (new Vector2(verts[x.vertIndexList[1] - 1].X, verts[x.vertIndexList[1] - 1].Y), new Vector2(verts[x.vertIndexList[2] - 1].X, verts[x.vertIndexList[2] - 1].Y), Color.White), (new Vector2(verts[x.vertIndexList[2] - 1].X, verts[x.vertIndexList[2] - 1].Y), new Vector2(verts[x.vertIndexList[0] - 1].X, verts[x.vertIndexList[0] - 1].Y), Color.White), } ); lines.Add(trilines.ToList()); var renderer = new LineRenderer2d(1024, 768, lines); var image = new ppmImage(1024, 768, 255); image.Colors = renderer.Render(); Assert.AreEqual(38703, image.Colors.Where(x => x == Color.White).Count()); System.IO.File.WriteAllBytes("../../../objLoaderTest2.ppm", image.toByteArray()); }
public void lineRender2dArrayedCircle() { var lines = new List <List <(Vector2, Vector2, Color)> >(); var center = new Vector2(100, 300); var points = Enumerable.Range(0, 360).Select(x => new Vector2( (float)(center.X + 100 * Math.Cos(x * (Math.PI / 180.0))), (float)(center.Y + 100 * Math.Sin(x * (Math.PI / 180.0)))) ); var pairs = points.Select(x => (center, x, Color.White)); lines.Add(pairs.ToList()); var renderer = new LineRenderer2d(640, 480, lines); var image = new ppmImage(640, 480, 255); image.Colors = renderer.Render(); Assert.AreEqual(24390, image.Colors.Where(x => x == Color.White).Count()); System.IO.File.WriteAllBytes("../../../linetest_circle.ppm", image.toByteArray()); }