Godot C# のMathf
クラスは、GDScript の数学定数・数学関数に対応するメンバーを提供している。
そのなかには、C# における標準ライブラリ提供のメンバーとオーバーラップしているため、処理がそのまま委譲されているものもある。
独自に提供されている機能を手軽に確認できるよう1、ソースをざっと確認してリストした。
- Godot 4.2.x
- .NET 8
一覧
name | note |
---|---|
AngleDifference | |
BezierDerivative | |
BezierInterpolate | |
CubicInterpolate | |
CubicInterpolateAngle | |
CubicInterpolateAngleInTime | |
CubicInterpolateInTime | |
DbToLinear | |
DecimalCount | |
DegToRad | |
Ease | |
Epsilon | Field |
InverseLerp | |
IsEqualApprox | |
IsZeroApprox | |
Lerp | ※ |
LerpAngle | |
LinearToDb | |
MoveToward | |
NearestPo2 | ※ |
PingPong | |
PosMod | |
RadToDeg | |
Remap | |
RotateToward | |
SmoothStep | |
Snapped | |
Sqrt2 | Field |
StepDecimals | |
Wrap |
一覧(メンバーすべて)
name | delegated as is | note |
---|---|---|
Abs | ✔ | |
Acos | ✔ | |
Acosh | ✔ | |
AngleDifference | ||
Asin | ✔ | |
Asinh | ✔ | |
Atan | ✔ | |
Atan2 | ✔ | |
Atanh | ✔ | |
BezierDerivative | ||
BezierInterpolate | ||
Ceil | ✔ | MathF.Ceiling |
CeilToInt | ✔ | (int)MathF.Ceiling |
Clamp | ✔ | |
Cos | ✔ | |
Cosh | ✔ | |
CubicInterpolate | ||
CubicInterpolateAngle | ||
CubicInterpolateAngleInTime | ||
CubicInterpolateInTime | ||
DbToLinear | ||
DecimalCount | ||
DegToRad | ||
E | ✔ | Field. not delegated as is, but Equals |
Ease | ||
Epsilon | Field | |
Exp | ✔ | |
Floor | ✔ | |
FloorToInt | ✔ | (int)MathF.Floor |
Inf | ✔ | Field. float.PositiveInfinity |
InverseLerp | ||
IsEqualApprox | ||
IsFinite | ✔ | |
IsInf | ✔ | float.IsInfinity |
IsNaN | ✔ | |
IsZeroApprox | ||
Lerp | ※ | |
LerpAngle | ||
LinearToDb | ||
Log | ✔ | |
Max | ✔ | |
Min | ✔ | |
MoveToward | ||
NaN | ✔ | Field |
NearestPo2 | ※ | |
Pi | ✔ | Field. not delegated as is, but Equals |
PingPong | ||
PosMod | ||
Pow | ✔ | |
RadToDeg | ||
Remap | ||
RotateToward | ||
Round | ✔ | |
RoundToInt | ✔ | (int)MathF.Round |
Sign | ✔ | |
Sin | ✔ | |
SinCos | ✔ | |
Sinh | ✔ | |
SmoothStep | ||
Snapped | ||
Sqrt | ✔ | |
Sqrt2 | Field | |
StepDecimals | ||
Tan | ✔ | |
Tanh | ✔ | |
Tau | ✔ | Field. not delegated as is, but Equals |
Wrap |
補足
Lerp
float.Lerp
について補足。一応、結果が異なりうる。
// Mathf.Lerp; same for Unity from + ((to - from) * weight); // float.Lerp (from * (1.0f - weight)) + (to * weight);
NearestPo2
標準ライブラリに存在するBitOperations.RoundUpToPowerOf2
を紹介する。同様の値を取得するが、可能な場合には高速な専用命令を使ってくれる。
var answer = BitOperations.RoundUpToPowerOf2(42); // 64
可能でない場合でもNearestPo2
と同様のアルゴリズムにフォールバックするので、ほぼ使い得(のはず)。