码迷,mamicode.com
首页 > 编程语言 > 详细

Unity3D 绘制扇形/环形

时间:2018-01-23 22:03:27      阅读:1155      评论:0      收藏:0      [点我收藏+]

标签:using   bubuko   []   .com   技术分享   bsp   orm   tor   vector   


using
UnityEngine; using System.Collections; using System.Collections.Generic; public class Cone : MonoBehaviour { public float anglefov = 30; public int quality = 2; public int[] triangles; public Vector2[] uvs; public Vector3[] vertices; public Vector3[] normals; public float dist_min = 0.0f; public float dist_max = 1f; public MeshFilter meshFilter; // Use this for initialization void Awake () { triangles = new int[quality * 2 * 3]; vertices = new Vector3[quality * 2 + 2]; uvs = new Vector2[vertices.Length]; normals = new Vector3[vertices.Length]; meshFilter = GetComponent<MeshFilter>(); } // Update is called once per frame void Update () { meshFilter.mesh.Clear(); Vector3 pos = Vector3.zero;//transform.position; float angle_lookat = transform.eulerAngles.y; float angle_fov = anglefov; float angle_start = angle_lookat - angle_fov; float angle_end = angle_lookat + angle_fov; float angle_delta = (angle_end - angle_start) / quality; float angle_curr = angle_end; for (int i = 0; i < quality + 1; i++) { Vector3 sphere_curr = new Vector3(); sphere_curr.z = Mathf.Cos(Mathf.Deg2Rad * angle_curr); sphere_curr.x = Mathf.Sin(Mathf.Deg2Rad * angle_curr); Vector3 pos_curr_min = pos + sphere_curr * dist_min; Vector3 pos_curr_max = pos + sphere_curr * dist_max; vertices[2 * i + 0] = pos_curr_min; vertices[2 * i + 1] = pos_curr_max; uvs[2 * i + 0] = new Vector2((float)(quality-i) / quality, 0); uvs[2 * i + 1] = new Vector2((float)(quality-i) / quality, 1); normals[2 * i + 0] = Vector3.up; normals[2 * i + 1] = Vector3.up; angle_curr -= angle_delta; } for (int i = 0; i < quality; i++) { // 5---3---1 // | /| /| // | / | / | // |/ |/ | // 4---2---0 int index_min_cur = i * 2 + 0; int index_max_cur = i * 2 + 1; int index_min_next = i * 2 + 2; int index_max_next = i * 2 + 3; triangles[6 * i + 0] = index_min_cur; triangles[6 * i + 1] = index_min_next; triangles[6 * i + 2] = index_max_cur; triangles[6 * i + 3] = index_min_next; triangles[6 * i + 4] = index_max_next; triangles[6 * i + 5] = index_max_cur; } meshFilter.sharedMesh.vertices = vertices; meshFilter.sharedMesh.triangles = triangles; meshFilter.sharedMesh.uv = uvs; } }

技术分享图片

技术分享图片

 

Unity3D 绘制扇形/环形

标签:using   bubuko   []   .com   技术分享   bsp   orm   tor   vector   

原文地址:https://www.cnblogs.com/louissong/p/8337855.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!