/// <summary> /// Only factors in used axes /// </summary> public static float Magnitude(this Vector3 v, IncludedAxes ia) { return(Mathf.Sqrt( ((((int)ia & 1) != 0) ? v.x * v.x : 0) + ((((int)ia & 2) != 0) ? v.y * v.y : 0) + ((((int)ia & 4) != 0) ? 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, IncludedAxes ia, 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( (((int)ia & 1) != 0) ? rawLerpedPos[0] : ((localPosition) ? go.transform.localPosition[0] : go.transform.position[0]), (((int)ia & 2) != 0) ? rawLerpedPos[1] : ((localPosition) ? go.transform.localPosition[1] : go.transform.position[1]), (((int)ia & 4) != 0) ? 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, IncludedAxes ia, bool localPosition = false) { Vector3 newpos = new Vector3( (((int)ia & 1) != 0) ? pos[0] : (localPosition) ? go.transform.localPosition[0] : go.transform.position[0], (((int)ia & 2) != 0) ? pos[1] : (localPosition) ? go.transform.localPosition[1] : go.transform.position[1], (((int)ia & 4) != 0) ? pos[2] : (localPosition) ? go.transform.localPosition[2] : go.transform.position[2]); if (!localPosition) { go.transform.position = newpos; } else { go.transform.localPosition = newpos; } }
public static void WriteWorldCompPosToBitstream(this CompressedElement compressedpos, ref UdpBitStream bitstream, IncludedAxes ia, bool lowerBitsOnly = false) { for (int axis = 0; axis < 3; axis++) { if (ia.IsXYZ(axis)) { bitstream.WriteUInt(compressedpos[axis], lowerBitsOnly ? axisRanges[axis].lowerBits : axisRanges[axis].bits); } } }
public static CompressedElement ReadCompressedPosFromBitstream(ref UdpBitStream bitstream, IncludedAxes ia, bool lowerBitsOnly = false) { return(new CompressedElement( (ia.IsXYZ(0)) ? (bitstream.ReadUInt(lowerBitsOnly ? axisRanges[0].lowerBits : axisRanges[0].bits)) : 0, (ia.IsXYZ(1)) ? (bitstream.ReadUInt(lowerBitsOnly ? axisRanges[1].lowerBits : axisRanges[1].bits)) : 0, (ia.IsXYZ(2)) ? (bitstream.ReadUInt(lowerBitsOnly ? axisRanges[2].lowerBits : axisRanges[2].bits)) : 0)); }
public static void WriteWorldCompPosToBitstream(this CompressedElement compressedpos, ref UdpBitStream bitstream, IncludedAxes ia, BitCullingLevel bcl) { for (int axis = 0; axis < 3; axis++) { if (ia.IsXYZ(axis)) { bitstream.WriteUInt(compressedpos[axis], axisRanges[axis].GetBitsAtCullLevel(bcl)); } } }
public static CompressedElement ReadCompressedPosFromBitstream(ref UdpBitStream bitstream, IncludedAxes ia, BitCullingLevel bcl) { return(new CompressedElement( null, (ia.IsXYZ(0)) ? (bitstream.ReadUInt(axisRanges[0].GetBitsAtCullLevel(bcl))) : 0, (ia.IsXYZ(1)) ? (bitstream.ReadUInt(axisRanges[1].GetBitsAtCullLevel(bcl))) : 0, (ia.IsXYZ(2)) ? (bitstream.ReadUInt(axisRanges[2].GetBitsAtCullLevel(bcl))) : 0)); }
public void Serialize(byte[] buffer, ref int bitposition, IncludedAxes ia, BitCullingLevel bcl = BitCullingLevel.NoCulling) { crusher.Write(this, buffer, ref bitposition, ia, bcl); }
public static bool IsXYZ(this IncludedAxes ia, int axesId) { return(((int)ia & (1 << axesId)) != 0); }
public static bool IsZ(this IncludedAxes ia) { return(((int)ia & 4) != 0); }
// Constructor public RotationElement() { rotationType = RotationType.Quaternion; includedAxes = (IncludedAxes)7; elementType = ElementType.Rotation; }