protected void Update() //mengambil input pergerakan { TimeSpan elapsed = DateTime.Now.Subtract(CurrentTime); CurrentTime = DateTime.Now; World.Prepare(this); if (!updating) { return; } double sx = 0; double sy = 0; double sz = 0; sx += PressedKeyRight?1:0; sx += PressedKeyLeft?-1:0; sy += PressedKeyUp?1:0; sy += PressedKeyDown?-1:0; sz += PressedKeyBackward?1:0; sz += PressedKeyForward?-1:0; this.strafeDir = new Point3D(sx, sy, sz); int xcenter = this.ViewPort.Width >> 1; int ycenter = this.ViewPort.Height >> 1; if (started) { WinApi.Point p = WinApi.GetCursorPos(); camera.Pan((-p.x + xcenter) / 10f, (-p.y + ycenter) / 10f); } else { started = true; } Point3D moveDir = camera.StrafeDir(this.strafeDir.Scaled(elapsed.TotalSeconds * this.StrafeSpeed)); Point3D ColisionNormal = (ghostMode)?new Point3D(0, 0, 0):World.ColisionNormal(camera.Origin, moveDir, 30); if (ColisionNormal.Norm > 0) { moveDir += ColisionNormal; ColisionNormal = World.ColisionNormal(camera.Origin, moveDir, 30); } //tembus tembok if (ColisionNormal.Norm < .5 && moveDir.Norm > 1) { camera.Translate(moveDir); } WinApi.SetCursorPos(xcenter, ycenter); }
/// <summary> /// Processes mouse events, which are bubbled /// through the class' routed events, trigger /// certain actions (e.g. show a popup), or /// both. /// </summary> /// <param name="me">Event flag.</param> private void OnMouseEvent(MouseEvent me) { if (IsDisposed) { return; } switch (me) { case MouseEvent.MouseMove: RaiseTrayMouseMoveEvent(); //immediately return - there's nothing left to evaluate return; case MouseEvent.IconRightMouseDown: RaiseTrayRightMouseDownEvent(); break; case MouseEvent.IconLeftMouseDown: RaiseTrayLeftMouseDownEvent(); break; case MouseEvent.IconRightMouseUp: RaiseTrayRightMouseUpEvent(); break; case MouseEvent.IconLeftMouseUp: RaiseTrayLeftMouseUpEvent(); RaiseTrayMouseClickEvent(); break; case MouseEvent.IconMiddleMouseDown: RaiseTrayMiddleMouseDownEvent(); break; case MouseEvent.IconMiddleMouseUp: RaiseTrayMiddleMouseUpEvent(); break; case MouseEvent.IconDoubleClick: //cancel single click timer _SingleClickTimer.Change(Timeout.Infinite, Timeout.Infinite); //bubble event RaiseTrayMouseDoubleClickEvent(); break; case MouseEvent.BalloonToolTipClicked: RaiseTrayBalloonTipClickedEvent(); break; default: throw new ArgumentOutOfRangeException(nameof(me), $@"Missing handler for mouse event flag: {me}"); } //get mouse coordinates var cursor_position = new WinApi.Point(); //physical cursor position is supported for Vista and above if (_MessageSink.Version == NotifyIconVersion.Vista) { WinApi.GetPhysicalCursorPos(ref cursor_position); } else { WinApi.GetCursorPos(ref cursor_position); } cursor_position = GetDeviceCoordinates(cursor_position); var isLeftClickCommandInvoked = false; //show popup, if requested if (me.IsMatch(PopupActivation)) { if (me == MouseEvent.IconLeftMouseUp) { //show popup once we are sure it's not a double click _SingleClickTimerAction = () => { LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this); ShowTrayPopup(cursor_position); }; _SingleClickTimer.Change(WinApi.GetDoubleClickTime(), Timeout.Infinite); isLeftClickCommandInvoked = true; } else //show popup immediately { ShowTrayPopup(cursor_position); } } //show context menu, if requested if (me.IsMatch(MenuActivation)) { if (me == MouseEvent.IconLeftMouseUp) { //show context menu once we are sure it's not a double click _SingleClickTimerAction = () => { LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this); ShowContextMenu(cursor_position); }; _SingleClickTimer.Change(WinApi.GetDoubleClickTime(), Timeout.Infinite); isLeftClickCommandInvoked = true; } else //show context menu immediately { ShowContextMenu(cursor_position); } } //make sure the left click command is invoked on mouse clicks if (me != MouseEvent.IconLeftMouseUp || isLeftClickCommandInvoked) { return; } //show context menu once we are sure it's not a double click _SingleClickTimerAction = () => LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this); _SingleClickTimer.Change(WinApi.GetDoubleClickTime(), Timeout.Infinite); }