コード例 #1
0
Entity* WorldManager::DoSelectionTest( const Vector2f& pSelectionPoint )
{
    Int32     viewport[4];
    Renderer* renderer = GraphicSubsystem::Instance()->GetRenderer();
    renderer->GetViewport(viewport);

    Vector3f screenRay( pSelectionPoint.x, viewport[3] - pSelectionPoint.y - 1, 0 );
    Vector3f worldRay = renderer->ScreenToWorld( screenRay );

    // Get the vector from the mouse positions.
    Vector3f testOrigin = worldRay;    
    Vector3f testDir = worldRay - GetCurrentCamera()->GetPosition();
    testDir.Normalize();

    return LineTrace( testOrigin, testDir );
}
コード例 #2
0
bool ATankPlayerController::GetSightRayHitLocation(FVector& HitLocation) const
{
	FVector2D CrosshairLocation;
	GetCrosshairScreenLocation(CrosshairLocation);
	
	FVector WorldLocation;
	FVector WorldDirection;

	if (DeprojectScreenPositionToWorld(CrosshairLocation.X, CrosshairLocation.Y, WorldLocation, WorldDirection)) {
		//UE_LOG(LogTemp, Warning, TEXT("World location: %s World direction: %s"), *WorldLocation.ToString(), *WorldDirection.ToString());
	}
	
	TArray<FHitResult> HitResults = TArray<FHitResult>();
	
	if (LineTrace(WorldLocation, WorldDirection, HitResults)) {
		bool aimingThroughPlayer = false;
		for (int i = 0; i < HitResults.Num(); i++) {
			FHitResult HitResult = HitResults[i];
			if (HitResult.IsValidBlockingHit()) {
				if (HitResult.GetActor() != GetControlledTank()) {
					if (aimingThroughPlayer)
					{
						UE_LOG(LogTemp, Warning, TEXT("Aiming through player tank actor, next hit is: %s"), *HitResult.ImpactPoint.ToString());
					}

					HitLocation = HitResult.ImpactPoint;
					return true;
				}else
				{
					aimingThroughPlayer = true;
					UE_LOG(LogTemp, Warning, TEXT("%i hits, aiming through player tank actor: %s"),HitResults.Num(), *HitResult.ImpactPoint.ToString());
				}
			}
			else
			{
				HitLocation = FVector(0);
				return false;
			}
		}
		
	}

	return false;
}