unity C# Mathf类源码

本文介绍了C#中几个常用的数学函数实现,包括循环函数Repeat、取值限制函数Clamp及线性插值函数Lerp,并对源代码进行了分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

从 变量命名和大量的goto可以看出 大部分源码看似是自动生成的,也可能是反编译工具的问题

1.Repeat

    public static float Repeat(float t, float length)
        {
            return (t - (Floor(t / length) * length));
        }

大部分可用整除%替代(C#整除支持float double)

2.Clamp

     public static int Clamp(int value, int min, int max)
        {
            if (value >= min)
            {
                goto Label_000F;
            }
            value = min;
            goto Label_0019;
        Label_000F:
            if (value <= max)
            {
                goto Label_0019;
            }
            value = max;
        Label_0019:
            return value;
        }

3.Lerp,Linearly interpolates between a and b by t.

 public static float Lerp(float a, float b, float t)
        {
            return (a + ((b - a) * Clamp01(t)));
        }

 

转载于:https://my.oschina.net/kkkkkkkkkkkkk/blog/679757

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值