public static float Magnitude(this Vector3 v, XYZBool includexyz) { return(Mathf.Sqrt( ((includexyz.x) ? v.x * v.x : 0) + ((includexyz.y) ? v.y * v.y : 0) + ((includexyz.z) ? v.z * v.z : 0))); }
/// <summary> /// Lerp extension that only applies the lerp to axis indicated by the XYZ. Other axis return the same axis value as start. /// </summary> public static Vector3 Lerp(this GameObject go, Vector3 start, Vector3 end, XYZBool includexyz, float t, bool localPosition = false) { // the lerped position, not accounting for any axis that are not included Vector3 rawLerpedPos = Vector3.Lerp(start, end, t); // for non-included axis, use the current postion return(new Vector3( (includexyz[0]) ? rawLerpedPos[0] : ((localPosition) ? go.transform.localPosition[0] : go.transform.position[0]), (includexyz[1]) ? rawLerpedPos[1] : ((localPosition) ? go.transform.localPosition[1] : go.transform.position[1]), (includexyz[2]) ? rawLerpedPos[2] : ((localPosition) ? go.transform.localPosition[2] : go.transform.position[2]))); }
/// <summary> /// Set position applying ONLY the values indicated as included, non-included axis use the current axis of the gameobject. /// </summary> public static void SetPosition(this GameObject go, Vector3 pos, XYZBool includexyz, bool localPosition = false) { Vector3 newpos = new Vector3( (includexyz[0]) ? pos[0] : (localPosition) ? go.transform.localPosition[0] : go.transform.position[0], (includexyz[1]) ? pos[1] : (localPosition) ? go.transform.localPosition[1] : go.transform.position[1], (includexyz[2]) ? pos[2] : (localPosition) ? go.transform.localPosition[2] : go.transform.position[2]); if (!localPosition) { go.transform.position = newpos; } else { go.transform.localPosition = newpos; } }
public static CompressedElement ReadCompressedPosFromBitstream(ref UdpKit.UdpBitStream bitstream, XYZBool _includeXYZ, bool lowerBitsOnly = false) { return(new CompressedElement( (_includeXYZ[0]) ? (bitstream.ReadUInt(lowerBitsOnly ? AxisRanges(0).lowerBits : AxisRanges(0).bits)) : 0, (_includeXYZ[1]) ? (bitstream.ReadUInt(lowerBitsOnly ? AxisRanges(1).lowerBits : AxisRanges(1).bits)) : 0, (_includeXYZ[2]) ? (bitstream.ReadUInt(lowerBitsOnly ? AxisRanges(2).lowerBits : AxisRanges(2).bits)) : 0)); }
public static void WriteCompPosToBitstream(this CompressedElement compressedpos, ref UdpKit.UdpBitStream bitstream, XYZBool _includeXYZ, bool lowerBitsOnly = false) { for (int axis = 0; axis < 3; axis++) { //TODO: use lowerbits from inside ranges if (_includeXYZ[axis]) { bitstream.WriteUInt(compressedpos[axis], lowerBitsOnly ? AxisRanges(axis).lowerBits : AxisRanges(axis).bits); } } }
public static bool All(this XYZBool xyzbool) => xyzbool.X && xyzbool.Y && xyzbool.Z;
public static bool None(this XYZBool xyzbool) => !xyzbool.X && !xyzbool.Y && !xyzbool.Z;
public static bool Any(this XYZBool xyzbool) => xyzbool.X || xyzbool.Y || xyzbool.Z;