• Unity3D 绘制扇形/环形



    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; } }

  • 相关阅读:
    055——VUE中vue-router之路由参数的随意设置与伪静态链接地址处理:
    将PCM格式存储成WAV格式文件
    pcm、wav、amr说明
    使用ffmpeg.exe进行转码参数说明
    使用Java调用exe可执行文件
    函数和宏实现打印的增强myprintf
    va_start和va_end使用详解
    为何windows自带的文件搜索这么慢,而Everything的这么快
    clearfix清除浮动
    DISCUZ! X2.5设置仅允许QQ登录注册论坛 加固会员注册机制
  • 原文地址:https://www.cnblogs.com/louissong/p/8337855.html
Copyright © 2020-2023  润新知