void AMobileOpenCVCharacter::TouchUpdate(const ETouchIndex::Type FingerIndex, const FVector Location)
{
	if ((TouchItem.bIsPressed == true) && ( TouchItem.FingerIndex==FingerIndex))
	{
		if (TouchItem.bIsPressed)
		{
			if (GetWorld() != nullptr)
			{
				UGameViewportClient* ViewportClient = GetWorld()->GetGameViewport();
				if (ViewportClient != nullptr)
				{
					FVector MoveDelta = Location - TouchItem.Location;
					FVector2D ScreenSize;
					ViewportClient->GetViewportSize(ScreenSize);
					FVector2D ScaledDelta = FVector2D( MoveDelta.X, MoveDelta.Y) / ScreenSize;									
					if (ScaledDelta.X != 0.0f)
					{
						TouchItem.bMoved = true;
						float Value = ScaledDelta.X * BaseTurnRate;
						AddControllerYawInput(Value);
					}
					if (ScaledDelta.Y != 0.0f)
					{
						TouchItem.bMoved = true;
						float Value = ScaledDelta.Y* BaseTurnRate;
						AddControllerPitchInput(Value);
					}
					TouchItem.Location = Location;
				}
				TouchItem.Location = Location;
			}
		}
	}
}
void AFP_FirstPersonCharacter::TouchUpdate(const ETouchIndex::Type FingerIndex, const FVector Location)
{
	// If we are processing a touch event and this index matches the initial touch event process movement
	if ((TouchItem.bIsPressed == true) && (TouchItem.FingerIndex == FingerIndex))
	{
		if (GetWorld() != nullptr)
		{
			UGameViewportClient* ViewportClient = GetWorld()->GetGameViewport();
			if (ViewportClient != nullptr)
			{
				FVector MoveDelta = Location - TouchItem.Location;
				FVector2D ScreenSize;
				ViewportClient->GetViewportSize(ScreenSize);
				FVector2D ScaledDelta = FVector2D(MoveDelta.X, MoveDelta.Y) / ScreenSize;
				if (ScaledDelta.X != 0.0f)
				{
					TouchItem.bMoved = true;
					float Value = ScaledDelta.X * BaseTurnRate;
					AddControllerYawInput(Value);
				}
				if (ScaledDelta.Y != 0.0f)
				{
					TouchItem.bMoved = true;
					float Value = ScaledDelta.Y* BaseTurnRate;
					AddControllerPitchInput(Value);
				}
				TouchItem.Location = Location;
			}
			TouchItem.Location = Location;
		}
	}
}
/*
* Putting my own functionality in the TouchUpdate; this way we can swipe up/down/left/right from the center
* of the screen and move the character in that direction.
*/
void ASterlingResortsCharacter::TouchUpdate(const ETouchIndex::Type FingerIndex, const FVector Location)
{
    if ((TouchItem.bIsPressed == true) && (TouchItem.FingerIndex == FingerIndex))
    {
        if (TouchItem.bIsPressed)
        {
            if (GetWorld() != nullptr)
            {
                UGameViewportClient* ViewportClient = GetWorld()->GetGameViewport();
                if (ViewportClient != nullptr)
                {
                    FVector2D ScreenSize;
                    ViewportClient->GetViewportSize(ScreenSize);
                    FVector2D ScreenCenter = ScreenSize / 2.0f;

                    FVector MoveDelta = Location - TouchItem.Location;
                    FVector2D ScaledDelta = FVector2D(MoveDelta.X, MoveDelta.Y) / ScreenSize;
                    //FVector2D ScaledDelta = FVector2D(MoveDelta.X - ScreenCenter.X, MoveDelta.Y - ScreenCenter.Y) / ScreenCenter;
                    if (ScaledDelta.X != 0.0f)
                    {
                        TouchItem.bMoved = true;
                        MoveRight(ScaledDelta.X * BaseTurnRate * -1.0f);
                    }
                    if (ScaledDelta.Y != 0.0f)
                    {
                        TouchItem.bMoved = true;
                        MoveForward(ScaledDelta.Y * BaseTurnRate * -1.0f);
                    }
                }
            }
        }
    }
}
Esempio n. 4
0
void AECommanderPawn::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);

	// Get the game viewport and make sure it exists as there is no
	// guarantee that it does.
	UGameViewportClient* GameViewport = GEngine->GameViewport;
	if (!GameViewport)
	{
		return;
	}

	// Get the position of the mouse on the screen.
	FVector2D MousePosition;
	GameViewport->GetMousePosition(MousePosition);

	// Get the size of the screen.
	FVector2D ViewportSize;
	GameViewport->GetViewportSize(ViewportSize);

	// Make sure the game view port has focus (contains the mouse).
	if (!GameViewport->IsFocused(GameViewport->Viewport))
	{
		return;
	}

	// Check if the mouse is at the left or right side of the
	// screen and move accordingly.
	if (MousePosition.X < CameraScrollBoundary)
	{
	}
	else if ((ViewportSize.X - MousePosition.X) < CameraScrollBoundary)
	{
	}

	// Check if the mouse is at the top or bottom of the screen
	// and move accordingly.
	if (MousePosition.Y < CameraScrollBoundary)
	{
	}
	else if ((ViewportSize.Y - MousePosition.Y) < CameraScrollBoundary)
	{
	}
}
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);

	}
	
}