unity日常——Mathf
来源:互联网 发布:中国科学院科学数据库 编辑:程序博客网 时间:2024/06/07 08:46
unity日常—Mathf
这一次讲讲unity里面的Mathf函数
主要是加强我的记忆,有好多不常用的我会忘掉,就算是常用的我有时也会忘,在这里写下来哪一天忘了在来看看。
(一)Mathf.Abs绝对值
public static float Abs(float f);
计算并返回指定参数f绝对值
(二)Mathf.Acos反余弦
public static function Acos (f : float) : float
以弧度为单位计算并返回参数 f 中指定的数字的反余弦值。
(三)Mathf.Approximately近似
public static bool Approximately(float a, float b);
比较两个浮点值,如果它们相似,则返回true。
浮点不精确使得使用等号运算符的浮点数比较不准确。例如,(1 = 10 / 10)可能每次都不返回true。
(四)Mathf.Asin反正弦
public static float Asin(float f);
以弧度为单位计算并返回参数 f 中指定的数字的反正弦值。
(五)Mathf.Atan反正切
public static float Atan(float f);
计算并返回参数 f 中指定的数字的反正切值。返回值介于负二分之 pi 与正二分之 pi 之间。
(六)Mathf.Atan2反正切
public static float Atan2(float y, float x);
以弧度为单位计算并返回 y/x 的反正切值。返回值表示相对直角三角形对角的角,其中 x 是临边边长,而 y 是对边边长。
返回值是在x轴和一个二维向量开始于0个结束在(x,y)处之间的角。
using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour { public Transform target; void Update() { Vector3 relative = transform.InverseTransformPoint(target.position); float angle = Mathf.Atan2(relative.x, relative.z) * Mathf.Rad2Deg; transform.Rotate(0, angle, 0); }}
(七)Mathf.Ceil上限值
public static float Ceil(float f);
返回大于或等于f的最小整数。
// Prints 10 Debug.Log(Mathf.Ceil(10.0F)); // Prints 11 Debug.Log(Mathf.Ceil(10.2F)); // Prints 11 Debug.Log(Mathf.Ceil(10.7F)); // Prints -10 Debug.Log(Mathf.Ceil(-10.0F)); // Prints -10 Debug.Log(Mathf.Ceil(-10.2F)); // Prints -10 Debug.Log(Mathf.Ceil(-10.7F));
(八)Mathf.CeilToInt最小整数
public static int CeilToInt(float f);
返回大于或等于f的最小整数
Debug.Log(Mathf.CeilToInt(10.0F)); Debug.Log(Mathf.CeilToInt(10.2F)); Debug.Log(Mathf.CeilToInt(10.7F)); Debug.Log(Mathf.CeilToInt(-10.0F)); Debug.Log(Mathf.CeilToInt(-10.2F)); Debug.Log(Mathf.CeilToInt(-10.7F));
(九)Mathf.Clamp限制
public static float Clamp(float value, float min, float max);
public static int Clamp(int value, int min, int max);
限制value的值在min和max之间, 如果value小于min,返回min。 如果value大于max,返回max,否则返回value
transform.position = new Vector3(Mathf.Clamp(Time.time, 1.0F, 3.0F), 0, 0);
(十)Mathf.Clamp01限制0~1
public static float Clamp01(float value);
夹值在0到1之间,返回值。
transform.position = new Vector3(Mathf.Clamp01(Time.time), 0, 0);
(十一)Mathf.ClosestPowerOfTwo最近的二次方
public static int ClosestPowerOfTwo(int value);
返回距离value最近的2的次方数。
Debug.Log(Mathf.ClosestPowerOfTwo(7)); Debug.Log(Mathf.ClosestPowerOfTwo(19));
(十二)Mathf.CorrelatedColorTemperatureToRGB
public static Color CorrelatedColorTemperatureToRGB(float kelvin);
把温度(开氏度)变成颜色,kelvin范围在1000到40000。
(十三)Mathf.Cos余弦
public static float Cos(float f);
返回由参数 f 指定的角的余弦值(介于 -1.0 与 1.0 之间的值)。
(十四)Mathf.DeltaAngle增量角
public static float DeltaAngle(float current, float target);
计算给定角度的两个给定角度之间的最短差。
Debug.Log(Mathf.DeltaAngle(1080, 90));
(十五)Mathf.Exp指数
public static float Exp(float power);
返回 e 的 power 次方的值。
print(Mathf.Exp(6));
(十六)Mathf.Floor下限值
public static float Floor(float f);
返回小于或等于f的最大整数。
Debug.Log(Mathf.Floor(10.0F)); Debug.Log(Mathf.Floor(10.2F)); Debug.Log(Mathf.Floor(10.7F)); Debug.Log(Mathf.Floor(-10.0F)); Debug.Log(Mathf.Floor(-10.2F)); Debug.Log(Mathf.Floor(-10.7F));
(十七)Mathf.FloorToInt最大整数
public static int FloorToInt(float f);
返回小于或等于f的最大整数。
Debug.Log(Mathf.FloorToInt(10.0F)); Debug.Log(Mathf.FloorToInt(10.2F)); Debug.Log(Mathf.FloorToInt(10.7F)); Debug.Log(Mathf.FloorToInt(-10.0F)); Debug.Log(Mathf.FloorToInt(-10.2F)); Debug.Log(Mathf.FloorToInt(-10.7F));
(十八)Mathf.GammaToLinearSpace
public static float GammaToLinearSpace(float value);
转换gamma(sRGB)到linear color space。没有写完,以后会完善的,有的我还没有用过所以有错误的请指出来,我会改正。
—— 这是官网 [ 传送门 ]
—— 上一篇 [ unity日常—函数执行顺序 ]
—— 下一篇 [ unity日常—游戏存档 ]
- unity日常——Mathf
- Unity < 常用数学运算 —— Mathf >
- 网络学习——unity中Mathf数学运算
- unity日常——EventTrigger
- Unity中的Mathf类
- UNITY 5.2 Mathf 结构
- Unity 的 mathf.lerp
- Unity Mathf 数学运算
- Unity Mathf类 笔记
- unity Mathf API
- Unity日常——关于射线
- unity日常——函数执行顺序
- unity日常——游戏存档
- unity日常——游戏优化
- unity中Mathf.Lerp、Mathf.MoveTowards、Mathf.SmoothStep、Mathf.SmoothDamp的区别
- unity Mathf 数学运算(C#)
- Unity Mathf 数学运算(C#)
- Unity Mathf 数学运算(C#)
- Python学习笔记(11)- 函数(1)
- 高性能Mysql:服务器性能剖析
- javascript 高级——几种对象创建方法
- java中char类型的默认值是 '\u0000' 吗?是空字符还是空格?
- 01 开始Python数据分析之旅
- unity日常——Mathf
- HTML5学习----拖拽效果
- MAC freeswitch 安装教程
- Gr
- Android四大组件之Service全面学习
- Root of AVL Tree(25 分)
- 判断两个对象是否相等
- Vue.js入门第二篇
- 解决Linux下编译Java产生 illegal character: \65279 错误的问题