绘制三角形,保证三个点要能构成三角形。
示例代码如下:
- public Material mat;
- void OnPostRender ()
- {
- DrawTriangle (30, 0, 100, 250, 200, 100, mat);//三角形的三个定点坐标
- }
- void DrawTriangle (float x1, float y1, float x2, float y2, float x3, float y3, Material mat)
- {
- GL.PushMatrix ();
- mat.SetPass (0);
- GL.LoadOrtho ();//把绘制对象显示在平面上
- GL.Begin (GL.TRIANGLES);//绘制三角形
- //GL.Begin (GL.LINES);//绘制线
- //三个点的顺序是顺时针方向
- GL.Vertex3 (x1 / Screen.width, y1 / Screen.height, 0);
- GL.Vertex3 (x2 / Screen.width, y2 / Screen.height, 0);
- GL.Vertex3 (x3 / Screen.width, y3 / Screen.height, 0);
- GL.End ();
- GL.PopMatrix ();
- }
这个脚本要挂载在摄像机上。