这个是画线部分
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. 09Vue.js快速入门-Vue入门之Vuex实战

    9.1. 引言 Vue组件化做的确实非常彻底,它独有的vue单文件组件也是做的非常有特色.组件化的同时带来的是:组件之间的数据共享和通信的难题. 尤其Vue组件设计的就是,父组件通过子组件的prop进 ...

  2. js实现完美身份证号有效性验证(转)

    转载自:http://www.cnblogs.com/lzrabbit/archive/2011/10/23/2221643.html 最近需要对身份证合法性进行验证,实名验证是不指望了,不过原来的验 ...

  3. JAVA字符串怎么转换成整数

    首先你要确定你的字符串可以转换为int类型的,比如说: String s = "123"; 如果String s = "abc";则转换时会报错! 需要的包是& ...

  4. PostgreSQL LIKE 查询效率提升实验<转>

    一.未做索引的查询效率 作为对比,先对未索引的查询做测试 EXPLAIN ANALYZE select * from gallery_map where author = '曹志耘'; QUERY P ...

  5. redis的setbit命令

    redis的setbit这个bit怎么理解,配合bitcount使用? 这个是SETBIT使用方法的简单说明&lt;img src="https://pic4.zhimg.com/8 ...

  6. Android——开源框架Universal-Image-Loader + Fragment使用+轮播广告

    原文地址: Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用 Android 开源框架Universal-Image-Loader完全解析(二) ...

  7. fastjson生成JSON字符串的时候出现$ref

    fastjson生成JSON字符串的时候出现$ref 转载自:http://wuzhuti.cn/201426!826!05!130202.html 可以通过选项 DisableCircularRef ...

  8. 分治算法--寻找第k大数

    问题描述:给定线性序集中n个元素和一个整数k,1≤k≤n,要求找出这n个元素中第k大的元素,(这里给定的线性集是无序的). 其实这个问题很简单,直接对线性序列集qsort,再找出第k个即可.但是这样的 ...

  9. MySQL递归查询树状表的子节点、父节点

    表结构和表数据就不公示了,查询的表user_role,主键是id,每条记录有parentid字段; 如下mysql查询函数即可实现根据一个节点查询所有的子节点,根据一个子节点查询所有的父节点.对于数据 ...

  10. 巧用style的另类写法

    看到style,不少人可能会说这个我知道,就是控件写属性的话可以通过style来实现代码的复用,单独把这些属性及其参数写成style就可以便捷的调用. <?xml version="1 ...