绘制三角形,要保证三个点可以构成三角形,本方法是绘制了三条相连的线段。
示例代码如下:
- public Material material;
- void OnPostRender ()
- {
- if (!material) {
- Debug.LogError ("请给材质赋值");
- return;
- }
- material.SetPass (0);
- GL.LoadOrtho ();//把绘制的对象显示在平面上
- GL.Begin (GL.LINES);//划线
- //三个顶点要顺时针排列
- DrawLines (30, 0, 100, 250);
- DrawLines (100, 250, 200, 100);
- DrawLines (200, 100, 30, 0);
- GL.End ();
- }
- void DrawLines (float x1, float y1, float x2, float y2)
- {
- //注意GL.Vertex 与GL.Vertex3的区别
- GL.Vertex (new Vector3 (x1 / Screen.width, y1 / Screen.height, 0));
- GL.Vertex (new Vector3 (x2 / Screen.width, y2 / Screen.height, 0));
- }
这个脚本要挂载在摄像机上。

博客介绍了绘制三角形的方法,需保证三点构成三角形,通过绘制三条相连线段实现。给出了示例代码,包括材质赋值、绘制对象显示设置、划线等操作,还提到脚本要挂载在摄像机上。
4234

被折叠的 条评论
为什么被折叠?



