Ejemplo n.º 1
0
        public int getBiomeIndex(double lon, double lat)
        {
            if (body.BiomeMap == null)
            {
                return(-1);
            }
            if (body.BiomeMap.Map == null)
            {
                return(-1);
            }
            double u = ((lon + 360 + 180 + 90)) % 360;
            double v = ((lat + 180 + 90)) % 180;

            if (u < 0 || v < 0 || u >= 360 || v >= 180)
            {
                return(-1);
            }
            CBAttributeMap.MapAttribute att = body.BiomeMap.GetAtt(Mathf.Deg2Rad * lat, Mathf.Deg2Rad * lon);
            for (int i = 0; i < body.BiomeMap.Attributes.Length; ++i)
            {
                if (body.BiomeMap.Attributes[i] == att)
                {
                    return(i);
                }
            }
            return(-1);
        }
Ejemplo n.º 2
0
        internal static int getBiomeIndex(CelestialBody body, double lon, double lat)
        {
            if (body.BiomeMap == null)
            {
                return(-1);
            }
            if (body.BiomeMap.Map == null)
            {
                return(-1);
            }
            //double u = fixLon(lon);
            //double v = fixLat(lat);

            //if (badDLonLat(u, v))
            //    return -1;
            CBAttributeMap.MapAttribute att = body.BiomeMap.GetAtt(Mathf.Deg2Rad * lat, Mathf.Deg2Rad * lon);
            for (int i = 0; i < body.BiomeMap.Attributes.Length; ++i)
            {
                if (body.BiomeMap.Attributes[i] == att)
                {
                    return(i);
                }
            }
            return(-1);
        }
Ejemplo n.º 3
0
        public string GetBiomeString()
        {
            string biome_desc = "";

            CBAttributeMap.MapAttribute mapAttribute;

            try
            {
                CBAttributeMap BiomeMap = ActiveVessel.mainBody.BiomeMap;

                double lat = ActiveVessel.latitude * Math.PI / 180d;
                double lon = ActiveVessel.longitude * Math.PI / 180d;

                mapAttribute = BiomeMap.GetAtt(lat, lon);

                biome_desc = mapAttribute.name;
            }
            catch (NullReferenceException)
            {
                mapAttribute      = new CBAttributeMap.MapAttribute();
                mapAttribute.name = "N/A";
            }

            return(biome_desc);
        }
Ejemplo n.º 4
0
 public string getBiomeName(double lon, double lat)
 {
     CBAttributeMap.MapAttribute a = getBiome(lon, lat);
     if (a == null)
     {
         return("unknown");
     }
     return(a.name);
 }
        //Another MechJeb function I have very little understanding of.
        public static CBAttributeMap.MapAttribute CBAttributeMapGetAtt(CBAttributeMap cbmap, double lat, double lon)
        {
            if (cbmap.Map == null)
            {
                return(cbmap.defaultAttribute);
            }

            lon -= Math.PI / 2d;
            if (lon < 0d)
            {
                lon += 2d * Math.PI;
            }

            float v = (float)(lat / Math.PI) + 0.5f;
            float u = (float)(lon / (2d * Math.PI));

            Color pixelBilinear = cbmap.Map.GetPixelBilinear(u, v);

            CBAttributeMap.MapAttribute defaultAttribute = cbmap.defaultAttribute;
            if (!cbmap.exactSearch)
            {
                float maxValue = float.MaxValue;
                for (int i = 0; i < cbmap.Attributes.Length; i++)
                {
                    var   vector       = (Vector4)(cbmap.Attributes[i].mapColor - pixelBilinear);
                    float sqrMagnitude = vector.sqrMagnitude;
                    // Analysis disable once CompareOfFloatsByEqualityOperator
                    if ((sqrMagnitude < maxValue) && ((cbmap.nonExactThreshold == -1f) || (sqrMagnitude < cbmap.nonExactThreshold)))
                    {
                        defaultAttribute = cbmap.Attributes[i];
                        maxValue         = sqrMagnitude;
                    }
                }
            }
            else
            {
                for (int j = 0; j < cbmap.Attributes.Length; j++)
                {
                    if (pixelBilinear == cbmap.Attributes[j].mapColor)
                    {
                        defaultAttribute = cbmap.Attributes[j];
                        break;
                    }
                }
            }
            return(defaultAttribute);
        }
Ejemplo n.º 6
0
        public CBAttributeMap.MapAttribute GetBiome()
        {
            CBAttributeMap.MapAttribute mapAttribute;

            try
            {
                CBAttributeMap BiomeMap = ActiveVessel.mainBody.BiomeMap;

                double lat = ActiveVessel.latitude * Math.PI / 180d;
                double lon = ActiveVessel.longitude * Math.PI / 180d;

                mapAttribute = BiomeMap.GetAtt(lat, lon);
            }
            catch (NullReferenceException)
            {
                mapAttribute      = new CBAttributeMap.MapAttribute();
                mapAttribute.name = "N/A";
            }

            return(mapAttribute);
        }
Ejemplo n.º 7
0
        private bool VerifyBiomeResult(double lat, double lon, CBAttributeMap.MapAttribute target)
        {
            if (projectedMap == null)
            {
                Log.Debug("Cannot verify biome result; no projected map exists");
                return(true); // we'll have to assume it's accurate since we can't prove otherwise
            }

            if (target == null || target.mapColor == null)
            {
                return(true); // this shouldn't happen
            }
            lon -= Mathf.PI * 0.5f;
            if (lon < 0d)
            {
                lon += Mathf.PI * 2d;
            }
            lon %= Mathf.PI * 2d;

            int x_center = (int)Math.Round(projectedMap.width * (float)(lon / (Mathf.PI * 2)), 0);
            int y_center = (int)Math.Round(projectedMap.height * ((float)(lat / Mathf.PI) + 0.5f), 0);

            for (int y = y_center - HALF_SEARCH_DIMENSIONS; y < y_center + HALF_SEARCH_DIMENSIONS; ++y)
            {
                for (int x = x_center - HALF_SEARCH_DIMENSIONS; x < x_center + HALF_SEARCH_DIMENSIONS; ++x)
                {
                    Color c = projectedMap.GetPixel(x, y);

#if DEBUG
                    //Log.Write("Projected is {0}, comparing to {1}, comparison is {2}", c, target.mapColor, Similar(c, target.mapColor));
#endif
                    if (Similar(c, target.mapColor))
                    {
                        return(true); // we have a match, no need to look further
                    }
                }
            }

            return(false);
        }