unity3d 使用GL 方式画线

这个是画线部分
private Vector3[] linePoints;
public int m_LineCount;
public int m_PointUsed;

public void RenderPath()
{

GL.Begin(GL.LINES);

for (int i = 0; i < m_LineCount - 1; ++i)
{

GL.Vertex(GetPoint(i));

GL.Vertex(GetPoint(i + 1));

}

GL.End();
}

void OnPostRender()
{

GL.Color(Color.red);
GL.PushMatrix();
mat.SetPass(0);
m_linePath[0].RenderPath();
m_linePath[1].RenderPath();
m_linePath[2].RenderPath();

GL.PopMatrix();
}

class MiCirle
{
private  Vector3[] linePoints;
private int m_PointCount = 0;
private Vector3 m_EarthPos;

public void Init(Vector3 _Pos,float _s)
{
m_EarthPos = _Pos;
linePoints = new Vector3[390];

CompliteAllPoint(_s);

}

{
return x * 0.017453292519943295769f;
}

{
return x * 57.295779513082321f;
}

{
linePoints[m_PointCount++] = _vec;

}
Vector3 GetPoint(int _x)
{
if (_x > 360)
return new Vector3(0, 0, 0);
else
return linePoints[_x];

}

void CompliteAllPoint(float _size)
{
float angle = 0;
float SizeX = _size;

for (int i = 0; i < 361; 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);

}

}

public void RenderLines()
{
GL.Begin(GL.LINES);

for (int i = 0; i < 360; ++i)
{
GL.Color(Color.white);
GL.Vertex(GetPoint(i));

GL.Vertex(GetPoint(i + 1));
}

GL.End();

}

public void RenderVirtualLine()
{

}

};

public class MainScript : MonoBehaviour
{
public GameObject m_ObjEarth;
public GameObject m_ObjMoon;

private int m_LineCount =0;
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\" {" +
"   BindChannels { Bind \"Color\",color }" +
"   Blend SrcAlpha OneMinusSrcAlpha" +
"   ZWrite Off Cull Off Fog { Mode Off }" +
"} } }");

lineMaterial.hideFlags = HideFlags.HideAndDontSave;

}

// Update is called once per frame
void Update ()
{

}

void OnPostRender()
{
lineMaterial.SetPass(0);

//  Debug.Log("Render lines");

GL.Color(Color.red);
GL.PushMatrix();
m_CircleNomal.RenderLines();
m_CircleBig.RenderLines();
m_CircleSmall.RenderLines();

GL.PopMatrix();
}
}

【Unity3d开发记录】Unity动态画曲线、弧线（GL画线）在UI上的显示

2016-04-28 07:59:40

《高效学习OpenGL》之缓冲区对象 glGenBuffers(), glBindBuffer(), glBufferData(),glMapBuffer()

2014-02-17 10:32:19

2016-05-07 10:10:31

【OpenGL】使用Unity来学习OpenGL

2013-09-09 22:39:53

unity3d OpenGL实现画符功能

2017-09-06 16:26:40

Unity3D Camera设置结合OpenGL详细解读

2017-03-15 00:02:24

OpenGL函数思考-glBindTexture

2012-02-09 09:41:26

Unity自带GL详解

2015-12-31 01:53:01

10 WebGL的缓冲区对象使用

2017-05-07 00:12:22

unity3D 鼠标点击拖动画线(平面)

2016-10-13 16:24:23