/** * Calculate cell for the coefficient cache. */ private unsafe void CalculateCacheCell(MyHeightmapFace map, Cache.Cell *cell, bool compouteBounds = false) { int sx = cell->Coord.X; int sy = cell->Coord.Y; fixed(float *row = &s_Cz.M11) { int linear = map.GetRowStart(sy - 1) + sx - 1; fixed(ushort *texture = map.Data) { map.Get4Row(linear, row, texture); linear += map.RowStride; map.Get4Row(linear, row + 4, texture); linear += map.RowStride; map.Get4Row(linear, row + 8, texture); linear += map.RowStride; map.Get4Row(linear, row + 12, texture); Matrix.Multiply(ref CR, ref s_Cz, out cell->Gz); Matrix.Multiply(ref cell->Gz, ref CRT, out cell->Gz); if (compouteBounds) { float Min = float.PositiveInfinity; float Max = float.NegativeInfinity; Matrix heights; Matrix.Multiply(ref BInv, ref cell->Gz, out heights); Matrix.Multiply(ref heights, ref BInvT, out heights); /* Will do good old pointer magic */ float *values = &heights.M11; for (int i = 0; i < 16; ++i) { if (Max < values[i]) { Max = values[i]; } if (Min > values[i]) { Min = values[i]; } } cell->Max = Max; cell->Min = Min; } else { cell->Max = 1; cell->Min = 0; } } } }
private unsafe void CalculateCacheCell(MyHeightmapFace map, Cache.Cell *cell, bool compouteBounds = false) { ushort *numPtr2; ushort[] pinned numArray; int x = cell.Coord.X; int y = cell.Coord.Y; float *values = &s_Cz.M11; int linearOfft = (map.GetRowStart(y - 1) + x) - 1; if (((numArray = map.Data) == null) || (numArray.Length == 0)) { numPtr2 = null; } else { numPtr2 = numArray; } map.Get4Row(linearOfft, values, numPtr2); linearOfft += map.RowStride; map.Get4Row(linearOfft, values + (4 * 4), numPtr2); linearOfft += map.RowStride; map.Get4Row(linearOfft, values + (8 * 4), numPtr2); linearOfft += map.RowStride; map.Get4Row(linearOfft, values + (12 * 4), numPtr2); Matrix.Multiply(ref CR, ref s_Cz, out cell.Gz); Matrix.Multiply(ref cell.Gz, ref CRT, out cell.Gz); if (!compouteBounds) { cell.Max = 1f; cell.Min = 0f; } else { Matrix matrix; float positiveInfinity = float.PositiveInfinity; float negativeInfinity = float.NegativeInfinity; Matrix.Multiply(ref BInv, ref cell.Gz, out matrix); Matrix *matrixPtr1 = (Matrix *)ref matrix; Matrix.Multiply(ref (Matrix) ref matrixPtr1, ref BInvT, out matrix); float *numPtr3 = &matrix.M11; int num6 = 0; while (true) { if (num6 >= 0x10) { cell.Max = negativeInfinity; cell.Min = positiveInfinity; break; } if (negativeInfinity < numPtr3[num6 * 4]) { negativeInfinity = numPtr3[num6 * 4]; } if (positiveInfinity > numPtr3[num6 * 4]) { positiveInfinity = numPtr3[num6 * 4]; } num6++; } } numArray = null; fixed(float *numRef = null) { return; } }
/** * Calculate cell for the coefficient cache. */ private unsafe void CalculateCacheCell(MyHeightmapFace map, Cache.Cell* cell, bool compouteBounds = false) { int sx = cell->Coord.X; int sy = cell->Coord.Y; fixed (float* row = &s_Cz.M11) { int linear = map.GetRowStart(sy - 1) + sx - 1; fixed (ushort* texture = map.Data) { map.Get4Row(linear, row, texture); linear += map.RowStride; map.Get4Row(linear, row + 4, texture); linear += map.RowStride; map.Get4Row(linear, row + 8, texture); linear += map.RowStride; map.Get4Row(linear, row + 12, texture); Matrix.Multiply(ref CR, ref s_Cz, out cell->Gz); Matrix.Multiply(ref cell->Gz, ref CRT, out cell->Gz); if (compouteBounds) { float Min = float.PositiveInfinity; float Max = float.NegativeInfinity; Matrix heights; Matrix.Multiply(ref BInv, ref cell->Gz, out heights); Matrix.Multiply(ref heights, ref BInvT, out heights); /* Will do good old pointer magic */ float* values = &heights.M11; for (int i = 0; i < 16; ++i) { if (Max < values[i]) Max = values[i]; if (Min > values[i]) Min = values[i]; } cell->Max = Max; cell->Min = Min; } else { cell->Max = 1; cell->Min = 0; } } } }