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 ...
随机推荐
- Python 数据分析—第十章 日期处理
日期时间数据类型及工具 from datetime import datetime now = datetime.now() print(now.year,now.month,now.day) #以毫 ...
- 19、Semantic-UI之图片的动画效果
在Semantic-UI中定义了很多图片动画效果,可以直接使用. 示例:定义图片动画 <!DOCTYPE html> <html lang="en"> ...
- Java NIO学习-详细内容(二)
五.Selector与SelectionKey Selector是SelectableChannel 对象的多路复用器,为什么使用Selector? 仅用单个线程来处理多个Channels的好处是,只 ...
- Android-ListView-(BaseAdapter使用)
在Android中就提供了专门列表显示条目的控件,ListView控件,ListView控件不是一次性加载全部数据,他是只加载用户在屏幕看得到的数据,当用户滑动的过程中在去加载新的数据,同时会自动销毁 ...
- git command cheat sheet
clone:克隆 --non-bare:(默认值)一般的克隆方式 --bare:只克隆.git目录 --mirror:只克隆.git目录,并且还保持与origin的关联,可以fetch commit: ...
- vcenter安装错误The DSN is pointing to anunspported ODBC driver...
在安装vcenter server中采用现有独立sql server数据库时出现下列错误. 这是由于当前独立数据库版本和当前系统的客户端驱动不匹配.导致我们在odbc中配置dsn无法正常运行. 如sq ...
- C++三种野指针及应对/内存泄露
C++三种野指针及应对/内存泄露 野指针,也就是指向不可用内存区域的指针.如果对野指针进行操作,将会使程序发生不可预知的错误,甚至可能直接引起崩溃. 野指针不是NULL指针,是指 ...
- Python strip()函数用法
Python中字符串处理函数里有三个去空格(包括'\n', '\r', '\t', ' ')的函数: strip 同时去掉左右两边的空格lstrip 去掉左边的空格rstrip 去掉右边的空格 具体示 ...
- UITextInputMode
An instance of the UITextInputMode class represents the current text-input mode. You can use this ob ...
- 【手记】如果Idx/Sub字幕导不进MKVToolNix,看看是否这个原因
用记事本之类的文本编辑器打开idx文件,看看时间轴部分是不是存在不规范的条目,比如: timestamp: :::, filepos: 注意,上述条目中,filepos:后面缺了一个空格,就这么一处问 ...