using UnityEngine;
using System.Collections;
using System.Collections.Generic; public class Cone : MonoBehaviour { public float anglefov = ;
public int quality = ;
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 * * ];
vertices = new Vector3[quality * + ];
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 = ; i < quality + ; 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[ * i + ] = pos_curr_min;
vertices[ * i + ] = pos_curr_max; uvs[ * i + ] = new Vector2((float)(quality-i) / quality, );
uvs[ * i + ] = new Vector2((float)(quality-i) / quality, ); normals[ * i + ] = Vector3.up;
normals[ * i + ] = Vector3.up; angle_curr -= angle_delta;
} for (int i = ; i < quality; i++)
{
// 5---3---1
// | /| /|
// | / | / |
// |/ |/ |
// 4---2---0 int index_min_cur = i * + ;
int index_max_cur = i * + ;
int index_min_next = i * + ;
int index_max_next = i * + ; triangles[ * i + ] = index_min_cur;
triangles[ * i + ] = index_min_next;
triangles[ * i + ] = index_max_cur;
triangles[ * i + ] = index_min_next;
triangles[ * i + ] = index_max_next;
triangles[ * i + ] = index_max_cur; } meshFilter.sharedMesh.vertices = vertices;
meshFilter.sharedMesh.triangles = triangles;
meshFilter.sharedMesh.uv = uvs;
}
}

最新文章

  1. chrome浏览器 开发者工具简介
  2. Last-Modified、If-Modified-Since 实现缓存和 OutputCache 的区别
  3. PHP获取一年有几周以及每周开始日期和结束日期
  4. java类中成员的划分
  5. lua table序列化和反序列化
  6. linux下shell脚本学习
  7. 第二百八十九天 how can I 坚持
  8. int、bigint、smallint 和 tinyint
  9. Poco::TCPServer框架解析
  10. 无法远程连接mysql,连接后也没有权限创建数据库
  11. 翻译连载 | 附录 B: 谦虚的 Monad-《JavaScript轻量级函数式编程》 |《你不知道的JS》姊妹篇
  12. 一个BAT老程序员的忠告!
  13. exit(0)与exit(1)、return的区别
  14. DevOps 解决方案 - 腾讯云
  15. Return array from functions in C++
  16. Android 包信息工具类
  17. 斯皮尔曼等级相关(Spearman’s correlation coefficient for ranked data)
  18. zuul源码分析-探究原生zuul的工作原理
  19. 在linux上配置Django项目
  20. ES6--Set之再理解

热门文章

  1. 2018.5.22 Oracle安装配置在虚拟机中外部电脑连接服务
  2. bootstrap table加载数据
  3. python内置函数map/reduce/filter
  4. Load事件中控件Focus()无效解决办法
  5. package.json字段分析
  6. Mysql的一些纪要
  7. MySQL解决中文编码问题
  8. Linux下面自动清理超过指定大小的文件
  9. Java泛型和反射
  10. 29.VUE学习之--键盘事件.键盘修饰符的实例讲解