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. linux命令-tar打包和压缩并用

    tar在打包的时候进行压缩 支持 gzip bzip2 xz 格式 -z  gzip格式 -j  bzip2格式 -J  xz格式 压缩打包 [root@wangshaojun ~]# tar -zc ...

  2. 洛谷-关押罪犯-NOIP2010提高组复赛

    题目描述 S 城现有两座监狱,一共关押着N 名罪犯,编号分别为1~N.他们之间的关系自然也极不和谐.很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发冲突.我们用“怨气值”(一个正整数值)来表示 ...

  3. http相关理解

    http://blog.csdn.net/generon/article/details/73920945

  4. Ubuntu下crontab命令的用法

    cron是一个Linux下的后台进程,用来定期的执行一些任务.因为我用的是Ubuntu,所以这篇文章中的所有命令也只能保证在Ubuntu下有效,但其他系统应该也差不多. 想要让cron执行你指定的任务 ...

  5. win7 失去焦点解决方案

    将HKEY_CURRENT_USER\Control Panel\Desktop中的ForegroundLockTimeout的选项,改成十进制的200000毫秒或者十六进制30d40. 参考链接: ...

  6. js复习笔记

    isNaN(x) 1.判断结果不是纯数字, var a=1234var b =isNan(a) //b是 false 因为a是纯数字 var a="abc123"var b =is ...

  7. Net Core 下载图片

    直接上代码 string url = https://www.cnblogs.com/images/logo_small.gif; //获取网站当前根目录 string sWebRootFolder ...

  8. [WIP]JavaScript import, export

    创建: 2019/06/14 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/import h ...

  9. 通过增删改查对比Array,Map,Set,Object的使用成本和实现方式

    1.Array 和 Map 对比 { // array and map 增 查 改 删 let map = new Map(); let arr = []; // 增 map.set('a', 1); ...

  10. elasticsearch shard 和 replica

    (1)index包含多个shard(2)每个shard都是一个最小工作单元,承载部分数据,lucene实例,完整的建立索引和处理请求的能力(3)增减节点时,shard会自动在nodes中负载均衡(4) ...