Unity下GL没有画圆的函数,只能自己来了。

如果能帮到大家,我也很高兴。

虽然没有画圆的函数,但是能画直线,利用这一点,配合微积分什么的,就可以画出来了。反正就是花很多连在一起的直线,每条直线足够短的时候,就足够圆了

 void DrawCircle(float x, float y, float z, float r, float accuracy)
{
GL.PushMatrix ();
//绘制2D图像
GL.LoadOrtho (); float stride = r * accuracy;
float size = / accuracy;
float x1 = x, x2 = x, y1 = , y2 = ;
float x3 = x, x4 = x, y3 = , y4 = ; double squareDe;
squareDe = r * r - Math.Pow (x - x1, );
squareDe = squareDe > ? squareDe : ;
y1 = (float)(y + Math.Sqrt (squareDe));
squareDe = r * r - Math.Pow (x - x1, );
squareDe = squareDe > ? squareDe : ;
y2 = (float)(y - Math.Sqrt (squareDe));
for (int i = ; i < size; i++) {
x3 = x1 + stride;
x4 = x2 - stride;
squareDe = r * r - Math.Pow (x - x3, );
squareDe = squareDe > ? squareDe : ;
y3 = (float)(y + Math.Sqrt (squareDe));
squareDe = r * r - Math.Pow (x - x4, );
squareDe = squareDe > ? squareDe : ;
y4 = (float)(y - Math.Sqrt (squareDe)); //绘制线段
GL.Begin (GL.LINES);
GL.Color (Color.blue);
GL.Vertex (new Vector3 (x1 / Screen.width, y1 / Screen.height, z));
GL.Vertex (new Vector3 (x3 / Screen.width, y3 / Screen.height, z));
GL.End ();
GL.Begin (GL.LINES);
GL.Color (Color.blue);
GL.Vertex (new Vector3 (x2 / Screen.width, y1 / Screen.height, z));
GL.Vertex (new Vector3 (x4 / Screen.width, y3 / Screen.height, z));
GL.End ();
GL.Begin (GL.LINES);
GL.Color (Color.blue);
GL.Vertex (new Vector3 (x1 / Screen.width, y2 / Screen.height, z));
GL.Vertex (new Vector3 (x3 / Screen.width, y4 / Screen.height, z));
GL.End ();
GL.Begin (GL.LINES);
GL.Color (Color.blue);
GL.Vertex (new Vector3 (x2 / Screen.width, y2 / Screen.height, z));
GL.Vertex (new Vector3 (x4 / Screen.width, y4 / Screen.height, z));
GL.End (); x1 = x3;
x2 = x4;
y1 = y3;
y2 = y4;
}
GL.PopMatrix ();
}

参数分别为: x,y,z 中心点三维坐标, r 圆的半径, accuracy 精度,精度越小,越圆

如有错误,请不吝指教

Unity GL 画圆的更多相关文章

  1. Unity GL画折线

    新建一个脚本,这个物体得挂在有摄像机组件的物体上才能生效 OnPostRender() 这个函数才会被自动调用(类似生命周期自动调用) 然后就可以代码画线了,原理是openGL的画线 using Un ...

  2. unity gl 画线

    using UnityEngine; using System.Collections; public class TGLLine : MonoBehaviour { private static M ...

  3. 《图形学》实验六:中点Bresenham算法画圆

    开发环境: VC++6.0,OpenGL 实验内容: 使用中点Bresenham算法画圆. 实验结果: 代码: #include <gl/glut.h> #define WIDTH 500 ...

  4. 【openGL】画圆

    #include "stdafx.h" #include <GL/glut.h> #include <stdlib.h> #include <math ...

  5. OpenGL 3:画圆

    这次使用OpenGL画圆,而且中间画一个实心的五角星. 1. 画实心五角: 由于之前使用Polygen画会出现故障,或许是各个GPU硬件也会不一样的,所以使用Polygen画实心五角星并不可靠: 所以 ...

  6. 中点Bresenham画圆

    这里不仔细讲原理,只是把我写的算法发出来,跟大家分享下,如果有错误的话,还请大家告诉我,如果写的不好,也请指出来,一起讨论进步. 算法步骤: (1) 输入圆的半径R. (2) 计算初始值d = 1 - ...

  7. WebGIS中基于AGS的画圆查询简析以及通过Polygon来构造圆的算法

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.背景 某个项目需求中需要在前端进行画圆查询,将圆范围上的多边形要素 ...

  8. ArcGIS JS 学习笔记2 实现仿百度的拖拽画圆

    一.前言 吐槽一下,百度在国内除了百度地图是良心产品外,其他的真的不敢恭维.在上一篇笔记里,我已经实现了自定义的地图测量模块.在百度地图里面(其他地图)都有一个周边搜索的功能,拖拽画一个圆,然后以圆半 ...

  9. canvas入门(画圆)

    1.想在H5上画一个canvas,必须在页面上你需要的地方添加canvas标签, <canvas id="myCanvas"></canvas>   接着需 ...

随机推荐

  1. MODBUS TCP和MODBUS RTU的差别

    TCP和RTU协议非常类似, MBAP Header长度共7个字节,分别为Transaction identifier(事务标识符),Protocol identifier(协议标识符),Length ...

  2. 什么是Nginx?为什么使用Nginx?

    源自 https://blog.csdn.net/yougoule/article/details/78186138 一.前言      为毛要用nginx服务器代理,不直接用tomcat 7.0,还 ...

  3. SpringMVC 学习笔记(请求方法的返回值和参数)

    在用注解对配置 处理器时,一般是一个方法处理一个请求,不同方法的返回类型有着不同的意义. 返回值为 ModelAndView 类型 ModelAndView 是Model 和 View 的一个集合类型 ...

  4. /*去hover动画效果*/

    <!DOCTYPE html> /*去hover动画效果*/ <html lang="en"> <head> <meta charset= ...

  5. redis-数据类型-string、hash、list、set、zset

    String 类型操作string是redis最基本的类型,而且string类型是二进制安全的.意思是redis的string可以包含任何数据.比如jpg图片或者序列化的对象. $redis-> ...

  6. ServerSocket01

    ServerSocket表示服务端套接字:我们首先来看下其中的一个构造器: public ServerSocket(int port,int backlog) throws IOException 其 ...

  7. Ubuntu使用crontab 使用举例

    除了这些固定值外,还可以配合星号(*),逗号(,),和斜线(/)来表示一些其他的含义:     星号          表示任意值,比如在小时部分填写 * 代表任意小时(每小时)   逗号      ...

  8. jquery获取ASP.NET服务器端控件dropdownlist和radiobuttonlist生成客户端HTML标签后的value和text值

    —.获取dropdownlist的text(ddlList为服务器端dropdownlist的ID,生成name属性等于ddlList的select标签) $("#ddlList optio ...

  9. HTTP协议格式及基础

    HTTP请求数据: HTTP请求信息由3部分组成: ① 请求方法 URI 协议/版本 ② 请求头(Request Header) ③     请求正文 HTTP 请求 数据 例子举例: GET/sam ...

  10. Eclipse 整合SpringMybatis,SpringMVC,用Maven管理项目搭建详情

    环境:JDK下载地址 https://pan.baidu.com/s/1UyvEAI-4Ci6TDdVJiYUUiQ 密码:ma51 IDE:eclipse下载地址 https://pan.baidu ...