1. 这个是画线部分
  1. private Vector3[] linePoints;
  2. public int m_LineCount;
  3. public int m_PointUsed;
  4.  
  5. public void RenderPath()
  6. {
  7.  
  8. GL.Begin(GL.LINES);
  9.  
  10. for (int i = ; i < m_LineCount - ; ++i)
  11. {
  12.  
  13. GL.Vertex(GetPoint(i));
  14.  
  15. GL.Vertex(GetPoint(i + ));
  16.  
  17. }
  18.  
  19. GL.End();
  20. }

但是这个画线部分要放到   void OnPostRender() 这个函数里面去

  1. void OnPostRender()
  2. {
  3.  
  4. GL.Color(Color.red);
  5. GL.PushMatrix();
  6. mat.SetPass();
  7. m_linePath[].RenderPath();
  8. m_linePath[].RenderPath();
  9. m_linePath[].RenderPath();
  10.  
  11. GL.PopMatrix();
  12. }

而void OnPostRender() 这个函数的类的脚本需要绑定到摄像机上面才能显示线条,绑定其他物体是不行的

  1. class MiCirle
  2. {
  3. private Vector3[] linePoints;
  4. private int m_PointCount = ;
  5. private Vector3 m_EarthPos;
  6.  
  7. public void Init(Vector3 _Pos,float _s)
  8. {
  9. m_EarthPos = _Pos;
  10. linePoints = new Vector3[];
  11.  
  12. CompliteAllPoint(_s);
  13.  
  14. }
  15.  
  16. float DegreetoRadians(float x)
  17. {
  18. return x * 0.017453292519943295769f;
  19. }
  20.  
  21. float RadianstoDegrees(float x)
  22. {
  23. return x * 57.295779513082321f;
  24. }
  25.  
  26. void AddPoint(Vector3 _vec)
  27. {
  28. linePoints[m_PointCount++] = _vec;
  29.  
  30. }
  31. Vector3 GetPoint(int _x)
  32. {
  33. if (_x > )
  34. return new Vector3(, , );
  35. else
  36. return linePoints[_x];
  37.  
  38. }
  39.  
  40. void CompliteAllPoint(float _size)
  41. {
  42. float angle = ;
  43. float SizeX = _size;
  44.  
  45. for (int i = ; i < ; i++)
  46. {
  47. float XPos = Mathf.Sin(DegreetoRadians(i)) * SizeX;
  48. float YPos = Mathf.Cos(DegreetoRadians(i)) * SizeX;
  49.  
  50. Vector3 temp = new Vector3(m_EarthPos.x + XPos, m_EarthPos.y + YPos, m_EarthPos.z);
  51.  
  52. AddPoint(temp);
  53.  
  54. }
  55.  
  56. }
  57.  
  58. public void RenderLines()
  59. {
  60. GL.Begin(GL.LINES);
  61.  
  62. for (int i = ; i < ; ++i)
  63. {
  64. GL.Color(Color.white);
  65. GL.Vertex(GetPoint(i));
  66.  
  67. GL.Vertex(GetPoint(i + ));
  68. }
  69.  
  70. GL.End();
  71.  
  72. }
  73.  
  74. public void RenderVirtualLine()
  75. {
  76.  
  77. }
  78.  
  79. };

调用则:

  1. public class MainScript : MonoBehaviour
  2. {
  3. public GameObject m_ObjEarth;
  4. public GameObject m_ObjMoon;
  5.  
  6. private int m_LineCount =;
  7. private MiCirle m_CircleNomal;
  8. private MiCirle m_CircleBig;
  9. private MiCirle m_CircleSmall;
  10.  
  11. private Vector3 m_EarthPos;
  12. private Material lineMaterial;
  13.  
  14. void Start ()
  15. {
  16.  
  17. m_EarthPos = m_ObjEarth.transform.position;
  18. m_CircleNomal = new MiCirle();
  19. m_CircleBig = new MiCirle();
  20. m_CircleSmall = new MiCirle();
  21.  
  22. m_CircleNomal.Init(m_EarthPos,3.5f);
  23. m_CircleBig.Init(m_EarthPos,4.0f);
  24. m_CircleSmall.Init(m_EarthPos,3.0f);
  25.  
  26. lineMaterial = new Material("Shader \"Lines/Colored Blended\" {" +
  27. "SubShader { Pass {" +
  28. " BindChannels { Bind \"Color\",color }" +
  29. " Blend SrcAlpha OneMinusSrcAlpha" +
  30. " ZWrite Off Cull Off Fog { Mode Off }" +
  31. "} } }");
  32.  
  33. lineMaterial.hideFlags = HideFlags.HideAndDontSave;
  34.  
  35. lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
  36.  
  37. }
  38.  
  39. // Update is called once per frame
  40. void Update ()
  41. {
  42.  
  43. }
  44.  
  45. void OnPostRender()
  46. {
  47. lineMaterial.SetPass();
  48.  
  49. // Debug.Log("Render lines");
  50.  
  51. GL.Color(Color.red);
  52. GL.PushMatrix();
  53. m_CircleNomal.RenderLines();
  54. m_CircleBig.RenderLines();
  55. m_CircleSmall.RenderLines();
  56.  
  57. GL.PopMatrix();
  58. }
  59. }

unity3d 使用GL 方式画线的更多相关文章

  1. unity3d之在屏幕上画线

    如何在屏幕上画线,简单的代码如下: using UnityEngine; public class Test : MonoBehaviour { void OnGUI() { GL.LoadOrtho ...

  2. unity3d NavMeshAgent 寻路画线/画路径

    今天在群里看见有个小伙在问Game视图寻路时怎么画线 正好前几天写了个寻路,而且自己也不知道具体怎么在寻路时画线,所以决定帮帮他,自己也好学习一下 在百度查了一下资料,直接搜寻路画路径.寻路画线... ...

  3. Unity3D 画线插件 Vectrosity_Simple2DLine

    Vectrosity是一个很方便的画线插件,用它我们可以画出2D,3D,贝塞尔,圆,椭圆等各种线条图案. :链接: http://pan.baidu.com/s/1pJjTFjt 密码: uesn 首 ...

  4. OpenGL进阶演示样例1——动态画线(虚线、实线、颜色、速度等)

            用OpenGL动态绘制线段.事实上非常easy,但到如今为止.网上可參考资料并不多. 于是亲自己主动手写一个函数,方便动态绘制线段.代码例如以下: #include<GL/glu ...

  5. CGContextRef 画线简单用法

    CGContextRef CGContextMoveToPoint(context,150,50);//圆弧的起始点 CGContextAddArcToPoint(context,100,80,130 ...

  6. Android中Path类的lineTo方法和quadTo方法画线的区别

    转载:http://blog.csdn.net/stevenhu_223/article/details/9229337 当我们需要在屏幕上形成画线时,Path类的应用是必不可少的,而Path类的li ...

  7. WPF画线问题,几千条以后就有明显的延迟了。

      我现在是这么画的,class A { private GeometryGroup _lines; private Path _path; public A() {    _path.Data = ...

  8. Unity之屏幕画线

    using UnityEngine;using System.Collections; public class DrawRectangle : MonoBehaviour { public Colo ...

  9. win32画线考虑去锯齿

    整理日: 2015年2月16日 这几天一直在研究win32 SDk下画线去锯齿,之前一直用的QT的画线接口函数,里面有去锯齿的效果,可是突然项目要求不能用QT的只能用win32 SDK下的GDI画线接 ...

随机推荐

  1. django配置超级管理员

    Admin站点管理: 概述: 内容发布:负责添加,修改,删除内容的 公告访问 配置Admin应用: 在settings.py文件中的INSTALLED_APPS中添加'django.contrib.a ...

  2. MAC层作用

    对于无线传感网 MAC,顾名思义,就是介质访问控制,是用来控制无线介质的访问的,由于无线传输是共享空中资源的,必然存在多个无线传感器节点对传输介质的争用,MAC层协议就是用来解决这个问题的,包括冲突的 ...

  3. [Note] Collaborator vs. the Factory

    Collaborator-vs-he-Factoryhtml, body {overflow-x: initial !important;}html { font-size: 14px; } body ...

  4. 让PHP7达到最高性能的几个Tips(转)

    PHP7已经发布了, 作为PHP10年来最大的版本升级, 最大的性能升级, PHP7在多放的测试中都表现出很明显的性能提升, 然而, 为了让它能发挥出最大的性能, 我还是有几件事想提醒下. PHP7 ...

  5. Unity Shader学习资料

    文本教程 http://www.cnblogs.com/polobymulberry/p/4314147.html 视频教程 http://www.sikiedu.com/my/course/37 冯 ...

  6. C++中cin的用法汇总

    cin可以用于接收输入,最常见的是从控制台接收.在刚学习C++的时候经常会用cin来接收数据,这里想要系统的总结一下cin的用法,保证不灌水. C++中的cin是一个 istream对象,从标准输入中 ...

  7. am335x 配置 GPIO 为可输入也可输出

    主要配置设备树如下模式即可 0x1AC (PIN_INPUT_PULLUP | MUX_MODE7)

  8. String Format for Double [C#]

    转载:http://www.csharp-examples.net/string-format-double/ he following examples show how to format flo ...

  9. CLR、内存分配和垃圾回收

    一.CLR CLR:即公共语言运行时(Common Language Runtime),是中间语言(IL)的运行时环境,负责将编译生成的MSIL编译成计算机可以识别的机器码,负责资源管理(内存分配和垃 ...

  10. CSS遮罩层的实现

    偶然发现自己原来写了一个CSS遮罩层,虽然这个东西没什么技术含量,但如果本人离开公司后又遇见此类问题,那么可能又得花些时间来找资料了.所以决定还是把它记下来吧. 直接上代码吧. 第一步,html代码: ...