Пример #1
0
        private void ChangeColors()
        {
            const double ALPHAMULT = .33d;

            if (this.IsEnabled)
            {
                this.ArrowBorderFinal         = new SolidColorBrush(this.ArrowBorder);
                this.ArrowBackgroundFromFinal = this.ArrowBackgroundFrom;
                this.ArrowBackgroundToFinal   = this.ArrowBackgroundTo;
            }
            else
            {
                ColorHSV hsv = this.ArrowBorder.ToHSV();
                double   a   = UtilityCore.GetScaledValue_Capped(0d, 255d, 0d, 255d, this.ArrowBorder.A * ALPHAMULT);
                this.ArrowBorderFinal = new SolidColorBrush(UtilityWPF.HSVtoRGB(Convert.ToByte(a), hsv.H, 0d, hsv.V));

                hsv = this.ArrowBackgroundFrom.ToHSV();
                a   = UtilityCore.GetScaledValue_Capped(0d, 255d, 0d, 255d, this.ArrowBackgroundFrom.A * ALPHAMULT);
                this.ArrowBackgroundFromFinal = UtilityWPF.HSVtoRGB(Convert.ToByte(a), hsv.H, 0d, hsv.V);

                hsv = this.ArrowBackgroundTo.ToHSV();
                a   = UtilityCore.GetScaledValue_Capped(0d, 255d, 0d, 255d, this.ArrowBackgroundTo.A * ALPHAMULT);
                this.ArrowBackgroundToFinal = UtilityWPF.HSVtoRGB(Convert.ToByte(a), hsv.H, 0d, hsv.V);
            }
        }
Пример #2
0
        private Tuple <Point3D, Vector3D> GetPositionVelocity(double mass)
        {
            //mass of ice = .46
            //mass of platinum = 10.7

            //small asteroid = 80-226
            //large asteroid = 550-916

            // Percent (more massive toward the center)
            double percent = UtilityCore.GetScaledValue_Capped(.05, .85, 0, 1000, mass);

            percent = 1d - percent;                //GetScaledValue can't handle inverted ranges, so invert outside of it
            percent = percent * percent * percent; // it works better with nonlinear

            // Position
            Vector3D posXY = Math3D.GetRandomVector_Circular(_boundryMax.X * (percent - .03), _boundryMax.X * (percent + .03));
            double   z     = Math1D.GetNearZeroValue(_boundryMax.Z) * .15;

            Point3D position = new Point3D(posXY.X, posXY.Y, z);

            // Velocity
            double speed = UtilityCore.GetScaledValue_Capped(_boundryMax.X * .001, _boundryMax.X * .05, 0, 1, percent);

            Vector3D velocity = posXY.ToUnit().GetRotatedVector(new Vector3D(0, 0, 1), -90) * speed;

            return(Tuple.Create(position, velocity));
        }
Пример #3
0
        private void trkSimulationSpeed_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            if (_world == null || trkSimulationSpeed == null || lblSimSpeed == null)
            {
                return;
            }

            double speed = 1d;

            double halfRange = trkSimulationSpeed.Minimum + ((trkSimulationSpeed.Maximum - trkSimulationSpeed.Minimum) / 2d);

            if (trkSimulationSpeed.Value >= halfRange)
            {
                speed = UtilityCore.GetScaledValue_Capped(1d, 10d, halfRange, trkSimulationSpeed.Maximum, trkSimulationSpeed.Value);
            }
            else
            {
                speed = UtilityCore.GetScaledValue_Capped(.1d, 1d, trkSimulationSpeed.Minimum, halfRange, trkSimulationSpeed.Value);
            }

            _world.SimulationSpeed = speed;

            speed = Math.Round(speed, 3);
            lblSimSpeed.Content = speed.ToString();
        }
Пример #4
0
        private static (double speed, double error) GetWeaponSpeedError(ArcBot2 bot, double minSpeed, double maxSpeed, double maxSpeed2)
        {
            Vector3D relativeSpeed = bot.Weapon.VelocityWorld - bot.VelocityWorld;

            // This is kind of rough, because it will be the speed of the center point.  May also need angular velocity
            double speed = relativeSpeed.Length;

            double error = 0;

            if (speed < minSpeed)
            {
                error = UtilityCore.GetScaledValue_Capped(0, 1, minSpeed, 0, speed);
            }
            else if (speed > maxSpeed)
            {
                if (speed > maxSpeed2)
                {
                    error = 1;
                }
                else
                {
                    error = UtilityCore.GetScaledValue_Capped(0, 1, maxSpeed, maxSpeed2, speed);
                }
            }

            return(speed, error);
        }
Пример #5
0
        private void UpdateNeurons_progressiveRadius(Vector3D gravity, double magnitude)
        {
            if (Math3D.IsNearZero(gravity))
            {
                // There is no gravity to report
                for (int cntr = 0; cntr < _neurons.Length; cntr++)
                {
                    _neurons[cntr].Value = 0d;
                }
                return;
            }

            for (int cntr = 0; cntr < _neurons.Length; cntr++)
            {
                if (_neurons[cntr].PositionUnit == null)
                {
                    // This neuron is sitting at 0,0,0
                    _neurons[cntr].Value = magnitude;
                }
                else
                {
                    // Scale minDot
                    double radiusPercent = _neurons[cntr].PositionLength / _neuronMaxRadius;

                    _neurons[cntr].Value = UtilityCore.GetScaledValue_Capped(0d, 1d, 0d, 1d, 1d - radiusPercent);
                }
            }
        }
Пример #6
0
        private void trkCrossoverDistance_Scroll(object sender, EventArgs e)
        {
            double distance = UtilityCore.GetScaledValue_Capped(double.Parse(lblCrossoverMin.Text), double.Parse(lblCrossoverMax.Text), trkCrossoverDistance.Minimum, trkCrossoverDistance.Maximum, trkCrossoverDistance.Value);

            toolTip1.SetToolTip(trkCrossoverDistance, distance.ToString());

            _shipController.MachineGunCrossoverDistance = distance;
        }
Пример #7
0
        private void GetMineralBlipSprtCacheProps()
        {
            // Get the min/max values
            double minDollars = double.MaxValue;
            double maxDollars = double.MinValue;

            SortedList <MineralType, double> dollars = new SortedList <MineralType, double>();

            foreach (MineralType mineralType in Enum.GetValues(typeof(MineralType)))
            {
                if (mineralType == MineralType.Custom)
                {
                    continue;
                }

                decimal suggestedDollars       = Mineral.GetSuggestedValue(mineralType);
                double  suggestedDollarsScaled = Math.Sqrt(Convert.ToDouble(suggestedDollars));   // taking the square root, because the values are exponential, and I want the color scale more linear
                dollars.Add(mineralType, suggestedDollarsScaled);

                if (suggestedDollarsScaled < minDollars)
                {
                    minDollars = suggestedDollarsScaled;
                }

                if (suggestedDollarsScaled > maxDollars)
                {
                    maxDollars = suggestedDollarsScaled;
                }
            }

            // Store color based on those values
            _mineralColors = new SortedList <MineralType, MineralBlipProps>();
            Color maxColor = Colors.Chartreuse;

            foreach (MineralType mineralType in Enum.GetValues(typeof(MineralType)))
            {
                MineralBlipProps props = new MineralBlipProps();

                if (mineralType == MineralType.Custom)
                {
                    props.DiffuseColor  = Colors.HotPink;     // not sure what to do here.  maybe I'll know more if I ever use custom minerals  :)
                    props.SpecularColor = props.DiffuseColor;
                    props.Size          = 4;
                }
                else
                {
                    double dollar = dollars[mineralType];

                    double colorPercent = UtilityCore.GetScaledValue_Capped(.33d, 1d, minDollars, maxDollars, dollar);
                    props.DiffuseColor  = UtilityWPF.AlphaBlend(maxColor, Colors.Transparent, colorPercent);
                    props.SpecularColor = props.DiffuseColor;

                    props.Size = UtilityCore.GetScaledValue_Capped(2d, 5d, minDollars, maxDollars, dollar);
                }

                _mineralColors.Add(mineralType, props);
            }
        }
Пример #8
0
        private void PhysicsBody_BodyMoved(object sender, EventArgs e)
        {
            if (!_isVisualAdded)
            {
                return;
            }

            // Graphics need to be updated here.  If I wait until world update, this graphic will be one frame
            // behind, which is very noticable when the bot has a high velocity

            double damageMult = GetDamageMultiplier();

            Vector3D velocity = _bot.VelocityWorld;
            var      dna      = this.DNA;

            // Light size
            double lightSize = UtilityCore.GetScaledValue_Capped(0, _bot.Radius * 4, 0, dna.DamageMult * 20, damageMult);

            UtilityWPF.SetAttenuation(_light, lightSize, .1d);
            _light.Color = Color.FromArgb(Convert.ToByte(UtilityCore.GetScaledValue_Capped(0, 192, 0, dna.DamageMult * 10, damageMult)), 255, 0, 0);

            // Scale
            double scale;

            if (damageMult < dna.DamageMult * 4)
            {
                scale = 0;
            }
            else
            {
                scale = UtilityCore.GetScaledValue_Capped(0, _bot.Radius, dna.DamageMult * 4, dna.DamageMult * 25, damageMult);
            }
            _scale.ScaleX = scale;
            _scale.ScaleY = scale;
            _scale.ScaleZ = scale;

            // Translate
            Point3D position = _bot.PositionWorld + (velocity.ToUnit() * (_bot.Radius * UtilityCore.GetScaledValue_Capped(1.05, 1.3, 0, dna.DamageMult * 25, damageMult)));

            _translate.OffsetX = position.X;
            _translate.OffsetY = position.Y;
            _translate.OffsetZ = position.Z;

            // Rotate
            Vector3D xAxis = new Vector3D(1, 0, 0);

            Vector3D axis  = Vector3D.CrossProduct(xAxis, velocity);
            double   angle = Vector3D.AngleBetween(xAxis, velocity);

            if (Math3D.IsNearZero(axis) || Math1D.IsNearZero(angle))
            {
                _rotate.Quaternion = Quaternion.Identity;
            }
            else
            {
                _rotate.Quaternion = new Quaternion(axis, angle);
            }
        }
Пример #9
0
        /// <summary>
        /// This will return null if it's not a multiplier, or not valid to do a multiplier
        /// </summary>
        private ConvertProps IsMultiplier()
        {
            if (this.Parent == null)
            {
                return(null);
            }
            else if (!this.Parent.IsMultiplier)
            {
                return(null);
            }

            // They want log, make sure min and max are appropriate

            double absMin = Math.Abs(this.Parent.Minimum);
            double absMax = Math.Abs(this.Parent.Maximum);

            if (absMin > 1 || absMax < 1)
            {
                // 1 needs to be between them
                return(null);
            }
            else if (absMin == 0)
            {
                // Min can't be zero, that's an asymptote
                return(null);
            }

            bool isMinPositive = this.Parent.Minimum > 0;
            bool isMaxPositive = this.Parent.Maximum > 0;

            if (isMinPositive != isMaxPositive)
            {
                // They must either both be negative, or both be positive
                return(null);
            }

            // Use the ratio of min:max to figure out the percent along the progress bar one should be at.  If the ratio is the same
            // (.25 to 4, or .1 to 10, etc), then the % should be .5.  If there is more to the right than left, then adjust the mid point
            // left a bit so that more of the progress bar is available
            double invertAbsMin = 1d / absMin;

            double ratio = invertAbsMin / absMax;

            if (ratio < 1)
            {
                ratio = UtilityCore.GetScaledValue_Capped(.25d, .5, .1, 1, ratio);        //reusing the ratio variable to be % along progress bar.  never let it go less than .25 so that the progress bar stays usable
            }
            else
            {
                ratio = UtilityCore.GetScaledValue_Capped(.5d, .75, 1, 10, ratio);
            }

            double absMiddle = absMin + ((absMax - absMin) * ratio);

            // Need to do a multiplier scale.  Return a filled out object
            return(new ConvertProps(absMin, absMax, absMiddle, isMinPositive));
        }
Пример #10
0
        /// <summary>
        /// This sets all the neurons from 0 to magnitude.  Magnitude needs to be from 0 to 1, and is based on the currently felt gravity compared
        /// to what the sensor has seen as the max felt
        /// </summary>
        internal static void UpdateNeurons(Neuron_SensorPosition[] neurons, double neuronMaxRadius, Vector3D vector, double magnitude)
        {
            const double MINDOT = 1.25d;

            if (Math3D.IsNearZero(vector))
            {
                // There is no gravity to report
                for (int cntr = 0; cntr < neurons.Length; cntr++)
                {
                    neurons[cntr].Value = 0d;
                }
                return;
            }

            Vector3D gravityUnit = vector.ToUnit();

            for (int cntr = 0; cntr < neurons.Length; cntr++)
            {
                if (neurons[cntr].PositionUnit == null)
                {
                    // This neuron is sitting at 0,0,0
                    neurons[cntr].Value = magnitude;
                }
                else
                {
                    // Figure out how aligned this neuron is with the gravity vector
                    double dot = Vector3D.DotProduct(gravityUnit, neurons[cntr].PositionUnit.Value);
                    dot += 1d;          // get this to scale from 0 to 2 instead of -1 to 1

                    // Scale minDot
                    double radiusPercent = neurons[cntr].PositionLength / neuronMaxRadius;
                    double revisedMinDot = UtilityCore.GetScaledValue_Capped(0d, MINDOT, 0d, 1d, radiusPercent);

                    // Rig it so that the lower radius neurons will fire stronger
                    double minReturn = 1d - radiusPercent;
                    if (minReturn < 0d)
                    {
                        minReturn = 0d;
                    }

                    // Figure out what percentage of magnitude to use
                    double percent;
                    if (dot < revisedMinDot)
                    {
                        percent = UtilityCore.GetScaledValue_Capped(0d, minReturn, 0d, revisedMinDot, dot);
                    }
                    else
                    {
                        percent = UtilityCore.GetScaledValue_Capped(minReturn, 1d, revisedMinDot, 2d, dot);
                    }

                    // Set the neuron
                    neurons[cntr].Value = percent * magnitude;
                }
            }
        }
Пример #11
0
        private void UpdateNeurons()
        {
            const double MINDOT = 1.75d;     //it's dot+1, so dot goes from 0 to 2

            // Get the direction from the current position to the home point
            Vector3D direction = GetDirectionModelCoords();

            if (Math3D.IsNearZero(direction))
            {
                // They are sitting on the home point.  Zero everything out and exit
                for (int cntr = 0; cntr < _neurons.Length; cntr++)
                {
                    _neurons[cntr].Value = 0d;
                }

                return;
            }

            // Get max neuron value
            double directionLength = direction.Length;
            double magnitude;

            if (directionLength < _homeRadius)
            {
                magnitude = directionLength / _homeRadius;
            }
            else
            {
                magnitude = 1;
            }

            Vector3D directionUnit = direction.ToUnit();

            for (int cntr = 0; cntr < _neurons.Length; cntr++)
            {
                if (_neurons[cntr].PositionUnit == null)
                {
                    // This neuron is sitting at 0,0,0
                    _neurons[cntr].Value = 0d;
                }
                else
                {
                    double dot = Vector3D.DotProduct(directionUnit, _neurons[cntr].PositionUnit.Value);
                    dot += 1d;          // get this to scale from 0 to 2 instead of -1 to 1

                    if (dot < MINDOT)
                    {
                        _neurons[cntr].Value = 0d;
                    }
                    else
                    {
                        _neurons[cntr].Value = UtilityCore.GetScaledValue_Capped(0d, magnitude, MINDOT, 2d, dot);
                    }
                }
            }
        }
Пример #12
0
        public FitnessInfo?EvaluateTick(double elapedTime)
        {
            if (!_isEvaluating)
            {
                // This is called after the score has been given, but before a new phenome is assigned
                throw new InvalidOperationException("EvaluateTick was called at an invalid time.  Either StartNewEvaluation was never called, or the current phenome has returned a final score and this class is waiting for a new call to StartNewEvaluation");
            }

            // Get the bot's distance from home
            double distance = (_bot.PositionWorld - _homePoint).Length;

            // Run that distance through a scoring function
            double thisError = 0d;

            if (distance < _minDistance)
            {
                thisError = UtilityCore.GetScaledValue_Capped(1, 0, 0, _minDistance, distance);
            }
            else if (distance > _maxDistance2)
            {
                thisError = 1;
            }
            else if (distance > _maxDistance)
            {
                thisError = UtilityCore.GetScaledValue_Capped(0, 1, _maxDistance, _maxDistance2, distance);
            }

            // Add the error to the total (cap it if time is exceeded)
            double actualElapsed = elapedTime;

            if (_runningTime + elapedTime > _maxEvalTime)
            {
                actualElapsed = _maxEvalTime - _runningTime;
            }

            thisError *= actualElapsed;

            _error += thisError;

            _runningTime += elapedTime;

            // If the counter is a certain amount, return the final score
            if (_runningTime >= _maxEvalTime)
            {
                // It's been tested long enough.  Return the score (score needs to grow, so an error of zero will give max score)
                double fitness = _runningTime - _error;
                return(new FitnessInfo(fitness, fitness));
            }
            else
            {
                // Still evaluating
                return(null);
            }
        }
Пример #13
0
            public void SetPercent(double percent)
            {
                //if (percent < 0) percent = 0;     // capped caps the output anyway
                //else if (percent > 1) percent = 1;

                // If it gets much smaller than .75, it won't be visible, and much bigger than .92, it will poke though the outer visual
                double scale = UtilityCore.GetScaledValue_Capped(.75, .92, 0, 1, percent);

                this.Scale.ScaleX = scale;
                this.Scale.ScaleY = scale;
                this.Scale.ScaleZ = scale;
            }
Пример #14
0
        /// <summary>
        /// This will emulate sounds coming from locations relative to the listener
        /// </summary>
        /// <remarks>
        /// Note that sound intensity doesn't diminish linearly from by distance, but by:
        ///    I = P/(4*pi*r^2)
        ///
        /// I is final intensity
        /// P is intensity at the source
        /// r is distance from the listener
        /// </remarks>
        /// <param name="volume">0 (none) to 1 (full)</param>
        /// <param name="balance">-1 (all left) to 1 (all right)</param>
        /// <param name="offset">The location of the sound relative to the listener</param>
        /// <param name="sourceVolume">0 (none) to 1 (full) - this is how loud the source would be at the listener</param>
        private void GetPositionalSoundSettings(out double volume, out double balance, Vector3D offset, double sourceVolume)
        {
            #region Calculate Volume

            // I won't range check the input volume - I'll leave it up to the media player to either bomb or cap it

            double intensityRatio = 1d;
            double offsetLength   = offset.Length;
            if (_distanceFalloffRatio == 0d || Math1D.IsNearZero(offsetLength))
            {
                volume = sourceVolume;
            }
            else
            {
                double distance = offsetLength * _distanceFalloffRatio;

                intensityRatio = 1d / (4d * Math.PI * distance * distance);    // I need this intensity when calculating balance
                volume         = sourceVolume * intensityRatio;
            }

            #endregion

            #region Calculate Balance

            // This means that if a sound is a distance of very near zero, and all the way to the left or right, then instead of +-1, it is +-.5
            const double MAXOPPOSITE_EAR = .5d;
            // When the intensity would be 75% of max, then I won't add anything to the opposite ear
            const double MAXOPPOSITE_DISTANCEINTENSITY = .75d;

            // Getting the angle (I don't want Z)
            double angle = Vector3D.AngleBetween(new Vector3D(1, 0, 0), new Vector3D(offset.X, offset.Y, 0));

            // cos(0) is 1, cos(90) is 0, cos(180) is -1.  Exactly what I need
            balance = Math.Cos(Math1D.DegreesToRadians(angle));

            //NOTE:  The problem with a pure cosine is that if a loud sound is sitting very near the person, but on the left, then in reality, the right
            // ear would hear something, but a simple cosine would be all the way -1
            //
            // So, I'm going to approach .5 for objects that are near (still on the left, but can be heard on the right)
            if (intensityRatio > MAXOPPOSITE_DISTANCEINTENSITY)
            {
                // So when the intensity is 1 (right next to the head), then I will give back .5
                // When the intensity is at the limit, then balance will be the pure cosine value
                // Anywhere in between is a linear interpelation
                balance = UtilityCore.GetScaledValue_Capped(balance, MAXOPPOSITE_EAR * balance, MAXOPPOSITE_DISTANCEINTENSITY, 1d, intensityRatio);
            }

            #endregion

            //TODO:  Take in relative velocity, then manipulate playback speed to emulate doppler (unless there is a way to change pitch directly)
        }
Пример #15
0
        private static Color GetNodeColor_Finish(Tuple <double, double, double> raw)
        {
            // Scale to bytes.  This assumes that the weights are normalized between -1 and 1
            //TODO: Handle negatives
            Color orig = Color.FromRgb(
                Convert.ToByte(UtilityCore.GetScaledValue_Capped(0, 255, 0, 1, Math.Abs(raw.Item1))),
                Convert.ToByte(UtilityCore.GetScaledValue_Capped(0, 255, 0, 1, Math.Abs(raw.Item2))),
                Convert.ToByte(UtilityCore.GetScaledValue_Capped(0, 255, 0, 1, Math.Abs(raw.Item3))));

            // Bring up the saturation
            ColorHSV hsv = UtilityWPF.RGBtoHSV(orig);

            return(UtilityWPF.HSVtoRGB(hsv.H, Math.Max(hsv.S, 40), hsv.V));
        }
Пример #16
0
        private Color GetGreenRedColor(double minTarget, double maxTarget, double actualValue, double sizePercent)
        {
            if (sizePercent < .9d)
            {
                return(Color.OliveDrab);
            }
            else
            {
                double derivedMinTarget = UtilityCore.GetScaledValue(minTarget, maxTarget, 0d, 1d, .9d);
                double colorPercent     = UtilityCore.GetScaledValue_Capped(0d, 1d, derivedMinTarget, maxTarget * 3d, actualValue);

                return(UtilityGDI.AlphaBlend(Color.Firebrick, Color.OliveDrab, colorPercent));
            }
        }
Пример #17
0
            /// <summary>
            /// This returns a linear gradient brush to paint an arrow.  The arrow gets darker as the speed increases
            /// </summary>
            private static LinearGradientBrush GetArrowBrush(double speed)
            {
                // Since the speed is distance cubed, I want to take the cube root so the darkness grows linearly.  If I don't
                // then it stays light for most of the range, and spikes to dark.
                //double cubeRoot = Math.Pow(speed, .33333333333d);
                double cubeRoot = Math.Pow(speed, .5d);         // actually, I decided to take the square root, sort of splitting the difference between linear and extreme

                //double darkAlpha = UtilityHelper.GetScaledValue_Capped(45, 192, 0, 500, speed);
                //double darkAlpha = UtilityHelper.GetScaledValue_Capped(45, 192, 0, 7.9370052d, cubeRoot);
                double darkAlpha  = UtilityCore.GetScaledValue_Capped(45, 192, 0, 22.3606798d, cubeRoot);
                double lightAlpha = darkAlpha / 1.4d;

                return(new LinearGradientBrush(Color.FromArgb(Convert.ToByte(darkAlpha), 0, 0, 0), Color.FromArgb(Convert.ToByte(lightAlpha), 0, 0, 0), 90));
            }
Пример #18
0
        private void FireAttractEvent()
        {
            if (this.AttractionChanged == null)
            {
                return;
            }

            BodyAttractionType attractionType = GetAttractionType();

            double distance = trkDistance.Value;
            double strength;

            switch (attractionType)
            {
            case BodyAttractionType.Gravity:
                strength = UtilityCore.GetScaledValue_Capped(0, 125, trkStrength.Minimum, trkStrength.Maximum, trkStrength.Value);
                break;

            case BodyAttractionType.Spring:
                strength = UtilityCore.GetScaledValue_Capped(0, 10, trkStrength.Minimum, trkStrength.Maximum, trkStrength.Value);
                break;

            case BodyAttractionType.SpringDesiredDistance:
                strength = UtilityCore.GetScaledValue_Capped(0, 50, trkStrength.Minimum, trkStrength.Maximum, trkStrength.Value);
                distance = UtilityCore.GetScaledValue_Capped(0, 100, trkDistance.Minimum, trkDistance.Maximum, trkDistance.Value);
                break;

            case BodyAttractionType.SpringInverseDist:
                strength = UtilityCore.GetScaledValue_Capped(0, 10, trkStrength.Minimum, trkStrength.Maximum, trkStrength.Value);
                break;

            case BodyAttractionType.Tangent:
                strength = UtilityCore.GetScaledValue_Capped(0, 200, trkStrength.Minimum, trkStrength.Maximum, trkStrength.Value);
                distance = UtilityCore.GetScaledValue_Capped(0, 50, trkDistance.Minimum, trkDistance.Maximum, trkDistance.Value);
                break;

            case BodyAttractionType.Constant:
                strength = UtilityCore.GetScaledValue_Capped(0, 20, trkStrength.Minimum, trkStrength.Maximum, trkStrength.Value);
                break;

            default:
                strength = UtilityCore.GetScaledValue_Capped(0, 100, trkStrength.Minimum, trkStrength.Maximum, trkStrength.Value);
                break;
            }

            BodyAttractionArgs args = new BodyAttractionArgs(GetAttractionType(), GetIsToward(), strength, distance);

            this.AttractionChanged(this, args);
        }
Пример #19
0
        private void AdjustPlates()
        {
            // Pixels
            if (chkShowPixels.IsChecked.Value)
            {
                grdPixels.Visibility = Visibility.Visible;
                grdPixels.Opacity    = UtilityCore.GetScaledValue_Capped(0d, 1d, trkPixelOpacity.Minimum, trkPixelOpacity.Maximum, trkPixelOpacity.Value);
            }
            else
            {
                grdPixels.Visibility = Visibility.Collapsed;
            }

            // Polygons
            if (chkShowPolygons.IsChecked.Value)
            {
                grdPolygons.Visibility = Visibility.Visible;
                grdPolygons.Opacity    = UtilityCore.GetScaledValue_Capped(0d, 1d, trkPolygonOpacity.Minimum, trkPolygonOpacity.Maximum, trkPolygonOpacity.Value);
            }
            else
            {
                grdPolygons.Visibility = Visibility.Collapsed;
            }

            // Triangles
            if (chkShowTriangles.IsChecked.Value)
            {
                grdTriangles.Visibility = Visibility.Visible;
                grdTriangles.Opacity    = UtilityCore.GetScaledValue_Capped(0d, 1d, trkTriangleOpacity.Minimum, trkTriangleOpacity.Maximum, trkTriangleOpacity.Value);
            }
            else
            {
                grdTriangles.Visibility = Visibility.Collapsed;
            }

            // Circles
            if (chkShowCircles.IsChecked.Value)
            {
                grdCircles.Visibility = Visibility.Visible;
                grdCircles.Opacity    = UtilityCore.GetScaledValue_Capped(0d, 1d, trkCircleOpacity.Minimum, trkCircleOpacity.Maximum, trkCircleOpacity.Value);
            }
            else
            {
                grdCircles.Visibility = Visibility.Collapsed;
            }

            grdTriangles_SizeChanged(this, null);
        }
Пример #20
0
        private void GetMineralBlipSprtCacheProps()
        {
            // Get the min/max values
            double minDollars = double.MaxValue;
            double maxDollars = double.MinValue;

            SortedList <MineralType, double> dollars = new SortedList <MineralType, double>();

            foreach (MineralType mineralType in Enum.GetValues(typeof(MineralType)))
            {
                //decimal suggestedDollars = Mineral.GetSuggestedCredits(mineralType);
                decimal suggestedDollars       = ItemOptionsAstMin2D.GetCredits_Mineral(mineralType);
                double  suggestedDollarsScaled = Math.Sqrt(Convert.ToDouble(suggestedDollars));   // taking the square root, because the values are exponential, and I want the color scale more linear
                dollars.Add(mineralType, suggestedDollarsScaled);

                if (suggestedDollarsScaled < minDollars)
                {
                    minDollars = suggestedDollarsScaled;
                }

                if (suggestedDollarsScaled > maxDollars)
                {
                    maxDollars = suggestedDollarsScaled;
                }
            }

            // Store color based on those values
            _mineralColors = new SortedList <MineralType, MineralBlipProps>();
            Color maxColor = Colors.Chartreuse;

            foreach (MineralType mineralType in Enum.GetValues(typeof(MineralType)))
            {
                Color  diffuse, specular;
                double size;

                double dollar = dollars[mineralType];

                double colorPercent = UtilityCore.GetScaledValue_Capped(.33d, 1d, minDollars, maxDollars, dollar);
                diffuse  = UtilityWPF.AlphaBlend(maxColor, Colors.Transparent, colorPercent);
                specular = diffuse;

                //size = UtilityCore.GetScaledValue_Capped(2d, 5d, minDollars, maxDollars, dollar);
                size = UtilityCore.GetScaledValue_Capped(4d, 10d, minDollars, maxDollars, dollar);

                _mineralColors.Add(mineralType, new MineralBlipProps(diffuse, specular, size));
            }
        }
Пример #21
0
        //TODO: This functionality should be part of MapObjectChaseVelocity
        private static Point3D?AdjustIfOffPlane(Point3D itemPos, double itemRadius, DragHitShape dragPlane, Point3D?chasePoint)
        {
            const double MAXOFFSET    = 1.5;
            const double PERCENTATMAX = .01;        // even if they are really far off the plane, don't completely chase the plane, some percent needs to go toward the chase point passed in

            Point3D?pointOnPlane = dragPlane.CastRay(itemPos);

            if (pointOnPlane == null)
            {
                // Don't know where they are relative to the plane (this should never happen)
                return(chasePoint);
            }
            else if (Math3D.IsNearValue(pointOnPlane.Value, itemPos))
            {
                // They're position is the same as the point on the plane (they are already on the plane)
                return(chasePoint);
            }

            Vector3D vectToPlane = (itemPos - pointOnPlane.Value);
            double   distToPlane = vectToPlane.Length;

            if (distToPlane < itemRadius * .01)
            {
                // They are less than a percent of their body size off the plane, just return the point passed in
                return(chasePoint);
            }

            if (chasePoint == null)
            {
                // Null was passed in, just go straight for the plane (this should never happen)
                return(pointOnPlane);
            }

            // Figure out how much to dive for the plane vs go for the chase point
            double offset  = distToPlane / itemRadius;
            double percent = PERCENTATMAX;

            if (offset < MAXOFFSET)
            {
                // They are less than the max allowable distance from the plane
                percent = UtilityCore.GetScaledValue_Capped(PERCENTATMAX, 1d, 0, MAXOFFSET, MAXOFFSET - offset);
            }

            Vector3D direction = chasePoint.Value - pointOnPlane.Value;

            return(pointOnPlane.Value + (direction * percent));
        }
Пример #22
0
        public override bool Update(double elapsedTime)
        {
            bool retVal = base.Update(elapsedTime);

            if (retVal)
            {
                RemoveVisual();
            }
            else
            {
                #region Update Visual

                // Transparency
                double transparency = UtilityCore.GetScaledValue_Capped(0d, 1d, _visualStartRadius, this.MaxRadius * .75d, this.Radius);                // I want it to become invisible sooner
                _material.Brush = new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.Transparent, _baseColor, transparency));

                // Scale (this is what Body.OnBodyMoved does, plus scale)
                //NOTE:  The radius gets huge, but the force drops off quickly, so it doesn't look right if I scale it to full size
                double scale = UtilityCore.GetScaledValue_Capped(1d, (this.MaxRadius * .05d) / _visualStartRadius, _visualStartRadius, this.MaxRadius, this.Radius);

                Transform3DGroup transform = new Transform3DGroup();
                transform.Children.Add(new ScaleTransform3D(scale, scale, scale));

                if (this.Body == null)
                {
                    transform.Children.Add(new TranslateTransform3D(this.Position.ToVector()));
                }
                else
                {
                    transform.Children.Add(new MatrixTransform3D(this.Body.OffsetMatrix));
                }

                _visual.Transform = transform;

                //NOTE:  The shell is smaller than this.Radius (once it overtakes _visualStartRadius)
                if (this.Radius > _visualStartRadius * 2)
                {
                    _pointLight.Range = this.Radius;
                }

                #endregion
            }

            // Exit Function
            return(retVal);
        }
Пример #23
0
        private static (double distance, double error) GetDistanceError(Bot bot, Point3D center, double maxDistance, double maxDistance2)
        {
            // Get the bot's distance from home
            double distance = (bot.PositionWorld - center).Length;

            // Run that distance through a scoring function
            double error = 0d;

            if (distance > maxDistance2)
            {
                error = 1;
            }
            else if (distance > maxDistance)
            {
                error = UtilityCore.GetScaledValue_Capped(0, 1, maxDistance, maxDistance2, distance);
            }

            return(distance, error);
        }
Пример #24
0
        private void ResizeColorBar()
        {
            #region Figure out percent

            double percent = 0d;

            // If they don't add up, don't throw an error, just make it invisible (they are probably in the middle of setting the properties
            if (_minimum >= _maximum || _value < _minimum)
            {
                percent = 0d;
            }
            else if (_value > _maximum)
            {
                percent = 1d;
            }
            else
            {
                percent = UtilityCore.GetScaledValue_Capped(0d, 1d, _minimum, _maximum, _value);
            }

            #endregion

            #region Set grid column widths

            if (percent == 0d)
            {
                barWidth.Width       = new GridLength(0d);
                remainderWidth.Width = new GridLength(1d, GridUnitType.Star);
            }
            else if (percent == 1d)
            {
                barWidth.Width       = new GridLength(1d, GridUnitType.Star);
                remainderWidth.Width = new GridLength(0d);
            }
            else
            {
                // I propably don't need to multiply by 100, but I feel better
                barWidth.Width       = new GridLength(percent * 100, GridUnitType.Star);
                remainderWidth.Width = new GridLength((1d - percent) * 100, GridUnitType.Star);
            }

            #endregion
        }
Пример #25
0
        private double GetPastingBallsOpacity()
        {
            const int INITIALDELAY = 750;
            const int FADEDURATION = 300;

            int tickCount = Environment.TickCount;

            if (tickCount - _lastMouseMove <= INITIALDELAY)
            {
                return(1d);
            }

            if (tickCount - _lastMouseMove < INITIALDELAY + FADEDURATION)
            {
                int fadeElapse = FADEDURATION - (tickCount - _lastMouseMove - INITIALDELAY);            // I reversed it so I can run the result through the LERP function

                return(UtilityCore.GetScaledValue_Capped(0d, 1d, 0, FADEDURATION, fadeElapse));
            }

            return(0d);
        }
Пример #26
0
        private Model3D GetRing()
        {
            double size = UtilityCore.GetScaledValue_Capped(.025d, .15d, .1d, 10d, _radius);

            GeometryModel3D retVal   = new GeometryModel3D();
            MaterialGroup   material = new MaterialGroup();
            DiffuseMaterial diffuse  = new DiffuseMaterial(new SolidColorBrush(this.EditorColors.DraggableModifier));

            this.MaterialBrushes.Add(new MaterialColorProps(diffuse, diffuse.Brush, this.EditorColors.DraggableModifier));
            material.Children.Add(diffuse);
            SpecularMaterial specular = new SpecularMaterial(new SolidColorBrush(this.EditorColors.DraggableModifier_SpecularColor), this.EditorColors.DraggableModifier_SpecularPower);

            this.MaterialBrushes.Add(new MaterialColorProps(specular));
            material.Children.Add(specular);

            retVal.Material     = material;
            retVal.BackMaterial = material;
            retVal.Geometry     = UtilityWPF.GetRing(50, _radius - (size * .5d), _radius + (size * .5d), size, _initialRotateTransform);

            return(retVal);
        }
Пример #27
0
        private static (double speed, double error) GetSpeedError(Bot bot, double minSpeed, double maxSpeed, double maxSpeed2)
        {
            double speed = bot.VelocityWorld.Length;

            double error = 0;

            if (speed < minSpeed)
            {
                error = UtilityCore.GetScaledValue_Capped(0, 1, minSpeed, 0, speed);
            }
            else if (speed > maxSpeed2)
            {
                error = 1;
            }
            else if (speed > maxSpeed)
            {
                error = UtilityCore.GetScaledValue_Capped(0, 1, maxSpeed, maxSpeed2, speed);
            }

            return(speed, error);
        }
Пример #28
0
        /// <summary>
        /// Take the slider value, and map it to the public value
        /// </summary>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            double valueCast = (double)value;

            ConvertProps props = IsMultiplier();

            if (props != null)
            {
                double absValue = Math.Abs(valueCast);

                double retVal;

                if (absValue > props.AbsMiddle)
                {
                    double percent = (absValue - props.AbsMiddle) / (props.AbsMax - props.AbsMiddle);

                    // Scale that to go from 1 to max
                    retVal = UtilityCore.GetScaledValue_Capped(1d, props.AbsMax, 0d, 1d, percent);
                }
                else
                {
                    double percent = (absValue - props.AbsMin) / (props.AbsMiddle - props.AbsMin);

                    // Scale that to go from min to 1
                    retVal = UtilityCore.GetScaledValue_Capped(props.AbsMin, 1d, 0d, 1d, percent);
                }

                if (!props.IsPositive)
                {
                    // Negate
                    retVal *= -1d;
                }

                return(retVal);
            }
            else
            {
                return(valueCast);
            }
        }
Пример #29
0
        private void UpdateNeurons_fixed(Vector3D gravity, double magnitude)
        {
            const double MINDOT = 1d;

            if (Math3D.IsNearZero(gravity))
            {
                // There is no gravity to report
                for (int cntr = 0; cntr < _neurons.Length; cntr++)
                {
                    _neurons[cntr].Value = 0d;
                }
                return;
            }

            Vector3D gravityUnit = gravity.ToUnit();

            for (int cntr = 0; cntr < _neurons.Length; cntr++)
            {
                if (_neurons[cntr].PositionUnit == null)
                {
                    // This neuron is sitting at 0,0,0
                    _neurons[cntr].Value = magnitude;
                }
                else
                {
                    double dot = Vector3D.DotProduct(gravityUnit, _neurons[cntr].PositionUnit.Value);
                    dot += 1d;          // get this to scale from 0 to 2 instead of -1 to 1

                    if (dot < MINDOT)
                    {
                        _neurons[cntr].Value = 0d;
                    }
                    else
                    {
                        _neurons[cntr].Value = UtilityCore.GetScaledValue_Capped(0d, 1d, MINDOT, 2d, dot);
                    }
                }
            }
        }
Пример #30
0
        private static Quaternion?DoStep_Rotate(Vector3D torque, double size, double penetrationScale)
        {
            const double MAXANGLE = 12d; //22.5d;

            if (Math3D.IsNearZero(torque))
            {
                return(null);
            }

            double   length = torque.Length;
            Vector3D axis   = torque / length;

            // Since the max torque will be a full penetration out at radius, that will be penetration cross radius.  So the length of that will be
            // roughly (size/2)^2
            //double maxExpected = Math.Pow(size * .33d, 2d);		// make the max size a bit smaller than half, since a max penetration would be really rare
            //double maxExpected = size * size;

            double maxExpected = (size * .5d) * (size * penetrationScale);

            // Make the angle to be some proportion between the torque's length and the average size of the part
            double angle = UtilityCore.GetScaledValue_Capped(0d, MAXANGLE, 0d, maxExpected, length);

            return(new Quaternion(axis, angle));
        }