Exemple #1
0
        public CameraFirstPerson(float lrRot, float udRot, Vector3 startingPos, GraphicInfo graphicInfo)
#endif
        {
            init(lrRot, udRot, startingPos, graphicInfo);

#if WINDOWS_PHONE
            this.useAcelerometer = useAcelerometer;
            if (useAcelerometer)
            {
                accelSensor = new Microsoft.Devices.Sensors.Accelerometer();
                // Start the accelerometer
                try
                {
                    accelSensor.Start();
                    accelActive = true;
                }
                catch (Microsoft.Devices.Sensors.AccelerometerFailedException e)
                {
                    // the accelerometer couldn't be started.  No fun!
                    accelActive = false;
                }
                catch (UnauthorizedAccessException e)
                {
                    // This exception is thrown in the emulator-which doesn't support an accelerometer.
                    accelActive = false;
                }
                accelSensor.ReadingChanged += new EventHandler <Microsoft.Devices.Sensors.AccelerometerReadingEventArgs>(accelSensor_ReadingChanged);
            }
#endif
        }
Exemple #2
0
        /// <summary>
        /// Initializes the Accelerometer for the current game. This method can only be called once per game.
        /// </summary>
        public static void Initialize()
        {
            // make sure we don't initialize the Accelerometer twice
            if (isInitialized)
            {
                //throw new InvalidOperationException("Initialize can only be called once");
            }

#if WINDOWS_PHONE
            // try to start the sensor only on devices, catching the exception if it fails
            if (Microsoft.Devices.Environment.DeviceType == Microsoft.Devices.DeviceType.Device)
            {
                try
                {
                    accelerometer.ReadingChanged += new EventHandler <Microsoft.Devices.Sensors.AccelerometerReadingEventArgs>(sensor_ReadingChanged);
                    accelerometer.Start();
                    isActive = true;
                }
                catch (Microsoft.Devices.Sensors.AccelerometerFailedException)
                {
                    isActive = false;
                }
            }
            else
            {
                // we always return isActive on emulator because we use the arrow
                // keys for simulation which is always available.
                isActive = true;
            }
#endif

            // remember that we are initialized
            isInitialized = true;
        }
Exemple #3
0
        public static void Initialize()
        {
            if (isInitialized)
            {
                throw new InvalidOperationException("Initialize can only be called once !");
            }
#if WINDOWS_PHONE
            if (!Microsoft.Devices.Sensors.Accelerometer.IsSupported)
            {
                throw new RuntimeException("Not support accelerometer !");
            }
            if (Microsoft.Devices.Environment.DeviceType == Microsoft.Devices.DeviceType.Device)
            {
#pragma warning disable
                try
                {
                    accelerometer.TimeBetweenUpdates = TimeSpan.FromMilliseconds(16);
                    accelerometer.ReadingChanged    += new EventHandler <Microsoft.Devices.Sensors.AccelerometerReadingEventArgs>(Sensor_ReadingChanged);
                    accelerometer.Start();
                    isActive = true;
                }
                catch (Microsoft.Devices.Sensors.AccelerometerFailedException)
                {
                    isActive = false;
                }
#pragma warning restore
            }
            else
            {
                isActive = true;
            }
#endif
            isInitialized = true;
        }
        public void SetDelegate(ICCAccelerometerDelegate pDelegate)
        {
            m_pAccelDelegate = pDelegate;

            if (pDelegate != null && !m_bActive)
            {
                                #if !WINDOWS && !PSM && !OUYA && !XBOX360 && !NETFX_CORE && !MONOMAC
                try
                {
                    if (Microsoft.Devices.Sensors.Accelerometer.IsSupported)
                    {
                        accelerometer.CurrentValueChanged += accelerometer_CurrentValueChanged;
                        accelerometer.Start();
                        m_bActive = true;
                    }
                    else
                    {
                        m_bActive = false;
                    }
                }
                catch (Microsoft.Devices.Sensors.AccelerometerFailedException)
                {
                    m_bActive = false;
                }
#endif
                if (!m_bActive)
                {
                    m_bActive    = true;
                    m_bEmulation = true;
                }
                else
                {
                    m_bEmulation = false;
                }
            }
            else
            {
                if (m_bActive && !m_bEmulation)
                {
                                        #if !WINDOWS && !PSM && !OUYA && !XBOX360 && !NETFX_CORE && !MONOMAC
                    if (accelerometer != null)
                    {
                        accelerometer.CurrentValueChanged -= accelerometer_CurrentValueChanged;
                        accelerometer.Stop();
                    }
#endif
                }

                ResetAccelerometer();

                m_bActive    = false;
                m_bEmulation = false;
            }
        }
Exemple #5
0
        /// <summary>
        /// Initializes the Accelerometer for the current game. This method can only be called once per game.
        /// </summary>
        public static void Initialize()
        {
            // make sure we don't initialize the Accelerometer twice
            if (isInitialized)
            {
                throw new InvalidOperationException("Initialize can only be called once");
            }

#if WINDOWS_PHONE
            // ALVIN NOTE: Remove the block to only initialise for devices.  Emulation is now available!
            //// try to start the sensor only on devices, catching the exception if it fails
            //if (Microsoft.Devices.Environment.DeviceType == Microsoft.Devices.DeviceType.Device)
            //{
            try
            {
                // ALVIN NOTE: Updated to use the new types.
                accelerometer.CurrentValueChanged += new EventHandler <SensorReadingEventArgs <AccelerometerReading> >(sensor_ReadingChanged);
                accelerometer.TimeBetweenUpdates   = TimeSpan.FromMilliseconds(20);

                accelerometer.Start();
                isActive = true;
            }
            catch (Microsoft.Devices.Sensors.AccelerometerFailedException)
            {
                isActive = false;
            }

            // ALVIN NOTE: New in MANGO, no need to hide emulators!
            //}
            //else
            //{
            //    // we always return isActive on emulator because we use the arrow
            //    // keys for simulation which is always available.
            //    isActive = true;
            //}
#endif

            // remember that we are initialized
            isInitialized = true;
        }
        /// <summary>
        /// Initializes the Accelerometer for the current game. This method can only be called once per game.
        /// </summary>
        public static void Initialize()
        {
            // make sure we don't initialize the Accelerometer twice
            if (isInitialized)
            {
                throw new InvalidOperationException("Initialize can only be called once");
            }

            try
            {
                accelerometer.ReadingChanged += new EventHandler <Microsoft.Devices.Sensors.AccelerometerReadingEventArgs>(sensor_ReadingChanged);
                accelerometer.Start();
                isActive = true;
            }
            catch (Microsoft.Devices.Sensors.AccelerometerFailedException)
            {
                isActive = false;
            }

            // remember that we are initialized
            isInitialized = true;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CameraFirstPerson"/> class.
        /// </summary>
        /// <param name="lrRot">The leftright rotation.</param>
        /// <param name="udRot">The updown rotation.</param>
        /// <param name="startingPos">The starting pos.</param>
        /// <param name="viewport">The viewport.</param>
        public P3DCamera(IScene scene, float lrRot, float udRot, Vector3 startingPos, Viewport viewport)
        {
            this.world = scene.World;

            init(lrRot, udRot, startingPos, viewport);

            scene.BindInput(new SimpleConcreteGestureInputPlayable(Microsoft.Xna.Framework.Input.Touch.GestureType.FreeDrag,
                                                                   (sample) =>
            {
                leftrightRot -= rotationSpeed * sample.Delta.X;
                updownRot    -= rotationSpeed * sample.Delta.Y;
                UpdateViewMatrix();
            }
                                                                   ));

            scene.BindInput(new SimpleConcreteGestureInputPlayable(Microsoft.Xna.Framework.Input.Touch.GestureType.DoubleTap,
                                                                   (sample) =>
            {
                onunseek                     = true;
                Matrix projection            = world.CameraManager.ActiveCamera.Projection;
                Matrix viewProjection        = world.CameraManager.ActiveCamera.View * world.CameraManager.ActiveCamera.Projection;
                Matrix viewInverse           = Matrix.Invert(world.CameraManager.ActiveCamera.View);
                Matrix projectionInverse     = Matrix.Invert(world.CameraManager.ActiveCamera.Projection);
                Matrix viewProjectionInverse = projectionInverse * viewInverse;

                Vector3 v = new Vector3();
                v.X       = (((2.0f * sample.Position.X) / viewPort.Width) - 1);
                v.Y       = -(((2.0f * sample.Position.Y) / viewPort.Height) - 1);
                v.Z       = 0.0f;

                Ray pickRay        = new Ray();
                pickRay.Position.X = viewInverse.M41;
                pickRay.Position.Y = viewInverse.M42;
                pickRay.Position.Z = viewInverse.M43;
                pickRay.Direction  = Vector3.Normalize(Vector3.Transform(v, viewProjectionInverse) - pickRay.Position);

                SegmentInterceptInfo rti = world.PhysicWorld.SegmentIntersect(pickRay, (a) => true, 9999);
                if (rti == null)
                {
                }
                else
                {
                    Vector3 impact = rti.ImpactPosition;
                    Vector3 lookAt = Position - impact;
                    origem         = Position;
                    destino        = Position + lookAt * 0.8f;
                    passo          = 0;
                }
            }
                                                                   ));

            scene.BindInput(new SimpleConcreteGestureInputPlayable(Microsoft.Xna.Framework.Input.Touch.GestureType.Hold,
                                                                   (sample) =>
            {
                onseek                       = true;
                Matrix projection            = world.CameraManager.ActiveCamera.Projection;
                Matrix viewProjection        = world.CameraManager.ActiveCamera.View * world.CameraManager.ActiveCamera.Projection;
                Matrix viewInverse           = Matrix.Invert(world.CameraManager.ActiveCamera.View);
                Matrix projectionInverse     = Matrix.Invert(world.CameraManager.ActiveCamera.Projection);
                Matrix viewProjectionInverse = projectionInverse * viewInverse;

                Vector3 v = new Vector3();
                v.X       = (((2.0f * sample.Position.X) / viewPort.Width) - 1);
                v.Y       = -(((2.0f * sample.Position.Y) / viewPort.Height) - 1);
                v.Z       = 0.0f;

                Ray pickRay        = new Ray();
                pickRay.Position.X = viewInverse.M41;
                pickRay.Position.Y = viewInverse.M42;
                pickRay.Position.Z = viewInverse.M43;
                pickRay.Direction  = Vector3.Normalize(Vector3.Transform(v, viewProjectionInverse) - pickRay.Position);

                SegmentInterceptInfo rti = world.PhysicWorld.SegmentIntersect(pickRay, (a) => true, 9999);
                if (rti == null)
                {
                }
                else
                {
                    Vector3 impact = rti.ImpactPosition;
                    Vector3 lookAt = impact - Position;
                    destino        = Position + lookAt * 0.8f;
                    origem         = Position;
                    passo          = 0;
                }
            }
                                                                   ));



            if (useAcelerometer)
            {
                accelSensor = new Microsoft.Devices.Sensors.Accelerometer();
                // Start the accelerometer
                try
                {
                    accelSensor.Start();
                    accelActive = true;
                }
                catch (Microsoft.Devices.Sensors.AccelerometerFailedException e)
                {
                    // the accelerometer couldn't be started.  No fun!
                    accelActive = false;
                }
                catch (UnauthorizedAccessException e)
                {
                    // This exception is thrown in the emulator-which doesn't support an accelerometer.
                    accelActive = false;
                }
                accelSensor.ReadingChanged += new EventHandler <Microsoft.Devices.Sensors.AccelerometerReadingEventArgs>(accelSensor_ReadingChanged);
            }
        }
Exemple #8
0
 public Accelerometer()
 {
     acc = new Microsoft.Devices.Sensors.Accelerometer();
     acc.Start();
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="CameraFirstPerson"/> class.
        /// </summary>
        /// <param name="lrRot">The leftright rotation.</param>
        /// <param name="udRot">The updown rotation.</param>
        /// <param name="startingPos">The starting pos.</param>
        /// <param name="viewport">The viewport.</param>
        public P3DCamera(IScene scene, float lrRot, float udRot, Vector3 startingPos, Viewport viewport)
        {
            this.world = scene.World;
            
            init(lrRot, udRot, startingPos, viewport);

            scene.BindInput(new SimpleConcreteGestureInputPlayable(Microsoft.Xna.Framework.Input.Touch.GestureType.FreeDrag,
                  (sample) =>
                  {
                      leftrightRot -= rotationSpeed * sample.Delta.X;
                      updownRot -= rotationSpeed * sample.Delta.Y;
                      UpdateViewMatrix();
                  }
              ));

            scene.BindInput(new SimpleConcreteGestureInputPlayable(Microsoft.Xna.Framework.Input.Touch.GestureType.DoubleTap,
                  (sample) =>
                  {
                            onunseek = true;
                            Matrix projection = world.CameraManager.ActiveCamera.Projection;
                            Matrix viewProjection = world.CameraManager.ActiveCamera.View * world.CameraManager.ActiveCamera.Projection;
                            Matrix viewInverse = Matrix.Invert(world.CameraManager.ActiveCamera.View);
                            Matrix projectionInverse = Matrix.Invert(world.CameraManager.ActiveCamera.Projection);
                            Matrix viewProjectionInverse = projectionInverse * viewInverse;

                            Vector3 v = new Vector3();
                            v.X = (((2.0f * sample.Position.X) / viewPort.Width) - 1);
                            v.Y = -(((2.0f * sample.Position.Y) / viewPort.Height) - 1);
                            v.Z = 0.0f;

                            Ray pickRay = new Ray();
                            pickRay.Position.X = viewInverse.M41;
                            pickRay.Position.Y = viewInverse.M42;
                            pickRay.Position.Z = viewInverse.M43;
                            pickRay.Direction = Vector3.Normalize(Vector3.Transform(v, viewProjectionInverse) - pickRay.Position);

                            SegmentInterceptInfo rti = world.PhysicWorld.SegmentIntersect(pickRay, (a) => true, 9999);
                            if (rti == null)
                            {
                             
                            }
                            else
                            {
                                Vector3 impact = rti.ImpactPosition;
                                Vector3 lookAt = Position - impact;
                                origem = Position;
                                destino = Position + lookAt * 0.8f;
                                passo = 0;
                            }
                        


                  }
              ));

            scene.BindInput(new SimpleConcreteGestureInputPlayable(Microsoft.Xna.Framework.Input.Touch.GestureType.Hold,
                  (sample) =>
                  {
                      onseek = true;
                      Matrix projection = world.CameraManager.ActiveCamera.Projection;
                      Matrix viewProjection = world.CameraManager.ActiveCamera.View * world.CameraManager.ActiveCamera.Projection;
                      Matrix viewInverse = Matrix.Invert(world.CameraManager.ActiveCamera.View);
                      Matrix projectionInverse = Matrix.Invert(world.CameraManager.ActiveCamera.Projection);
                      Matrix viewProjectionInverse = projectionInverse * viewInverse;

                      Vector3 v = new Vector3();
                      v.X = (((2.0f * sample.Position.X) / viewPort.Width) - 1);
                      v.Y = -(((2.0f * sample.Position.Y) / viewPort.Height) - 1);
                      v.Z = 0.0f;

                      Ray pickRay = new Ray();
                      pickRay.Position.X = viewInverse.M41;
                      pickRay.Position.Y = viewInverse.M42;
                      pickRay.Position.Z = viewInverse.M43;
                      pickRay.Direction = Vector3.Normalize(Vector3.Transform(v, viewProjectionInverse) - pickRay.Position);

                      SegmentInterceptInfo rti = world.PhysicWorld.SegmentIntersect(pickRay, (a) => true, 9999);
                      if (rti == null)
                      {
                         
                      }
                      else
                      {
                          Vector3 impact = rti.ImpactPosition;
                          Vector3 lookAt = impact - Position;
                          destino = Position + lookAt * 0.8f;
                          origem = Position;
                          passo = 0;
                      }
                  }
              ));

           

            


            if (useAcelerometer)
            {
                accelSensor = new Microsoft.Devices.Sensors.Accelerometer();
                // Start the accelerometer
                try
                {
                    accelSensor.Start();
                    accelActive = true;
                }
                catch (Microsoft.Devices.Sensors.AccelerometerFailedException e)
                {
                    // the accelerometer couldn't be started.  No fun!
                    accelActive = false;
                }
                catch (UnauthorizedAccessException e)
                {
                    // This exception is thrown in the emulator-which doesn't support an accelerometer.
                    accelActive = false;
                }
                accelSensor.ReadingChanged += new EventHandler<Microsoft.Devices.Sensors.AccelerometerReadingEventArgs>(accelSensor_ReadingChanged);
            }


        }
 public void Start()
 {
     _accelerometer.Start();
     _isRunning = true;
 }
            public CameraFirstPerson(float lrRot, float udRot, Vector3 startingPos, GraphicInfo graphicInfo)
#endif
        {            
            init(lrRot, udRot, startingPos,graphicInfo);

#if WINDOWS_PHONE
            this.useAcelerometer = useAcelerometer;
            if (useAcelerometer)
            {
                accelSensor = new Microsoft.Devices.Sensors.Accelerometer();
                // Start the accelerometer
                try
                {
                    accelSensor.Start();
                    accelActive = true;
                }
                catch (Microsoft.Devices.Sensors.AccelerometerFailedException e)
                {
                    // the accelerometer couldn't be started.  No fun!
                    accelActive = false;
                }
                catch (UnauthorizedAccessException e)
                {
                    // This exception is thrown in the emulator-which doesn't support an accelerometer.
                    accelActive = false;
                }
                accelSensor.ReadingChanged += new EventHandler<Microsoft.Devices.Sensors.AccelerometerReadingEventArgs>(accelSensor_ReadingChanged);
            }
#endif

        }