Exemplo n.º 1
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);
        }
        //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);
        }
Exemplo n.º 3
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);
        }