unity3d 使用GL 方式画线

转载 2016年08月30日 18:13:34
这个是画线部分
复制代码
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() 这个函数里面去

复制代码
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();
    }
复制代码

而void OnPostRender() 这个函数的类的脚本需要绑定到摄像机上面才能显示线条,绑定其他物体是不行的

 

 

复制代码
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);
    
    }

    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 > 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);
           


            AddPoint(temp);

        }

    }

    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\" {" +
                "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(0);

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

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


        GL.PopMatrix();
    }
}
复制代码

相关文章推荐

游戏资源提取常用工具索引

常用工具: 1、3D Ripper DX:DX模型截取器,原名3D Ripper 2、GameAssassin:屏幕模型截取 3、sculptris-alpha:导出OBJ 4、Susie:支...

内存、优化工具若干

1,自带工具 SF: AMP UE3: StatsViewer GameplayProfiler MemoryProfiler AIProfiler 2,渲染分析 PIX GPA P...

搜狐畅游的免费开源游戏引擎Genesis-3D

在CSDN上看到了《搜狐畅游发布3D游戏引擎Genesis-3D 基于MIT协议开源》(http://www.csdn.net/article/2013-11-21/2817585-changyou-...

CIO烦恼之五:IT系统管理复杂化,CIO疲于奔命

只要系统上线,CIO们几乎都有个共同感觉,就是自己和手下的人明明每天忙得要死,这里做维护那里做维修,但是偏偏到了年底,各部门进行工作评价时,被投诉最多的反而就是IT部门。  在这样的企业里,CIO和他...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)