public void Touch(TouchLocation location, SpriteBatch spriteBatch) { turnScore = 0; int x = Convert.ToInt16((location.Position.X / (spriteBatch.GraphicsDevice.Viewport.Width / (xGrid + 1))) - 1); int y = Convert.ToInt16(((location.Position.Y - (menuTexture.Height / 2)) / (spriteBatch.GraphicsDevice.Viewport.Height / (yGrid + 1))) - 1); try { //Check x,y is within Grid and not been tried before if (!(x < 0 || y < 0 || x > xGrid || y > yGrid) && !grid[x, y].InvertColour) { score = 0; bInProgress = true; selectedPiece = grid[x, y]; grid[x, y].Selected = true; grid[x, y].Rotate(true); initialPieceX = x; initialPieceY = y; score = 1; attempts++; selectedPiece.Score = score; turnScore = 1; pieces.Add(grid[x, y]); } } catch (IndexOutOfRangeException ex) { //If the player touches the far right or extreme bottom, we do nothing! } }
public override void Update(GameTime gameTime, TouchCollection touchCollection) { ProcessTouch(gameTime, touchCollection); BackgroundScrollable bgs = (BackgroundScrollable)this.background; Point topLeftBG = bgs.GetTopLeftCoordinate(); foreach (Planet planet in listPlanets) { if (planet.Intersects(rocket, (int)topLeftBG.X, (int)topLeftBG.Y, bgs.scale)) { if (touchCollection.Count > 0) { TouchLocation touch = touchCollection[0]; if (touch.State == TouchLocationState.Pressed) { if (buttonEnterPlanet.IsPressed((int)touch.Position.X, (int)touch.Position.Y)) { if (!planet.isVisited) { visited++; planet.isVisited = true; } if (planet.name.Equals("Mercury")) { NextScreen = game.GetNewScreenMercury(); } else if (planet.name.Equals("Venus")) { NextScreen = game.GetNewScreenVenus(); } else if (planet.name.Equals("Earth")) { NextScreen = game.GetNewScreenEarth(); } else if (planet.name.Equals("Mars")) { NextScreen = game.GetNewScreenMars(); } else if (planet.name.Equals("Jupiter")) { NextScreen = game.GetNewScreenJupiter(); } else if (planet.name.Equals("Saturn")) { NextScreen = game.GetNewScreenSaturn(); } else if (planet.name.Equals("Uranus")) { NextScreen = game.GetNewScreenUranus(); } else if (planet.name.Equals("Neptune")) { NextScreen = game.GetNewScreenNeptune(); } } } } } } }
private Movement guessMovement(TouchLocation tl) { float x = tl.Position.X; float y = tl.Position.Y; Point p = new Point((int)x, (int)y); // System.Diagnostics.Debug.WriteLine("x:" + x + "y:" + y); if (leftTouchZone.Contains(p)) { // System.Diagnostics.Debug.WriteLine("Touch: Left"); moving = true; return(Movement.Left); } if (topTouchZone.Contains(p)) { // System.Diagnostics.Debug.WriteLine("Touch: Up"); moving = true; return(Movement.Up); } if (rightTouchZone.Contains(p)) { // System.Diagnostics.Debug.WriteLine("Touch: Right"); moving = true; return(Movement.Right); } if (bottomTouchZone.Contains(p)) { // System.Diagnostics.Debug.WriteLine("Touch: Down"); moving = true; return(Movement.Down); } // System.Diagnostics.Debug.WriteLine("Touch: None"); return(orientation); }
public bool Touch(TouchLocation touchLocation) { if (!isActive) { if (touchLocation.State == TouchLocationState.Pressed && IsTouched(touchLocation.Position)) { StartTouching(touchLocation.Position); touchID = touchLocation.Id; return(true); } } else if (touchLocation.Id == touchID) { switch (touchLocation.State) { case TouchLocationState.Moved: ContinueTouching(touchLocation.Position); break; case TouchLocationState.Released: EndTouching(); break; } return(true); } return(false); }
internal static void Begin() { Kbs = Keyboard.GetState(); try { Oldkbs.GetPressedKeys(); } catch { Oldkbs = Kbs; } if (Input != null) { _oldTouchLocation = _touchLocation; _touchLocation = Input.GetInputPoint(); #if TOUCHPANEL TouchIsFromTouchPanel = Input.TouchIsFromTouchPanel; #if !MOUSE if (_touchLocation.State != TouchLocationState.Invalid) #endif #endif { _mousePos = _touchLocation.Position; } } _mousePoint.X = (int)_mousePos.X; _mousePoint.Y = (int)_mousePos.Y; }
void AnalyzeTouchPoint(ref TouchLocation touch, float time) { TouchElement element; if (!_elements.TryGetValue(touch.Id, out element)) { element = TouchElement.Invalid; } if (touch.State == TouchLocationState.Pressed || touch.State == TouchLocationState.Moved) { Vector2 pos = Vector2.Transform(touch.Position, TouchTransform); if (!element.Valid) { ProcessDown(touch.Id, pos, DateTime.Now); } else { ProcessMove(touch.Id, pos, DateTime.Now); } } else if (element.Valid) { Vector2 pos = Vector2.Transform(touch.Position, TouchTransform); ProcessUp(touch.Id, pos, DateTime.Now); } }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { Exit(); } if (TouchPanel.IsGestureAvailable) { var sample = TouchPanel.ReadGesture(); Vector2 touchPosition = sample.Position; Vector2 fling = sample.Delta; grid.SwapJewels(touchPosition, fling.Fling()); } TouchLocation location = TouchPanel.GetState().FirstOrDefault(); if (location != null) { if (location.Position.Y > 1600) { grid.PopulateGrid(); } } grid.Update(); base.Update(gameTime); }
public void Update(TouchLocation location) { lastState = State; for (int i = DELAY_FRAME - 1; i > 0; i--) { this.Positions[i] = this.Positions[i - 1]; } this.Positions[0] = location.Position; switch (location.State) { case TouchLocationState.Invalid: case TouchLocationState.Released: { this.State = TouchState.End; break; } case TouchLocationState.Pressed: { this.State = TouchState.Begin; break; } case TouchLocationState.Moved: { this.State = TouchState.OnTouch; break; } default: break; } }
public PongGameScreen() { TransitionOnTime = TimeSpan.FromSeconds(0.0); TransitionOffTime = TimeSpan.FromSeconds(0.0); screenLeftBound = 0; screenRightBound = 480; screenTopBound = 0; screenBottomBound = 800; Accelerometer = new Accelerometer(); if (Accelerometer.State == SensorState.Ready) { Accelerometer.ReadingChanged += (s, e) => { accelState = e; }; Accelerometer.Start(); } lastAccelInput = 0f; bottomPaddleTouch = new TouchLocation(); bottomPaddleTouchId = -1; lastTouchInput = new List <TouchLocation>(); lastKeyInput = new List <Keys>(); bottomPaddle = new DefaultPaddle(); topPaddle = new DefaultPaddle(); }
// Update is called once per frame void Update() { int cnt = 0; while (cnt < Input.touchCount) { Touch t = Input.GetTouch(cnt); print(cnt); if (t.phase == TouchPhase.Began) { touches.Add(new TouchLocation(t.fingerId, CreateCircle(t))); } else if (t.phase == TouchPhase.Ended) { TouchLocation thisTouch = touches.Find(touchLocation => touchLocation.touchId == t.fingerId); Destroy(thisTouch.circle); touches.RemoveAt(touches.IndexOf(thisTouch)); } else if (t.phase == TouchPhase.Moved) { Debug.Log("Touch Moved"); TouchLocation thisTouch = touches.Find(touchLocation => touchLocation.touchId == t.fingerId); thisTouch.circle.transform.position = getTouchPosition(t.position); } cnt++; } }
public override void Update(GameTime gameTime) { TouchCollection state = TouchPanel.GetState(); if (state.IsConnected && state.Count > 0) { IsTouch = true; } Vector2 touchPosUIScale = TouchToUI = new Vector2( 1920f / Celeste.Instance.GraphicsDevice.PresentationParameters.BackBufferWidth, // TouchPanel.DisplayWidth, 1080f / Celeste.Instance.GraphicsDevice.PresentationParameters.BackBufferHeight // TouchPanel.DisplayHeight ); HashSet <int> consumedIds = new HashSet <int>(); /* * Logger.Log(LogLevel.Verbose, "touch", "--------"); * Logger.Log(LogLevel.Verbose, "touch", $"Connected: {state.IsConnected}; IsTouch: {IsTouch}; Count: {state.Count}"); * for (int ti = 0; ti < state.Count; ti++) { * Logger.Log(LogLevel.Verbose, "touch", $"[{ti}]: {state[ti].State} {state[ti].Position * touchPosUIScale}"); * } */ for (int i = 0; i < Regions.Count; i++) { ATouchRegion region = Regions[i]; if (region == null) { continue; } TouchLocation?touchInside = null; for (int ti = 0; ti < state.Count; ti++) { TouchLocation touch = state[ti]; if (consumedIds.Contains(touch.Id)) { continue; } Vector2 touchPosUI = touch.Position * touchPosUIScale; if (touchPosUI.X < region.Position.X - region.Size.X * 0.5f || touchPosUI.X > region.Position.X + region.Size.X * 0.5f || touchPosUI.Y < region.Position.Y - region.Size.Y * 0.5f || touchPosUI.Y > region.Position.Y + region.Size.Y * 0.5f) { continue; } touchInside = touch; } bool consumed = region.Update(state, touchInside ?? default); if (consumed && touchInside != null) { consumedIds.Add(touchInside.Value.Id); } } base.Update(gameTime); }
private void AddHighlightEvent(TouchLocation touch) { //add a highlight event at that location var coord = ConvertCoordinate(touch.Position); Highlights.Add(new HighlightEventArgs(coord, this)); }
public void Update(TouchLocation touchLocation) { if (touchLocation.State == TouchLocationState.Pressed && _picked < 0) { Vector2 delta = touchLocation.Position - _position; if (delta.LengthSquared() <= 2025f) { _picked = touchLocation.Id; } } if ((touchLocation.State == TouchLocationState.Pressed || touchLocation.State == TouchLocationState.Moved) && touchLocation.Id == _picked) { Vector2 delta = touchLocation.Position - _center; if (delta != Vector2.Zero) { float _length = delta.Length(); if (_length > 25f) { delta *= (25f / _length); } StickPosition = delta / 25f; StickPosition.Y *= -1f; _position = _center + delta; } } if (touchLocation.State == TouchLocationState.Released && touchLocation.Id == _picked) { _picked = -1; _position = _center; StickPosition = Vector2.Zero; } }
public bool OnClick(TouchLocation touch) { if (Contains(touch.Position, (int)Position.X, (int)Position.Y, regions[index].Bounds.Width, regions[index].Bounds.Height)) { if (touch.State == TouchLocationState.Pressed) { index = (~index) & 1; isPressed = true; } else if (touch.State == TouchLocationState.Released && isPressed) { isPressed = false; if (CheckedAction != null) { this.CheckedAction(this); } } return(ContinueCheck); } else if (isPressed && touch.State == TouchLocationState.Released) { index = (~index) & 1; index = 0; } return(true); }
public void update() { for (int i = 0; i < Game1.touchState.Count; i++) { touchLocation = Game1.touchState[i]; if (Game1.touchState[i].State == TouchLocationState.Released) { for (int j = 0; j < btns.Length; j++) { if (!btnsT[j]) { continue;//代表此按鈕不開放 } //按鈕 if (btns[j].touchXY(touchLocation.Position.X, touchLocation.Position.Y)) { chked = j; btnchked.loc.X = btns[chked].loc.X; btnchked.loc.Y = btns[chked].loc.Y; updateBefore(); return; } } //for } //if } //for }
public bool OnClick(TouchLocation touch) { if (Contains(touch.Position)) { if (touch.State == TouchLocationState.Pressed) { index = regions.Length - 1; isPressed = true; } else if (touch.State == TouchLocationState.Released && isPressed) { if (ButtonPressed != null) { this.ButtonPressed(this); } index = 0; } return(ContinueCheck); } else if (isPressed && touch.State == TouchLocationState.Released) { isPressed = false; index = 0; } return(true); }
/// <summary> /// Calculate a ray between the camer and the selected point /// </summary> private void CalculateRay() { // Get the current touch location currentLocation = touchPanelState.First(); // Apply the near point: nearPoint.X = currentLocation.Position.X; nearPoint.Y = currentLocation.Position.Y; nearPoint.Z = 0f; // And the far point farPoint.X = currentLocation.Position.X; farPoint.Y = currentLocation.Position.Y; farPoint.Z = 1f; // Unproject both to get the 2d point in a 3d screen projections. nearPoint = Camera.Unproject(ref nearPoint); farPoint = Camera.Unproject(ref farPoint); // Now, we have a 3d point. We calculate the point direction direction = farPoint - nearPoint; // And normalized it. direction.Normalize(); // Set the ray to the cached variable ray.Direction = direction; ray.Position = nearPoint; }
public void Update(GameTime gameTime) { var location = GetTouchLocation(); if (null != location) { TouchLocation touchLocation = (TouchLocation)location; TouchPosition = GetTouchPosition(touchLocation.Position); CurrTouchX = (Int32)(TouchPosition.X); CurrTouchY = (Int32)(TouchPosition.Y); TouchState = touchLocation.State; } else { TouchPosition = Vector2.Zero; CurrTouchX = 0; CurrTouchY = 0; TouchState = TouchLocationState.Invalid; } Tap = Hold = DoubleTap = HorizontalDrag = VerticalDrag = false; if (!TouchPanel.IsGestureAvailable) { return; } GestureSample gesture = TouchPanel.ReadGesture(); Tap = gesture.GestureType == GestureType.Tap; Hold = gesture.GestureType == GestureType.Hold; DoubleTap = gesture.GestureType == GestureType.DoubleTap; HorizontalDrag = gesture.GestureType == GestureType.HorizontalDrag; VerticalDrag = gesture.GestureType == GestureType.VerticalDrag; }
private Vector2 GetTouchPoint(TouchLocation touchLocation) { var point = ViewportAdapter?.PointToScreen((int)touchLocation.Position.X, (int)touchLocation.Position.Y) ?? touchLocation.Position.ToPoint(); return(new Vector2(point.X, point.Y)); }
private void ProcessTouch(GameTime gameTime, TouchCollection touchCollection) { if (touchCollection.Count > 0) { TouchLocation touch = touchCollection[0]; Vector2 position = touch.Position; int changeX = 0; int changeY = 0; if (rocket.centerX < position.X) { changeX = Rocket.SPEED; } else if (rocket.centerX > position.X) { changeX = -1 * Rocket.SPEED; } if (rocket.centerY < position.Y) { changeY = Rocket.SPEED; } else if (rocket.centerY > position.Y) { changeY = -1 * Rocket.SPEED; } //System.Diagnostics.Debug.WriteLine(changeX + " " + changeY); ((BackgroundScrollable)background).Scroll(changeX, changeY); rocket.Update(gameTime, touchCollection); } }
public override void Update(GameTime gameTime, TouchCollection touchCollection) { if (touchCollection.Count() > 0) { //get the first touch TouchLocation touch = touchCollection.ElementAt(0); if (touch.State == TouchLocationState.Pressed) { String command = Helper.GetFirstButtonPressCommand(listButtons, (int)touch.Position.X, (int)touch.Position.Y); if (command.Equals("returnToSolarSystem")) { NextScreen = game.screenSolarSystem; } else if (command.Equals("nasa")) { AnimationFixed background = new AnimationFixed(game.textureMarsNASAInfo, 1, 0, 800, 480, 0, 0, 0); NextScreen = new ScreenInfo(game, new Background(background, null), null, this); } else if (command.Equals("moon")) { AnimationFixed background = new AnimationFixed(game.textureMarsMoonInfo, 1, 0, 800, 480, 0, 0, 0); NextScreen = new ScreenInfo(game, new Background(background, null), null, this); } else if (command.Equals("storm")) { AnimationFixed background = new AnimationFixed(game.textureMarsStormInfo, 1, 0, 800, 480, 0, 0, 0); NextScreen = new ScreenInfo(game, new Background(background, null), null, this); } } } }
public bool CheckInput(TouchLocation touch) { Vector2 position = touch.Position.ScreenToWorldPosition(); switch (touch.State) { case TouchLocationState.Pressed: if (Press(position)) { touchId = touch.Id; } break; case TouchLocationState.Moved: if (touchId == touch.Id) { Hold(position); } break; case TouchLocationState.Released: if (touchId == touch.Id) { Release(position); } break; } return(false); }
private TouchCollection GetState() { TouchCollection actualState = Microsoft.Xna.Framework.Input.Touch.TouchPanel.GetState(); TouchLocation[] locations = new TouchLocation[1]; if (actualState.Count > 0) { TouchLocation location = actualState[0]; TouchLocation previousState; location.TryGetPreviousLocation(out previousState); if (previousState.State == TouchLocationState.Pressed) { locations[0] = new TouchLocation(previousState.Id, TouchLocationState.Pressed, location.Position); } else { locations[0] = location; } previousLocation = location; return(new TouchCollection(locations)); } else if (previousLocation.State == TouchLocationState.Moved) { locations[0] = new TouchLocation(previousLocation.Id, TouchLocationState.Released, previousLocation.Position); previousLocation = new TouchLocation(); return(new TouchCollection(locations)); } return(new TouchCollection(empty)); }
//检查鼠标与哪一个方块碰撞了 public int Collide(TouchLocation tl) { Rectangle mouseRect = new Rectangle((int)tl.Position.X - 10, (int)tl.Position.Y - 10, 20, 20); for (int i = 0; i < 25; i++) { if (squareRect[i].Intersects(mouseRect)) { return(i); } } Rectangle musicPos = new Rectangle(30, 700, 40, 40); if (musicPos.Intersects(mouseRect)) { return(29); } Rectangle pausePos = new Rectangle(10, 20, 40, 40); if (pausePos.Intersects(mouseRect)) { return(30); } return(27); }
/// <summary> /// check to see if the button was pressed or released /// </summary> public override void HandleTouch(TouchLocation loc) { if (loc.State == TouchLocationState.Pressed) { if (pressId == 0 && HitTest(loc.Position)) { if (IsVisible) { pressId = loc.Id; } } } else if (loc.State == TouchLocationState.Released) { if (pressId == loc.Id) { pressId = 0; if (HitTest(loc.Position) && OnClick != null) { OnClick(this); } } } }
/// <summary> /// Handles the touch events /// </summary> /// <param name="touch">Touch information concerning an individual touch point</param> public override void TouchEvent(TouchLocation touch) { if (showInfo) { if (touch.State == TouchLocationState.Released) { showInfo = false; } return; } foreach (Button button in buttons) { button.TouchEvent(touch); if (button.Contains(touch.Position)) { return; } } if (touch.State == TouchLocationState.Pressed) { foreach (Pad pad in pads) { if (pad.Contains(touch.Position)) { pad.PlaySound(); return; } } } }
/// <summary> /// Adds a <see cref="TouchLocation"/> to the current active touches. /// </summary> /// <param name="touch">The touch location.</param> /// <param name="isNew">Whether such touch must be considered as new.</param> public void AddTouch(TouchLocation touch, bool isNew) { touch.IsNew = isNew; if (!this.ProjectCamera) { this.currentTouches.Add(touch); } else { float drawOrder = this.Transform2D.DrawOrder; Ray ray; Vector3 pointWorld; Vector2 worldPoint2D; foreach (Camera2D camera in this.RenderManager.Camera2DList) { camera.CalculateRay(ref touch.Position, out ray); ray.IntersectionZPlane(drawOrder, out pointWorld); pointWorld.ToVector2(out worldPoint2D); touch.Position = worldPoint2D; this.currentTouches.Add(touch); } } }
public virtual void ActOnBuilding() { if (InputManager.GetTouchCount() > 0) { TouchLocation tl = InputManager.GetTouchPoint(0); if (IsPointInBuilding(tl)) { if (!contextTimer.IsRunning) { contextTimer.StartTimer(); } } } else { if (contextTimer.IsRunning) { contextTimer.ResetTimer(false); } else if (contextTimer.IsCompleted) { contextMenu.Deactivate(); } } }
public override void HandleInput(InputState input) { if (input.TouchState.Count() > 0) { touchLocation = input.TouchState[0]; if (touchLocation.State == TouchLocationState.Pressed) { dragging = true; lastY = touchLocation.Position.Y; } else if (touchLocation.State == TouchLocationState.Released) { dragging = false; } } if (dragging) { speed = lastY - touchLocation.Position.Y; lastY = touchLocation.Position.Y; } else { if (textPos.Y < minY) { if (speed > 0) { speed -= (minY - textPos.Y) * 0.02f; } else { speed = (textPos.Y - minY) * 0.1f; } } else if (maxY < textPos.Y) { if (speed < 0) { speed -= (maxY - textPos.Y) * 0.02f; } else { speed = (textPos.Y - maxY) * 0.1f; } } } speed *= 0.95f; textPos.Y -= speed; if (input.GamepadState.Buttons.Back == ButtonState.Pressed) { // Exit from AboutScreen screenManager.ExitScreen(); // Show the MainMenuScreen screenManager.AddScreen(new MainMenuScreen()); } }
public override void OnTouchDown(TouchLocation state) { if (!this.IsDropDownOpen) { base.OnTouchDown(state); } }
public AtlasTouchPosition(TouchLocation t) { _last = _t = t; }
/// <summary> /// Calculate a ray between the camer and the selected point /// </summary> private void CalculateRay() { // Get the current touch location currentLocation = touchPanelState.First(); // Apply the near point: nearPoint.X = currentLocation.Position.X; nearPoint.Y = currentLocation.Position.Y; nearPoint.Z = 0f; // And the far point farPoint.X = currentLocation.Position.X; farPoint.Y = currentLocation.Position.Y; farPoint.Z = 1f; // Unproject both to get the 2d point in a 3d screen projections. nearPoint = Camera.Unproject(ref nearPoint, ref Camera.View, ref Camera.Projection, ref identity); farPoint = Camera.Unproject(ref farPoint, ref Camera.View, ref Camera.Projection, ref identity); // Now, we have a 3d point. We calculate the point direction direction = farPoint - nearPoint; // And normalized it. direction.Normalize(); // Set the ray to the cached variable ray.Direction = direction; ray.Position = nearPoint; }
internal void Update(TouchLocation t) { _last = _t; _t = t; }
/// <summary> /// Calculate a ray between the camer and the selected point /// </summary> private void CalculateRay() { // Get the current touch location currentLocation = touchPanelState.First(); //Labels.Add("MouseX", currentLocation.Position.X.ToString()); //Labels.Add("MouseY", currentLocation.Position.Y.ToString()); // Apply the near point: nearPoint = Vector3.Zero; farPoint = Vector3.Zero; nearPoint.X = currentLocation.Position.X; nearPoint.Y = currentLocation.Position.Y; nearPoint.Z = 0f; // And the far point farPoint.X = currentLocation.Position.X; farPoint.Y = currentLocation.Position.Y; farPoint.Z = 1f; //Labels.Add("Nearpoint", nearPoint.ToString()); //Labels.Add("Farpoint", farPoint.ToString()); Matrix world = Matrix.CreateTranslation(0, 0, 0); // Unproject both to get the 2d point in a 3d screen projections. nearPoint = Camera.Unproject(ref nearPoint); farPoint = Camera.Unproject(ref farPoint); // Now, we have a 3d point. We calculate the point direction direction = farPoint - nearPoint; // And normalized it. direction.Normalize(); // Set the ray to the cached variable ray.Direction = direction; ray.Position = nearPoint; this.line2.StartPoint = nearPoint; this.line2.EndPoint = farPoint; }
/// <summary> /// Adds a <see cref="TouchLocation"/> to the current active touches. /// </summary> /// <param name="touch">The touch location.</param> /// <param name="isNew">Whether such touch must be considered as new.</param> public void AddTouch(TouchLocation touch, bool isNew) { touch.IsNew = isNew; if (!this.projectCamera) { this.currentTouches.Add(touch); } else { float drawOrder = this.Transform2D.DrawOrder; Ray ray; Vector3 pointWorld; Vector2 worldPoint2D; foreach (Camera2D camera in this.RenderManager.Camera2DList) { camera.CalculateRay(ref touch.Position, out ray); ray.IntersectionZPlane(drawOrder, out pointWorld); pointWorld.ToVector2(out worldPoint2D); touch.Position = worldPoint2D; this.currentTouches.Add(touch); } } }
/// <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; } }
/// <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); } }
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; } } }
private int getTouchState(TouchLocation touchLocation) { if (gravity == Direction.right || gravity == Direction.left) { if (touchLocation.Position.Y < 240) { return -1; } else { return 1; } } else if(gravity == Direction.up) { if (touchLocation.Position.X < 136) { return -1; } else { return 1; } } else { if (touchLocation.Position.X > 136) { return -1; } else { return 1; } } }
/// <summary> /// Adds a touch location to the current active touches. /// </summary> /// <param name="touch">The touch location.</param> /// <param name="isNew">if set to <c>true</c> [is new].</param> public void AddTouch(TouchLocation touch, bool isNew) { touch.IsNew = isNew; this.currentTouches.Add(touch); }