private void OnlineGraphControl_MouseDown(object sender, MouseEventArgs e) { _panning = true; Point p = PointToClient(e.Location); if (e.Button == MouseButtons.Left) { if (e.Location.X > this.ClientRectangle.Width - 75) { } // anders misschien inzoomen else if (e.Location.Y > this.ClientRectangle.Height - 100) { } else { // pan left or right depending on position on graph if (e.Location.X > this.ClientRectangle.Width / 2) { // pan right _pantype = PanType.PanRight; PanToRight(); } else { // pan left _pantype = PanType.PanLeft; PanToLeft(); } } } }
/// <summary> /// Pan the camera by setting a target offset and then lerping towards that position. /// </summary> /// <param name="amount">The amount to pan the camera</param> /// <param name="speed">The speed to pan the camera</param> public void panCamera(Vector3 amount, float speed) { targetPanDestination = amount; panningCamera = true; this.moveSpeed = speed; panType = PanType.offset; startTime = Time.time; }
private uint[] GetPanTable(PanType panType) { if (m_panTables.ContainsKey(panType)) { return(m_panTables[panType]); } Logger.Error("Unknown PanType: {0}", panType); return(new uint[6]); }
/// <summary> /// Pan the camera to a point in the World. /// </summary> /// <param name="point">The location to pan to</param> /// <param name="type">The type of pan to do</param> /// <param name="duration">How long (in ms) the pan should last for</param> public void PanTo(Vector2 point, PanType type, long duration) { _start = new Vector2(X, Y); _end = point; this._duration = duration; this._type = type; _moving = true; _started = Screen.TickCount; }
void Start() { _panType = PanType.None; _touchState = TouchState.None; _touchLayer = 1 << 29; _touchEvent = new TouchEvent(); _touchEvent.Initialize(); _shootEvent = new ShootEvent(); _shootEvent.Initialize(); }
void UpdateDesktopInput() { if (Input.GetButtonDown("Fire1")) { _touchState = TouchState.InitPan; _initPanPosition = Input.mousePosition; _prevPanPosition = Vector2.zero; _curPanPosition = Input.mousePosition; var ray = Camera.main.ScreenPointToRay(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f)); Debug.DrawRay(ray.origin, ray.direction * 20f, Color.magenta, 1f); RaycastHit hit; if (Physics.Raycast(ray.origin, ray.direction, out hit, 9999f, _touchLayer)) { _panType = PanType.Player; } else { _panType = PanType.World; } //Debug.Log("START PAN WITH " + _panType); TriggerTouchEvent(Vector2.zero); return; } if (Input.GetButton("Fire1")) { _touchState = TouchState.UpdatePan; _prevPanPosition = _curPanPosition; _curPanPosition = Input.mousePosition; //Debug.Log("PREV " + _prevPanPosition + " CUR: " + _curPanPosition + " DELTA " + (_curPanPosition - _prevPanPosition)); TriggerTouchEvent(_curPanPosition - _prevPanPosition); } if (Input.GetButtonUp("Fire1")) { _touchState = TouchState.FinishPan; TriggerTouchEvent(_curPanPosition - _prevPanPosition); } }
/// <summary> /// Snap the camera back to the player. AKA center it back on the player. /// </summary> /// <param name="resetOffset">Whether or not to reset the offset for the camera from the player.</param> /// <param name="panPlayer">Whether the camera pans to the player or instantly warps to the player.</param> /// <param name="followPlayer">Whether the camera should follow the player once it is done panning.</param> /// <param name="speed">The move speed for the panning. If panPlayer=false then this value is ignored.</param> public void snapToPlayer(bool resetOffset = true, bool panPlayer = false, bool followPlayer = true, float speed = 1f) { Debug.Log("SNAP"); if (resetOffset) { offset = new Vector3(); } if (panPlayer) { panType = PanType.snapToPlayer; startTime = Time.time; targetPanDestination = this.gameObject.transform.position; panningCamera = true; this.followPlayer = followPlayer; this.moveSpeed = speed; } else { followPlayer = true; } }
/// <summary> /// Pan the camera to a point in the World. /// </summary> /// <param name="x">The X location to pan to</param> /// <param name="y">The Y location to pan to</param> /// <param name="type">The type of pan to do</param> /// <param name="duration">How long (in ms) the pan should last for</param> public void PanTo(float x, float y, PanType type, long duration) { PanTo(new Vector2(x, y), type, duration); }
/* * XNA mouse wheel value is exactly 120 units increment/decrement * per notch, starting at 0 when your game begins. We use the mouse * wheel to control the zooming of the camera. Dividing by 120 will give * you the total number of wheel rotation per notch from the last * wheel value subtracted by current mouse wheel value. just give some * offset value if you want to zoom faster or slower. */ protected void handleMousePanAndZoom(GameTime gameTime) { if (isCameraLocked) { return; } mouseStateCurrent = Mouse.GetState(); //LHGCommon.printToConsole("mouse", mouseStateCurrent); if (mouseStateCurrent.X < 0 || mouseStateCurrent.X > width || mouseStateCurrent.Y < 0 || mouseStateCurrent.Y > height) { //LHGCommon.printToConsole("Mouse Out of Range!"); return; } if (allowZoom) { // Zoom In if (mouseStateCurrent.ScrollWheelValue > mouseStatePrevious.ScrollWheelValue) { // LHGCommon.printToConsole("Zooming In!"); int wheelValue = (mouseStateCurrent.ScrollWheelValue - mouseStatePrevious.ScrollWheelValue) / 120; this.zoomOutValue = 0; this.zoomInValue += (wheelValue * this.zoomOffsetValue); } //! Scroll-Down | Zoom Out if (mouseStateCurrent.ScrollWheelValue < mouseStatePrevious.ScrollWheelValue) { //LHGCommon.printToConsole("Zooming Out!"); int wheelValue = (mouseStatePrevious.ScrollWheelValue - mouseStateCurrent.ScrollWheelValue) / 120; this.zoomInValue = 0; this.zoomOutValue += (wheelValue * this.zoomOffsetValue); } if (mouseStateCurrent.ScrollWheelValue != mouseStatePrevious.ScrollWheelValue) { // We are zooming in or out, update the board to reflect this. Zoom(this.zoomInValue, this.zoomOutValue, gameTime); } } // Manual Pan if (allowManualPan) { if (mouseStateCurrent.LeftButton == ButtonState.Pressed && mouseStatePrevious.LeftButton == ButtonState.Pressed) { // Left mouse button is being depressed. Check if the user is dragging. if (mouseStateCurrent.X != mouseStatePrevious.X) { // Left Right ScrollLeftRight(mouseStatePrevious.X, mouseStateCurrent.X, gameTime); } if (mouseStateCurrent.Y != mouseStatePrevious.Y) { // Left Right ScrollUpDown(mouseStatePrevious.Y, mouseStateCurrent.Y, gameTime); } } } allowAutomaticPan = false; // Automatic Pan if (allowAutomaticPan) { PanType pan = getPanType(mouseStateCurrent.X, mouseStateCurrent.Y); switch (pan) { case PanType.North: ScrollUpDown(30, 5, gameTime); break; case PanType.South: ScrollUpDown(5, 30, gameTime); break; case PanType.East: ScrollLeftRight(30, 5, gameTime); break; case PanType.West: ScrollLeftRight(5, 30, gameTime); break; case PanType.Idle: break; } } mouseStatePrevious = mouseStateCurrent; }