本文整理汇总了C#中OpenMetaverse.BitPack.PackBit方法的典型用法代码示例。如果您正苦于以下问题:C# BitPack.PackBit方法的具体用法?C# BitPack.PackBit怎么用?C# BitPack.PackBit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenMetaverse.BitPack
的用法示例。
在下文中一共展示了BitPack.PackBit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BitPacking
public void BitPacking()
{
byte[] packedBytes = new byte[12];
BitPack bitpacker = new BitPack(packedBytes, 0);
bitpacker.PackBits(0x0ABBCCDD, 32);
bitpacker.PackBits(25, 5);
bitpacker.PackFloat(123.321f);
bitpacker.PackBits(1000, 16);
bitpacker = new BitPack(packedBytes, 0);
int b = bitpacker.UnpackBits(32);
Assert.IsTrue(b == 0x0ABBCCDD, "Unpacked " + b + " instead of 2864434397");
b = bitpacker.UnpackBits(5);
Assert.IsTrue(b == 25, "Unpacked " + b + " instead of 25");
float f = bitpacker.UnpackFloat();
Assert.IsTrue(f == 123.321f, "Unpacked " + f + " instead of 123.321");
b = bitpacker.UnpackBits(16);
Assert.IsTrue(b == 1000, "Unpacked " + b + " instead of 1000");
packedBytes = new byte[1];
bitpacker = new BitPack(packedBytes, 0);
bitpacker.PackBit(true);
bitpacker = new BitPack(packedBytes, 0);
b = bitpacker.UnpackBits(1);
Assert.IsTrue(b == 1, "Unpacked " + b + " instead of 1");
packedBytes = new byte[1] { Byte.MaxValue };
bitpacker = new BitPack(packedBytes, 0);
bitpacker.PackBit(false);
bitpacker = new BitPack(packedBytes, 0);
b = bitpacker.UnpackBits(1);
Assert.IsTrue(b == 0, "Unpacked " + b + " instead of 0");
}
示例2: SplitParcel
public void SplitParcel(SceneParcel parcel, int startX, int endX, int startY, int endY)
{
SceneParcel newParcel = new SceneParcel(parcel);
newParcel.ID = UUID.Random();
newParcel.LocalID = System.Threading.Interlocked.Increment(ref m_currentParcelID);
newParcel.ClaimDate = DateTime.UtcNow;
newParcel.Dwell = 0f;
m_parcels.Add(newParcel.ID, newParcel.LocalID, newParcel);
// Update parcel bitmaps
BitPack origParcelBitmap = new BitPack(parcel.Bitmap, 0);
BitPack parcelBitmap = new BitPack(new byte[512], 0);
BitPack newParcelBitmap = new BitPack(newParcel.Bitmap, 0);
for (int y = 0; y < 64; y++)
{
for (int x = 0; x < 64; x++)
{
bool origParcelBit = (origParcelBitmap.UnpackBits(1) != 0);
if (x >= startX && x <= endX && y >= startY && y <= endY)
{
// Inside the new parcel
parcelBitmap.PackBit(false);
newParcelBitmap.PackBit(true);
m_parcelOverlay[y * 64 + x] = newParcel.LocalID;
}
else
{
// Not inside the new parcel
parcelBitmap.PackBit(origParcelBit);
newParcelBitmap.PackBit(false);
}
}
}
// Update parcel landing info
SceneParcel landingParcel;
if (TryGetParcel(newParcel.LandingLocation, out landingParcel) && landingParcel == parcel)
{
newParcel.Landing = LandingType.None;
newParcel.LandingLocation = Vector3.Zero;
}
else
{
parcel.Landing = LandingType.None;
parcel.LandingLocation = Vector3.Zero;
}
// Update max prim counts
Vector3 aabbMin, aabbMax;
int area = GetParcelArea(parcel, out aabbMin, out aabbMax);
parcel.MaxPrims = (int)Math.Round((float)area * m_primsPerSquareMeter);
area = GetParcelArea(newParcel, out aabbMin, out aabbMax);
newParcel.MaxPrims = (int)Math.Round((float)area * m_primsPerSquareMeter);
Serialize();
}