Unity implementation draw line break two---draw a rectangular wireframe with GL

Source: Internet
Author: User

Today is a bit of time to remember the last time you wrote the line frame, and then the last section of the line, we will take a look at the GL Draw line

Directly on the code

Using unityengine;using system.collections;using system.collections.generic;public class  joint{      public Vector3 org;       public Vector3 end;  }  public class example :  monobehaviour {    event e;         private vector3 orgpos;        private vector3  endpos;        private bool candrawlines  =  false;        arraylist posal;       ArrayList temppos;      public Material lineMaterial;       public List <Vector3> Pos = new List< vector3>  ();    &nBsp;void start ()       {           temppos=new arraylist ();           posal=new   arraylist ();      }      void  Update ()       {          if ( Input.getmousebuttonup (0))           {               canDrawLines = true;             }           if (E.type!=null &candrawlines)          {                 if (E.type  == eventtype.mousedown) &Nbsp;               {                                      orgpos= input.mouseposition;                               }                              if (e.type==eventtype.mouseup)                  {                                                         endPos=Input.mousePosition;                  Pos.Add  (Endpos);                 for  (int i = 0; i  < pos.count-1; i++)  {                     Vector3 p = Pos [i];                 }                 GLDrawLine  (orgpos,  Endpos);                 orgpos  = endpos;            }             }        }       Void gldrawline (vector3 beg ,vector3 end )          {                   if (!candrawlines)                  return;            gl. pushmatrix  ();           gl. loadortho  ();             beg.x=beg.x/ screen.width;            end.x=end.x/screen.width;             beg.y=beg.y/screen.height;            end.y=end.y/ Screen.height;            joint tmpjoint  = new joint ();             tmpjoint.org=beg;            tmpjoint.end=end;             posal.add (TmpJoint);             linematerial.setpass ( 0 );             gl. Begin (&NBSP;GL. lines );           gl. Color ( new color (1,1,1,1f)  );          for (int  i= 1;i<posal.count;i++) &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSp {&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;JOINT&NBSP;TJ   = (joint) posal[i];                 Vector3 tmpBeg  = tj.org;                 Vector3 tmpEnd=tj.end;                 gl. Vertex3 ( tmpBeg.x,tmpBeg.y,tmpBeg.z );                 gl. Vertex3 ( tmpEnd.x,tmpEnd.y,tmpEnd.z );           }                gl. End ();             gl. popmatrix  ();         }         void ongui ()          {            e = Event.current;             if (GUI. Button (New  rect (150,0,100,50), "End lines"))              {                 clearlines ();            }          if  (GUI. button  (New rect (10,5,100,50), "Read"))  {             Read  ();         }    }       void clearlines () &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;{&NBsp;           candrawlines = false;             posal.clear ();            Pos.Clear  ();    }       void onpostrender ()  {            Gldrawline (Orgpos,endpos);       }      public  void read ()     {        for  (int  i = 0; i < pos.count; i++)  {             Debug.Log  (Pos [i]);         }    }         This is the GL line, but one problem is that GL lines cannot change the width of the line, It is the default, in order to make him wider, you can consider drawing two lines between each two points, between the two antennas with a pictureFill.      I hope you can use it.


This article is from the "Unity_3d Technology discussion" blog, please be sure to keep this source http://myselfdream.blog.51cto.com/9944020/1828494

Unity implementation draw line break two---draw a rectangular wireframe with GL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.