Esempio n. 1
0
 public override GenericX Decompress(CompressedElement comp)
 {
     if (rotationType == RotationType.Quaternion)
     {
         return(QuatCompress.DecompressBitBufferToQuat(comp.quat, totalBitsForQuat));
     }
     else
     {
         return(new GenericX(
                    (includedAxes.IsX()) ? DecompressFloat(comp[0], 0) : 0,
                    (includedAxes.IsY()) ? DecompressFloat(comp[1], 1) : 0,
                    (includedAxes.IsZ()) ? DecompressFloat(comp[2], 2) : 0
                    ));
     }
 }
Esempio n. 2
0
 public override CompressedElement Compress(GenericX uncompressed)
 {
     if (rotationType == RotationType.Quaternion)
     {
         return(QuatCompress.CompressQuatToBitsBuffer(uncompressed, totalBitsForQuat));
     }
     else
     {
         return(new CompressedElement(
                    (includedAxes.IsX()) ? CompressFloat(uncompressed[0], 0) : 0,
                    (includedAxes.IsY()) ? CompressFloat(uncompressed[1], 1) : 0,
                    (includedAxes.IsZ()) ? CompressFloat(uncompressed[2], 2) : 0
                    ));
     }
 }
Esempio n. 3
0
        public override void WriteToBitstream(ref UdpBitStream bitstream, MsgType msgType, bool forceUpdate, bool isKeyframe)
        {
            // Base class does some forceUpdate checking, keep it around.
            //forceUpdate = base.WriteToBitstream(ref bitstream, msgType, forceUpdate);
            //bool hasChanged = false;

            if (rotationType == XType.Quaternion)
            {
                ulong compressedQuat = QuatCompress.CompressQuatToBitsBuffer(Localized, totalBitsForQuat);

                // For frames between forced updates, we need to first send a flag bit for if this element is being sent
                if (!forceUpdate)
                {
                    bool hasChanged = compressedQuat != lastSentCompressed;
                    bitstream.WriteBool(hasChanged);

                    // if no changes have occured we are done.
                    if (!hasChanged)
                    {
                        return;
                    }
                }

                bitstream.WriteULong(compressedQuat, totalBitsForQuat);
                lastSentCompressed = compressedQuat;
                return;
            }

            else
            {
                // Euler types...

                CompressedElement newValues = new CompressedElement(0, 0, 0);

                // populate the new compressed position, and test if any of the axes have changed.
                for (int axis = 0; axis < 3; axis++)
                {
                    if (rotationType.IsXYZ(axis))
                    {
                        newValues[axis] = CompressFloat(((Vector3)Localized)[axis], axis);
                    }
                }

                // For frames between forced updates, we need to first send a flag bit for if this element is being sent
                if (!forceUpdate)
                {
                    bool hasChanged = !CompressedElement.Compare(newValues, lastSentCompressed);
                    bitstream.WriteBool(hasChanged);

                    // if no changes have occured we are done.
                    if (!hasChanged)
                    {
                        return;
                    }
                }

                for (int axis = 0; axis < 3; axis++)
                {
                    if (rotationType.IsXYZ(axis))
                    {
                        bitstream.WriteUInt(newValues[axis], xyzBits[axis]);
                        lastSentCompressed[axis] = newValues[axis];
                    }
                }
            }
        }