Example #1
0
 private void DoMove(double x=0, double y=0)
 {
     var parameters = new CartesianPositionParameters()
     {
         X = x,
         Y = y
     };
     ViewModel.Movement.RollCommand.Execute(parameters);
 }
        private void AccelerometerOnReadingAvailable(object sender, MvxValueEventArgs<Reading> mvxValueEventArgs)
        {
            // note that the switchover between Y and X here is deliberate!
            // and that we invert Y
            // this may need tweaking platform-by-platform 
            // and phone by phone - and maybe at runtime too!

            var parameters = new CartesianPositionParameters
                {
                    X = MakeSafe(-mvxValueEventArgs.Value.Y),
                    Y = MakeSafe(mvxValueEventArgs.Value.X),
                };

            DoRoll(parameters);
        }
Example #3
0
        private void AccelerometerOnReadingAvailable(object sender, MvxValueEventArgs <Reading> mvxValueEventArgs)
        {
            // note that the switchover between Y and X here is deliberate!
            // and that we invert Y
            // this may need tweaking platform-by-platform
            // and phone by phone - and maybe at runtime too!

            var parameters = new CartesianPositionParameters
            {
                X = MakeSafe(-mvxValueEventArgs.Value.Y),
                Y = MakeSafe(mvxValueEventArgs.Value.X),
            };

            DoRoll(parameters);
        }
        protected void DoRoll(CartesianPositionParameters positionParameters)
        {
            // TODO - put the check back in for 'too close'
            //if (Position.AbsoluteDistance < DistanceThreshold)
            //{
            //    return;
            //}

            Position = positionParameters;

            int headingDegrees = positionParameters.HeadingDegrees;
            var speed = (int) ((SpeedService.SpeedPercent*positionParameters.AbsoluteDistance)/100.0);

            SpheroTrace.Trace("Rolling to {0} with speed {1})", headingDegrees, speed);
            var rollCommand = new RollCommand(speed, headingDegrees, false);
            SendCommand(rollCommand);
        }
        protected void DoRoll(CartesianPositionParameters positionParameters)
        {
            // TODO - put the check back in for 'too close'
            //if (Position.AbsoluteDistance < DistanceThreshold)
            //{
            //    return;
            //}

            Position = positionParameters;

            int headingDegrees = positionParameters.HeadingDegrees;
            var speed          = (int)((SpeedService.SpeedPercent * positionParameters.AbsoluteDistance) / 100.0);

            SpheroTrace.Trace("Rolling to {0} with speed {1})", headingDegrees, speed);
            var rollCommand = new RollCommand(speed, headingDegrees, false);

            SendCommand(rollCommand);
        }
 protected BaseSpheroMovementViewModel(ISpheroParentViewModel parent) : base(parent)
 {
     Position = new CartesianPositionParameters();
 }
 protected BaseSpheroMovementViewModel(ISpheroParentViewModel parent) : base(parent)
 {
     Position = new CartesianPositionParameters();
 }
Example #8
0
 protected void OnNewCoordinates()
 {
     var parameters = new CartesianPositionParameters()
     {
         X = newX / (ellipseSense.ActualWidth / 2),
         Y = newY / (ellipseSense.ActualWidth / 2),
     };
     var handler = NewCoordinates;
     if (handler != null)
         handler(this, new MvxValueEventArgs<CartesianPositionParameters>(parameters));
 }
 public double SimpleDistanceFrom(CartesianPositionParameters other)
 {
     return Math.Abs(other.X - this.X) + Math.Abs(other.Y - this.Y);
 }
Example #10
0
        private void UpdateTouchPosition(float x, float y)
        {
            var height = this.Height;
            var width = this.Width;
            var minimal = Math.Min(height, width);
            var relativeX = 2*(x - width/2)/minimal;
            var relativeY = 2*(y - height/2)/minimal;

            if (relativeX > 1.0f)
                relativeX = 1.0f;
            if (relativeX < -1.0f)
                relativeX = -1.0f;

            if (relativeY > 1.0f)
                relativeY = 1.0f;
            if (relativeY < -1.0f)
                relativeY = -1.0f;

            // note that we rotate x and y here because we want 0 to be up the screen
            TouchPosition = new CartesianPositionParameters {Y = relativeX, X = -relativeY};
            Fire(TouchPositionChanged);
        }
 public double SimpleDistanceFrom(CartesianPositionParameters other)
 {
     return(Math.Abs(other.X - this.X) + Math.Abs(other.Y - this.Y));
 }