I’am currently upgrading a old project to the Unity.Mathematics System to Burst Compile.
I search the Mathf.PingPong Function, is there something available?
Later i will add other searches here, so if someone can’t find Functions from the old Mathf in the new Mathematics, let me know.
Thanks
tertle
December 29, 2021, 11:29am
2
There’s a few useful ported functions here (not pingpong)
//#define INCLUDEMATHCHECKS
using System;
using Unity.Mathematics;
using Unity.Sample.Core;
using UnityEngine;
// Collection of converted classic Unity (Mathf, Vector3 etc.) + some homegrown math functions using Unity.Mathematics
// These are made/converted for production and unlike a proper library they are lacking any tests, so use at your own peril!
public static class MathHelper
{
const float kEpsilonNormalSqrt = 1e-15F;
// TODO: Should likely be platform dependent, maybe a value in unity.math?
const float kEpisilon = 1.17549435E-38f;
[ConfigVar(Name = "math.show.comparison", DefaultValue = "1", Description = "Show old vs new math comparison")]
public static ConfigVar CompareMath;
This file has been truncated. show original
such as SmoothDampnalge, Repeat, DeltaAngle, MoveTowards, LerpAngle etc etc
You can always port directly from Mathf. Either by decompiling, or you can find decompiled sources, e.g.:
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Threading;
using System.Runtime.CompilerServices;
using uei = UnityEngine.Internal;
using UnityEngine.Bindings;
namespace UnityEngineInternal
{
[Unity.IL2CPP.CompilerServices.Il2CppEagerStaticClassConstruction]
public partial struct MathfInternal
{
public static volatile float FloatMinNormal = 1.17549435E-38f;
public static volatile float FloatMinDenormal = Single.Epsilon;
public static bool IsFlushToZeroEnabled = (FloatMinDenormal == 0);
}
This file has been truncated. show original
As for the PingPong method, here it is:
// PingPongs the value t, so that it is never larger than length and never smaller than 0.
public static float PingPong(float t, float length)
{
t = Repeat(t, length * 2F);
return length - Mathf.Abs(t - length);
}
1 Like
Thank you that is what i searched for, i can change the Mathf.Abs function to the new Mathematics.Abs function, to get it Burst ready