本文整理汇总了C#中OpenMetaverse.TerrainPatch类的典型用法代码示例。如果您正苦于以下问题:C# TerrainPatch类的具体用法?C# TerrainPatch怎么用?C# TerrainPatch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TerrainPatch类属于OpenMetaverse命名空间,在下文中一共展示了TerrainPatch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DecompressLand
private void DecompressLand(Simulator simulator, BitPack bitpack, TerrainPatch.GroupHeader group)
{
int x;
int y;
int[] patches = new int[32 * 32];
int count = 0;
while (true)
{
TerrainPatch.Header header = TerrainCompressor.DecodePatchHeader(bitpack);
if (header.QuantWBits == TerrainCompressor.END_OF_PATCHES)
break;
x = header.X;
y = header.Y;
if (x >= TerrainCompressor.PATCHES_PER_EDGE || y >= TerrainCompressor.PATCHES_PER_EDGE)
{
Logger.Log(String.Format(
"Invalid LayerData land packet, x={0}, y={1}, dc_offset={2}, range={3}, quant_wbits={4}, patchids={5}, count={6}",
x, y, header.DCOffset, header.Range, header.QuantWBits, header.PatchIDs, count),
Helpers.LogLevel.Warning, Client);
return;
}
// Decode this patch
TerrainCompressor.DecodePatch(patches, bitpack, header, group.PatchSize);
// Decompress this patch
float[] heightmap = TerrainCompressor.DecompressPatch(patches, header, group);
count++;
try { OnLandPatchReceived(new LandPatchReceivedEventArgs(simulator, x, y, group.PatchSize, heightmap)); }
catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
if (Client.Settings.STORE_LAND_PATCHES)
{
TerrainPatch patch = new TerrainPatch();
patch.Data = heightmap;
patch.X = x;
patch.Y = y;
simulator.Terrain[y * 16 + x] = patch;
}
}
}
示例2: CreateLayerDataPacket
public static LayerDataPacket CreateLayerDataPacket(TerrainPatch[] patches, TerrainPatch.LayerType type)
{
LayerDataPacket layer = new LayerDataPacket();
layer.LayerID.Type = (byte)type;
TerrainPatch.GroupHeader header = new TerrainPatch.GroupHeader();
header.Stride = STRIDE;
header.PatchSize = 16;
header.Type = type;
// Should be enough to fit even the most poorly packed data
byte[] data = new byte[patches.Length * 16 * 16 * 2];
BitPack bitpack = new BitPack(data, 0);
bitpack.PackBits(header.Stride, 16);
bitpack.PackBits(header.PatchSize, 8);
bitpack.PackBits((int)header.Type, 8);
for (int i = 0; i < patches.Length; i++)
CreatePatch(bitpack, patches[i].Data, patches[i].X, patches[i].Y);
bitpack.PackBits(END_OF_PATCHES, 8);
layer.LayerData.Data = new byte[bitpack.BytePos + 1];
Buffer.BlockCopy(bitpack.Data, 0, layer.LayerData.Data, 0, bitpack.BytePos + 1);
return layer;
}
示例3: CreateLayerDataPacket
// Used to send cloud and wind patches
public static LayerDataPacket CreateLayerDataPacket(TerrainPatch[] patches, byte type, int pRegionSizeX,
int pRegionSizeY)
{
LayerDataPacket layer = new LayerDataPacket {LayerID = {Type = type}};
TerrainPatch.GroupHeader header = new TerrainPatch.GroupHeader
{Stride = STRIDE, PatchSize = Constants.TerrainPatchSize};
// Should be enough to fit even the most poorly packed data
byte[] data = new byte[patches.Length*Constants.TerrainPatchSize*Constants.TerrainPatchSize*2];
BitPack bitpack = new BitPack(data, 0);
bitpack.PackBits(header.Stride, 16);
bitpack.PackBits(header.PatchSize, 8);
bitpack.PackBits(type, 8);
foreach (TerrainPatch t in patches)
CreatePatch(bitpack, t.Data, t.X, t.Y, pRegionSizeX, pRegionSizeY);
bitpack.PackBits(END_OF_PATCHES, 8);
layer.LayerData.Data = new byte[bitpack.BytePos + 1];
Buffer.BlockCopy(bitpack.Data, 0, layer.LayerData.Data, 0, bitpack.BytePos + 1);
return layer;
}
示例4: GetHeightMap
static float[,] GetHeightMap(TerrainPatch[] Terrain)
{
float average = 23;
float[,] height = new float[256, 256];
for (int x = 0; x < 256; x++)
{
for (int y = 0; y < 256; y++)
{
int patchX = x / 16;
int patchY = y / 16;
TerrainPatch patch = Terrain[patchY * 16 + patchX];
if (patch != null)
{
height[x, y] = average = patch.Data[(y % 16) * 16 + (x % 16)];
}
else
{
height[x, y] = average;
}
}
}
return height;
}
示例5: CompressPatch
private static int[] CompressPatch(float[] heightmap, int patchX, int patchY, TerrainPatch.Header header,
int prequant, int RegionSizeX, int RegionSizeY, out int wbits)
{
float[] block = new float[Constants.TerrainPatchSize * Constants.TerrainPatchSize];
int wordsize = prequant;
float oozrange = 1.0f / header.Range;
float range = (1 << prequant);
float premult = oozrange * range;
float sub = (1 << (prequant - 1)) + header.DCOffset * premult;
header.QuantWBits = wordsize - 2;
header.QuantWBits |= (prequant - 2) << 4;
int k = 0;
for (int j = patchY * Constants.TerrainPatchSize;
j <
((patchY >= (RegionSizeY / Constants.TerrainPatchSize)
? (RegionSizeY - Constants.TerrainPatchSize) / Constants.TerrainPatchSize
: patchY) + 1) * Constants.TerrainPatchSize;
j++)
{
for (int i = patchX * Constants.TerrainPatchSize;
i <
((patchX >= (RegionSizeX / Constants.TerrainPatchSize)
? (RegionSizeX - Constants.TerrainPatchSize) / Constants.TerrainPatchSize
: patchX) + 1) * Constants.TerrainPatchSize;
i++)
{
block[k++] = (heightmap[j * RegionSizeX + i]) * premult - sub;
}
}
float[] ftemp = new float[Constants.TerrainPatchSize * Constants.TerrainPatchSize];
int[] itemp = new int[Constants.TerrainPatchSize * Constants.TerrainPatchSize];
int maxWbits = prequant + 5;
wbits = (prequant >> 1);
for (int o = 0; o < Constants.TerrainPatchSize; o++)
DCTLine16(block, ftemp, o);
for (int o = 0; o < Constants.TerrainPatchSize; o++)
wbits = DCTColumn16Wbits(ftemp, itemp, o, wbits, maxWbits);
return itemp;
}
示例6: CompressPatch
private static int[] CompressPatch(float[] heightmap, int patchX, int patchY, TerrainPatch.Header header, int prequant)
{
float[] block = new float[16 * 16];
int wordsize = prequant;
float oozrange = 1.0f / (float)header.Range;
float range = (float)(1 << prequant);
float premult = oozrange * range;
float sub = (float)(1 << (prequant - 1)) + header.DCOffset * premult;
header.QuantWBits = wordsize - 2;
header.QuantWBits |= (prequant - 2) << 4;
int k = 0;
for (int j = patchY * 16; j < (patchY + 1) * 16; j++)
{
for (int i = patchX * 16; i < (patchX + 1) * 16; i++)
block[k++] = heightmap[j * 256 + i] * premult - sub;
}
float[] ftemp = new float[16 * 16];
int[] itemp = new int[16 * 16];
for (int o = 0; o < 16; o++)
DCTLine16(block, ftemp, o);
for (int o = 0; o < 16; o++)
DCTColumn16(ftemp, itemp, o);
return itemp;
}
示例7: CompressPatch
private static int[] CompressPatch(float[] patchData, TerrainPatch.Header header, int prequant)
{
float[] block = new float[Constants.TerrainPatchSize * Constants.TerrainPatchSize];
int wordsize = prequant;
float oozrange = 1.0f / (float)header.Range;
float range = (float)(1 << prequant);
float premult = oozrange * range;
float sub = (float)(1 << (prequant - 1)) + header.DCOffset * premult;
header.QuantWBits = wordsize - 2;
header.QuantWBits |= (prequant - 2) << 4;
int k = 0;
for (int j = 0; j < Constants.TerrainPatchSize; j++)
{
for (int i = 0; i < Constants.TerrainPatchSize; i++)
block[k++] = patchData[j * Constants.TerrainPatchSize + i] * premult - sub;
}
float[] ftemp = new float[Constants.TerrainPatchSize * Constants.TerrainPatchSize];
int[] itemp = new int[Constants.TerrainPatchSize * Constants.TerrainPatchSize];
for (int o = 0; o < Constants.TerrainPatchSize; o++)
DCTLine16(block, ftemp, o);
for (int o = 0; o < Constants.TerrainPatchSize; o++)
DCTColumn16(ftemp, itemp, o);
return itemp;
}
示例8: CompressPatch
private static int[] CompressPatch(float[] patchData, TerrainPatch.Header header, int prequant, out int wbits)
{
float[] block = new float[Constants.TerrainPatchSize * Constants.TerrainPatchSize];
float oozrange = 1.0f / header.Range;
float range = (1 << prequant);
float premult = oozrange * range;
float sub = 0.5f * header.Range + header.DCOffset;
int wordsize = (prequant - 2) & 0x0f;
header.QuantWBits = wordsize;
header.QuantWBits |= wordsize << 4;
int k = 0;
for (int j = 0; j < Constants.TerrainPatchSize; j++)
{
for (int i = 0; i < Constants.TerrainPatchSize; i++)
block[k++] = (patchData[j * Constants.TerrainPatchSize + i] - sub) * premult;
}
float[] ftemp = new float[Constants.TerrainPatchSize * Constants.TerrainPatchSize];
int[] iout = new int[Constants.TerrainPatchSize * Constants.TerrainPatchSize];
wbits = (prequant >> 1);
dct16x16(block, iout, ref wbits);
return iout;
}
示例9: EncodePatchHeader
private static int EncodePatchHeader(BitPack output, TerrainPatch.Header header, int[] patch)
{
int temp;
int wbits = (header.QuantWBits & 0x0f) + 2;
uint maxWbits = (uint)wbits + 5;
uint minWbits = ((uint)wbits >> 1);
wbits = (int)minWbits;
for (int i = 0; i < patch.Length; i++)
{
temp = patch[i];
if (temp != 0)
{
// Get the absolute value
if (temp < 0) temp *= -1;
for (int j = (int)maxWbits; j > (int)minWbits; j--)
{
if ((temp & (1 << j)) != 0)
{
if (j > wbits) wbits = j;
break;
}
}
}
}
wbits += 1;
header.QuantWBits &= 0xf0;
if (wbits > 17 || wbits < 2)
{
Logger.Log("Bits needed per word in EncodePatchHeader() are outside the allowed range",
Helpers.LogLevel.Error);
}
header.QuantWBits |= (wbits - 2);
output.PackBits(header.QuantWBits, 8);
output.PackFloat(header.DCOffset);
output.PackBits(header.Range, 16);
output.PackBits(header.PatchIDs, 10);
return wbits;
}
示例10: DecompressPatch
public static float[] DecompressPatch(int[] patches, TerrainPatch.Header header, TerrainPatch.GroupHeader group)
{
float[] block = new float[group.PatchSize*group.PatchSize];
float[] output = new float[group.PatchSize*group.PatchSize];
int prequant = (header.QuantWBits >> 4) + 2;
int quantize = 1 << prequant;
float ooq = 1.0f/quantize;
float mult = ooq*header.Range;
float addval = mult*(1 << (prequant - 1)) + header.DCOffset;
if (group.PatchSize == Constants.TerrainPatchSize)
{
for (int n = 0; n < Constants.TerrainPatchSize*Constants.TerrainPatchSize; n++)
{
block[n] = patches[CopyMatrix16[n]]*DequantizeTable16[n];
}
float[] ftemp = new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
for (int o = 0; o < Constants.TerrainPatchSize; o++)
IDCTColumn16(block, ftemp, o);
for (int o = 0; o < Constants.TerrainPatchSize; o++)
IDCTLine16(ftemp, block, o);
}
else
{
for (int n = 0; n < Constants.TerrainPatchSize*2*Constants.TerrainPatchSize*2; n++)
{
block[n] = patches[CopyMatrix32[n]]*DequantizeTable32[n];
}
Logger.Log("Implement IDCTPatchLarge", Helpers.LogLevel.Error);
}
for (int j = 0; j < block.Length; j++)
{
output[j] = block[j]*mult + addval;
}
return output;
}
示例11: CompressPatch
private static int[] CompressPatch(TerrainData terrData, int patchX, int patchY, TerrainPatch.Header header,
int prequant, out int wbits)
{
float[] block = new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
int wordsize = prequant;
float oozrange = 1.0f/header.Range;
float range = (1 << prequant);
float premult = oozrange*range;
float sub = (1 << (prequant - 1)) + header.DCOffset*premult;
header.QuantWBits = wordsize - 2;
header.QuantWBits |= (prequant - 2) << 4;
int k = 0;
int yPatchLimit = patchY >= (terrData.SizeY / Constants.TerrainPatchSize) ?
(terrData.SizeY - Constants.TerrainPatchSize) / Constants.TerrainPatchSize : patchY;
yPatchLimit = (yPatchLimit + 1) * Constants.TerrainPatchSize;
int xPatchLimit = patchX >= (terrData.SizeX / Constants.TerrainPatchSize) ?
(terrData.SizeX - Constants.TerrainPatchSize) / Constants.TerrainPatchSize : patchX;
xPatchLimit = (xPatchLimit + 1) * Constants.TerrainPatchSize;
for (int yy = patchY * Constants.TerrainPatchSize; yy < yPatchLimit; yy++)
{
for (int xx = patchX * Constants.TerrainPatchSize; xx < xPatchLimit; xx++)
{
block[k++] = terrData[xx, yy] * premult - sub;
}
}
float[] ftemp = new float[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
int[] itemp = new int[Constants.TerrainPatchSize*Constants.TerrainPatchSize];
int maxWbits = prequant + 5;
wbits = (prequant >> 1);
for (int o = 0; o < Constants.TerrainPatchSize; o++)
DCTLine16(block, ftemp, o);
for (int o = 0; o < Constants.TerrainPatchSize; o++)
wbits = DCTColumn16Wbits(ftemp, itemp, o, wbits, maxWbits);
return itemp;
}
示例12: DecompressLand
private void DecompressLand(Simulator simulator, BitPack bitpack, TerrainPatch.GroupHeader group)
{
int x;
int y;
int[] patches = new int[32 * 32];
int count = 0;
while (true)
{
TerrainPatch.Header header = TerrainCompressor.DecodePatchHeader(bitpack);
if (header.QuantWBits == TerrainCompressor.END_OF_PATCHES)
break;
x = header.PatchIDs >> 5;
y = header.PatchIDs & 0x1F;
if (x >= TerrainCompressor.PATCHES_PER_EDGE || y >= TerrainCompressor.PATCHES_PER_EDGE)
{
Logger.Log(String.Format(
"Invalid LayerData land packet, x={0}, y={1}, dc_offset={2}, range={3}, quant_wbits={4}, patchids={5}, count={6}",
x, y, header.DCOffset, header.Range, header.QuantWBits, header.PatchIDs, count),
Helpers.LogLevel.Warning, Client);
return;
}
// Decode this patch
TerrainCompressor.DecodePatch(patches, bitpack, header, group.PatchSize);
// Decompress this patch
float[] heightmap = TerrainCompressor.DecompressPatch(patches, header, group);
count++;
if (OnLandPatch != null)
{
try { OnLandPatch(simulator, x, y, group.PatchSize, heightmap); }
catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
}
if (Client.Settings.STORE_LAND_PATCHES)
{
lock (SimPatches)
{
if (!SimPatches.ContainsKey(simulator.Handle))
SimPatches.Add(simulator.Handle, new TerrainPatch[16 * 16]);
SimPatches[simulator.Handle][y * 16 + x] = new TerrainPatch();
SimPatches[simulator.Handle][y * 16 + x].Heightmap = heightmap;
}
}
}
}
示例13: EncodePatchHeader
private static int EncodePatchHeader(BitPack output, TerrainPatch.Header header, int[] patch, int RegionSizeX,
int RegionSizeY, int wbits)
{
// better check
if (wbits > 17)
wbits = 16;
else if (wbits < 3)
wbits = 3;
header.QuantWBits &= 0xf0;
header.QuantWBits |= (wbits - 2);
output.PackBits(header.QuantWBits, 8);
output.PackFloat(header.DCOffset);
output.PackBits(header.Range, 16);
if (RegionSizeX > Constants.RegionSize || RegionSizeY > Constants.RegionSize)
output.PackBits(header.PatchIDs, 32);
else
output.PackBits(header.PatchIDs, 10);
return wbits;
}
示例14: SendLayerData
public void SendLayerData(int[] x, int[] y, float[] map, TerrainPatch.LayerType type)
{
}
示例15: DecompressWind
private void DecompressWind(Simulator simulator, BitPack bitpack, TerrainPatch.GroupHeader group)
{
;
}