unity3d 使用GL 方式画线
- 这个是画线部分
- private Vector3[] linePoints;
- public int m_LineCount;
- public int m_PointUsed;
- public void RenderPath()
- {
- GL.Begin(GL.LINES);
- for (int i = ; i < m_LineCount - ; ++i)
- {
- GL.Vertex(GetPoint(i));
- GL.Vertex(GetPoint(i + ));
- }
- GL.End();
- }
但是这个画线部分要放到 void OnPostRender() 这个函数里面去
- void OnPostRender()
- {
- GL.Color(Color.red);
- GL.PushMatrix();
- mat.SetPass();
- m_linePath[].RenderPath();
- m_linePath[].RenderPath();
- m_linePath[].RenderPath();
- GL.PopMatrix();
- }
而void OnPostRender() 这个函数的类的脚本需要绑定到摄像机上面才能显示线条,绑定其他物体是不行的
- class MiCirle
- {
- private Vector3[] linePoints;
- private int m_PointCount = ;
- private Vector3 m_EarthPos;
- public void Init(Vector3 _Pos,float _s)
- {
- m_EarthPos = _Pos;
- linePoints = new Vector3[];
- CompliteAllPoint(_s);
- }
- float DegreetoRadians(float x)
- {
- return x * 0.017453292519943295769f;
- }
- float RadianstoDegrees(float x)
- {
- return x * 57.295779513082321f;
- }
- void AddPoint(Vector3 _vec)
- {
- linePoints[m_PointCount++] = _vec;
- }
- Vector3 GetPoint(int _x)
- {
- if (_x > )
- return new Vector3(, , );
- else
- return linePoints[_x];
- }
- void CompliteAllPoint(float _size)
- {
- float angle = ;
- float SizeX = _size;
- for (int i = ; i < ; i++)
- {
- float XPos = Mathf.Sin(DegreetoRadians(i)) * SizeX;
- float YPos = Mathf.Cos(DegreetoRadians(i)) * SizeX;
- Vector3 temp = new Vector3(m_EarthPos.x + XPos, m_EarthPos.y + YPos, m_EarthPos.z);
- AddPoint(temp);
- }
- }
- public void RenderLines()
- {
- GL.Begin(GL.LINES);
- for (int i = ; i < ; ++i)
- {
- GL.Color(Color.white);
- GL.Vertex(GetPoint(i));
- GL.Vertex(GetPoint(i + ));
- }
- GL.End();
- }
- public void RenderVirtualLine()
- {
- }
- };
调用则:
- public class MainScript : MonoBehaviour
- {
- public GameObject m_ObjEarth;
- public GameObject m_ObjMoon;
- private int m_LineCount =;
- private MiCirle m_CircleNomal;
- private MiCirle m_CircleBig;
- private MiCirle m_CircleSmall;
- private Vector3 m_EarthPos;
- private Material lineMaterial;
- void Start ()
- {
- m_EarthPos = m_ObjEarth.transform.position;
- m_CircleNomal = new MiCirle();
- m_CircleBig = new MiCirle();
- m_CircleSmall = new MiCirle();
- m_CircleNomal.Init(m_EarthPos,3.5f);
- m_CircleBig.Init(m_EarthPos,4.0f);
- m_CircleSmall.Init(m_EarthPos,3.0f);
- lineMaterial = new Material("Shader \"Lines/Colored Blended\" {" +
- "SubShader { Pass {" +
- " BindChannels { Bind \"Color\",color }" +
- " Blend SrcAlpha OneMinusSrcAlpha" +
- " ZWrite Off Cull Off Fog { Mode Off }" +
- "} } }");
- lineMaterial.hideFlags = HideFlags.HideAndDontSave;
- lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
- }
- // Update is called once per frame
- void Update ()
- {
- }
- void OnPostRender()
- {
- lineMaterial.SetPass();
- // Debug.Log("Render lines");
- GL.Color(Color.red);
- GL.PushMatrix();
- m_CircleNomal.RenderLines();
- m_CircleBig.RenderLines();
- m_CircleSmall.RenderLines();
- GL.PopMatrix();
- }
- }
unity3d 使用GL 方式画线的更多相关文章
- unity3d之在屏幕上画线
如何在屏幕上画线,简单的代码如下: using UnityEngine; public class Test : MonoBehaviour { void OnGUI() { GL.LoadOrtho ...
- unity3d NavMeshAgent 寻路画线/画路径
今天在群里看见有个小伙在问Game视图寻路时怎么画线 正好前几天写了个寻路,而且自己也不知道具体怎么在寻路时画线,所以决定帮帮他,自己也好学习一下 在百度查了一下资料,直接搜寻路画路径.寻路画线... ...
- Unity3D 画线插件 Vectrosity_Simple2DLine
Vectrosity是一个很方便的画线插件,用它我们可以画出2D,3D,贝塞尔,圆,椭圆等各种线条图案. :链接: http://pan.baidu.com/s/1pJjTFjt 密码: uesn 首 ...
- OpenGL进阶演示样例1——动态画线(虚线、实线、颜色、速度等)
用OpenGL动态绘制线段.事实上非常easy,但到如今为止.网上可參考资料并不多. 于是亲自己主动手写一个函数,方便动态绘制线段.代码例如以下: #include<GL/glu ...
- CGContextRef 画线简单用法
CGContextRef CGContextMoveToPoint(context,150,50);//圆弧的起始点 CGContextAddArcToPoint(context,100,80,130 ...
- Android中Path类的lineTo方法和quadTo方法画线的区别
转载:http://blog.csdn.net/stevenhu_223/article/details/9229337 当我们需要在屏幕上形成画线时,Path类的应用是必不可少的,而Path类的li ...
- WPF画线问题,几千条以后就有明显的延迟了。
我现在是这么画的,class A { private GeometryGroup _lines; private Path _path; public A() { _path.Data = ...
- Unity之屏幕画线
using UnityEngine;using System.Collections; public class DrawRectangle : MonoBehaviour { public Colo ...
- win32画线考虑去锯齿
整理日: 2015年2月16日 这几天一直在研究win32 SDk下画线去锯齿,之前一直用的QT的画线接口函数,里面有去锯齿的效果,可是突然项目要求不能用QT的只能用win32 SDK下的GDI画线接 ...
随机推荐
- django配置超级管理员
Admin站点管理: 概述: 内容发布:负责添加,修改,删除内容的 公告访问 配置Admin应用: 在settings.py文件中的INSTALLED_APPS中添加'django.contrib.a ...
- MAC层作用
对于无线传感网 MAC,顾名思义,就是介质访问控制,是用来控制无线介质的访问的,由于无线传输是共享空中资源的,必然存在多个无线传感器节点对传输介质的争用,MAC层协议就是用来解决这个问题的,包括冲突的 ...
- [Note] Collaborator vs. the Factory
Collaborator-vs-he-Factoryhtml, body {overflow-x: initial !important;}html { font-size: 14px; } body ...
- 让PHP7达到最高性能的几个Tips(转)
PHP7已经发布了, 作为PHP10年来最大的版本升级, 最大的性能升级, PHP7在多放的测试中都表现出很明显的性能提升, 然而, 为了让它能发挥出最大的性能, 我还是有几件事想提醒下. PHP7 ...
- Unity Shader学习资料
文本教程 http://www.cnblogs.com/polobymulberry/p/4314147.html 视频教程 http://www.sikiedu.com/my/course/37 冯 ...
- C++中cin的用法汇总
cin可以用于接收输入,最常见的是从控制台接收.在刚学习C++的时候经常会用cin来接收数据,这里想要系统的总结一下cin的用法,保证不灌水. C++中的cin是一个 istream对象,从标准输入中 ...
- am335x 配置 GPIO 为可输入也可输出
主要配置设备树如下模式即可 0x1AC (PIN_INPUT_PULLUP | MUX_MODE7)
- String Format for Double [C#]
转载:http://www.csharp-examples.net/string-format-double/ he following examples show how to format flo ...
- CLR、内存分配和垃圾回收
一.CLR CLR:即公共语言运行时(Common Language Runtime),是中间语言(IL)的运行时环境,负责将编译生成的MSIL编译成计算机可以识别的机器码,负责资源管理(内存分配和垃 ...
- CSS遮罩层的实现
偶然发现自己原来写了一个CSS遮罩层,虽然这个东西没什么技术含量,但如果本人离开公司后又遇见此类问题,那么可能又得花些时间来找资料了.所以决定还是把它记下来吧. 直接上代码吧. 第一步,html代码: ...