Guest User

Untitled

a guest
Dec 28th, 2012
55
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void FixHeight(float[,] heights)
  2. {
  3. // fix X-axis
  4. for (int z = 0; z < 5; z++)
  5. {
  6. // left side
  7.  
  8. float before = heights[0, z];
  9.  
  10. heights[0, z] = (float)Math.Round(heights[0, z]);
  11.  
  12. if (heights[0, z] < 0)
  13. heights[0, z] = 0;
  14. if (heights[0, z] > 1)
  15. heights[0, z] = 1;
  16.  
  17. float diff = before - heights[0, z];
  18.  
  19. for (int x = 1; x < 5; x++)
  20. {
  21. heights[x, z] = heights[x, z] - diff * (float)(4 - x) / 4f;
  22. }
  23.  
  24. // right side
  25. before = heights[4, z];
  26.  
  27. heights[4, z] = (float)Math.Round(heights[4, z]);
  28.  
  29. if (heights[4, z] < 0)
  30. heights[4, z] = 0;
  31. if (heights[4, z] > 1)
  32. heights[4, z] = 1;
  33.  
  34. diff = before - heights[4, z];
  35.  
  36. for (int x = 0; x < 4; x++)
  37. {
  38. heights[x, z] = heights[x, z] - diff * (float)x / 4f;
  39. }
  40. }
  41.  
  42. // fix z-axis
  43. for (int x = 0; x < 5; x++)
  44. {
  45. // left side
  46.  
  47. float before = heights[x, 0];
  48.  
  49. heights[x, 0] = (float)Math.Round(heights[x, 0]);
  50.  
  51. if (heights[x, 0] < 0)
  52. heights[x, 0] = 0;
  53. if (heights[x, 0] > 1)
  54. heights[x, 0] = 1;
  55.  
  56. float diff = before - heights[x, 0];
  57.  
  58. for (int z = 1; z < 5; z++)
  59. {
  60. heights[x, z] = heights[x, z] - diff * (float)(4 - z) / 4f;
  61. }
  62.  
  63. // right side
  64. before = heights[x, 4];
  65.  
  66. heights[x, 4] = (float)Math.Round(heights[x, 4]);
  67.  
  68. if (heights[x, 4] < 0)
  69. heights[x, 4] = 0;
  70. if (heights[x, 4] > 1)
  71. heights[x, 4] = 1;
  72.  
  73. diff = before - heights[x, 4];
  74.  
  75. for (int z = 0; z < 4; z++)
  76. {
  77. heights[x, z] = heights[x, z] - diff * (float)z / 4f;
  78. }
  79. }
  80. }
RAW Paste Data