static void DrawTri(MyVertexPoint _p0, MyVertexPoint _p1, MyVertexPoint _p2, MyShader shader) { Vector3 p0 = shader.VertexShader(_p0).position; Vector3 p1 = shader.VertexShader(_p1).position; Vector3 p2 = shader.VertexShader(_p2).position; char tag = _p0.tag; float minx = Math.Min(p0.x, p1.x); float maxx = Math.Max(p0.x, p1.x); float miny = Math.Min(p0.y, p1.y); float maxy = Math.Max(p0.y, p1.y); minx = Math.Min(minx, p2.x); maxx = Math.Max(maxx, p2.x); miny = Math.Min(miny, p2.y); maxy = Math.Max(maxy, p2.y); for (int i = (int)minx; i < (int)maxx; i++) { for (int j = (int)miny; j < (int)maxy; j++) { if (i < 0 || i >= 80) continue; if (j < 0 || j >= 25) continue; Vector3 p = new Vector3(i, j, 0); if (PointinTriangle(p0, p1, p2, p)) { MyVertexPoint _p = new MyVertexPoint(p, tag); Console.SetCursorPosition(i, j); Console.Write(shader.PixelShader(_p)); } } } }
static void Main(string[] args) { int w = 80; int h = 24; Random r = new Random(); MyVertexPoint t1 = new MyVertexPoint(new Vector3(-5, -5, 0), '0'); MyVertexPoint t2 = new MyVertexPoint(new Vector3(-5, 5, 0), '0'); MyVertexPoint t3 = new MyVertexPoint(new Vector3(5, 5, 0), '0'); MyVertexPoint t11 = new MyVertexPoint(new Vector3(-5, -5, 0), '1'); MyVertexPoint t12 = new MyVertexPoint(new Vector3(5, -5, 0), '1'); MyVertexPoint t13 = new MyVertexPoint(new Vector3(5, 5, 0), '1'); List <MyVertexPoint> vec3 = new List <MyVertexPoint>(); vec3.Add(t1); vec3.Add(t2); vec3.Add(t3); vec3.Add(t11); vec3.Add(t12); vec3.Add(t13); MyShader shader = new MyShader(); shader.mat = new Matrix(); shader.mat.m14 = 40; shader.mat.m24 = 15; float rotate = 0; float jump = 0; float scale = 0f; while (true) { rotate += 0.1f; //旋转 jump += 2; //跳跃 if (jump > 10) { jump = 0; } scale += 0.3f; if (scale > 2.0f) { scale = 0f; } float rscale = Math.Abs(scale - 1.0f) + 1.0f;//我眯眯眼 shader.mat.m11 = (float)Math.Cos(rotate) * rscale; shader.mat.m12 = (float)-Math.Sin(rotate); shader.mat.m21 = (float)Math.Sin(rotate); shader.mat.m22 = (float)Math.Cos(rotate) / rscale; shader.mat.m24 = 15 - Math.Abs(jump - 5); Console.Clear(); for (int i = 0; i < vec3.Count / 3; i++) { DrawTri(vec3[i * 3 + 0], vec3[i * 3 + 1], vec3[i * 3 + 2], shader); } System.Threading.Thread.Sleep(100); } }
static void Main(string[] args) { int w = 80; int h = 24; Random r = new Random(); MyVertexPoint t1 = new MyVertexPoint(new Vector3(-5, -5, 0), '0'); MyVertexPoint t2 = new MyVertexPoint(new Vector3(-5, 5, 0), '0'); MyVertexPoint t3 = new MyVertexPoint(new Vector3(5, 5, 0), '0'); MyVertexPoint t11 = new MyVertexPoint(new Vector3(-5, -5, 0), '1'); MyVertexPoint t12 = new MyVertexPoint(new Vector3(5, -5, 0), '1'); MyVertexPoint t13 = new MyVertexPoint(new Vector3(5, 5, 0), '1'); List<MyVertexPoint> vec3 = new List<MyVertexPoint>(); vec3.Add(t1); vec3.Add(t2); vec3.Add(t3); vec3.Add(t11); vec3.Add(t12); vec3.Add(t13); MyShader shader = new MyShader(); shader.mat = new Matrix(); shader.mat.m14 = 40; shader.mat.m24 = 15; float rotate = 0; float jump = 0; float scale = 0f; while (true) { rotate += 0.1f;//旋转 jump += 2;//跳跃 if (jump > 10) jump = 0; scale += 0.3f; if (scale > 2.0f) scale = 0f; float rscale = Math.Abs(scale - 1.0f) + 1.0f;//我眯眯眼 shader.mat.m11 = (float)Math.Cos(rotate) * rscale; shader.mat.m12 = (float)-Math.Sin(rotate); shader.mat.m21 = (float)Math.Sin(rotate); shader.mat.m22 = (float)Math.Cos(rotate) / rscale; shader.mat.m24 = 15 -Math.Abs(jump-5); Console.Clear(); for (int i = 0; i < vec3.Count / 3; i++) { DrawTri(vec3[i * 3 + 0], vec3[i * 3 + 1], vec3[i * 3 + 2], shader); } System.Threading.Thread.Sleep(100); } }
static void Main(string[] args) { int w = 80; int h = 24; Random r = new Random(); MyVertexPoint t1 = new MyVertexPoint(new Vector3(-5, -5, 0), '0'); MyVertexPoint t2 = new MyVertexPoint(new Vector3(-5, 5, 0), '0'); MyVertexPoint t3 = new MyVertexPoint(new Vector3(5, 5, 0), '0'); MyVertexPoint t11 = new MyVertexPoint(new Vector3(-5, -5, 0), '1'); MyVertexPoint t12 = new MyVertexPoint(new Vector3(5, -5, 0), '1'); MyVertexPoint t13 = new MyVertexPoint(new Vector3(5, 5, 0), '1'); List<MyVertexPoint> vec3 = new List<MyVertexPoint>(); vec3.Add(t1); vec3.Add(t2); vec3.Add(t3); vec3.Add(t11); vec3.Add(t12); vec3.Add(t13); MyShader shader = new MyShader(); shader.mat = new Matrix(); shader.mat.m14 = 40; shader.mat.m24 = 10; float rotate = 0; while (true) { rotate += 0.1f; shader.mat.m11 = (float)Math.Cos(rotate);//旋转 shader.mat.m12 = (float)-Math.Sin(rotate); shader.mat.m21 = (float)Math.Sin(rotate); shader.mat.m22 = (float)Math.Cos(rotate); Console.Clear(); for (int i = 0; i < vec3.Count / 3; i++) { DrawTri(vec3[i * 3 + 0], vec3[i * 3 + 1], vec3[i * 3 + 2], shader); } System.Threading.Thread.Sleep(100); } }
static void DrawTri(MyVertexPoint _p0, MyVertexPoint _p1, MyVertexPoint _p2, MyShader shader) { Vector3 p0 = shader.VertexShader(_p0).position; Vector3 p1 = shader.VertexShader(_p1).position; Vector3 p2 = shader.VertexShader(_p2).position; char tag = _p0.tag; float minx = Math.Min(p0.x, p1.x); float maxx = Math.Max(p0.x, p1.x); float miny = Math.Min(p0.y, p1.y); float maxy = Math.Max(p0.y, p1.y); minx = Math.Min(minx, p2.x); maxx = Math.Max(maxx, p2.x); miny = Math.Min(miny, p2.y); maxy = Math.Max(maxy, p2.y); for (int i = (int)minx; i < (int)maxx; i++) { for (int j = (int)miny; j < (int)maxy; j++) { if (i < 0 || i >= 80) { continue; } if (j < 0 || j >= 25) { continue; } Vector3 p = new Vector3(i, j, 0); if (PointinTriangle(p0, p1, p2, p)) { MyVertexPoint _p = new MyVertexPoint(p, tag); Console.SetCursorPosition(i, j); Console.Write(shader.PixelShader(_p)); } } } }
protected override void OnLoad(EventArgs e) { Bindings.OpenTK.SLSharp.Init(); _myShader = Shader.CreateSharedShader <MyShader>(); }