Beispiel #1
0
        private void PropsChangedSprtThrusters()
        {
            if (_type != ShipTypeQual.SolidBall)
            {
                return;  // the ball just has the thruster in the center
            }

            MyVector thrusterSeed = new MyVector(0, _ship.Ball.Radius, 0);
            MyVector zAxis        = new MyVector(0, 0, 1);

            // Bottom Thrusters
            _thrusterOffset_BottomRight = thrusterSeed.Clone();
            _thrusterOffset_BottomRight.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(_thrusterAngle * -1));

            _thrusterOffset_BottomLeft = thrusterSeed.Clone();
            _thrusterOffset_BottomLeft.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(_thrusterAngle));

            // Top Thrusters
            thrusterSeed             = new MyVector(0, _ship.Ball.Radius * -1, 0);
            _thrusterOffset_TopRight = thrusterSeed.Clone();
            _thrusterOffset_TopRight.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(_thrusterAngle));

            _thrusterOffset_TopLeft = thrusterSeed.Clone();
            _thrusterOffset_TopLeft.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(_thrusterAngle * -1));
        }
Beispiel #2
0
        private void chkIncludeShip_CheckedChanged(object sender, EventArgs e)
        {
            const double THRUSTERANGLE = 75;

            if (chkIncludeShip.Checked)
            {
                if (_ship == null)
                {
                    #region Create Ship

                    // Set up the ship
                    double    radius = MINRADIUSMASS + (_rand.NextDouble() * (MAXRADIUSMASS - MINRADIUSMASS));
                    SolidBall ship   = new SolidBall(Utility3D.GetRandomVector(_boundryLower, _boundryUpper), new DoubleVector(0, 1, 0, 1, 0, 0), radius, GetMass(radius), GetElasticity(), 1, 1, _boundryLower, _boundryUpper);

                    // Set up the thrusters
                    MyVector thrusterSeed = new MyVector(0, ship.Radius, 0);
                    MyVector zAxis        = new MyVector(0, 0, 1);

                    // Bottom Thrusters
                    _shipThrusterOffset_BottomRight = thrusterSeed.Clone();
                    _shipThrusterOffset_BottomRight.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(THRUSTERANGLE * -1));

                    _shipThrusterOffset_BottomLeft = thrusterSeed.Clone();
                    _shipThrusterOffset_BottomLeft.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(THRUSTERANGLE));

                    // Top Thrusters
                    thrusterSeed = new MyVector(0, ship.Radius * -1, 0);
                    _shipThrusterOffset_TopRight = thrusterSeed.Clone();
                    _shipThrusterOffset_TopRight.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(THRUSTERANGLE));

                    _shipThrusterOffset_TopLeft = thrusterSeed.Clone();
                    _shipThrusterOffset_TopLeft.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(THRUSTERANGLE * -1));

                    // Add to the map
                    _ship = new BallBlip(ship, CollisionStyle.Standard, RadarBlipQual.BallUserDefined03, TokenGenerator.NextToken());
                    _map.Add(_ship);

                    #endregion
                }
            }
            else
            {
                if (_ship != null)
                {
                    _map.Remove(_ship.Token);
                    _ship = null;
                }
            }
        }
Beispiel #3
0
        void picturebox_MouseMove(object sender, MouseEventArgs e)
        {
            _lastMouseMove = Environment.TickCount;

            // Remember the mouse position
            if (_curMousePoint != null && _prevMousePositions != null && _picturebox != null)
            {
                _prevMousePositions.Add(new MousePosition(_curMousePoint.Clone()));
                _curMousePoint = _picturebox.GetPositionViewToWorld(new MyVector(e.X, e.Y, 0));
            }

            if (!_active || _isMouseDown == MouseButtonDown.None)
            {
                return;
            }

            if (_isMouseDown == MouseButtonDown.Left)
            {
                #region Left

                switch (_mode)
                {
                case SelectionMode.Rectangle:
                    // Nothing to do, when draw is called, the rectangle will correspond to the new position
                    break;

                case SelectionMode.Selected:
                    // Move the objects to the new locations.  If they collide along the way, I will need to reset
                    // their positions during timer.
                    #region Set Positions

                    foreach (RadarBlip blip in _map.GetAllBlips())
                    {
                        if (_selectedObjects.Contains(blip.Token))
                        {
                            blip.Sphere.Position.StoreNewValues(_curMousePoint + _draggingPositionOffsets[blip.Token]);
                        }
                    }

                    #endregion
                    break;

                default:
                    throw new ApplicationException("Unknown SelectionMode: " + _mode);
                }

                #endregion
            }
        }
Beispiel #4
0
        private void ResetFieldSprtSwirl(bool goLeft)
        {
            // Init the grid
            _grid = new MyVector[_squaresPerSideX * _squaresPerSideY];

            // I'm going to rotate everything 90 degrees
            MyVector rotateAxis = new MyVector(0, 0, 1);
            double   radians    = Math.PI / 2d;

            if (goLeft)
            {
                radians *= -1d;
            }

            foreach (MyVector center in GetGridCenters())
            {
                // Get the local position
                MyVector localPosition = center - _position;

                // Turn that into a constant length, pointing in or out
                MyVector fieldLine = localPosition.Clone();
                fieldLine.BecomeUnitVector();
                fieldLine.Multiply(_strength);
                fieldLine.RotateAroundAxis(rotateAxis, radians);

                // Store it
                _grid[GetIndexForLocalPosition(localPosition)] = fieldLine;
            }
        }
Beispiel #5
0
        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            MyVector thrusterSeed = new MyVector(0, _ship.Radius, 0);
            MyVector zAxis        = new MyVector(0, 0, 1);
            double   angle        = trackBar1.Value;

            // Bottom Thrusters
            _shipThrusterOffset_BottomRight = thrusterSeed.Clone();
            _shipThrusterOffset_BottomRight.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(angle * -1));

            _shipThrusterOffset_BottomLeft = thrusterSeed.Clone();
            _shipThrusterOffset_BottomLeft.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(angle));

            // Top Thrusters
            thrusterSeed = new MyVector(0, _ship.Radius * -1, 0);
            _shipThrusterOffset_TopRight = thrusterSeed.Clone();
            _shipThrusterOffset_TopRight.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(angle));

            _shipThrusterOffset_TopLeft = thrusterSeed.Clone();
            _shipThrusterOffset_TopLeft.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(angle * -1));
        }
Beispiel #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            MyVector v1 = new MyVector(3, 4, 5);

            v1.Add(1, 2, 3);

            v1.BecomeUnitVector();

            MyVector v2 = v1.Clone();

            v2.Multiply(3);

            v1.Divide(3);
        }
Beispiel #7
0
        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            _prevRadians    = _currentRadians;
            _currentRadians = Utility3D.GetDegreesToRadians(trackBar1.Value);

            #region Draw Current

            Graphics graphics = pictureBox2.CreateGraphics();
            graphics.Clear(pictureBox1.BackColor);

            DrawVector(graphics, _sphere.Position, _sphere.Position + (_sphere.DirectionFacing.Standard * 100d), Color.White);
            DrawVector(graphics, _sphere.Position, _sphere.Position + (_sphere.DirectionFacing.Orth * 100d), Color.Silver);

            MyVector rotatedOffset = _sphere.Rotation.GetRotatedVector(_offset, true);

            DrawVector(graphics, _sphere.Position, _sphere.Position + rotatedOffset, Color.Orange);
            DrawDot(graphics, _sphere.Position + rotatedOffset, 3, Color.Gold);

            #endregion

            double radians = _currentRadians - _prevRadians;

            if (radOffset.Checked)
            {
                // Remember where the offset is in world coords
                MyVector offsetRotated = _sphere.Rotation.GetRotatedVector(_offset, true);
                MyVector offsetWorld   = _sphere.Position + offsetRotated;

                DrawDot(graphics, offsetWorld, 5, Color.DodgerBlue);

                // Get the opposite of the local offset
                MyVector posRelativeToOffset = offsetRotated.Clone();
                posRelativeToOffset.Multiply(-1d);

                // Rotate the center of position around the center of mass
                posRelativeToOffset.RotateAroundAxis(_rotationAxis, radians);

                // Now figure out the new center of position
                _sphere.Position.X = offsetWorld.X + posRelativeToOffset.X;
                _sphere.Position.Y = offsetWorld.Y + posRelativeToOffset.Y;
                _sphere.Position.Z = offsetWorld.Z + posRelativeToOffset.Z;
            }

            _sphere.RotateAroundAxis(_rotationAxis, radians);
        }
Beispiel #8
0
        private void ResetFieldSprtInOut(double direction)
        {
            // Init the grid
            _grid = new MyVector[_squaresPerSideX * _squaresPerSideY];

            foreach (MyVector center in GetGridCenters())
            {
                // Get the local position
                MyVector localPosition = center - _position;

                // Turn that into a constant length, pointing in or out
                MyVector fieldLine = localPosition.Clone();
                fieldLine.BecomeUnitVector();
                fieldLine.Multiply(_strength * direction);

                // Store it
                _grid[GetIndexForLocalPosition(localPosition)] = fieldLine;
            }
        }
Beispiel #9
0
        /// <summary>
        /// If the user clicks on a picture box, you need to run those coords through this function to figure out where they
        /// clicked in world coords
        /// </summary>
        /// <param name="position">A point in PictureBox coords</param>
        /// <returns>The point in World Coords</returns>
        public MyVector GetPositionViewToWorld(MyVector position)
        {
            MyVector retVal = position.Clone();

            // Figure out the world coords that the top left of the picturebox represents
            double picLeft = _centerPoint.X - ((this.Width / 2d) / _zoom);
            double picTop  = _centerPoint.Y - ((this.Height / 2d) / _zoom);

            // The point passed in is a distance from the top left of the picture box to where they clicked.  Turn this view
            // coords into world coords
            retVal.Divide(_zoom);

            // Add these world coords to the top left of the picture box
            retVal.X += picLeft;
            retVal.Y += picTop;

            // It's now what it needs to be
            return(retVal);
        }
Beispiel #10
0
        private MyVector GetSpinVelocityAtPoint(ref AngularVelocityInfo angularInfo, out MyVector dirToCenterLine, MyVector dirFacingWorld, MyVector lineBetween, MyVector blipPosition)
        {
            // Get a line that's orthogonal to lineBetween, and always points toward the dirFacingWorld vector
            dirToCenterLine = MyVector.Cross(MyVector.Cross(lineBetween, dirFacingWorld), lineBetween);
            dirToCenterLine.BecomeUnitVector();

            if (angularInfo == null)
            {
                #region Cache Angular Velocity

                angularInfo = new AngularVelocityInfo();

                if (_ship.TorqueBall != null)
                {
                    angularInfo.AngularVelocity = _ship.TorqueBall.AngularVelocity.GetMagnitude();

                    angularInfo.SpinDirection = MyVector.Cross(_ship.TorqueBall.AngularVelocity, _ship.TorqueBall.DirectionFacing.Standard);
                    angularInfo.SpinDirection.BecomeUnitVector();

                    angularInfo.CenterMass = _ship.TorqueBall.Rotation.GetRotatedVector(_ship.TorqueBall.CenterOfMass, true);
                    angularInfo.CenterMass.Add(_ship.TorqueBall.Position);
                }
                else
                {
                    angularInfo.SpinDirection   = dirToCenterLine.Clone();
                    angularInfo.AngularVelocity = 0d;
                    angularInfo.CenterMass      = _ship.Ball.Position.Clone();
                }

                #endregion
            }

            // Get the line between the blip and the center of mass
            MyVector lineBetweenCM = blipPosition - angularInfo.CenterMass;

            // Figure out my velocity of spin where the blip is
            return(angularInfo.SpinDirection * (angularInfo.AngularVelocity * lineBetweenCM.GetMagnitude()));
        }
Beispiel #11
0
        void picturebox_MouseDown(object sender, MouseEventArgs e)
        {
            if (_mode == AddingMode.Inactive)
            {
                return;
            }

            if (e.Button == MouseButtons.Left)
            {
                _isMouseDown                = true;
                _mouseDownPoint             = _picturebox.GetPositionViewToWorld(new MyVector(e.X, e.Y, 0));
                _curMousePoint              = _mouseDownPoint.Clone();
                _lastCreateTime             = Environment.TickCount;
                _createdBallDuringMouseDrag = false;
                //_diminishPercent = 1d;

                if (_newBallProps.SizeMode == BallProps.SizeModes.Draw)
                {
                    // I need to create an object now (but don't commit it to the map), so that the user can see
                    // it while they drag the size
                    _drawingBall = BuildObject();
                }
            }
        }
Beispiel #12
0
        private Ball BuildObject()
        {
            double radius;

            #region Calculate Radius

            switch (_newBallProps.SizeMode)
            {
            case BallProps.SizeModes.Draw:
                radius = .01d;                  // this function will only get called during mouse down if it's in draw mode, so I need to start with an arbitrarily small radius
                break;

            case BallProps.SizeModes.Fixed:
                radius = _newBallProps.SizeIfFixed;
                break;

            case BallProps.SizeModes.Random:
                radius = _rand.Next(Convert.ToInt32(_newBallProps.MinRandSize), Convert.ToInt32(_newBallProps.MaxRandSize));
                break;

            default:
                throw new ApplicationException("Unknown BallProps.SizeModes: " + _newBallProps.SizeMode);
            }

            if (radius < MINRADIUS)
            {
                radius = MINRADIUS;
            }

            #endregion

            double mass = UtilityCore.GetMassForRadius(radius, 1d);

            MyVector velocity;
            #region Calculate Velocity

            if (_newBallProps.RandomVelocity)
            {
                velocity = Utility3D.GetRandomVectorSpherical2D(_newBallProps.MaxVelocity);
            }
            else
            {
                velocity = _newBallProps.Velocity;              // no need to clone it.  I won't manipulate it
            }

            #endregion

            //TODO:  Listen to global props
            double elasticity      = .75d;
            double kineticFriction = .75d;
            double staticFriction  = 1d;

            Ball retVal;
            #region Build the ball

            switch (_mode)
            {
            case AddingMode.AddBall:
                #region Create Ball

                retVal = new Ball(_curMousePoint.Clone(), new DoubleVector(0, 1, 0, 1, 0, 0), radius, mass, elasticity, kineticFriction, staticFriction, _boundryLower, _boundryUpper);
                retVal.Velocity.Add(velocity);

                #endregion
                break;

            case AddingMode.AddSolidBall:
                #region Create Solid Ball

                retVal = new SolidBall(_curMousePoint.Clone(), new DoubleVector(0, 1, 0, 1, 0, 0), radius, mass, elasticity, kineticFriction, staticFriction, _boundryLower, _boundryUpper);
                retVal.Velocity.Add(velocity);
                //StoreAngularVelocity(retVal);		// no reason to do this here.  it will be applied during commit (if I'm in draw mode, the size will change, and the angular velocity will need to be reapplied anyway)

                #endregion
                break;

            default:
                throw new ApplicationException("Unsupported AddingMode: " + _mode.ToString());
            }

            #endregion

            // Exit Function
            return(retVal);
        }
Beispiel #13
0
 /// <summary>
 /// This function tells me to look at the point passed in, but keep looking at where it is now, not actively track it.
 /// I will store the clone of it, so you don't have to make a clone before you pass me the pointer to a position
 /// </summary>
 public void StaticPoint(MyVector point)
 {
     _centerPoint = point.Clone();
 }
Beispiel #14
0
 /// <summary>
 /// This function tells me to use the last known position of pclsCenterPoint, and stare at that instead of actively
 /// tracking something
 /// </summary>
 public void StaticPoint()
 {
     _centerPoint = _centerPoint.Clone();
 }
Beispiel #15
0
        void picturebox_MouseDown(object sender, MouseEventArgs e)
        {
            if (!_active)
            {
                return;
            }

            if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
            {
                _mouseDownPoint = _picturebox.GetPositionViewToWorld(new MyVector(e.X, e.Y, 0));
                _curMousePoint  = _mouseDownPoint.Clone();
                _prevMousePositions.Clear();
                _tempStationaryObjects.Clear();         // this should be cleared by now anyway
            }

            if (e.Button == MouseButtons.Left)
            {
                #region Left

                _isMouseDown = MouseButtonDown.Left;

                // Get all the blips
                List <RadarBlip> remainingBlips = new List <RadarBlip>(_map.GetAllBlips());

                bool selectedPrevious = false;
                #region See if they selected one of the previously selected objects

                foreach (long token in _selectedObjects)
                {
                    RadarBlip blip = FindAndRemove(token, remainingBlips);

                    if (blip == null)
                    {
                        continue;
                    }

                    if (selectedPrevious)
                    {
                        // I just wanted to remove this blip from the total list
                        continue;
                    }

                    if (SelectionTest(blip, _curMousePoint))
                    {
                        selectedPrevious = true;
                    }
                }

                #endregion

                // Check for ctrl or shift key being pressed (if they are, don't clear the previous)
                if (!selectedPrevious && !(_isShiftPressed || _isCtrlPressed))
                {
                    _selectedObjects.Clear();
                }

                bool selectedNew = false;
                #region See if they clicked on any other objects

                foreach (RadarBlip blip in remainingBlips)
                {
                    if (SelectionTest(blip, _curMousePoint))
                    {
                        _selectedObjects.Add(blip.Token);
                        selectedNew = true;
                    }
                }

                #endregion

                // Set my mode
                if (selectedPrevious || selectedNew)
                {
                    _mode = SelectionMode.Selected;

                    #region Rebuild the offsets list (and temp stationary)

                    _draggingPositionOffsets.Clear();
                    foreach (RadarBlip blip in _map.GetAllBlips())
                    {
                        if (_selectedObjects.Contains(blip.Token))
                        {
                            _draggingPositionOffsets.Add(blip.Token, blip.Sphere.Position - _curMousePoint);

                            if (blip.CollisionStyle == CollisionStyle.Standard)
                            {
                                _tempStationaryObjects.Add(blip.Token);
                                blip.CollisionStyle = CollisionStyle.Stationary;
                            }
                        }
                    }

                    #endregion
                }
                else
                {
                    _mode = SelectionMode.Rectangle;
                }

                #endregion
            }
            else if (e.Button == MouseButtons.Right)
            {
                #region Right

                if (_mode == SelectionMode.Selected && _selectedObjects.Count > 0)
                {
                    _isMouseDown = MouseButtonDown.Right;
                }
                else
                {
                    // If nothing is selected, then there is nothing for me to do
                    _isMouseDown = MouseButtonDown.None;
                }

                #endregion
            }
        }