/// <summary>
        /// Construct Object ViewModel as a wrap around a <see cref="InterstellaObject"/> to present it to a CanvasPage
        /// </summary>
        /// <param name="interstellaObject"></param>
        public InterstellaObjectViewModel(InterstellaObject interstellaObject)
        {
            _InterstellaObject = interstellaObject;

            // Subcribe to the Interstellar Object's updated event
            _InterstellaObject.ObjectUpdated += interstellaObject_ObjectUpdated;
        }
        /// <summary>
        /// On Drop event on canvas add new dragged item to the canvas at drop point
        /// </summary>
        private void dropNewObject(object sender, DragEventArgs e)
        {
            // Get the object that was dropped
            InterstellaObject DroppedObject = e.Data.GetData(typeof(InterstellaObject)) as InterstellaObject;

            // If Failed to get object return
            if (DroppedObject == null)
            {
                return;
            }

            // Get the point at which the object was dropped as a vector
            Point  DropPoint          = e.GetPosition((Canvas)sender);
            Vector DropPositionVector = new Vector(DropPoint.X, DropPoint.Y);

            // Find and set the relative position in the model of this object
            // It is Important that these are done in this order!
            DropPositionVector  = Helpers.Centrlize(DropPositionVector, Helpers.CanvasOrigin.TopLeft);
            DropPositionVector -= CanvasPageViewModel.PanVector;
            DropPositionVector  = CanvasPageViewModel.InverseSeperationScaler(DropPositionVector);
            DropPositionVector += CanvasPageViewModel.RadiusScale(DroppedObject.Radius);

            DroppedObject.Position = DropPositionVector;

            // Use the View Model to add the object, at this position, to the model
            _VM.AddObject(new InterstellaObject(DroppedObject));
        }
Esempio n. 3
0
        /// <summary>
        /// Get the velocity an object needs to orbit a second object at its current distance
        /// </summary>
        /// <param name="interstellaObject"></param>
        /// <param name="objectToOrbit"></param>
        static public Vector GetOrbitVelocity(InterstellaObject interstellaObject, InterstellaObject objectToOrbit)
        {
            // Seperation, Large object - small object
            Vector R1R2     = objectToOrbit.Position - interstellaObject.Position;
            Vector R1R2Unit = R1R2 / R1R2.Magnitude;

            // Calculate Magnitude Of Velocity, V = GM/|r|
            double VectorMag = Math.Sqrt((6.674E-11 * objectToOrbit.Mass) / R1R2.Magnitude);

            // Velocity should be at a normal to the force. So multiply by normal to force unit vector.
            Vector Velocity = VectorMag * R1R2Unit.Normal;

            // Randomize orbit direction and Add the velocity of the obejct to orbit too the relative velocity to orbit.
            if (Helpers.RNG.Next(0, 1) == 1)
            {
                Velocity += objectToOrbit.Velocity;
            }

            else
            {
                Velocity = (-1 * Velocity) + objectToOrbit.Velocity;
            }

            return(Velocity);
        }
Esempio n. 4
0
        /// <summary>
        /// Add an obect to the logical system being displayed by the canvas page.
        /// </summary>
        /// <param name="newInterstellaObject"></param>
        public void AddObject(InterstellaObject newInterstellaObject)
        {
            // Add the object ot the syste,
            System.AddObject(newInterstellaObject);

            // Notify the view the canvas objects have changed
            NotifyPropertyChanged(this, nameof(CanvasObjects));

            // Create and add a view model for the object and add it to the side bar
            //InterstellaObjectViewModel newObjectVm = new InterstellaObjectViewModel(newInterstellaObject);
            //SideBarVM.InfoPannelVM.AddDisplayObject(newObjectVm);
        }