Unity GL画折线
新建一个脚本,这个物体得挂在有摄像机组件的物体上才能生效
OnPostRender() 这个函数才会被自动调用(类似生命周期自动调用)
然后就可以代码画线了,原理是openGL的画线
using UnityEngine;
using System.Collections;
using System.Collections.Generic; /// <summary>
/// GL画图
/// </summary>
public class GLDraw : UnityNormalSingleton<GLDraw> { public Transform p1;
public Transform p2;
private List<Vector2> pointList;
private bool isOpen; private Material mat;
private Shader shader; private void Start()
{
pointList = new List<Vector2>();
shader = Shader.Find("Unlit/Color");
mat = new Material(shader);
mat.SetColor("Main Color", Color.black);
} public void DrawLine(List<object> list)
{
pointList.Clear();
for (int i = ; i < list.Count; i++)
{
Vector2 screenPos = (Vector2)list[i];
pointList.Add(new Vector2(screenPos.x, Screen.height - screenPos.y));
}
} public void ShowLine(bool b)
{
isOpen = b;
} void OnPostRender()
{
if (!isOpen)
{
return;
} //mat = new Material(Shader.Find("Unlit/Color"));
//Debug.Log("调用");
//if (!mat)
//{
// Debug.LogError("Please Assign a material on the inspector");
// return;
//}
GL.PushMatrix(); //保存当前Matirx
mat.SetPass(); //刷新当前材质
GL.LoadPixelMatrix();//设置pixelMatrix
GL.Color(Color.yellow);
GL.Begin(GL.LINES); //画2次,奇偶数画连续折线法
for (int i = ; i < pointList.Count; i++)
{
GL.Vertex3(pointList[i].x, pointList[i].y, );
}
for (int i = ; i < pointList.Count; i++)
{
GL.Vertex3(pointList[i].x, pointList[i].y, );
}
//单次画线发
//GL.Vertex3(0, 0, 0);//GL.Vertex3(Screen.width, Screen.height, 0);
//固定2点画
//GL.Vertex3(p1.position.x, p1.position.y, 0);
//GL.Vertex3(p2.position.x, p2.position.y, 0);
GL.End();
GL.PopMatrix();//读取之前的Matrix
}
}
Unity GL画折线的更多相关文章
- Unity GL 画圆
Unity下GL没有画圆的函数,只能自己来了. 如果能帮到大家,我也很高兴. 虽然没有画圆的函数,但是能画直线,利用这一点,配合微积分什么的,就可以画出来了.反正就是花很多连在一起的直线,每条直线足够 ...
- unity gl 画线
using UnityEngine; using System.Collections; public class TGLLine : MonoBehaviour { private static M ...
- python中matplotlib画折线图实例(坐标轴数字、字符串混搭及标题中文显示)
最近在用python中的matplotlib画折线图,遇到了坐标轴 "数字+刻度" 混合显示.标题中文显示.批量处理等诸多问题.通过学习解决了,来记录下.如有错误或不足之处,望请指 ...
- SAS 画折线图PROC GPLOT
虽然最后做成PPT里的图表会被要求用EXCEL画,但当我们只是在分析的过程中,想看看数据的走势,直接在SAS里画会比EXCEL画便捷的多. 修改起来也会更加的简单,,不用不断的修改程序然后刷新EXCE ...
- echarts入门基础,画折线图
注意:一定要自己引入echarts库 <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...
- Matplotlib学习---用matplotlib画折线图(line chart)
这里利用Jake Vanderplas所著的<Python数据科学手册>一书中的数据,学习画图. 数据地址:https://raw.githubusercontent.com/jakevd ...
- echars画折线图的一种数据处理方式
echars画折线图的一种数据处理方式 <!DOCTYPE html> <html> <head> <meta charset="utf-8&quo ...
- python的turtle模块画折线图
代码如下: import turtle yValues = [10.0,7.4,6.4,5.3,4.4,3.7,2.6] def main(): t = turtle.Turtle() t.hidet ...
- 使用OpenCV画折线图
使用OpenCV画直方图是一件轻松的事情,画折线图就没有那么Easy了,还是使用一个库吧: GraphUtils 源代码添加入工程 原文链接:http://www.360doc.com/content ...
随机推荐
- Panda3d code in github
https://github.com/panda3d/panda3d [ref files] http://www.panda3d.noie.name/ https://www.panda3d.org ...
- Android-Application来传递数据
在上一篇博客中介绍到,Android-Intent意图传递数据,能够传递基本数据类型系列,能够传递对象(需要序列化),等操作: 但是如果要传递 List<T>,这种类型的数据,就不能通过I ...
- Transaction And Lock--存在嵌套事务吗?
在很多编程语言中,可以实现嵌套,但在TSQL中,可以实现嵌套事务吗? 答案:不可以 虽然我们可以写如下code: CREATE TABLE #TB1 ( ID INT ) --创建事务1 BEGIN ...
- 前台通过form表单向Django后台传输数据,Django处理后返回给前台
摘要:Django前后台数据传递 通过action将数据传输给apitest这个地址,使用get方法传递,此处需要传递name="request_method"的下拉列表值和nam ...
- RobotFramework与Jenkins集成后失败用例重跑
Jenkins的执行Windows批处理命令填写如下: call pybot.bat -i 1adsInterface 01_测试用例\接口测试用例\adsInterface.txt call pyb ...
- 【QTP专题】连接数据库
获取数据库连接串 在本地新建一个.txt文件,修改扩展名名*.udl:双击*.udl文件,打开数据库链接属性,定位到"提供程序"选显卡,选中如sqlserver的连接 Micro ...
- OCP 12c最新考试原题及答案(071-8)
8.(5-4) choose the best answer:You need to produce a report where each customer's credit limit has b ...
- offsetWidth和width的区别
1.offsetWidth属性可以返回对象的padding+border+width属性值之和,style.width返回值就是定义的width属性值. 2.offsetWidth属性仅是可读属性,而 ...
- Ajax请求的一个重要属性contentType
比如 contentType : 'application/json;charset=UTF-8', 或者 contentType : 'text/html;charset=UTF-8', 如果不加此 ...
- [转贴]VC编译器版本号_MSC_VER and _MSC_FULL_VER
Visual Studio version and discrimination macros Abbreviation Product name [Visual Studio version] †1 ...