Пример #1
0
        public GameWindow(Game game, RectangleF frame) : base(frame)
        {
            if (game == null)
            {
                throw new ArgumentNullException("game");
            }
            _game           = game;
            _platform       = (MacGamePlatform)_game.Services.GetService(typeof(MacGamePlatform));
            TouchPanelState = new TouchPanelState(this);

            //LayerRetainsBacking = false;
            //LayerColorFormat	= EAGLColorFormat.RGBA8;
            this.AutoresizingMask = MonoMac.AppKit.NSViewResizingMask.HeightSizable
                                    | MonoMac.AppKit.NSViewResizingMask.MaxXMargin
                                    | MonoMac.AppKit.NSViewResizingMask.MinYMargin
                                    | MonoMac.AppKit.NSViewResizingMask.WidthSizable;

            RectangleF rect = NSScreen.MainScreen.Frame;

            clientBounds = new Rectangle(0, 0, (int)rect.Width, (int)rect.Height);

            // Enable multi-touch
            //MultipleTouchEnabled = true;

            Mouse.Window = this;
        }
Пример #2
0
        public GameState(GameState state, GameTime time, GameWindow window)
        {
            this.State = state;
            this.Time  = time;

            this.Mouse    = new MouseState(this.State, Microsoft.Xna.Framework.Input.Mouse.GetState(window));
            this.Keyboard = Microsoft.Xna.Framework.Input.Keyboard.GetState();

            this.GamePads = new GamePadState[GamePad.MaximumGamePadCount];
            for (int playerIndex = 0; playerIndex < this.GamePads.Length; playerIndex++)
            {
                this.GamePads[playerIndex] = GamePad.GetState(playerIndex);
            }

            if (Joystick.IsSupported)
            {
                this.Joysticks = new JoystickState[4];
                for (int playerIndex = 0; playerIndex < this.Joysticks.Length; playerIndex++)
                {
                    this.Joysticks[playerIndex] = Joystick.GetState(playerIndex);
                }
            }
            else
            {
                this.Joysticks = new JoystickState[0];
            }

            this.TouchPanel = Microsoft.Xna.Framework.Input.Touch.TouchPanel.GetState(window);
        }
Пример #3
0
        protected override void Update(TimeSpan gameTime)
        {
            touchPanelState = WaveServices.Input.TouchPanelState;

            if (touchPanelState.IsConnected && touchPanelState.Count > 0)
            {
                if (!pressed)
                {
                    pressed = true;

                    if (ball == null)
                    {
                        ball = Helpers.CreateSphere("ball", Vector3.Zero, ballSize, BALL_MASS, Color.Gray);
                        EntityManager.Add(ball);
                    }

                    RigidBody3D rigidBody = ball.FindComponent <RigidBody3D>();
                    rigidBody.ResetPosition(Camera.Position);
                    var direction = Camera.Transform.WorldTransform.Forward;
                    direction.Normalize();
                    rigidBody.ApplyLinearImpulse(direction * 100f);
                }
            }
            else
            {
                pressed = false;
            }
        }
Пример #4
0
        protected GameWindow()
        {
#if !ANDROID
            // TODO: Fix the AndroidGameWindow!
            TouchPanelState = new TouchPanelState(this);
#endif
        }
Пример #5
0
        /// <summary>
        /// Move the camera using the touch panel
        /// </summary>
        /// <param name="amount">The amount of time</param>
        private void HandleTouch(float amount)
        {
            TouchPanelState touchState = this.input.TouchPanelState;

            if (touchState.Count >= 2)
            {
                Vector2 touch1 = touchState[0].Position;
                Vector2 touch2 = touchState[1].Position;
                Vector2 dragPosition;
                Vector2.Lerp(ref touch1, ref touch2, 0.5f, out dragPosition);

                if (this.isDragging)
                {
                    float deltaX = dragPosition.X - this.lastDragPosition.X;
                    float deltaY = dragPosition.Y - this.lastDragPosition.Y;

                    Vector2 zoom = this.transform2D.Scale;

                    // Up
                    this.positionDelta.X = this.positionDelta.X - (deltaY * zoom.X * this.up.X);
                    this.positionDelta.Y = this.positionDelta.Y - (deltaY * zoom.Y * this.up.Y);

                    // Right
                    this.positionDelta.X = this.positionDelta.X - (deltaX * zoom.X * this.right.X);
                    this.positionDelta.Y = this.positionDelta.Y - (deltaX * zoom.Y * this.right.Y);
                }

                this.lastDragPosition = dragPosition;
                this.isDragging       = true;
            }
            else
            {
                this.isDragging = false;
            }
        }
Пример #6
0
        private void OnMouseState(object sender, MouseEventArgs mouseEventArgs)
        {
            var previousState = MouseState.LeftButton;

            MouseState.X                 = mouseEventArgs.X;
            MouseState.Y                 = mouseEventArgs.Y;
            MouseState.LeftButton        = (_mouseDownButtonsState & MouseButtons.Left) == MouseButtons.Left ? ButtonState.Pressed : ButtonState.Released;
            MouseState.MiddleButton      = (_mouseDownButtonsState & MouseButtons.Middle) == MouseButtons.Middle ? ButtonState.Pressed : ButtonState.Released;
            MouseState.RightButton       = (_mouseDownButtonsState & MouseButtons.Right) == MouseButtons.Right ? ButtonState.Pressed : ButtonState.Released;
            MouseState.ScrollWheelValue += mouseEventArgs.Delta;

            TouchLocationState?touchState = null;

            if (MouseState.LeftButton == ButtonState.Pressed)
            {
                if (previousState == ButtonState.Released)
                {
                    touchState = TouchLocationState.Pressed;
                }
                else
                {
                    touchState = TouchLocationState.Moved;
                }
            }
            else if (previousState == ButtonState.Pressed)
            {
                touchState = TouchLocationState.Released;
            }

            if (touchState.HasValue)
            {
                TouchPanelState.AddEvent(0, touchState.Value, new Vector2(MouseState.X, MouseState.Y), true);
            }
        }
Пример #7
0
        public override void Update(GameTime gameTime)
        {
            var currentState    = TouchPanel.GetState(_window);
            var touchCollection = currentState.GetState();

            if (touchCollection.Count > 0)
            {
                var first           = touchCollection.FirstOrDefault();
                var currentPosition = Vector2.Transform(first.Position, Global.ScaleMatrix);
                OnMove(currentPosition);
                if (first.State == TouchLocationState.Pressed)
                {
                    _startPressed ??= currentPosition;
                    OnPressedMove(_startPressed.Value, currentPosition);
                }

                if (first.State == TouchLocationState.Released)
                {
                    _startPressed = null;
                    var lastTouchCollection = _state.GetState();
                    if (lastTouchCollection.Count == 0 || lastTouchCollection.FirstOrDefault().State == TouchLocationState.Pressed)
                    {
                        OnPress(currentPosition);
                    }
                }

                _state = currentState;
            }
        }
Пример #8
0
        protected override void Update(TimeSpan gameTime)
        {
            touchPanelState = WaveServices.Input.TouchPanelState;

             if (touchPanelState.IsConnected && touchPanelState.Count > 0)
             {
                 if (!pressed)
                 {
                     pressed = true;

                     if (ball == null)
                     {
                         ball = Helpers.CreateSphere("ball", Vector3.Zero, ballSize, BALL_MASS, Color.Gray);
                         EntityManager.Add(ball);
                     }

                     RigidBody3D rigidBody = ball.FindComponent<RigidBody3D>();
                     rigidBody.ResetPosition(Camera.Position);
                     var direction = Camera.LookAt - Camera.Position;
                     rigidBody.ApplyLinearImpulse(3000 * direction);
                 }
             }
             else
             {
                 pressed = false;
             }
        }
Пример #9
0
        private void UpdateMouseState()
        {
            // If we call the form client functions before the form has
            // been made visible it will cause the wrong window size to
            // be applied at startup.
            if (!Form.Visible)
            {
                return;
            }

            var clientPos    = Form.PointToClient(Control.MousePosition);
            var withinClient = Form.ClientRectangle.Contains(clientPos);
            var buttons      = Control.MouseButtons;

            var previousState = MouseState.LeftButton;

            MouseState.X            = clientPos.X;
            MouseState.Y            = clientPos.Y;
            MouseState.LeftButton   = (buttons & MouseButtons.Left) == MouseButtons.Left ? ButtonState.Pressed : ButtonState.Released;
            MouseState.MiddleButton = (buttons & MouseButtons.Middle) == MouseButtons.Middle ? ButtonState.Pressed : ButtonState.Released;
            MouseState.RightButton  = (buttons & MouseButtons.Right) == MouseButtons.Right ? ButtonState.Pressed : ButtonState.Released;

            // Don't process touch state if we're not active
            // and the mouse is within the client area.
            if (!_platform.IsActive || !withinClient)
            {
                if (MouseState.LeftButton == ButtonState.Pressed)
                {
                    // Release mouse TouchLocation
                    var touchX = MathHelper.Clamp(MouseState.X, 0, Form.ClientRectangle.Width - 1);
                    var touchY = MathHelper.Clamp(MouseState.Y, 0, Form.ClientRectangle.Height - 1);
                    TouchPanelState.AddEvent(0, TouchLocationState.Released, new Vector2(touchX, touchY), true);
                }
                return;
            }

            TouchLocationState?touchState = null;

            if (MouseState.LeftButton == ButtonState.Pressed)
            {
                if (previousState == ButtonState.Released)
                {
                    touchState = TouchLocationState.Pressed;
                }
                else
                {
                    touchState = TouchLocationState.Moved;
                }
            }
            else if (previousState == ButtonState.Pressed)
            {
                touchState = TouchLocationState.Released;
            }

            if (touchState.HasValue)
            {
                TouchPanelState.AddEvent(0, touchState.Value, new Vector2(MouseState.X, MouseState.Y), true);
            }
        }
Пример #10
0
        protected override void Update(TimeSpan gameTime)
        {
            var rotation = Vector3.Zero;
            var input    = WaveServices.Input.KeyboardState;

#if WINDOWS
            if (input.W == WaveEngine.Common.Input.ButtonState.Pressed)
            {
                rotation.Y -= (float)gameTime.TotalSeconds;
            }

            if (input.S == WaveEngine.Common.Input.ButtonState.Pressed)
            {
                rotation.Y += (float)gameTime.TotalSeconds;
            }

            if (input.A == WaveEngine.Common.Input.ButtonState.Pressed)
            {
                rotation.X += (float)gameTime.TotalSeconds;
            }

            if (input.D == WaveEngine.Common.Input.ButtonState.Pressed)
            {
                rotation.X -= (float)gameTime.TotalSeconds;
            }
#endif

            TouchPanelState state = WaveServices.Input.TouchPanelState;

            foreach (var touch in state)
            {
                Vector2 touchPosition = touch.Position;

                var touchFactorX = touchPosition.X > this.centerX ? -0.001f : 0.001f;
                var touchFactorY = touchPosition.Y > this.centerY ? -0.001f : 0.001f;

                var deltaFromCenterX = Math.Abs(touchPosition.X - this.centerX);
                var deltaFromCenterY = Math.Abs(touchPosition.Y - this.centerY);

                rotation.X += (float)gameTime.TotalSeconds * deltaFromCenterX * touchFactorX;
                rotation.Y += (float)gameTime.TotalSeconds * deltaFromCenterY * touchFactorY;
            }

            this.Transform.LocalOrientation *= Quaternion.CreateFromYawPitchRoll(rotation.X, rotation.Y, rotation.Z);

            var localPosition = this.Transform.LocalPosition;

            //localPosition.Z -= this.currentSpeed * (float)gameTime.TotalSeconds;
            //this.Transform.LocalPosition = localPosition;

            this.Transform.LocalPosition += (float)gameTime.TotalSeconds * this.currentSpeed * this.Transform.WorldTransform.Forward;

            // Update score
            Game.score++;
            this.lbScoreEntity.FindComponent <TextComponent>().Text = Game.score.ToString();
        }
Пример #11
0
        private void Canvas_TouchEnd(TouchEvent e)
        {
            foreach (var touch in e.changedTouches)
            {
                var x = (int)(touch.clientX - _canvas.offsetLeft);
                var y = (int)(touch.clientY - _canvas.offsetTop);

                TouchPanelState.AddEvent(touch.identifier.As <int>(), TouchLocationState.Released, new Vector2(x, y));
            }
        }
        private void HandleInput(float amount)
        {
            this.isTouchPanelConnected = this.input.TouchPanelState.IsConnected;

            if (this.isTouchPanelConnected)
            {
                if (this.isTouchPanelConnected)
                {
                    this.currentTouchPanelState = this.input.TouchPanelState;
                }

                // If there's a touch or right mouse button is pressed...
                if ((this.isTouchPanelConnected && this.currentTouchPanelState.Count == 1))
                {
                    // If there's a touch, capture its touch properties
                    if (this.isTouchPanelConnected && this.currentTouchPanelState.Count == 1)
                    {
                        this.currentTouchLocation = this.currentTouchPanelState.First();
                    }

                    // If current touch is pressed or moved
                    if ((this.isTouchPanelConnected &&
                         (this.currentTouchLocation.State == TouchLocationState.Pressed ||
                          this.currentTouchLocation.State == TouchLocationState.Moved)))
                    {
                        if (this.isDragging == false)
                        {
                            isDragging = true;
                        }
                        else
                        {
                            // Get the current different between x and Y
                            // From touchpad
                            if (this.currentTouchPanelState.IsConnected)
                            {
                                this.xDifference = this.currentTouchLocation.Position.X - this.lastTouchLocation.Position.X;
                                this.yDifference = this.currentTouchLocation.Position.Y - this.lastTouchLocation.Position.Y;
                            }

                            // Calculated yaw and pitch
                            float yaw   = -this.xDifference * this.rotationSpeed;
                            float pitch = -this.yDifference * this.rotationSpeed;

                            this.UpdateOrientation(yaw, pitch);
                        }
                    }

                    this.lastTouchLocation = this.currentTouchLocation;
                }
                else
                {
                    this.IsDragging = this.isDragging = false;
                }
            }
        }
Пример #13
0
 private void UpdateInputStates()
 {
     _previousGamePadState    = _currentGamePadState;
     _currentGamePadState     = GamePad.GetState(PlayerIndex.One);
     _previousKeyboardState   = _currentKeyboardState;
     _currentKeyboardState    = Keyboard.GetState();
     _previousMouseState      = _currentMouseState;
     _currentMouseState       = Mouse.GetState();
     _previousTouchPanelState = _currentTouchPanelState;
     _currentTouchPanelState  = TouchPanel.GetState(this.Window);
 }
Пример #14
0
        public override void Draw(TimeSpan gameTime)
        {
            TouchPanelState state = WaveServices.Input.TouchPanelState;

            foreach (var Touch in state)
            {
                this.layer.SpriteBatch.Draw(
                    texture,
                    Touch.Position - origin,
                    Color.White);
            }
        }
Пример #15
0
        protected override void DrawBasicUnit(int parameter)
        {
            TouchPanelState state = WaveServices.Input.TouchPanelState;

            foreach (var Touch in state)
            {
                spriteBatch.Draw(
                    texture,
                    Touch.Position - origin,
                    Color.White);
            }
        }
Пример #16
0
        /// <summary>
        /// Update method
        /// </summary>
        /// <param name="gameTime"></param>
        protected override void Update(TimeSpan gameTime)
        {
            touchPanelState = WaveServices.Input.TouchPanelState;
            bestValue       = float.MaxValue;
            if (touchPanelState.IsConnected && touchPanelState.Count > 0)
            {
                // Calculate the ray
                CalculateRay();

                // Look for all entities in the game...
                for (int i = 0; i < EntityManager.Count; i++)
                {
                    currentEntity = EntityManager.EntityGraph.ElementAt(i);;

                    entityCollider = currentEntity.FindComponent <Collider3D>(false);
                    // ... but only a collidable entities ( entities which have a boxCollider component)
                    if (entityCollider != null)
                    {
                        if (entityCollider is BoxCollider3D)
                        {
                            // Intersect our calculated ray with the entity's boxCollider
                            collisionResult = (entityCollider as BoxCollider3D).Intersects(ref ray);
                        }
                        else if (entityCollider is SphereCollider3D)
                        {
                            collisionResult = (entityCollider as SphereCollider3D).Intersects(ref ray);
                        }

                        // If any collision
                        if (collisionResult.HasValue)
                        {
                            // Check the distance. We want to have the closer to the screen entity, so we want to get the low collisionResult value
                            if (collisionResult.Value < bestValue)
                            {
                                // Send to the scene the new entity picked name
                                if (this.myScene != null)
                                {
                                    this.myScene.ShowPickedEntity(currentEntity.Name);
                                }
                                bestValue = collisionResult.Value;
                            }
                        }
                    }
                }
            }
            else
            {
                if (this.myScene != null)
                {
                    this.myScene.ShowPickedEntity("None");
                }
            }
        }
Пример #17
0
        protected override void Update(TimeSpan gameTime)
        {
            TouchPanelState state = WaveServices.Input.TouchPanelState;

            if (state.IsConnected && state.Any())
            {
                var activeCamera3D = this.RenderManager.ActiveCamera3D;

                var touchLocation = state.FirstOrDefault();

                Ray(activeCamera3D, touchLocation);
            }
        }
Пример #18
0
        internal void DoUpdate(GameTime gameTime)
        {
            AssertNotDisposed();
            if (Platform.BeforeUpdate(gameTime))
            {
                // Once per frame, we need to check currently
                // playing sounds to see if they've stopped,
                // and return them back to the pool if so.
                SoundEffectInstancePool.Update();

                //The TouchPanel needs to know the time for when touches arrive
                TouchPanelState.Update(gameTime);

                Update(gameTime);
            }
        }
Пример #19
0
        /// <summary>
        /// Manage the touch state input when dragging to calculate delta, phi and theta angles
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        /// <remarks>
        /// This method will not be executed if the <see cref="Component" />, or the <see cref="Entity" />
        /// owning it are not <c>Active</c>.
        /// </remarks>
        protected override void Update(TimeSpan gameTime)
        {
            this.touchState = WaveServices.Input.TouchPanelState;
            if (this.touchState.Count > 0 && this.touchState[0].State == TouchLocationState.Pressed)
            {
                if (!this.isDragging)
                {
                    this.isDragging   = true;
                    this.prevPosition = this.touchState[0].Position;
                }
                else
                {
                    this.currentPosition = this.touchState[0].Position;
                    this.delta           = (this.currentPosition - this.prevPosition) * ((float)Math.PI / 180);
                    this.prevPosition    = this.currentPosition;
                    this.phi            += this.delta.X * this.RotationSpeed;
                    this.theta          -= this.delta.Y * this.RotationSpeed;

                    if (this.theta <= -MathHelper.TwoPi)
                    {
                        this.theta += MathHelper.TwoPi;
                    }

                    if (this.theta > MathHelper.TwoPi)
                    {
                        this.theta -= MathHelper.TwoPi;
                    }

                    if (this.phi <= -MathHelper.TwoPi)
                    {
                        this.phi += MathHelper.TwoPi;
                    }

                    if (this.phi > MathHelper.TwoPi)
                    {
                        this.phi -= MathHelper.TwoPi;
                    }

                    this.UpdateCameraPosition();
                }
            }
            else
            {
                this.isDragging = false;
            }
        }
 public ShooterGameInputState(GamePadState currentGamePadState, GamePadState previousGamePadState,
                              KeyboardState currentKeyboardState, KeyboardState previousKeyboardState, MouseState currentMouseState,
                              MouseState previousMouseState,
                              TouchPanelState currentTouchPanelState,
                              TouchPanelState previousTouchPanelState,
                              GameTime gameTime)
 {
     GameTime                = gameTime;
     PreviousMouseState      = previousMouseState;
     CurrentTouchPanelState  = currentTouchPanelState;
     PreviousTouchPanelState = previousTouchPanelState;
     CurrentMouseState       = currentMouseState;
     PreviousKeyboardState   = previousKeyboardState;
     CurrentKeyboardState    = currentKeyboardState;
     PreviousGamePadState    = previousGamePadState;
     CurrentGamePadState     = currentGamePadState;
 }
Пример #21
0
        /// <summary>
        /// Update method
        /// </summary>
        /// <param name="gameTime"></param>
        protected override void Update(TimeSpan gameTime)
        {
            touchPanelState = WaveServices.Input.TouchPanelState;
            bestValue = float.MaxValue;
            if (touchPanelState.IsConnected && touchPanelState.Count > 0)
            {
                // Calculate the ray
                CalculateRay();

                // Look for all entities in the game...
                for (int i = 0; i < EntityManager.Count; i++)
                {
                    currentEntity = EntityManager.EntityGraph.ElementAt(i); ;

                    entityCollider = currentEntity.FindComponent<BoxCollider3D>();
                    // ... but only a collidable entities ( entities which have a boxCollider component)
                    if (entityCollider != null)
                    {
                        // Intersect our calculated ray with the entity's boxCollider
                        collisionResult = entityCollider.Intersects(ref ray);
                        // If any collision
                        if (collisionResult.HasValue)
                        {
                            // Check the distance. We want to have the closer to the screen entity, so we want to get the low collisionResult value
                            if (collisionResult.Value < bestValue)
                            {
                                // Send to the scene the new entity picked name
                                if (this.myScene != null)
                                {
                                    this.myScene.ShowPickedEntity(currentEntity.Name);
                                }
                                bestValue = collisionResult.Value;
                            }
                        }
                    }
                }
            }
            else
            {
                if (this.myScene != null)
                {
                    this.myScene.ShowPickedEntity("None");
                }
            }
        }
Пример #22
0
        public override void Draw(TimeSpan gameTime)
        {
            TouchPanelState state = WaveServices.Input.TouchPanelState;

            int index = 0;

            foreach (var touch in state)
            {
                Vector2 touchPosition = touch.Position;
                this.vm.ToVirtualPosition(ref touchPosition);

                this.layer.SpriteBatch.Draw(
                    texture,
                    touchPosition - origin,
                    Color.White);

                Labels.Add("Touch" + index++, touch.Position);
            }
        }
Пример #23
0
        /// <summary>
        /// Manage the touch state input when dragging to calculate delta, phi and theta angles
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        /// <remarks>
        /// This method will not be executed if the <see cref="Component" />, or the <see cref="Entity" />
        /// owning it are not <c>Active</c>.
        /// </remarks>
        protected override void Update(TimeSpan gameTime)
        {
            this.touchState = this.input.TouchPanelState;
            if (this.touchState.Count > 0)
            {
                var currentState = this.touchState[0].State;

                if (currentState == TouchLocationState.Pressed)
                {
                    this.prevPosition = this.touchState[0].Position;
                }
                else if (currentState == TouchLocationState.Moved)
                {
                    this.currentPosition = this.touchState[0].Position;
                    this.delta           = (this.currentPosition - this.prevPosition) * ((float)Math.PI / 180);
                    this.prevPosition    = this.currentPosition;
                    this.phi            -= this.delta.X * this.RotationSpeed;
                    this.theta          += this.delta.Y * this.RotationSpeed;

                    if (this.theta <= -MathHelper.TwoPi)
                    {
                        this.theta += MathHelper.TwoPi;
                    }

                    if (this.theta > MathHelper.TwoPi)
                    {
                        this.theta -= MathHelper.TwoPi;
                    }

                    if (this.phi <= -MathHelper.TwoPi)
                    {
                        this.phi += MathHelper.TwoPi;
                    }

                    if (this.phi > MathHelper.TwoPi)
                    {
                        this.phi -= MathHelper.TwoPi;
                    }

                    this.UpdateCameraPosition();
                }
            }
        }
Пример #24
0
        /// <summary>
        /// Update method
        /// </summary>
        /// <param name="gameTime"></param>
        protected override void Update(TimeSpan gameTime)
        {
            touchPanelState = WaveServices.Input.TouchPanelState;
            // bestValue = float.MaxValue;
            if (touchPanelState.IsConnected && touchPanelState.Count > 0)
            {
                // Calculate the ray
                CalculateRay();

                var hitResult = this.myScene.PhysicsManager.Simulation3D.RayCast(ref this.ray, 1000);
                if (hitResult.Succeeded)
                {
                    var userData = (Collider3D)hitResult.Collider.UserData;
                    this.myScene.ShowPickedEntity(userData.Owner.Name);
                }
            }
            else
            {
                if (this.myScene != null)
                {
                    this.myScene.ShowPickedEntity("None");
                }
            }
        }
Пример #25
0
        private void SetDisplayOrientation(DisplayOrientation value)
        {
            if (value != _currentOrientation)
            {
                DisplayOrientation supported            = GetEffectiveSupportedOrientations();
                ScreenOrientation  requestedOrientation = ScreenOrientation.Unspecified;
                bool wasPortrait     = _currentOrientation == DisplayOrientation.Portrait || _currentOrientation == DisplayOrientation.PortraitDown;
                bool requestPortrait = false;

                bool didOrientationChange = false;
                // Android 2.3 and above support reverse orientations
                int sdkVer = (int)Android.OS.Build.VERSION.SdkInt;
                if (sdkVer >= 10)
                {
                    // Check if the requested orientation is supported. Default means all are supported.
                    if ((supported & value) != 0)
                    {
                        didOrientationChange = true;
                        _currentOrientation  = value;
                        switch (value)
                        {
                        case DisplayOrientation.LandscapeLeft:
                            requestedOrientation = (ScreenOrientation)ScreenOrientationAll.Landscape;
                            requestPortrait      = false;
                            break;

                        case DisplayOrientation.LandscapeRight:
                            requestedOrientation = (ScreenOrientation)ScreenOrientationAll.ReverseLandscape;
                            requestPortrait      = false;
                            break;

                        case DisplayOrientation.Portrait:
                            requestedOrientation = (ScreenOrientation)ScreenOrientationAll.Portrait;
                            requestPortrait      = true;
                            break;

                        case DisplayOrientation.PortraitDown:
                            requestedOrientation = (ScreenOrientation)ScreenOrientationAll.ReversePortrait;
                            requestPortrait      = true;
                            break;
                        }
                    }
                }
                else
                {
                    // Check if the requested orientation is either of the landscape orientations and any landscape orientation is supported.
                    if ((value == DisplayOrientation.LandscapeLeft || value == DisplayOrientation.LandscapeRight) &&
                        ((supported & (DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight)) != 0))
                    {
                        didOrientationChange = true;
                        _currentOrientation  = DisplayOrientation.LandscapeLeft;
                        requestedOrientation = ScreenOrientation.Landscape;
                        requestPortrait      = false;
                    }
                    // Check if the requested orientation is either of the portrain orientations and any portrait orientation is supported.
                    else if ((value == DisplayOrientation.Portrait || value == DisplayOrientation.PortraitDown) &&
                             ((supported & (DisplayOrientation.Portrait | DisplayOrientation.PortraitDown)) != 0))
                    {
                        didOrientationChange = true;
                        _currentOrientation  = DisplayOrientation.Portrait;
                        requestedOrientation = ScreenOrientation.Portrait;
                        requestPortrait      = true;
                    }
                }

                if (didOrientationChange)
                {
                    // Android doesn't fire Released events for existing touches
                    // so we need to clear them out.
                    if (wasPortrait != requestPortrait)
                    {
                        TouchPanelState.ReleaseAllTouches();
                    }

                    OnOrientationChanged();
                }
            }
        }
Пример #26
0
        protected override void Update(TimeSpan gameTime)
        {
            touchPanelState = WaveServices.Input.TouchPanelState;

            if (touchPanelState.IsConnected && touchPanelState.Count > 0)
            {
                // Calculate the ray
                CalculateRay();

                // Look for all entities in the game...
                Entity auxEntity = currentEntity = null;
                bestValue = float.MaxValue;
                for (int i = 0; i < EntityManager.Count; i++)
                {
                    auxEntity = EntityManager.EntityGraph.ElementAt(i);
                    entityCollider = auxEntity.FindComponent<BoxCollider>();
                    // ... but only a collidable entities ( entities which have a boxCollider component)
                    if (entityCollider != null && ( auxEntity.Name.Contains("box") ||
                                                  auxEntity.Name.Contains("anchor") ||
                                                  auxEntity.Name.Contains("BigBall")) )
                    {
                        // Intersect our calculated ray with the entity's boxCollider
                        collisionResult = entityCollider.Intersects(ref ray);
                        // If any collision
                        if (collisionResult.HasValue && collisionResult.Value > 0.001f)
                        {
                            //Labels.Add("CollisionResult", collisionResult.ToString());
                            //Labels.Add("CollisionValue", collisionResult.Value.ToString());
                            // Check the distance. We want to have the closer to the screen entity, so we want to get the low collisionResult value
                            if (collisionResult.Value < bestValue)
                            {
                                this.currentEntity = auxEntity;
                                bestValue = collisionResult.Value;
                            }
                        }
                    }
                }

                if (this.currentEntity != null)
                {
                    Vector3 entityPosition = this.currentEntity.FindComponent<Transform3D>().Position;
                    Vector3 impulse = entityPosition - this.Camera.Position;
                    this.currentEntity.FindComponent<RigidBody3D>().ApplyLinearImpulse(impulse*FORCE);

                    this.line.StartPoint = ray.Position;
                    this.line.EndPoint = entityPosition;

                    Labels.Add("Entity", this.currentEntity.Name);
                    //Labels.Add("Impulse", impulse.ToString());
                    //Labels.Add("IsActive", this.currentEntity.FindComponent<RigidBody3D>().IsActive.ToString());
                }
                else
                {
                    Labels.Add("Entity", "None");
                    //Labels.Add("Impulse", "0,0,0");
                }
            }

            //RenderManager.LineBatch3D.DrawLine(ref line);
            //RenderManager.LineBatch3D.DrawLine(ref line2);
        }
Пример #27
0
 public void SetUp()
 {
     TouchPanelState.CurrentTimestamp = GameTimeForFrame(0);
     _tps = new TouchPanelState(new MockWindow());
 }
Пример #28
0
        /// <summary>
        /// Update Method
        /// </summary>
        /// <param name="gameTime">Current Game Time</param>
        protected override void Update(TimeSpan gameTime)
        {
            this.input = WaveServices.Input;

            if (this.input.TouchPanelState.IsConnected)
            {
                this.touchState = this.input.TouchPanelState;

                // Checks Mouse Left Button Click and anyone entity linked
                if (this.touchState.Count > 0 && this.mouseJoint == null)
                {
                    // Udpates Mouse Position
                    this.touchPosition = this.touchState[0].Position;

                    foreach (Entity entity in this.Scene.EntityManager.EntityGraph)
                    {
                        Collider2D collider = entity.FindComponent <Collider2D>(false);
                        if (collider != null)
                        {
                            // Collider Test
                            if (collider.Contain(touchPosition))
                            {
                                RigidBody2D rigidBody = entity.FindComponent <RigidBody2D>();
                                if (rigidBody != null)
                                {
                                    // Forbiden Mouse Joint of Kinematic Bodies
                                    if (rigidBody.PhysicBodyType != PhysicBodyType.Kinematic)
                                    {
                                        this.connectedEntity = entity;

                                        // Create Mouse Joint
                                        this.mouseJoint = new FixedMouseJoint2D(this.touchPosition);
                                        JointMap2D jointMap = this.connectedEntity.FindComponent <JointMap2D>();
                                        jointMap.AddJoint("mouseJoint", this.mouseJoint);

                                        // We can break after collider test when true, but we'll miss overlapped entities if Physic entity is
                                        // under a non Physic entity. We are breaking here just for sample.
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                // Checks Mouse Left Button Release
                if (this.touchState.Count == 0 && this.mouseJoint != null)
                {
                    if (!this.connectedEntity.IsDisposed)
                    {
                        // Remove Fixed Joint
                        JointMap2D jointMap2D = this.connectedEntity.FindComponent <JointMap2D>();
                        jointMap2D.RemoveJoint("mouseJoint");
                    }

                    this.mouseJoint = null;
                }

                // If joint exists then update joint anchor position
                if (this.mouseJoint != null)
                {
                    this.touchPosition          = this.touchState[0].Position;
                    this.mouseJoint.WorldAnchor = this.touchPosition;
                }
            }
        }
Пример #29
0
        /// <summary>
        /// Update method
        /// </summary>
        /// <param name="gameTime">game time</param>
        protected override void Update(TimeSpan gameTime)
        {
            this.input = WaveServices.Input;

            KeyboardState currentKeyboardState = this.input.KeyboardState;

            if (currentKeyboardState.IsConnected)
            {
                if (currentKeyboardState.IsKeyPressed(Keys.O) &&
                    this.lastKeyboardState.IsKeyReleased(Keys.O))
                {
                    this.RenderManager.DebugLines = !this.RenderManager.DebugLines;
                }

                this.lastKeyboardState = currentKeyboardState;
            }

            if (this.input.TouchPanelState.IsConnected)
            {
                this.touchState = this.input.TouchPanelState;

                if (this.touchState.Count > 0 && this.mouseJoint == null)
                {
                    this.TouchPosition = this.touchState[0].Position;
                    this.vsm.ToVirtualPosition(ref this.TouchPosition);

                    foreach (Entity entity in this.Owner.Scene.EntityManager.FindAllByTag("Draggable"))
                    {
                        Collider2D collider = entity.FindComponent <Collider2D>(false);
                        if (collider != null)
                        {
                            if (collider.Contain(TouchPosition))
                            {
                                RigidBody2D rigidBody = entity.FindComponent <RigidBody2D>();
                                if (rigidBody != null)
                                {
                                    if (rigidBody.PhysicBodyType == WaveEngine.Common.Physics2D.RigidBodyType2D.Dynamic)
                                    {
                                        this.ConnectedEntity = entity;

                                        //Create Joint
                                        this.mouseJoint = new MouseJoint2D()
                                        {
                                            Target = this.TouchPosition,
                                        };
                                        this.ConnectedEntity.AddComponent(mouseJoint);

                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                if (this.touchState.Count == 0 && this.mouseJoint != null)
                {
                    if (!this.ConnectedEntity.IsDisposed)
                    {
                        this.ConnectedEntity.RemoveComponent(this.mouseJoint);
                    }

                    this.mouseJoint = null;
                }

                if (this.mouseJoint != null)
                {
                    this.TouchPosition = this.touchState[0].Position;
                    this.vsm.ToVirtualPosition(ref this.TouchPosition);
                    this.mouseJoint.Target = this.TouchPosition;
                }
            }
        }
        /// <summary>
        /// The handle input.
        /// </summary>
        /// <param name="amount">
        /// The amount.
        /// </param>
        private void HandleInput(float amount)
        {
            this.input = WaveServices.Input;
            this.isMouseConnected = this.input.MouseState.IsConnected;
            this.isTouchPanelConnected = this.input.TouchPanelState.IsConnected;

            if (this.input.KeyboardState.IsConnected || this.isTouchPanelConnected)
            {
                this.keyboardState = this.input.KeyboardState;

                // If the touch panel is connected and it has two points, we can go forward
                if (this.isTouchPanelConnected)
                {
                    if (this.input.TouchPanelState.Count == 2)
                    {
                        this.moveWithTouchPanel = true;
                    }
                }

                this.moveForward = this.keyboardState.W == ButtonState.Pressed || this.moveWithTouchPanel;
                this.moveBack = this.keyboardState.S == ButtonState.Pressed;
                this.moveLeft = this.keyboardState.A == ButtonState.Pressed;
                this.moveRight = this.keyboardState.D == ButtonState.Pressed;
                this.UpdateCameraPosition(amount);

                this.moveWithTouchPanel = false;
            }

            if (this.isTouchPanelConnected || this.isMouseConnected)
            {
                if (this.isTouchPanelConnected)
                {
                    this.currentTouchPanelState = this.input.TouchPanelState;
                }

                if (this.isMouseConnected)
                {
                    this.currentMouseState = this.input.MouseState;
                }

                if ((this.isTouchPanelConnected && this.currentTouchPanelState.Count == 1)
                    || (this.isMouseConnected && this.currentMouseState.RightButton == ButtonState.Pressed))
                {
                    if (this.isTouchPanelConnected && this.currentTouchPanelState.Count == 1)
                    {
                        this.currentTouchLocation = this.currentTouchPanelState.First();
                    }

                    if ((this.isTouchPanelConnected
                         && (this.currentTouchLocation.State == TouchLocationState.Pressed
                             || this.currentTouchLocation.State == TouchLocationState.Moved))
                        || (this.isMouseConnected && this.currentMouseState.RightButton == ButtonState.Pressed))
                    {
                        if (this.isDragging == false)
                        {
                            this.isDragging = true;
                        }
                        else
                        {
                            // Get the current different between x and Y
                            // From touchpad
                            if (this.currentTouchPanelState.IsConnected)
                            {
                                this.xDifference = this.currentTouchLocation.Position.X - this.lastTouchLocation.Position.X;
                                this.yDifference = this.currentTouchLocation.Position.Y - this.lastTouchLocation.Position.Y;
                            }

                            if (this.isMouseConnected && this.input.TouchPanelState.Count == 0)
                            {
                                this.xDifference = this.currentMouseState.X - this.lastMouseState.X;
                                this.yDifference = this.currentMouseState.Y - this.lastMouseState.Y;
                            }

                            // Calculated yaw and pitch
                            float yaw   = -this.xDifference * this.rotationSpeed;
                            float pitch = -this.yDifference * this.rotationSpeed;

                            this.UpdateOrientation(yaw, pitch);
                        }
                    }

                    this.lastTouchLocation = this.currentTouchLocation;
                    this.lastMouseState = this.currentMouseState;
                }
                else
                {
                    this.isDragging = false;
                }
            }

            if (this.input.GamePadState.IsConnected)
            {
                /////////////////////////////////////////////////
                ////// Position Camera
                /////////////////////////////////////////////////
                GamePadState gamePadState = this.input.GamePadState;

                Vector2 leftStick = gamePadState.ThumbStricks.Left;

                float threshold = 0.2f;

                this.moveForward = leftStick.Y > threshold;
                this.moveBack = leftStick.Y < -threshold;
                this.moveRight = leftStick.X > threshold;
                this.moveLeft = leftStick.X < -threshold;

                this.UpdateCameraPosition(amount);

                /////////////////////////////////////////////////
                ////// LookAT
                /////////////////////////////////////////////////
                Vector2 rightStick = gamePadState.ThumbStricks.Right;
                this.xDifference = rightStick.X;
                this.yDifference = -rightStick.Y;

                ////// Calculated yaw and pitch
                float yaw = this.xDifference * amount * this.gamepadRotationSpeed;
                float pitch = this.yDifference * amount * this.gamepadRotationSpeed;

                this.UpdateOrientation(yaw, pitch);
            }
        }
Пример #31
0
        /// <summary>
        /// Update Method
        /// </summary>
        /// <param name="gameTime">Current Game Time</param>
        protected override void Update(TimeSpan gameTime)
        {
            this.input = WaveServices.Input;

            if (this.input.TouchPanelState.IsConnected)
            {
                this.touchState = this.input.TouchPanelState;

                // Checks Mouse Left Button Click and anyone entity linked
                if (this.touchState.Count > 0 && this.mouseJoint == null)
                {
                    // Udpates Mouse Position
                    this.touchPosition = this.touchState[0].Position;
                    this.vsm.ToVirtualPosition(ref this.touchPosition);

                    foreach (Entity entity in this.Owner.Scene.EntityManager.FindAllByTag("Draggable"))
                    {
                        Collider2D collider = entity.FindComponent<Collider2D>(false);
                        if (collider != null)
                        {
                            // Collider Test
                            if (collider.Contain(touchPosition))
                            {
                                RigidBody2D rigidBody = entity.FindComponent<RigidBody2D>();
                                if (rigidBody != null)
                                {
                                    // Forbiden Mouse Joint of Kinematic Bodies
                                    if (rigidBody.PhysicBodyType == PhysicBodyType.Dynamic)
                                    {
                                        this.connectedEntity = entity;

                                        // Create Mouse Joint
                                        this.mouseJoint = new FixedMouseJoint2D(this.touchPosition);
                                        this.connectedEntity.FindComponent<JointMap2D>().AddJoint("mouseJoint", this.mouseJoint);

                                        // We can break after collider test when true, but we'll miss overlapped entities if Physic entity is
                                        // under a non Physic entity. We are breaking here just for sample.
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                // Checks Mouse Left Button Release
                if (this.touchState.Count == 0 && this.mouseJoint != null)
                {
                    if (!this.connectedEntity.IsDisposed)
                    {
                        // Remove Fixed Joint
                        this.connectedEntity.FindComponent<JointMap2D>().RemoveJoint("mouseJoint");
                    }

                    this.mouseJoint = null;
                }

                // If joint exists then update joint anchor position
                if (this.mouseJoint != null)
                {
                    this.touchPosition = this.touchState[0].Position;
                    this.vsm.ToVirtualPosition(ref this.touchPosition);
                    this.mouseJoint.WorldAnchor = this.touchPosition;
                }
            }
        }
Пример #32
0
        /// <summary>
        /// Update method
        /// </summary>
        /// <param name="gameTime">game time</param>
        protected override void Update(TimeSpan gameTime)
        {
            this.input = WaveServices.Input;

            KeyboardState currentKeyboardState = this.input.KeyboardState;
            if (currentKeyboardState.IsConnected)
            {
                if (currentKeyboardState.IsKeyPressed(Keys.O) &&
                   this.lastKeyboardState.IsKeyReleased(Keys.O))
                {
                    this.RenderManager.DebugLines = !this.RenderManager.DebugLines;
                }

                this.lastKeyboardState = currentKeyboardState;
            }

            if (this.input.TouchPanelState.IsConnected)
            {
                this.touchState = this.input.TouchPanelState;

                if (this.touchState.Count > 0 && this.mouseJoint == null)
                {
                    this.TouchPosition = this.touchState[0].Position;
                    this.vsm.ToVirtualPosition(ref this.TouchPosition);

                    foreach (Entity entity in this.Owner.Scene.EntityManager.FindAllByTag("Draggable"))
                    {
                        Collider2D collider = entity.FindComponent<Collider2D>(false);
                        if (collider != null)
                        {
                            if (collider.Contain(TouchPosition))
                            {
                                RigidBody2D rigidBody = entity.FindComponent<RigidBody2D>();
                                if (rigidBody != null)
                                {
                                    if (rigidBody.PhysicBodyType == WaveEngine.Common.Physics2D.RigidBodyType2D.Dynamic)
                                    {
                                        this.ConnectedEntity = entity;

                                        //Create Joint
                                        this.mouseJoint = new MouseJoint2D()
                                        {
                                            Target = this.TouchPosition,
                                            //MaxForce = 100,
                                            //DampingRatio = 0.5f,
                                            //FrequencyHz = 2000,
                                        };
                                        this.ConnectedEntity.AddComponent(mouseJoint);

                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                if (this.touchState.Count == 0 && this.mouseJoint != null)
                {
                    if (!this.ConnectedEntity.IsDisposed)
                    {
                        this.ConnectedEntity.RemoveComponent(this.mouseJoint);
                    }

                    this.mouseJoint = null;
                }

                if (this.mouseJoint != null)
                {
                    this.TouchPosition = this.touchState[0].Position;
                    this.vsm.ToVirtualPosition(ref this.TouchPosition);
                    this.mouseJoint.Target = this.TouchPosition;
                }
            }
        }
Пример #33
0
        /// <summary>
        /// Fills the touches.
        /// </summary>
        /// <param name="touches">The touches.</param>
        private void FillTouches(NSSet touches)
        {
            UITouch[] touchArray = touches.ToArray <UITouch>();
            WaveEngine.Adapter.Input.InputManager inputManager = (WaveEngine.Adapter.Input.InputManager) this.adapter.InputManager;

            List <int> movedIds = new List <int>();

            TouchPanelState oldState = inputManager.CurrentState;

            inputManager.CurrentState.Clear();

            for (int i = 0; i < touchArray.Length; i++)
            {
                UITouch touch = touchArray[i];

                // Position is always the same since we rotate the view
                var position = touch.LocationInView(touch.View);
                position.X *= this.ContentScaleFactor;
                position.Y *= this.ContentScaleFactor;

                int touchId = touch.Handle.ToInt32();

                TouchLocationState state;

                // Touch Type
                switch (touch.Phase)
                {
                case UITouchPhase.Began:
                    state = TouchLocationState.Pressed;
                    break;

                case UITouchPhase.Ended:
                case UITouchPhase.Cancelled:
                    state = TouchLocationState.Release;
                    movedIds.Add(touchId);
                    break;

                case UITouchPhase.Stationary:
                case UITouchPhase.Moved:
                    state = TouchLocationState.Moved;
                    movedIds.Add(touchId);
                    break;

                default:
                    state = TouchLocationState.Invalid;
                    break;
                }

                if (state != TouchLocationState.Release)
                {
                    inputManager.CurrentState.AddTouchLocation(touchId, state, (float)position.X, (float)position.Y);
                }
            }

            foreach (TouchLocation location in oldState)
            {
                if ((location.State == TouchLocationState.Moved || location.State == TouchLocationState.Pressed) && !movedIds.Contains(location.Id))
                {
                    inputManager.CurrentState.AddTouchLocation(location.Id, location.State, location.Position.X, location.Position.Y);
                }
            }
        }
Пример #34
0
        /// <summary>
        /// The handle input.
        /// </summary>
        /// <param name="amount">
        /// The amount.
        /// </param>
        private void HandleInput(float amount)
        {
            this.input = WaveServices.Input;
            this.isMouseConnected = this.input.MouseState.IsConnected;
            this.isTouchPanelConnected = this.input.TouchPanelState.IsConnected;

            if (this.input.KeyboardState.IsConnected || this.isTouchPanelConnected)
            {
                this.keyboardState = this.input.KeyboardState;

                // If the touch panel is connected and it has two points, we can go forward
                if (this.isTouchPanelConnected)
                {
                    if (this.input.TouchPanelState.Count == 2)
                    {
                        this.moveWithTouchPanel = true;
                    }
                }

                this.moveForward = this.keyboardState.W == ButtonState.Pressed || this.moveWithTouchPanel;
                this.moveBack = this.keyboardState.S == ButtonState.Pressed;
                this.moveLeft = this.keyboardState.A == ButtonState.Pressed;
                this.moveRight = this.keyboardState.D == ButtonState.Pressed;

                if (this.moveForward)
                {
                    // Manual inline: position += speed * forward;
                    this.position.X = this.position.X + (amount * this.speed * this.forward.X);
                    this.position.Y = this.position.Y + (amount * this.speed * this.forward.Y);
                    this.position.Z = this.position.Z + (amount * this.speed * this.forward.Z);
                    this.UpdateCameraPosition();
                }
                else if (this.moveBack)
                {
                    // Manual inline: position -= speed * forward;
                    this.position.X = this.position.X - (amount * this.speed * this.forward.X);
                    this.position.Y = this.position.Y - (amount * this.speed * this.forward.Y);
                    this.position.Z = this.position.Z - (amount * this.speed * this.forward.Z);
                    this.UpdateCameraPosition();
                }

                if (this.moveLeft)
                {
                    // Manual inline: position -= speed * right;
                    this.position.X = this.position.X - (amount * this.speed * this.right.X);
                    this.position.Y = this.position.Y - (amount * this.speed * this.right.Y);
                    this.position.Z = this.position.Z - (amount * this.speed * this.right.Z);
                    this.UpdateCameraPosition();
                }
                else if (this.moveRight)
                {
                    // Manual inline: position += speed * right;
                    this.position.X = this.position.X + (amount * this.speed * this.right.X);
                    this.position.Y = this.position.Y + (amount * this.speed * this.right.Y);
                    this.position.Z = this.position.Z + (amount * this.speed * this.right.Z);
                    this.UpdateCameraPosition();
                }

                this.moveWithTouchPanel = false;
            }

            if (this.isTouchPanelConnected || this.isMouseConnected)
            {
                if (this.isTouchPanelConnected)
                {
                    this.currentTouchPanelState = this.input.TouchPanelState;
                }

                if (this.isMouseConnected)
                {
                    this.currentMouseState = this.input.MouseState;
                }

                if ((this.isTouchPanelConnected && this.currentTouchPanelState.Count == 1)
                    || (this.isMouseConnected && this.currentMouseState.RightButton == ButtonState.Pressed))
                {
                    if (this.isTouchPanelConnected && this.currentTouchPanelState.Count == 1)
                    {
                        this.currentTouchLocation = this.currentTouchPanelState.First();
                    }

                    if ((this.isTouchPanelConnected
                         && (this.currentTouchLocation.State == TouchLocationState.Pressed
                             || this.currentTouchLocation.State == TouchLocationState.Moved))
                        || (this.isMouseConnected && this.currentMouseState.RightButton == ButtonState.Pressed))
                    {
                        if (this.isDragging == false)
                        {
                            this.isDragging = true;
                        }
                        else
                        {
                            // Get the current different between x and Y
                            // From touchpad
                            if (this.currentTouchPanelState.IsConnected)
                            {
                                this.xDifference = this.currentTouchLocation.Position.X - this.lastTouchLocation.Position.X;
                                this.yDifference = this.currentTouchLocation.Position.Y - this.lastTouchLocation.Position.Y;
                            }

                            if (this.isMouseConnected && this.input.TouchPanelState.Count == 0)
                            {
                                this.xDifference = this.currentMouseState.X - this.lastMouseState.X;
                                this.yDifference = this.currentMouseState.Y - this.lastMouseState.Y;
                            }

                            // Calculated yaw and pitch
                            this.yaw = this.yaw - (this.xDifference * amount * this.rotationSpeed);
                            this.pitch = this.pitch - (this.yDifference * amount * this.rotationSpeed);

                            // Manual inline: forwardNormalizedVector = cameraRotation.Forward;
                            this.forwardNormalizedVector.X = this.cameraMatrixRotation.Forward.X;
                            this.forwardNormalizedVector.Y = this.cameraMatrixRotation.Forward.Y;
                            this.forwardNormalizedVector.Z = this.cameraMatrixRotation.Forward.Z;
                            this.forwardNormalizedVector.Normalize();

                            // Manual inline: rightNormalizedVector = cameraRotation.Right;
                            this.rightNormalizedVector.X = this.cameraMatrixRotation.Right.X;
                            this.rightNormalizedVector.Y = this.cameraMatrixRotation.Right.Y;
                            this.rightNormalizedVector.Z = this.cameraMatrixRotation.Right.Z;
                            this.rightNormalizedVector.Normalize();

                            // Manual inline: upNormalizedVector = cameraMatrixRotation.Up;
                            this.upNormalizedVector.X = this.cameraMatrixRotation.Up.X;
                            this.upNormalizedVector.Y = this.cameraMatrixRotation.Up.Y;
                            this.upNormalizedVector.Z = this.cameraMatrixRotation.Up.Z;
                            this.upNormalizedVector.Normalize();

                            // Calculate the new camera matrix angle with the normalized vectors
                            Matrix.CreateFromAxisAngle(
                                ref this.rightNormalizedVector, this.pitch, out this.tempRotationMatrix);
                            Matrix.Multiply(
                                ref this.cameraMatrixRotation,
                                ref this.tempRotationMatrix,
                                out this.cameraMatrixRotation);

                            Matrix.CreateFromAxisAngle(
                                ref this.upNormalizedVector, this.yaw, out this.tempRotationMatrix);
                            Matrix.Multiply(
                                ref this.cameraMatrixRotation,
                                ref this.tempRotationMatrix,
                                out this.cameraMatrixRotation);

                            Matrix.CreateFromAxisAngle(
                                ref this.forwardNormalizedVector, 0f, out this.tempRotationMatrix);
                            Matrix.Multiply(
                                ref this.cameraMatrixRotation,
                                ref this.tempRotationMatrix,
                                out this.cameraMatrixRotation);

                            // Restore the yaw and pitch
                            this.yaw = 0.0f;
                            this.pitch = 0.0f;

                            // Manual inline: forward = cameraRotation.Forward;
                            this.forward.X = this.cameraMatrixRotation.Forward.X;
                            this.forward.Y = this.cameraMatrixRotation.Forward.Y;
                            this.forward.Z = this.cameraMatrixRotation.Forward.Z;

                            // Manual inline: right = cameraRotation.Right;
                            this.right.X = this.cameraMatrixRotation.Right.X;
                            this.right.Y = this.cameraMatrixRotation.Right.Y;
                            this.right.Z = this.cameraMatrixRotation.Right.Z;

                            // Update the current look at
                            this.UpdateLookAt();

                            // Restore the current matrix rotation
                            this.cameraMatrixRotation =
                                Matrix.Invert(
                                    Matrix.CreateLookAt(this.Camera.Position, this.Camera.LookAt, this.Camera.UpVector));
                        }
                    }

                    this.lastTouchLocation = this.currentTouchLocation;
                    this.lastMouseState = this.currentMouseState;
                }
                else
                {
                    this.isDragging = false;
                }
            }

            if (this.input.GamePadState.IsConnected && this.input.MouseState.IsConnected)
            {
                /////////////////////////////////////////////
                // Position Camera
                /////////////////////////////////////////////
                GamePadState gamePadState = this.input.GamePadState;

                Vector2 leftStick = gamePadState.ThumbStricks.Left;

                float threshold = 0.1f;

                if (leftStick.Y > threshold)
                {
                    // Manual inline: position += speed * forward;
                    this.position.X = this.position.X + (amount * this.speed * this.forward.X * leftStick.Y);
                    this.position.Y = this.position.Y + (amount * this.speed * this.forward.Y * leftStick.Y);
                    this.position.Z = this.position.Z + (amount * this.speed * this.forward.Z * leftStick.Y);
                    this.UpdateCameraPosition();
                }
                else if (leftStick.Y < -threshold)
                {
                    // Manual inline: position -= speed * forward;
                    this.position.X = this.position.X + (amount * this.speed * this.forward.X * leftStick.Y);
                    this.position.Y = this.position.Y + (amount * this.speed * this.forward.Y * leftStick.Y);
                    this.position.Z = this.position.Z + (amount * this.speed * this.forward.Z * leftStick.Y);
                    this.UpdateCameraPosition();
                }

                if (leftStick.X > threshold)
                {
                    // Manual inline: position -= speed * right;
                    this.position.X = this.position.X + (amount * this.speed * this.right.X * leftStick.X);
                    this.position.Y = this.position.Y + (amount * this.speed * this.right.Y * leftStick.X);
                    this.position.Z = this.position.Z + (amount * this.speed * this.right.Z * leftStick.X);
                    this.UpdateCameraPosition();
                }
                else if (leftStick.X < -threshold)
                {
                    // Manual inline: position += speed * right;
                    this.position.X = this.position.X + (amount * this.speed * this.right.X * leftStick.X);
                    this.position.Y = this.position.Y + (amount * this.speed * this.right.Y * leftStick.X);
                    this.position.Z = this.position.Z + (amount * this.speed * this.right.Z * leftStick.X);
                    this.UpdateCameraPosition();
                }

                /////////////////////////////////////////////
                // LookAT
                /////////////////////////////////////////////
                Vector2 rightStick = gamePadState.ThumbStricks.Right;
                this.xDifference = rightStick.X;
                this.yDifference = -rightStick.Y;

                // Calculated yaw and pitch
                this.yaw = this.yaw - (this.xDifference * amount * this.gamepadRotationSpeed);
                this.pitch = this.pitch - (this.yDifference * amount * this.gamepadRotationSpeed);

                // Manual inline: forwardNormalizedVector = cameraRotation.Forward;
                this.forwardNormalizedVector.X = this.cameraMatrixRotation.Forward.X;
                this.forwardNormalizedVector.Y = this.cameraMatrixRotation.Forward.Y;
                this.forwardNormalizedVector.Z = this.cameraMatrixRotation.Forward.Z;
                this.forwardNormalizedVector.Normalize();

                // Manual inline: rightNormalizedVector = cameraRotation.Right;
                this.rightNormalizedVector.X = this.cameraMatrixRotation.Right.X;
                this.rightNormalizedVector.Y = this.cameraMatrixRotation.Right.Y;
                this.rightNormalizedVector.Z = this.cameraMatrixRotation.Right.Z;
                this.rightNormalizedVector.Normalize();

                // Manual inline: upNormalizedVector = cameraMatrixRotation.Up;
                this.upNormalizedVector.X = this.cameraMatrixRotation.Up.X;
                this.upNormalizedVector.Y = this.cameraMatrixRotation.Up.Y;
                this.upNormalizedVector.Z = this.cameraMatrixRotation.Up.Z;
                this.upNormalizedVector.Normalize();

                // Calculate the new camera matrix angle with the normalized vectors
                Matrix.CreateFromAxisAngle(
                    ref this.rightNormalizedVector, this.pitch, out this.tempRotationMatrix);
                Matrix.Multiply(
                    ref this.cameraMatrixRotation,
                    ref this.tempRotationMatrix,
                    out this.cameraMatrixRotation);

                Matrix.CreateFromAxisAngle(
                    ref this.upNormalizedVector, this.yaw, out this.tempRotationMatrix);
                Matrix.Multiply(
                    ref this.cameraMatrixRotation,
                    ref this.tempRotationMatrix,
                    out this.cameraMatrixRotation);

                Matrix.CreateFromAxisAngle(
                    ref this.forwardNormalizedVector, 0f, out this.tempRotationMatrix);
                Matrix.Multiply(
                    ref this.cameraMatrixRotation,
                    ref this.tempRotationMatrix,
                    out this.cameraMatrixRotation);

                // Restore the yaw and pitch
                this.yaw = 0.0f;
                this.pitch = 0.0f;

                // Manual inline: forward = cameraRotation.Forward;
                this.forward.X = this.cameraMatrixRotation.Forward.X;
                this.forward.Y = this.cameraMatrixRotation.Forward.Y;
                this.forward.Z = this.cameraMatrixRotation.Forward.Z;

                // Manual inline: right = cameraRotation.Right;
                this.right.X = this.cameraMatrixRotation.Right.X;
                this.right.Y = this.cameraMatrixRotation.Right.Y;
                this.right.Z = this.cameraMatrixRotation.Right.Z;

                // Update the current look at
                this.UpdateLookAt();

                // Restore the current matrix rotation
                this.cameraMatrixRotation =
                    Matrix.Invert(
                        Matrix.CreateLookAt(this.Camera.Position, this.Camera.LookAt, this.Camera.UpVector));

                this.lastMouseState = this.currentMouseState;
            }
        }
Пример #35
0
 protected GameWindow()
 {
     TouchPanelState = new TouchPanelState(this);
 }
Пример #36
0
        /// <summary>
        /// Manage the touch state input when dragging to calculate delta, phi and theta angles
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        /// <remarks>
        /// This method will not be executed if the <see cref="Component" />, or the <see cref="Entity" />
        /// owning it are not <c>Active</c>.
        /// </remarks>
        protected override void Update(TimeSpan gameTime)
        {
            this.touchState = WaveServices.Input.TouchPanelState;
            if (this.touchState.Count > 0 && this.touchState[0].State == TouchLocationState.Pressed)
            {
                if (!this.isDragging)
                {
                    this.isDragging = true;
                    this.prevPosition = this.touchState[0].Position;
                }
                else
                {
                    this.currentPosition = this.touchState[0].Position;
                    this.delta = (this.currentPosition - this.prevPosition) * ((float)Math.PI / 180);
                    this.prevPosition = this.currentPosition;
                    this.phi -= this.delta.X * this.RotationSpeed;
                    this.theta -= this.delta.Y * this.RotationSpeed;

                    if (this.theta <= -MathHelper.TwoPi)
                    {
                        this.theta += MathHelper.TwoPi;
                    }

                    if (this.theta > MathHelper.TwoPi)
                    {
                        this.theta -= MathHelper.TwoPi;
                    }

                    if (this.phi <= -MathHelper.TwoPi)
                    {
                        this.phi += MathHelper.TwoPi;
                    }

                    if (this.phi > MathHelper.TwoPi)
                    {
                        this.phi -= MathHelper.TwoPi;
                    }

                    this.UpdateCameraPosition();
                }
            }
            else
            {
                this.isDragging = false;
            }
        }
Пример #37
0
        protected override void Update(TimeSpan gameTime)
        {
            touchPanelState = WaveServices.Input.TouchPanelState;

            if (touchPanelState.IsConnected && touchPanelState.Count > 0)
            {
                // Calculate the ray
                CalculateRay();

                // Look for all entities in the game...
                Entity auxEntity = currentEntity = null;
                bestValue = float.MaxValue;
                for (int i = 0; i < EntityManager.Count; i++)
                {
                    auxEntity      = EntityManager.EntityGraph.ElementAt(i);
                    entityCollider = auxEntity.FindComponent <BoxCollider>();
                    // ... but only a collidable entities ( entities which have a boxCollider component)
                    if (entityCollider != null && (auxEntity.Name.Contains("box") ||
                                                   auxEntity.Name.Contains("anchor") ||
                                                   auxEntity.Name.Contains("BigBall")))
                    {
                        // Intersect our calculated ray with the entity's boxCollider
                        collisionResult = entityCollider.Intersects(ref ray);
                        // If any collision
                        if (collisionResult.HasValue && collisionResult.Value > 0.001f)
                        {
                            //Labels.Add("CollisionResult", collisionResult.ToString());
                            //Labels.Add("CollisionValue", collisionResult.Value.ToString());
                            // Check the distance. We want to have the closer to the screen entity, so we want to get the low collisionResult value
                            if (collisionResult.Value < bestValue)
                            {
                                this.currentEntity = auxEntity;
                                bestValue          = collisionResult.Value;
                            }
                        }
                    }
                }

                if (this.currentEntity != null)
                {
                    Vector3 entityPosition = this.currentEntity.FindComponent <Transform3D>().Position;
                    Vector3 impulse        = entityPosition - this.Camera.Position;
                    this.currentEntity.FindComponent <RigidBody3D>().ApplyLinearImpulse(impulse * FORCE);

                    this.line.StartPoint = ray.Position;
                    this.line.EndPoint   = entityPosition;

                    Labels.Add("Entity", this.currentEntity.Name);
                    //Labels.Add("Impulse", impulse.ToString());
                    //Labels.Add("IsActive", this.currentEntity.FindComponent<RigidBody3D>().IsActive.ToString());
                }
                else
                {
                    Labels.Add("Entity", "None");
                    //Labels.Add("Impulse", "0,0,0");
                }
            }

            //RenderManager.LineBatch3D.DrawLine(ref line);
            //RenderManager.LineBatch3D.DrawLine(ref line2);
        }
        /// <summary>
        /// Update method
        /// </summary>
        /// <param name="gameTime"></param>
        protected override void Update(TimeSpan gameTime)
        {
            this.input = WaveServices.Input;

            var activeCamera2D = this.RenderManager.ActiveCamera2D;

            if (this.input.TouchPanelState.IsConnected)
            {
                this.touchState = this.input.TouchPanelState;

                if (this.touchState.Count > 0 && this.mouseJoint == null)
                {
                    // Gets the virtual screen touch position
                    this.TouchPosition = this.touchState[0].Position;
                    this.vsm.ToVirtualPosition(ref this.TouchPosition);

                    // Launchs a ray from the virtual screen position
                    Ray r;
                    activeCamera2D.CalculateRay(ref this.TouchPosition, out r);
                    this.WorldPosition = r.IntersectionZPlane(0).ToVector2();

                    /// check collision with DRAGGABLE entities only
                    foreach (Entity entity in this.Owner.Scene.EntityManager.FindAllByTag(GameConstants.TAGDRAGGABLE))
                    {
                        Collider2D collider = entity.FindComponent <Collider2D>(false);
                        if (collider != null)
                        {
                            if (collider.Contain(this.WorldPosition))
                            {
                                RigidBody2D rigidBody = entity.FindComponent <RigidBody2D>();
                                if (rigidBody != null)
                                {
                                    if (rigidBody.PhysicBodyType == WaveEngine.Common.Physics2D.RigidBodyType2D.Dynamic)
                                    {
                                        this.ConnectedEntity = entity;

                                        //Create Joint
                                        this.mouseJoint = new MouseJoint2D()
                                        {
                                            Target = this.WorldPosition,
                                        };

                                        this.ConnectedEntity.AddComponent(mouseJoint);

                                        var audioService = WaveServices.GetService <AudioService>();
                                        audioService.Play(Audio.Sfx.Rubber_wav);

                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                // Touch just released, remove joint
                if (this.touchState.Count == 0 && this.mouseJoint != null)
                {
                    if (!this.ConnectedEntity.IsDisposed)
                    {
                        this.ConnectedEntity.RemoveComponent(this.mouseJoint);

                        var playerComponent = this.ConnectedEntity.FindComponent <PlayerComponent>();
                        playerComponent.Launch();
                    }

                    this.mouseJoint = null;
                }

                // update touch positions
                if (this.mouseJoint != null)
                {
                    this.TouchPosition = this.touchState[0].Position;
                    this.vsm.ToVirtualPosition(ref this.TouchPosition);

                    Ray r;
                    activeCamera2D.CalculateRay(ref this.TouchPosition, out r);
                    this.WorldPosition     = r.IntersectionZPlane(0).ToVector2();
                    this.mouseJoint.Target = this.WorldPosition;
                }
            }
        }
Пример #39
0
        private void HandleInput(float amount)
        {
            input = WaveServices.Input;
            isMouseConnected = input.MouseState.IsConnected;
            isTouchPanelConnected = input.MouseState.IsConnected;

            if (isMouseConnected)
            {
                isTouchPanelConnected = false;
            }

            if (input.KeyboardState.IsConnected)
            {
                keyboardState = input.KeyboardState;

                if (keyboardState.W == ButtonState.Pressed)
                {
                    // Manual inline: position += speed * forward;
                    position.X = position.X + (amount * speed * forward.X);
                    position.Y = position.Y + (amount * speed * forward.Y);
                    position.Z = position.Z + (amount * speed * forward.Z);
                    UpdateCameraPosition();
                }
                else if (keyboardState.S == ButtonState.Pressed)
                {
                    // Manual inline: position -= speed * forward;
                    position.X = position.X - (amount * speed * forward.X);
                    position.Y = position.Y - (amount * speed * forward.Y);
                    position.Z = position.Z - (amount * speed * forward.Z);
                    UpdateCameraPosition();
                }
                if (keyboardState.A == ButtonState.Pressed)
                {
                    // Manual inline: position -= speed * right;
                    position.X = position.X - (amount * speed * right.X);
                    position.Y = position.Y - (amount * speed * right.Y);
                    position.Z = position.Z - (amount * speed * right.Z);
                    UpdateCameraPosition();
                }
                else if (keyboardState.D == ButtonState.Pressed)
                {
                    // Manual inline: position += speed * right;
                    position.X = position.X + (amount * speed * right.X);
                    position.Y = position.Y + (amount * speed * right.Y);
                    position.Z = position.Z + (amount * speed * right.Z);
                    UpdateCameraPosition();
                }
            }

            if (isTouchPanelConnected || isMouseConnected)
            {
                if (isTouchPanelConnected)
                {
                    currentTouchPanelState = input.TouchPanelState;
                }
                if (isMouseConnected)
                {
                    currentMouseState = input.MouseState;
                }

                if ((isTouchPanelConnected && currentTouchPanelState.Count == 1)
                    || (isMouseConnected && currentMouseState.RightButton == ButtonState.Pressed))
                {
                    if (isTouchPanelConnected && currentTouchPanelState.Count == 1)
                    {
                        currentTouchLocation = currentTouchPanelState.First();
                    }

                    if ((isTouchPanelConnected && currentTouchLocation.State == TouchLocationState.Pressed)
                        ||
                        (isMouseConnected && currentMouseState.RightButton == ButtonState.Pressed))
                    {
                        if (isDragging == false)
                        {
                            isDragging = true;
                        }
                        else
                        {
                            if (currentTouchPanelState.IsConnected)
                            {
                                xDifference = (currentTouchLocation.Position.X - lastTouchLocation.Position.X);
                                yDifference = (currentTouchLocation.Position.Y - lastTouchLocation.Position.Y);
                            }
                            if (isMouseConnected)
                            {
                                xDifference = (currentMouseState.X - lastMouseState.X);
                                yDifference = (currentMouseState.Y - lastMouseState.Y);
                            }

                            yaw = yaw - (xDifference * amount * rotationSpeed);
                            pitch = pitch - (yDifference * amount * rotationSpeed);

                            // Manual inline: forwardNormalizedVector = cameraRotation.Forward;
                            forwardNormalizedVector.X = cameraMatrixRotation.Forward.X;
                            forwardNormalizedVector.Y = cameraMatrixRotation.Forward.Y;
                            forwardNormalizedVector.Z = cameraMatrixRotation.Forward.Z;
                            forwardNormalizedVector.Normalize();

                            // Manual inline: rightNormalizedVector = cameraRotation.Right;
                            rightNormalizedVector.X = cameraMatrixRotation.Right.X;
                            rightNormalizedVector.Y = cameraMatrixRotation.Right.Y;
                            rightNormalizedVector.Z = cameraMatrixRotation.Right.Z;
                            rightNormalizedVector.Normalize();

                            // Manual inline: upNormalizedVector = cameraMatrixRotation.Up;
                            upNormalizedVector.X = cameraMatrixRotation.Up.X;
                            upNormalizedVector.Y = cameraMatrixRotation.Up.Y;
                            upNormalizedVector.Z = cameraMatrixRotation.Up.Z;
                            upNormalizedVector.Normalize();

                            Matrix.CreateFromAxisAngle(ref rightNormalizedVector, pitch, out tempRotationMatrix);
                            Matrix.Multiply(ref cameraMatrixRotation, ref tempRotationMatrix, out cameraMatrixRotation);

                            Matrix.CreateFromAxisAngle(ref upNormalizedVector, yaw, out tempRotationMatrix);
                            Matrix.Multiply(ref cameraMatrixRotation, ref tempRotationMatrix, out cameraMatrixRotation);

                            Matrix.CreateFromAxisAngle(ref forwardNormalizedVector, 0f, out tempRotationMatrix);
                            Matrix.Multiply(ref cameraMatrixRotation, ref tempRotationMatrix, out cameraMatrixRotation);

                            // Original code
                            /*
                            cameraMatrixRotation.Forward.Normalize();
                            cameraMatrixRotation.Right.Normalize();
                            cameraMatrixRotation.Up.Normalize();
                            
                            cameraMatrixRotation *= Matrix.CreateFromAxisAngle(cameraMatrixRotation.Right, pitch);
                            cameraMatrixRotation *= Matrix.CreateFromAxisAngle(cameraMatrixRotation.Up, yaw);
                            cameraMatrixRotation *= Matrix.CreateFromAxisAngle(cameraMatrixRotation.Forward, 0f);
                            */

                            yaw = 0.0f;
                            pitch = 0.0f;

                            // Manual inline: forward = cameraRotation.Forward;
                            forward.X = cameraMatrixRotation.Forward.X;
                            forward.Y = cameraMatrixRotation.Forward.Y;
                            forward.Z = cameraMatrixRotation.Forward.Z;

                            //// Manual inline: right = cameraRotation.Right;
                            right.X = cameraMatrixRotation.Right.X;
                            right.Y = cameraMatrixRotation.Right.Y;
                            right.Z = cameraMatrixRotation.Right.Z;

                            UpdateLookAt();

                            //Restore the current matrix rotation
                            cameraMatrixRotation = Matrix.Invert(Matrix.CreateLookAt(camera.Position, camera.LookAt, camera.UpVector));
                        }
                    }
                    lastTouchLocation = currentTouchLocation;
                    lastMouseState = currentMouseState;
                }
                else
                {
                    isDragging = false;
                }
            }
        }