protected virtual void UpdatePositions(TimeSpan duration)
        {
            double timeFactor = (duration.TotalMilliseconds / 25) * time;

            time = MathTools.Clip(time, 0.1, 10);

            foreach (Node node in quadTree.AllNodes())
            {
                if (node.IsSelected || node.IsPositionLocked)
                {
                    // reset force
                    node.TotalForce = new Vector();
                    node.Velocity   = new Vector();
                }

                // add drag, todo: should be proportional to V, plus a fixed amount
                node.TotalForce -= (node.Velocity * friction);
                //if (node.Velocity.Length > 0)
                //{
                //    double dragStrength = 0.2 + (node.Velocity.LengthSquared / 100) * friction;

                //    Vector dragForce = node.Velocity;
                //    dragForce.Normalize();
                //    dragForce *= dragStrength;

                //    node.TotalForce -= dragForce;
                //}

                // calculate the acceleration, F = MA
                Vector acceleration = node.TotalForce / node.Mass;

                // calculate the new velocity, todo: should be V = AT
                node.Velocity += acceleration * timeFactor;

                // calculate the new position, V = D/T
                node.Position += node.Velocity * timeFactor;

                // reset force
                node.TotalForce = new Vector();

                quadTree.UpdateNodeQuadrant(node);
            }
        }
Пример #2
0
        /// <summary>
        /// Gets the smallest rect that contains all the nodes
        /// </summary>
        public Rect GetContentBounds()
        {
            Rect contentBounds = quadTree.AllNodes().Select(n => n.GetBounds()).GetBounds();

            return(contentBounds);
        }