1.用粒子制作抛物线。

1.创建一个枚举

public enum FunctionOption {Linear,Exponential,Parabola,Sine}

2.创建静态方法

//直线
private static float Linear (float x) {return x;}//曲线private static float Exponential (float x) {return x * x;}//抛物线private static float Parabola (float x){x = 2f * x - 1f;return x * x;}//Sine 曲线 可以通过相位来控制Shader水的流动,有兴趣的可以去实现private static float Sine (float x){return 0.5f + 0.5f * Mathf.Sin(2 * Mathf.PI * x + Time.timeSinceLevelLoad);}

3.创建委托函数

private delegate float FunctionDelegate (float x);private static FunctionDelegate[] functionDelegates = {Linear,Exponential,Parabola,Sine};public FunctionOption function;

4.创建点

private void CreatePoints () {currentResolution = resolution;points = new ParticleSystem.Particle[resolution];float increment = 1f / (resolution - 1);for (int i = 0; i < resolution; i++) {float x = i * increment;points[i].position = new Vector3(x, 0f, 0f);points[i].color = new Color(x, 0f, 0f);points[i].size = 0.1f;}}void Update () {if (currentResolution != resolution || points == null) {CreatePoints();}FunctionDelegate f = functionDelegates[(int)function];for (int i = 0; i < resolution; i++) {Vector3 p = points[i].position;p.y = f(p.x);points[i].position = p;Color c = points[i].startColor;c.g = p.y;points[i].startColor = c;}GetComponent<ParticleSystem>().SetParticles(points, points.Length);}

5.全部代码如下 ,并把他放在粒子物体上,不过这个一直是在Update里面执行,所以性能会比较耗性能,这
主要测试功能用的。

using UnityEngine;public class Test : MonoBehaviour {public enum FunctionOption {Linear,Exponential,Parabola,Sine}private delegate float FunctionDelegate (float x);private static FunctionDelegate[] functionDelegates = {Linear,Exponential,Parabola,Sine};public FunctionOption function;[Range(10, 100)]public int resolution = 10;private int currentResolution;private ParticleSystem.Particle[] points;private void CreatePoints () {currentResolution = resolution;points = new ParticleSystem.Particle[resolution];float increment = 1f / (resolution - 1);for (int i = 0; i < resolution; i++) {float x = i * increment;points[i].position = new Vector3(x, 0f, 0f);points[i].color = new Color(x, 0f, 0f);points[i].size = 0.1f;}}void Update () {if (currentResolution != resolution || points == null) {CreatePoints();}FunctionDelegate f = functionDelegates[(int)function];for (int i = 0; i < resolution; i++) {Vector3 p = points[i].position;p.y = f(p.x);points[i].position = p;Color c = points[i].startColor;c.g = p.y;points[i].startColor = c;}GetComponent<ParticleSystem>().SetParticles(points, points.Length);}private static float Linear (float x) {return x;}private static float Exponential (float x) {return x * x;}private static float Parabola (float x){x = 2f * x - 1f;return x * x;}private static float Sine (float x){return 0.5f + 0.5f * Mathf.Sin(2 * Mathf.PI * x + Time.timeSinceLevelLoad);}
}

Unity 抛物线,直线,Sine曲线等相关推荐

  1. TWaver3D直线、曲线、曲面的绘制

    插播一则广告(长期有效) TWaver需要在武汉招JavaScript工程师若干 要求:对前端技术(JavasScript.HTML.CSS),对可视化技术(Canvas.WebGL)有浓厚的兴趣 基 ...

  2. PCL:拟合平面直线和曲线以及空间曲线的原理到算法实现

    使用两种思路进行直线拟合: 1.利用逆矩阵思想 --------------进行下列公式的推导需要理解逆矩阵(求A矩阵的逆矩阵,则A矩阵必须是方阵)的知识: (1)为什么要引入逆矩阵呢? 逆矩阵可以类 ...

  3. Java swing实现Visio中对直线、曲线、折线的画及拖动删除

    原文:http://blog.csdn.net/cuiyaoqiang/article/details/46361133 最终线条如图显示,可以实现线条的拖动.删除等 以下是两个核心的类: packa ...

  4. 【python图像处理】直线和曲线的拟合与绘制(curve_fit()详解)

    在数据处理和绘图中,我们通常会遇到直线或曲线的拟合问题,python中scipy模块的子模块optimize中提供了一个专门用于曲线拟合的函数curve_fit(). 下面通过示例来说明一下如何使用c ...

  5. WinForm绘制直线、曲线、矩形、椭圆、圆弧

    WinForm绘制直线.曲线.矩形.椭圆.圆弧 新建一个窗体.添加六个按钮,插入下面的代码.得到上图. private void button1_Click(object sender, EventA ...

  6. 【笔记】位图(.bmp)和矢量图(Vector):位图是点阵图或光栅图,使用像素的一格一格来描述图像,放大以后每一个像素看就像是一个个的马赛克;矢量图是使用直线和曲线来描述图形,可以无限方法,不会失真

    一.什么是位图 计算机能以位图和矢量图格式显示图像. 1.位图(Bitmap): 图像又称点阵图或光栅图,它使用我们称为像素(象素,Pixel)的一格一格的小点来描述图像.计算机屏幕其实就是一张包含大 ...

  7. CAD中如何快速等分一条直线或曲线?教程详解

    一般图纸设计中的时候,在CAD中有时我们想得到直线或曲线的等分点,有时我们想沿直线或曲线等距或等分排列图形,这个时候该怎么办呢?但其实在CAD很早的版本就提供了定数等分和定距等分的功能,可能只是大家没 ...

  8. unity 控制点 贝塞尔曲线_在Unity中使用贝塞尔曲线(转)

    鼎鼎大名的贝塞尔曲线相信大家都耳熟能详.这两天因为工作的原因需要将贝塞尔曲线加在工程中,那么MOMO迅速的研究了一下成果就分享给大家了哦.贝塞尔曲线的原理是由两个点构成的任意角度的曲线,这两个点一个是 ...

  9. PhotoShop钢笔工具创建直线和曲线

    创建直线: 1.选择钢笔工具(P) 2.单击鼠标创建第一个锚点 3.在第二个锚点所在的位置上单击鼠标即可生成一条直线 创建曲线: 1.选择钢笔工具(P) 2.单击鼠标创建第一个锚点 3.创建第二个锚点 ...

最新文章

  1. javascript的垃圾回收机制指的是什么
  2. 为你的网站使用paypal
  3. 加锁查询 FOR UPDATE 解决表格查询极慢的问题
  4. python3 pyinstaller 打包后 程序会显示两个进程 解决方法
  5. MVVM实践中的Command与CommandParameter的使用
  6. matplotlib散点图笔记
  7. 前端学习(2458):素材管理
  8. 《2020饿了么蓝骑士报告》:贫困县骑手月入5800元 成脱贫新兴力量
  9. 如何创建和使用自引用层次结构表
  10. 杭电2100Lovekey
  11. BZOJ 3897: Power
  12. 2021陆川高考成绩查询,陆川中考成绩查询2021
  13. conda clean -i
  14. c语言中dist有是什么作用,C语言习题及答案(第九章).doc
  15. Protel99SE教程(一)——原理图封装
  16. 群赛 round#5 解题报告(superoxide,choice,rpwt)
  17. NLP入门干货:手把手教你3种中文规则分词方法
  18. git clone 失败问题解决方案
  19. 金典《歌手》2019即将首播 创作季上演神仙打架
  20. 数据加速器 GooseFS 1.3.0 版本正式发布

热门文章

  1. 易语言大漠圆形椭圆形渐开线结合鼠标特征码刷怪
  2. 중국인이 한국인을 보는눈길
  3. 【汇正财经】上证50逆势收涨,大盘健康震固
  4. 最让我感动的图片...
  5. R和Rstudio 下载安装
  6. 小甲鱼python视频bilibili_在B站上学编程,这几个视频你知道了么?
  7. 基于HMM的拼音转汉字程序
  8. 深度学习分类pytorch_pytorch使用转移学习的狗品种分类器
  9. Android Studio Shape属性(上)
  10. 锦标赛算法Python实现