Example #1
0
static void KeyboardCallback(unsigned char key, int x, int y)
{
	switch (key)
	{
		case 27:	exit(0); break;

		case '+':
		{
			if(gTest!=MAX_NB_TESTS-1)
			{
				gCollisionTests[gTest]->Deselect();
				gTest++;
				gSelectedTest++;
				gCollisionTests[gTest]->Select();
			}
		}
		break;

		case '-':
		{
			if(gTest)
			{
				gCollisionTests[gTest]->Deselect();
				gTest--;
				gSelectedTest--;
				gCollisionTests[gTest]->Select();
			}
		}
		break;

		case 101:	MoveCameraForward();									break;
		case 103:	MoveCameraBackward();									break;
		case 100:	MoveCameraRight();										break;
		case 102:	MoveCameraLeft();										break;
		default:	gCollisionTests[gTest]->KeyboardCallback(key, x, y);	break;
	}

	TwEventKeyboardGLUT(key, x, y);
}
void AMainCameraSpecPawn::Tick(float DeltaSeconds) {
	Super::Tick(DeltaSeconds);

	FVector2D MousePosition;
	FVector2D ViewportSize;

	UGameViewportClient* GameViewport = GEngine->GameViewport;

	check(GameViewport);
	GameViewport->GetViewportSize(ViewportSize);

	// Check if input is detectable
	if (GameViewport->IsFocused(GameViewport->Viewport) &&
		GameViewport->GetMousePosition(MousePosition) &&
		bCanMoveCamera) {

		// Edge of screen movement
		if (MousePosition.X < CameraScrollBounds) {
			YMovement = -1.0f;
		} else if (ViewportSize.X - MousePosition.X < CameraScrollBounds) {
			YMovement = 1.0f;
		}

		if (MousePosition.Y < CameraScrollBounds) {
			XMovement = 1.0f;
		}
		else if (ViewportSize.Y - MousePosition.Y < CameraScrollBounds) {
			XMovement = -1.0f;
		}

		// movement
		MoveCameraForward(XMovement * FastMoveMultiplier * DeltaSeconds);
		MoveCameraRight(YMovement * FastMoveMultiplier * DeltaSeconds);

	}
	
}
Example #3
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message)
	{
	case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// 分析菜单选择:
		switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;
	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		// TODO: 在此添加任意绘图代码...
		EndPaint(hWnd, &ps);
        break;
    case WM_MOUSEMOVE:
        moving = true;
        hovering = false;
        lastCursorPos = currentCursorPos;
        currentCursorPos.x = (float)GET_X_LPARAM(lParam);
		currentCursorPos.y = (float)GET_Y_LPARAM(lParam);
        TRACKMOUSEEVENT tme;
        tme.cbSize = sizeof(TRACKMOUSEEVENT);
        tme.dwFlags = TME_HOVER;
        tme.dwHoverTime = 100;
        tme.hwndTrack = hWnd;
        TrackMouseEvent(&tme);
        break;
    case WM_LBUTTONDOWN:
		currentCursorPos.x = (float)GET_X_LPARAM(lParam);
		currentCursorPos.y = (float)GET_Y_LPARAM(lParam);
        lastCursorPos = currentCursorPos;
        dragging = true;
        break;
    case WM_LBUTTONUP:
        dragging = false;
        break;
    case WM_MOUSEHOVER:
        lastCursorPos = currentCursorPos;
		currentCursorPos.x = (float)GET_X_LPARAM(lParam);
		currentCursorPos.y = (float)GET_Y_LPARAM(lParam);
        hovering = true;
        moving = false;
        break;
    case WM_KEYDOWN:
        switch(wParam)
        {
        case VK_ESCAPE:    //按Esc退出
            PostQuitMessage(0);
            break;
        case 'P': //按'P'暂停/恢复
            Pause = Pause ? false : true;
            break;
        //camera 操作
        case 'W':
            MoveCameraForward(3.0f);
            break;
        case 'S':
            MoveCameraBackward(3.0f);
            break;
        case 'A':
            MoveCameraLeft(3.0f);
            break;
        case 'D':
            MoveCameraRight(3.0f);
            break;
        case 'R':
            ResetCamera();
            break;
        //参考:http://forums.codeguru.com/showthread.php?302925-Where-is-Page-Up-Down-Accelerator-Key&p=981700#post981700
        //Page Up : VK_PRIOR
        //Page Down : VK_NEXT
        case VK_PRIOR:
            MoveCameraUpward(3.0f);
            break;
        case VK_NEXT:
            MoveCameraDownward(3.0f);
            break;
        case 'Q':
            RotateCameraHorizontally(-D3DX_PI/45);
            break;
        case 'E':
            RotateCameraHorizontally(D3DX_PI/45);
            break;
        case VK_HOME:
            RotateCameraVertically(-D3DX_PI/45);
            break;
        case VK_END:
            RotateCameraVertically(D3DX_PI/45);
            break;
        case VK_SPACE:
            bStepForward = true;
            break;
        }
        break;
	case WM_DESTROY:
        Destroy();
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}