Advertisement
Guest User

Reimplementation of CBAttributeMap.GetAtt()

a guest
Oct 18th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. protected CBAttributeMap.MapAttribute Toadicus_GetAtt()
  2. {
  3.     CBAttributeMap BiomeMap = vessel.mainBody.BiomeMap;
  4.     double lat = vessel.latitude * Math.PI / 180d;
  5.     double lon = vessel.longitude * Math.PI / 180d;
  6.  
  7.     lon -= Math.PI / 2d;
  8.  
  9.     if (lon < 0f)
  10.     {
  11.         lon = 2f * Math.PI - lon;
  12.     }
  13.  
  14.     float v = (float)(lat / 3.1415926535897931) + 0.5f;
  15.     float u = (float)(lon / 6.2831853071795862);
  16.  
  17.     Color pixelBilinear = BiomeMap.Map.GetPixelBilinear (u, v);
  18.     CBAttributeMap.MapAttribute mapAttribute = BiomeMap.defaultAttribute;
  19.  
  20.     if (BiomeMap.Map != null)
  21.     {
  22.         if (BiomeMap.exactSearch)
  23.         {
  24.             for (int i = 0; i < BiomeMap.Attributes.Length; ++i)
  25.             {
  26.                 if (pixelBilinear == BiomeMap.Attributes[i].mapColor)
  27.                 {
  28.                     mapAttribute = BiomeMap.Attributes[i];
  29.                 }
  30.             }
  31.         }
  32.         else
  33.         {
  34.             float zero = 0;
  35.             float num = 1 / zero;
  36.             for (int j = 0; j < BiomeMap.Attributes.Length; ++j)
  37.             {
  38.                 Color mapColor = BiomeMap.Attributes [j].mapColor;
  39.                 float sqrMagnitude = ((Vector4)(mapColor - pixelBilinear)).sqrMagnitude;
  40.                 if (sqrMagnitude < num)
  41.                 {
  42.                     bool testCase = true;
  43.                     if (BiomeMap.nonExactThreshold != -1)
  44.                     {
  45.                         testCase = (sqrMagnitude < BiomeMap.nonExactThreshold);
  46.                     }
  47.                     if (testCase)
  48.                     {
  49.                         mapAttribute = BiomeMap.Attributes[j];
  50.                         num = sqrMagnitude;
  51.                     }
  52.                 }
  53.             }
  54.         }
  55.     }
  56.  
  57.     return mapAttribute;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement