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. JavaScript语言精粹知识点总结

    1.NaN是一个数值,它表示一个不能产生正常结果的运算结果.NaN不等于任何值,包括它自己. 2.Infinity表示所有大于1.79769313486231570e+308的值,所以Infinity ...

  2. ubunt14.04搭建lNMP

    一.安装mysql 1.  sudo apt-get update 2.  sudo apt-get install apt-get nginx 二.安装mysql 1.  sudo apt-get ...

  3. error C2039: “addTextureMesh”: 不是“pcl::visualization::PCLVisualizer”的成员

    error C2039: "addTextureMesh": 不是"pcl::visualization::PCLVisualizer"的成员 PCL 1.6 ...

  4. 人工智能: 自动寻路算法实现(三、A*算法)

    博客转载自:https://blog.csdn.net/kwame211/article/details/78139506 本篇文章是机器人自动寻路算法实现的第三章.我们要讨论的是一个在一个M×N的格 ...

  5. HDU 5974 A Simple Math Problem (解方程)

    题意:给定a和b,求一组满足x+y=a && lcm(x, y)=b. 析:x+y = a, lcm(x, y) = b,=>x + y = a, x * y = b * k,其 ...

  6. Codeforces Round #179 (Div. 2) B. Yaroslav and Two Strings (容斥原理)

    题目链接 Description Yaroslav thinks that two strings s and w, consisting of digits and having length n  ...

  7. Golang : cobra 包解析

    笔者在<Golang : cobra 包简介>一文中简要的介绍了 cobra 包及其基本的用法,本文我们从代码的角度来了解下 cobra 的核心逻辑. Command 结构体 Comman ...

  8. 开发php接口注意点

    1.制定规范 开发前一定要定好一个规范,比如要定好数据返回的通用参数和格式.关于数据格式,用的比较多的有xml和json,我建议用json,因为json比xml的好处更多. 2.精简的返回数据 接口数 ...

  9. Python 生成个性二维码

    1.1 实验内容 本课程通过调用MyQR接口来实现生成个人所需二维码,并可以设置二维码的大小.是否在现有图片的基础上生成.是否生成动态二维码. 本课程主要面向Python3初学者. 1.2 知识点 P ...

  10. ios各个型号设备屏幕分辨率总结

    https://blog.csdn.net/amyloverice/article/details/79389357     iPhone: iPhone 1G 320x480 iPhone 3G 3 ...