#pragma once #pragma region CPL License /* Nuclex Unreal Module Copyright (C) 2014-2021 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #include #include #include #include "DialogPawn.generated.h" // --------------------------------------------------------------------------------------------- // /// Pawn that can be used as a stationary observer and to interact with 3D UI /// @remarks /// When to use: use this pawn for your main menu and simple 3D UI interaction /// where the player either uses the mouse or selects options by looking at them. /// /// This is not useful as a base class for complex characters or if you want to /// create a fancy VR game with support for 3D hand controllers. UCLASS() class NUCLEX_API ADialogPawn : public APawn { GENERATED_BODY() /// Sets default values for this pawn's properties public: ADialogPawn(); // // ADialogPawn implementation // /// Uses the current HMD location and rotation as the identity pose (if VR is active) /// @remarks /// SteamVR and other HMD APIs have multiple concepts of centeredness. Room-scale /// VR typically is ground-centered and the HMD camera ends up 2 meters above the /// pawn transform. Seated VR and early HMD use the calibrated center, so the camera /// matches the pawn position (+ BaseEyeHeight). /// /// This method lets you do away with all that and uses whatever location and orienation /// the HMD has as the identity transform. This is bullet-proof in that lets you /// reliably remove the uncertain transform for menu scenes or when the player is /// controlling something that's not supposed to be himself. public: UFUNCTION(BlueprintCallable, CallInEditor) void RecenterHmd(); /// Clears the HMD counter-transform, placing the HMD camera wherever the VR API wants /// @remarks /// This does the opposite of the RecenterHmd() function and places the HMD camera /// wherever the VR API thinks it should be. That may be 2 meters above the pawn /// for room-scale VR or at the pawn base (+ BaseEyeHeight) for seated VR. public: UFUNCTION(BlueprintCallable, CallInEditor) void ClearHmdCenter(); // // Internal implementation // /// Called when the game starts or when spawned protected: virtual void BeginPlay() override; #if defined(WANT_TO_HANDLE_INPUT_OURSELVES) /// Destroys the player input component when the pawn is no longer possessed protected: virtual void DestroyPlayerInputComponent() override; /// Sets up pawn-specific input bindings when the pawn is possessed by a player controller /// @param playerInputComponent Component through which input bindings are registered protected: virtual void SetupPlayerInputComponent( UInputComponent *playerInputComponent ) override; /// Sends a mouse down event to the UI on a touch or mouse button press private: void pointerPressed(); /// Sends a mouse up event to the UI on a touch or mouse button release private: void pointerReleased(); #endif // defined(WANT_TO_HANDLE_INPUT_OURSELVES) /// Transforms from the HMD 'zero' position to the player's chosen rest position /// @remarks /// In this game, the player can make the current HMD position the neutral position /// at any time by pressing the space bar. This transform translates from the chosen /// rest position to the HMD's 'zero' position. public: UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Camera") USceneComponent *HmdOffsetCompensation; /// Camera from which the scene is viewed public: UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Camera") UCameraComponent *ObserverCamera; /// Performs line traces to allow the player to interact with 3D UI /// @remarks /// This thing needs to be placed on the active camera in order to use the HMD's /// orientation (it works on the player controller only for mouse input). /// However, input needs to be sent from the player controller to here still /// unless we want to query and process input in the pawn. public: UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="UI") class UWidgetInteractionComponent *WidgetInteraction; /// Cached key for the left mouse button in Unreal's input system private: mutable FKey leftMouseButtonKey; }; // --------------------------------------------------------------------------------------------- //