Compression: ScaleToLong/Float Vector3Long variants to prepare for NetworkTransform V3

This commit is contained in:
vis2k 2022-11-01 17:34:10 +01:00
parent 701c16a307
commit 9e352f5be2

View File

@ -71,6 +71,13 @@ public static bool ScaleToLong(Vector3 value, float precision, out long x, out l
return result;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool ScaleToLong(Vector3 value, float precision, out Vector3Long quantized)
{
quantized = Vector3Long.zero;
return ScaleToLong(value, precision, out quantized.x, out quantized.y, out quantized.z);
}
// multiple by precision.
// for example, 0.1 cm precision converts '50' long to '5.0f' float.
public static float ScaleToFloat(long value, float precision)
@ -96,6 +103,10 @@ public static Vector3 ScaleToFloat(long x, long y, long z, float precision)
return v;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector3 ScaleToFloat(Vector3Long value, float precision) =>
ScaleToFloat(value.x, value.y, value.z, precision);
// scale a float within min/max range to an ushort between min/max range
// note: can also use this for byte range from byte.MinValue to byte.MaxValue
public static ushort ScaleFloatToUShort(float value, float minValue, float maxValue, ushort minTarget, ushort maxTarget)