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() 这个函数的类的脚本需要绑定到摄像机上面才能显示线条,绑定其他物体是不行的

unity3d 使用GL 方式画线

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();
}
}
上一篇:金融自助设备WOSA/XFS规范介绍


下一篇:python PIL 图像处理