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画线接 ...
随机推荐
- 玩转shell命令行
移动光标快捷键 ctrl+f 向前移动一个字符 ctrl+b 向后移动一个字符 ctrl+a 移动到当前行首home ctrl+e 移动到当前行尾end alt+f 向前移动一个单词 alt+b 向后 ...
- maven copy jar 插件
插件比较特殊 eclipse下的 首先声明插件 <pluginManagement> <plugin> <groupId>org.apache.maven.plu ...
- 07Vue.js快速入门-Vue路由详解
对于前端来说,其实浏览器配合超级连接就很好的实现了路由功能.但是对于单页面应用来说,浏览器和超级连接的跳转方式已经不能适用, 所以各大框架纷纷给出了单页面应用的解决路由跳转的方案. Vue框架的兼容性 ...
- Android开发(二)——自定义圆形控件的使用CircleImageView
CircleImageView,a fast circular ImageView perfect for profile images. 主要的类CircleImageView: package d ...
- Eigen教程(3)
整理下Eigen库的教程,参考:http://eigen.tuxfamily.org/dox/index.html 矩阵和向量的运算 提供一些概述和细节:关于矩阵.向量以及标量的运算. 介绍 Eige ...
- plsql 安装后database下拉没有东西(转)
转载自:http://www.cnblogs.com/yaobolove/p/5682982.html 今天来说一下问题,就是装了plsql竟然在database这一栏没有东西,我也是纠结了很久,感觉 ...
- [转]tppabs是什么?如何去除tppabs?
原文地址:http://www.cnblogs.com/gdsblog/archive/2017/03/25/6616561.html 不得不说,一款伟大的软件,就是用来解放人类双手的,Telepor ...
- 地铁盾构管片姿态测量软件(Excel)
记得11年刚开始从事盾构测量的时候,只知道搬站(倒站),测导线,还有就是测量管片.觉得最麻烦的就是在每个管片上面放个水平长尺,用全站仪测出他的水平位置和高程,但当时是本子记录每个数据,回去在敲到电脑上 ...
- 完美解决PHP中文乱码
一.首先是PHP网页的编码 1. php文件本身的编码与网页的编码应匹配 a. 如果欲使用gb2312编码,那么php要输出头:header(“Content-Type: text/html; cha ...
- redis关闭/重启服务器
通过docker实现: 一.创建redis服务器与客户端 docker run -p : -d --name redis-server docker.io/redis: redis-server -- ...