Changes related to ray-collision, and luprex global variable stuff

This commit is contained in:
2025-01-14 18:37:31 -05:00
parent cd3e78a206
commit a01f6f4e7b
24 changed files with 180 additions and 317 deletions

View File

@@ -87,8 +87,8 @@ void AIntegrationGameModeBase::ResetToInitialState()
PlayerId = 0;
// Clear the look-at state;
PreviousLookAt = nullptr;
CurrentLookAt = nullptr;
PreviousLookAt.Init();
CurrentLookAt.Init();
// Reset the clocks.
EngineSeconds = 0.0;
@@ -349,8 +349,8 @@ AIntegrationGameModeBase *AIntegrationGameModeBase::GetFromContext(UObject *cont
void AIntegrationGameModeBase::UpdateLookAt() {
// Rotate the variables.
PreviousLookAt = CurrentLookAt;
CurrentLookAt = nullptr;
CurrentLookAt.Init();
// Make sure the world is fully configured before we attempt to cast rays.
UlxTangible *possessed = TangibleManager->GetPossessedTangible();
if (possessed == nullptr) return;

View File

@@ -47,13 +47,13 @@ public:
int64 GetPlayerId();
UFUNCTION(BlueprintCallable, Category = "Luprex|Look-At Detection")
void SetLookAt(AActor *actor) { CurrentLookAt = actor; }
void SetLookAt(const FHitResult &hit) { CurrentLookAt = hit; }
UFUNCTION(BlueprintCallable, Category = "Luprex|Look-At Detection")
AActor *GetLookAt() const { return CurrentLookAt; }
const FHitResult &GetLookAt() const { return CurrentLookAt; }
UFUNCTION(BlueprintCallable, Category = "Luprex|Look-At Detection")
bool LookAtChanged() const { return CurrentLookAt != PreviousLookAt; }
bool LookAtChanged() const { return CurrentLookAt.HitObjectHandle != PreviousLookAt.HitObjectHandle; }
UFUNCTION(BlueprintImplementableEvent, Category = "Luprex|Look-At Detection")
void CalculateLookAt(AActor *Player, APlayerController *PlayerController, APlayerCameraManager *Camera);
@@ -111,13 +111,13 @@ public:
UPROPERTY()
UlxTangibleManager *TangibleManager;
// The actor that the player is looking at, previous frame.
// The actor that the player was looking at, previous frame.
UPROPERTY()
AActor *PreviousLookAt;
FHitResult PreviousLookAt;
// The actor that the player is looking at, current frame.
UPROPERTY()
AActor *CurrentLookAt;
FHitResult CurrentLookAt;
// The sensitivity level at which a log message triggers a debugger breakpoint.
UPROPERTY(EditAnywhere, Category="Debugging Tools")

View File

@@ -77,45 +77,16 @@ UEnhancedInputLocalPlayerSubsystem *UlxUtilityLibrary::GetEnhancedInputLocalPlay
return nullptr;
}
// bool UlxUtilityLibrary::LineTraceMultipleLines(const AActor* ReferenceActor, const FVector &Offset,
// const TArray<FlxTraceStartTraceEnd> &TraceStartAndTraceEnd, ETraceTypeQuery TraceChannel,
// bool bTraceComplex, const TArray<AActor*>& ActorsToIgnore, EDrawDebugTrace::Type DrawDebugType, FHitResult& OutHit, bool bIgnoreReferenceActor,
// FLinearColor TraceColor, FLinearColor TraceHitColor, float DrawTime)
// {
// OutHit.Init();
// OutHit.Distance = FLT_MAX;
// FTransform ReferenceTransform = ReferenceActor->GetActorTransform();
// for (const FlxTraceStartTraceEnd &Points : TraceStartAndTraceEnd) {
// FHitResult OneResult;
// FVector TraceStart = ReferenceTransform.TransformPosition(Points.TraceStart + Offset);
// FVector TraceEnd = ReferenceTransform.TransformPosition(Points.TraceEnd + Offset);
// bool Found = UKismetSystemLibrary::LineTraceSingle(ReferenceActor, TraceStart, TraceEnd, TraceChannel, bTraceComplex,
// ActorsToIgnore, DrawDebugType, OneResult, bIgnoreReferenceActor, TraceColor, TraceHitColor, DrawTime);
// if (Found && (OneResult.Distance < OutHit.Distance))
// {
// OutHit = OneResult;
// }
// }
// if (OutHit.Distance == FLT_MAX) {
// OutHit.Distance = 0.0;
// return false;
// } else {
// return true;
// }
// }
bool UlxUtilityLibrary::LineTraceThroughMousePointer(const APlayerController* PlayerController,
EMouseSpecificationType MouseSpecification, FVector2D ManualMouseXY, double MaxDistanceFromCamera,
bool UlxUtilityLibrary::LineTraceThroughPixel(const APlayerController* PlayerController,
FVector2D PixelXY, double MaxDistanceFromCamera,
ETraceTypeQuery TraceChannel, bool bTraceComplex, EDrawDebugTrace::Type DrawDebugType, bool bIgnorePlayerPawn,
const TArray<AActor*>& ActorsToIgnore, AActor *& Actor, FHitResult& HitResult)
const TArray<AActor*>& ActorsToIgnore, FHitResult& HitResult)
{
const FLinearColor TraceColor = FLinearColor::Red;
const FLinearColor TraceHitColor = FLinearColor::Green;
const double DrawTime = 1.0;
// Zero out the return values.
Actor = nullptr;
HitResult.Init();
// Sanity check the distance.
@@ -128,35 +99,9 @@ bool UlxUtilityLibrary::LineTraceThroughMousePointer(const APlayerController* Pl
AActor *PlayerPawn = PlayerController->GetPawn();
if (!PlayerPawn) return false;
// Get the Mouse XY.
FVector2D MouseXY;
switch (MouseSpecification)
{
case EMouseSpecificationType::GetMouseAutomatically:
{
double X, Y;
if (!PlayerController->GetMousePosition(X, Y)) return false;
MouseXY = FVector2D(X, Y);
break;
}
case EMouseSpecificationType::SpecifyMouseInPixels:
{
MouseXY = ManualMouseXY;
break;
}
case EMouseSpecificationType::SpecifyMouseAsZeroToOne:
{
int32 VX, VY;
PlayerController->GetViewportSize(VX, VY);
if ((VX == 0) || (VY == 0)) return false;
MouseXY = ManualMouseXY * FVector2D(VX, VY);
break;
}
}
// Calculate the trace start and trace end positions in world space.
FVector WorldStart, WorldDirection, WorldEnd;
if (!UGameplayStatics::DeprojectScreenToWorld(PlayerController, MouseXY, WorldStart, WorldDirection))
if (!UGameplayStatics::DeprojectScreenToWorld(PlayerController, PixelXY, WorldStart, WorldDirection))
{
return false;
}
@@ -166,12 +111,10 @@ bool UlxUtilityLibrary::LineTraceThroughMousePointer(const APlayerController* Pl
if (UKismetSystemLibrary::LineTraceSingle(PlayerPawn, WorldStart, WorldEnd, TraceChannel, bTraceComplex,
ActorsToIgnore, DrawDebugType, HitResult, bIgnorePlayerPawn, TraceColor, TraceHitColor, DrawTime))
{
Actor = HitResult.GetActor();
return true;
}
// Fail.
Actor = nullptr;
HitResult.Init();
return false;
}

View File

@@ -9,31 +9,6 @@
class UEnhancedInputLocalPlayerSubsystem;
USTRUCT(BlueprintType)
struct INTEGRATION_API FlxTraceStartTraceEnd
{
GENERATED_BODY()
UPROPERTY(EditAnywhere)
FVector TraceStart;
UPROPERTY(EditAnywhere)
FVector TraceEnd;
};
UENUM(BlueprintType)
enum class EMouseSpecificationType : uint8
{
// Automatically get the mouse position from the player controller. ManualMouseXY should be left blank.
GetMouseAutomatically,
// Specify the mouse position in pixels.
SpecifyMouseInPixels,
// Specify the mouse position as float from zero to one.
SpecifyMouseAsZeroToOne,
};
/**
*
* UlxUtilityLibrary is for functions that are aren't particularly luprex-specific,
@@ -75,22 +50,18 @@ public:
UFUNCTION(BlueprintCallable, BlueprintPure, Category="Player Controller|Local Player Subsystems")
static UEnhancedInputLocalPlayerSubsystem *GetEnhancedInputLocalPlayerSubsystem(AController *Controller);
// // Do a Line Trace by Channel for each start-and-end pair, then return the closest hit result of all.
// UFUNCTION(BlueprintCallable, Category="Collision", meta=(bIgnoreReferenceActor="true", AutoCreateRefTerm="ActorsToIgnore,Offset", DisplayName="Line Trace Multiple Lines by Channel", AdvancedDisplay="TraceColor,TraceHitColor,DrawTime", Keywords="raycast"))
// static bool LineTraceMultipleLines(const AActor* ReferenceActor, const FVector &Offset,
// const TArray<FlxTraceStartTraceEnd> &TraceStartAndTraceEnd, ETraceTypeQuery TraceChannel,
// bool bTraceComplex, const TArray<AActor*>& ActorsToIgnore, EDrawDebugTrace::Type DrawDebugType, FHitResult& OutHit, bool bIgnoreReferenceActor,
// FLinearColor TraceColor = FLinearColor::Red, FLinearColor TraceHitColor = FLinearColor::Green, float DrawTime = 5.0f);
// Do a Line Trace to find the actor that the mouse is pointing at.
// Do a Line Trace from the camera through a specified pixel.
//
// If you have some crosshairs in the viewport, then you can find the
// object under the crosshairs by specifying the crosshairs XY as the
// ManualMouseXY.
// This can be used when you have a crosshair on the screen and you want to
// determine the object that the crosshairs are pointing at. It can also
// be used to do a line trace through the mouse.
//
// Fractional pixels are allowed. Therefore, (0.0, 0.0) is the upper-left corner
// of the upper-left pixel, whereas (0.5, 0.5) is the center of the upper-left pixel.
//
UFUNCTION(BlueprintCallable, Category="Collision", meta=(AutoCreateRefTerm="ActorsToIgnore", Keywords="raycast"))
static bool LineTraceThroughMousePointer(const APlayerController* PlayerController,
EMouseSpecificationType MouseSpecification, FVector2D ManualMouseXY, double MaxDistanceFromCamera,
static bool LineTraceThroughPixel(const APlayerController* PlayerController,
FVector2D PixelXY, double MaxDistanceFromCamera,
ETraceTypeQuery TraceChannel, bool bTraceComplex, EDrawDebugTrace::Type DrawDebugType, bool bIgnorePlayerPawn,
const TArray<AActor*>& ActorsToIgnore, AActor *& Actor, FHitResult& HitResult);
const TArray<AActor*>& ActorsToIgnore, FHitResult& HitResult);
};