Exemplo n.º 1
0
 public override PointD GetVelocity(Position.IVirtualMousePosition m)
 {
     // velocity restriction
     double speed = m.GetSpeed();
     double speedLimit = m_Param.C  * 10 * GetStrength(m.GetVirtualPointD());
     if (speed > speedLimit)
     {
         PointD maxParts = new PointD(speedLimit * m.GetUnitDirection().X, speedLimit * m.GetUnitDirection().Y);
         return -1 * m.GetVelocity() + maxParts;
     }
     else
     {
         return PointD.Empty;
     }
 }
Exemplo n.º 2
0
        public override PointD GetVelocity(Position.IVirtualMousePosition m)
        {
            PointD direction = m.GetUnitDirection();
            if (direction.Magnitude() > 0.1)
            {
                m_direction = direction * 0.1 + m_direction * 0.9; // mixture of previous and current input
            }

            if (m_direction.Magnitude() > Render.DrawHelper.MIN_SPEED_SENSITIVITY)
            {
                m_direction = m_direction / m_direction.Magnitude(); // unit vector
                m_Param.V = m_direction; // direction stored internally, but exposed
                PointD velParallel;

                // prevent motion retracing the path (going in opposite direction)
                if (PointD.DotProduct(m_direction, m.GetVelocity()) > 0)
                {
                    velParallel = PointD.DotProduct(m_direction, m.GetVelocity()) * m_direction;
                }
                else
                {
                    // curving opposite motion slightly until more direction events received
                    // (how much velocity to go backwards)
                    velParallel = PointD.DotProduct(m_direction, m.GetVelocity()) * -(1 - m_Param.C) * m_direction;
                    //m_direction = -0.5 * m_direction;
                    //velParallel = PointD.DotProduct(m_direction, m.GetVelocity()) * m_direction;// PointD.DotProduct(m_direction, m.GetVelocity()) * -(1 - m_Param.C) * m_direction;
                }

                PointD origVelocityTangent = PointD.DotProduct(m_direction, m.GetVelocity()) * m_direction;
                PointD origVelocityNormal = PointD.DotProduct(PointD.Orthogonal(m_direction), m.GetVelocity()) * PointD.Orthogonal(m_direction);

                // first cancel out the original velocity, then put the new one in
                return -1 * origVelocityTangent + -m_Param.C * origVelocityNormal + velParallel;
            }
            else
            {
                return PointD.Empty;
            }
        }