GL Example 1

Source: Internet
Author: User

usingUnityengine;usingSystem.Collections; Public classjoint{ PublicVector3 org;  PublicVector3 end;} Public classexample:monobehaviour{Event E; PrivateVector3 Orgpos; PrivateVector3 Endpos; Private BOOLCandrawlines =false;    ArrayList posal;    ArrayList Temppos;  PublicMaterial linematerial; voidStart () {Temppos=NewArrayList (); Posal=NewArrayList (); }    voidUpdate () {if(Input.getmousebutton (0) ) {Candrawlines=true; }        if(E.type! =NULL&candrawlines) {              if(E.type = =eventtype.mousedown) {Orgpos=input.mouseposition; Endpos=input.mouseposition; }              if(E.type = =Eventtype.mousedrag) {Endpos=input.mouseposition; //storing mouse position information in an arrayTemppos.                ADD (input.mouseposition);                  Gldrawline (Orgpos, endpos); Orgpos=input.mouseposition; Print (Temppos.            Count); }              if(E.type = =eventtype.mouseup) {//orgpos=input.mouseposition; Endpos =input.mouseposition; }          }              }        voidGldrawline (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=NewJoint (); Tmpjoint.org=Beg; Tmpjoint.end=end;                  Posal.add (Tmpjoint); Linematerial.setpass (0); Gl. Begin (GL.          LINES); Gl. Color (NewColor (1,1,1,0.5f));  for(intI=0; i<posal.count; i++) {Joint 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 (); }        voidOngui () {e=event.current; if(GUI. Button (NewRect ( Max,0, -, -),"End Lines") ) {clearlines (); }      }    voidClearlines () {Candrawlines=false;      Posal.clear (); }        voidOnpostrender () {gldrawline (Orgpos, endpos); }   }

GL Example 1

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.