0

I want to implement this type of functionality using core motion. Any idea how to implement this type of functionality. From research I have find out we have to used Device Motion.

In this mode, the camera zoom is controlled by moving the phone from/to the user, that is, when the user moves the phone away from himself with the “zoom” button held down, the image is zoomed in, and when the user moves the phone towards himself, it zooms out. When you release the zoom button, the current zoom level is saved and does not change when moving.

The zoom should work in any plane and depend only on the direction of movement to /from the user(not only in the horizontal plane). The zoom level depends on the distance the device moves: the zoom changes gradually 2x times if the phone is moved for 5cm and 10x is max (when the phone is moved for 30cm).

Here I have used like this: How can I get the distance of device moves ???

motionManager.StartDeviceMotionUpdates(CMAttitudeReferenceFrame.XArbitraryCorrectedZVertical, 
        NSOperationQueue.CurrentQueue, delegate (CMDeviceMotion motion, NSError error) {

                CMAttitude attitude = motion.Attitude;
                CMAcceleration userAcceleration = motion.UserAcceleration;

                double roll = attitude.Roll;


                double pitch = attitude.Pitch;

                double yaw = attitude.Yaw;

                double accX = userAcceleration.X;

                double accY = userAcceleration.Y;

                double accZ = userAcceleration.Z;


                Console.WriteLine("Y"+ accY);
                Console.WriteLine("Z" + accZ);

                UpdateBallWithRoll(roll, pitch, yaw, accX, accY, accZ);

            });

        private void UpdateBallWithRoll(double roll, double pitch, double yaw, double accX, double accY, double accZ)
    {
        try
        {
            X += 2 * roll;
            Y += 2 * pitch;
           
            

            X *= 0.8;
            Y *= 0.8;
           


            double newX = ball.Frame.X + X;
            double newY = ball.Frame.Y + Y;
            

            newX = Math.Min(280, Math.Max(0, newX));
            newY = Math.Min(527, Math.Max(64, newY));
           
            double newR = R + 10 * accZ;
            ball.Frame = new CoreGraphics.CGRect(newX, newY, newR, newR);
            
        }
        catch (Exception ex)
        {

        }
    }
Vanjara Sweta
  • 81
  • 1
  • 10

0 Answers0