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画线接 ...
随机推荐
- 【AD】实用组策略/脚本集合 (重大更新20160627)
文章原始出处 http://blog.51cto.com/xifanliang/1793576 http://bbs.51cto.com/thread-1170777-1.html 作者:xifaln ...
- Grunt经常使用插件及演示样例说明
下述给出了经常使用Grunt插件,并列举了部分插件演示样例: 插件名称 说明 Github地址 grunt-contrib-clean 清空文件和目录 https://github.com/grunt ...
- AT24Cxx(EEPROM)子系统
1.配置内核 打开I2C功能: 打开杂项设备,该选项打开后,EEPROM也就打开了. 2. 修改代码 修改文件: linux/arch/arm/mach-s3c2440/mach-smdk2440.c ...
- 【转】15个最受欢迎的Python开源框架
以下是伯乐在线从GitHub中整理出的15个最受欢迎的Python开源框架.这些框架包括事件I/O,OLAP,Web开发,高性能网络通信,测试,爬虫等. Django: Python Web应用开发框 ...
- java replaceall 使用正则表达式替换单等号,不替换其他相关的等号。
写项目需要将公式配置到数据库中,取出后根据公式规则进行比较,由于公式的等于是用单等号,在java中无法直接使用,故需要将单等号替换成双等号,单又不能影响大于等于以及其他形式.故果断选择正则表达式替换. ...
- JavaScript(九):JavaScript中的内置对象
一.对象的概念 对象是一种特殊的数据类型(object). 拥有一系列的属性和方法. 分为内置对象和自定义对象. 二.String对象 String对象用来支持对于字符串的处理. 1.属性 lengt ...
- java对mongoDB的基本操作 ,游标使用
package com.mongodb.text; import java.net.UnknownHostException; import java.util.List; import org.bs ...
- 如何利用jsp实现防盗链功能
index.jsp ----------------------------- Place your content here here is index jsp get header info a. ...
- 记录一下寄几个儿的greendao数据库升级,可以说是非常菜鸡了嗯
之前使用的greendao数据库存储服务器所有的历史推送消息,但是后来消息需要加几个新的字段 举个栗子,比如要新增红色框住的字段到数据库中: 本仙女作为一只思想成熟的菜鸡,当然是加了字段就赶紧重新往里 ...
- 《FPGA全程进阶---实战演练》第十二章 二进制码与格雷码PK
大家在写程序的时候,可能会听闻,什么独热码,什么格雷码,什么二进制码等等,本节意在解释这几种编码之间的区别和优势以及用verilog怎么去实现,下面先介绍这几种编码的区别. 1 基础理论部分 1.1 ...