コード例 #1
0
 // public MainActivity(IGyroscopeService gyroscopeService, IAccelerometerService accelerometerService)
 // {
 // this.gyroscopeService = gyroscopeService;
 // this.accelerometerService = accelerometerService;
 // }
 public MainActivity()
 {
     gyroscopeService     = new GyroscopeService();
     accelerometerService = new AccelerometerService();
     accelerometerService.AccelerometerPoints = new List <AccelerometerPoint>();
     gyroscopeService.GyroscopePoints         = new List <GyroscopePoint>();
 }
コード例 #2
0
        /// <summary>
        /// UpdateBalls()
        /// Evalute ball physics, generate new velocities based on collisions, and update
        /// ball positions
        /// </summary>
        protected void UpdateBalls(float dt)
        {
            IAccelerometerService accel = (IAccelerometerService)Game.Services.GetService(typeof(IAccelerometerService));
            Vector3 gravity             = accel.RawAcceleration * 2000;

            // Update positions, add air friction and gravity
            foreach (Ball ball in Balls)
            {
                ball.Position += ball.Velocity * dt; // +(gravity * (dt * dt * 0.5f));
                ball.Velocity += gravity * dt;
            }

            // Resolve ball-ball collisions
            int ballCount = Balls.Count;

            for (int i = 0; i < ballCount; i++)
            {
                for (int j = i + 1; j < ballCount; j++)
                {
                    sphereCollisionImplicit(Balls[i], Balls[j]);
                }
            }

            // Resolve collisions with floor
            for (int i = 0; i < ballCount; i++)
            {
                Ball ball = Balls[i];

                // Resolves collisions with walls
                foreach (Plane wall in Walls)
                {
                    float depth = wall.DotCoordinate(ball.Position) - ball.Radius;
                    if (depth < 0)
                    {
                        // collision with wall
                        ball.Position -= wall.Normal * depth;

                        float impact = wall.DotNormal(ball.Velocity);
                        if (impact < 0)
                        {
                            ball.Velocity -= wall.Normal * (impact * (wallElasticity + 1));
                        }
                    }
                }
            }
        }
コード例 #3
0
 public void Dispose()
 {
     accelerometerService.TranslationChanged -= TranslationChanged;
     accelerometerService = null;
 }
コード例 #4
0
 public AccelerometerController(IAccelerometerService accelerometerService)
 {
     _accelerometerService = accelerometerService;
 }