Esempio n. 1
0
 private void btnBoth_Click(object sender, RoutedEventArgs e)
 {
     if (this.WhackEm != null)
     {
         SetVelocityArgs args = new SetVelocityArgs(GetDirection(), GetTranslationSpeed(), GetRotationSpeed(), GetOverwriteSetting());
         this.WhackEm(this, args);
     }
 }
		private void btnBoth_Click(object sender, RoutedEventArgs e)
		{
			if (this.WhackEm != null)
			{
				SetVelocityArgs args = new SetVelocityArgs(GetDirection(), GetTranslationSpeed(), GetRotationSpeed(), GetOverwriteSetting());
				this.WhackEm(this, args);
			}
		}
        private void setVelocities1_WhackEm(object sender, SetVelocityArgs e)
        {
            try
            {
                foreach (Body[] set in _bodySets)
                {
                    foreach (Body body in set)
                    {
                        if (e.TranslationSpeed > 0d)
                        {
                            #region Translate

                            // Figure out direction (not worried about length)
                            Vector3D direction;
                            switch (e.Direction)
                            {
                                case SetVelocityDirection.Random:
                                    direction = Math3D.GetRandomVector_Spherical(1d);
                                    break;

                                case SetVelocityDirection.FromCenter:
                                    direction = body.Position.ToVector();
                                    break;

                                case SetVelocityDirection.TowardCenter:
                                    direction = -body.Position.ToVector();
                                    break;

                                default:
                                    throw new ApplicationException("Unknown SetVelocityDirection: " + e.Direction.ToString());
                            }

                            // Set length to 1
                            direction.Normalize();
                            direction *= e.TranslationSpeed;

                            // Apply velocity
                            if (e.OverwriteCurrentVelocity)
                            {
                                body.Velocity = direction;
                            }
                            else
                            {
                                body.Velocity += direction;
                            }

                            #endregion
                        }

                        if (e.RotationSpeed > 0d)
                        {
                            #region Rotate

                            // Figure out axis (not worried about length)
                            Vector3D axis;
                            switch (e.Direction)
                            {
                                case SetVelocityDirection.Random:
                                case SetVelocityDirection.FromCenter:		// just letting all rotations be random
                                case SetVelocityDirection.TowardCenter:
                                    axis = Math3D.GetRandomVector_Spherical(1d);
                                    break;

                                //case SetVelocityDirection.FromCenter:
                                //TODO:  Make the axis at a right angle from the this direction (but with a consistent "up")
                                //axis = body.Position.ToVector();
                                //break;

                                //case SetVelocityDirection.TowardCenter:
                                //axis = -body.Position.ToVector();
                                //break;

                                default:
                                    throw new ApplicationException("Unknown SetVelocityDirection: " + e.Direction.ToString());
                            }

                            axis.Normalize();
                            axis *= e.RotationSpeed;

                            if (e.OverwriteCurrentVelocity)
                            {
                                body.AngularVelocity = axis;
                            }
                            else
                            {
                                body.AngularVelocity += axis;
                            }

                            #endregion
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 4
0
        private void setVelocities1_WhackEm(object sender, SetVelocityArgs e)
        {
            try
            {
                foreach (Body[] set in _bodySets)
                {
                    foreach (Body body in set)
                    {
                        if (e.TranslationSpeed > 0d)
                        {
                            #region Translate

                            // Figure out direction (not worried about length)
                            Vector3D direction;
                            switch (e.Direction)
                            {
                            case SetVelocityDirection.Random:
                                direction = Math3D.GetRandomVector_Spherical(1d);
                                break;

                            case SetVelocityDirection.FromCenter:
                                direction = body.Position.ToVector();
                                break;

                            case SetVelocityDirection.TowardCenter:
                                direction = -body.Position.ToVector();
                                break;

                            default:
                                throw new ApplicationException("Unknown SetVelocityDirection: " + e.Direction.ToString());
                            }

                            // Set length to 1
                            direction.Normalize();
                            direction *= e.TranslationSpeed;

                            // Apply velocity
                            if (e.OverwriteCurrentVelocity)
                            {
                                body.Velocity = direction;
                            }
                            else
                            {
                                body.Velocity += direction;
                            }

                            #endregion
                        }

                        if (e.RotationSpeed > 0d)
                        {
                            #region Rotate

                            // Figure out axis (not worried about length)
                            Vector3D axis;
                            switch (e.Direction)
                            {
                            case SetVelocityDirection.Random:
                            case SetVelocityDirection.FromCenter:               // just letting all rotations be random
                            case SetVelocityDirection.TowardCenter:
                                axis = Math3D.GetRandomVector_Spherical(1d);
                                break;

                            //case SetVelocityDirection.FromCenter:
                            //TODO:  Make the axis at a right angle from the this direction (but with a consistent "up")
                            //axis = body.Position.ToVector();
                            //break;

                            //case SetVelocityDirection.TowardCenter:
                            //axis = -body.Position.ToVector();
                            //break;

                            default:
                                throw new ApplicationException("Unknown SetVelocityDirection: " + e.Direction.ToString());
                            }

                            axis.Normalize();
                            axis *= e.RotationSpeed;

                            if (e.OverwriteCurrentVelocity)
                            {
                                body.AngularVelocity = axis;
                            }
                            else
                            {
                                body.AngularVelocity += axis;
                            }

                            #endregion
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }