这个是画线部分
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 方式画线的更多相关文章

  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. js 去掉html标签

    方法一: /// <summary> /// 去除HTML标记 /// </summary> /// <param name="NoHTML"> ...

  2. JAVA-JSP内置对象之page对象调用Servlet

    相关资料:<21天学通Java Web开发> page对象1.page对象代表JSP转译后的Servlet.2.通过page对象可以非常方便地调用Servlet类中定义的方法. pageD ...

  3. webscan v0.01

    ps:本人不是写代码的料.写出来的贼垃圾.大牛看了如果有可以优化的提出来哈. #by def import urllib res = {} website = raw_input() if " ...

  4. phalcon无法更新分区字段解决办法

    表里面有个分区字段,更新后,保存成功,结果实际上数据库没有更新. 后来使用原生sql,解决了这个问题. 获取di中的数据库连接,直接执行sql语句即可,下面的db为注册的数据库服务名 $db = $t ...

  5. JavaScript JSON 数据处理

    在JavaScript 也自带了 JSON 格式的处理 <!doctype html> <html> <script> var test_json_str = { ...

  6. Vagrant (3) —— 复制/备份Vagrant Box

    Vagrant (3) -- 复制/备份Vagrant Box 摘要 介绍复制/备份Vagrant Box基本方法 版本 Vagrant版本: 1.8.1 内容 复制vagrant box并压缩 关闭 ...

  7. 推荐几个不错的h5游戏引擎

    http://www.phaser.io/examples http://www.cocos.com/ http://cn.cocos2d-x.org/tutorial/lists?id=30 coc ...

  8. [Python学习]Python学习资料汇总

    Python其实很简单,入门+提高看一些简单的教程就能学会,这里列出一些比较好的资料: 廖雪峰博客 https://www.liaoxuefeng.com/wiki/0014316089557264a ...

  9. Thymeleaf select 数据回显 选中

    <select style='width: 148.15px' name="dlrlx" th:field="*{Ygdly.dlrlx}"> &l ...

  10. WebRTC 源码分析(五):安卓 P2P 连接过程和 DataChannel 使用

    从本篇起,我们将迈入新的领域:网络传输.首先我们看看 P2P 连接的建立过程,以及 DataChannel 的使用,最终我们会利用 DataChannel 实现一个 P2P 的文字聊天功能. P2P ...