Advertisement
Guest User

Toadicus_GetAtt

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