Unity draws lines with GL Library

Source: Internet
Author: User
Tags cos sin

Real machine debugging, sometimes need to quickly add some debugging information on the screen, such as the character's collision box, the crosshair range, can be used GL on the screen to draw a rectangular circle, etc. to display:

Start Drawing:

void Begin (color color) {    ifnull)        new Material (Shader.find ("  unlit/color"));        S_material. SetPass (0);        Gl. Loadortho ();        Gl. Begin (GL. LINES);        S_material. SetColor ("_color", Color);}

End Drawing:

void End () {    GL. End ();}

To draw a rectangle:

 Public voiddrawscreenrect (rect rect, color color) {Begin (color); Gl. Vertex3 (Rect.xmin/Screen.width, Rect.ymin/screen.height,0); Gl. Vertex3 (Rect.xmin/Screen.width, Rect.ymax/screen.height,0); Gl. Vertex3 (Rect.xmin/Screen.width, Rect.ymax/screen.height,0); Gl. Vertex3 (Rect.xmax/Screen.width, Rect.ymax/screen.height,0); Gl. Vertex3 (Rect.xmax/Screen.width, Rect.ymax/screen.height,0); Gl. Vertex3 (Rect.xmax/Screen.width, Rect.ymin/screen.height,0); Gl. Vertex3 (Rect.xmax/Screen.width, Rect.ymin/screen.height,0); Gl. Vertex3 (Rect.xmin/Screen.width, Rect.ymin/screen.height,0); End ();}

To draw an ellipse:

 Public voidDrawscreenellipse (Vector2 Center,floatXradius,floatYradius, color color,intSmooth = -) {Begin (color);  for(inti =0; i < smooth; ++i) {intNextStep = (i +1) %Smooth; Gl. Vertex3 ((center.x+ Xradius * Mathf.cos (2* Mathf.pi/smooth * i)/Screen.width, (Center.y+ Yradius * Mathf.sin (2* Mathf.pi/smooth * i))/Screen.height,0); Gl. Vertex3 ((center.x+ Xradius * Mathf.cos (2* Mathf.pi/smooth * nextStep))/Screen.width, (Center.y+ Yradius * Mathf.sin (2* Mathf.pi/smooth * nextStep))/Screen.height,0); } End ();}

Unity draws lines with GL Library

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.