一、得到当前运行的屏幕分辨率:
FVector2D ScreenPos = GEngine->GameViewport->Viewport->GetSizeXY();
二、使用DeprojectScreenPositionToWorld运算:
PlayerController->DeprojectScreenPositionToWorld(ScreenPos.X / 2.0f, ScreenPos.Y / 2.0f, MousePos, MouseDir);
其中,PlayerController为对应的控制器。
/** The view port representing the current game instance. Can be 0 so don‘t use without checking. */ UPROPERTY() class UGameViewportClient* GameViewport;
UGameViewportClient的说明:
/**
* A game viewport (FViewport) is a high-level abstract interface for the
* platform specific rendering, audio, and input subsystems.
* GameViewportClient is the engine‘s interface to a game viewport.
* Exactly one GameViewportClient is created for each instance of the game. The
* only case (so far) where you might have a single instance of Engine, but
* multiple instances of the game (and thus multiple GameViewportClients) is when
* you have more than one PIE window running.
*
* Responsibilities:
* propagating input events to the global interactions list
*
* @see UGameViewportClient
*/
UCLASS(Within=Engine, transient, config=Engine)
class ENGINE_API UGameViewportClient : public UScriptViewportClient, public FExec
{
解(反)投影?不确切这个词怎么译,反正就是投影的逆运算
/** Convert current mouse 2D position to World Space 3D position and direction. Returns false if unable to determine value. **/ UFUNCTION(BlueprintCallable, Category = "Game|Player", meta = (DisplayName = "ConvertScreenLocationToWorldSpace", Keywords = "deproject")) bool DeprojectScreenPositionToWorld(float ScreenX, float ScreenY, FVector& WorldLocation, FVector& WorldDirection) const;
原文:http://www.cnblogs.com/redeyerabbit/p/6652004.html