mirror of
https://github.com/litruv/TobiiEyetracking.git
synced 2026-07-25 11:16:10 +10:00
Added Tobii from 4.23 + updated
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
/******************************************************************************
|
||||
* Copyright 2017- Tobii Technology AB. All rights reserved.
|
||||
*
|
||||
* @author Temaran | Fredrik Lindh | fredrik.lindh@tobii.com | https://github.com/Temaran
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/ActorComponent.h"
|
||||
#include "GameFramework/ProjectileMovementComponent.h"
|
||||
|
||||
#include "TobiiProjectileComponent.generated.h"
|
||||
|
||||
UENUM()
|
||||
enum class ETobiiProjectileHomingBehavior
|
||||
{
|
||||
//This is the default behavior. The projectile will accelerate towards the target. This also means the projectile will speed up. If this is not what you want, consider using another behavior.
|
||||
Acceleration,
|
||||
|
||||
//In this mode, imagine the projectile has side thrusters to enable it to turn gradually towards the target. This behavior preserves projectile speed.
|
||||
Steering
|
||||
};
|
||||
|
||||
UENUM()
|
||||
enum class ETobiiProjectileGuidanceSystem
|
||||
{
|
||||
//This is the default behavior. The projectile will home towards the target's last known location.
|
||||
Simple,
|
||||
|
||||
//This mode will predict possible impact times and locations to avoid orbiting. Considers position, velocity and acceleration. Is quite expensive.
|
||||
Prediction,
|
||||
|
||||
//In addition to normal prediction, this guidance system mode will also calculate the closest approach if no direct hit is possible. More expensive than standard prediction
|
||||
ComplexPrediction
|
||||
};
|
||||
|
||||
UCLASS(BlueprintType, Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup=(Tobii))
|
||||
class UTobiiProjectileComponent : public UProjectileMovementComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
//Use this if you need to set starting values from the outside, don't use Velocity.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Projectile")
|
||||
FVector InitialVelocity;
|
||||
|
||||
//If this is true, gravity acceleration will be added to the projectile.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Projectile")
|
||||
bool bAffectedByGravity;
|
||||
|
||||
//If bAffectedByGravity is true, this is the gravity acceleration vector that will be applied to the projectile. If this is zero, the default GetGravityZ will be used.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Projectile")
|
||||
FVector WorldSpaceGravity;
|
||||
|
||||
//If fuel runs out, homing behavior stops for the projectile. 0 means infinite fuel.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Projectile")
|
||||
float InitialFuelSecs;
|
||||
|
||||
//The projectile is destroyed if it manages to stay alive for this amount of time. 0 means infinite lifetime.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Projectile")
|
||||
float MaxLifeTimeSecs;
|
||||
|
||||
public:
|
||||
//Allows you to customize the homing behavior if you have homing projectiles on. The homing target will always be set to the user's gaze target.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Homing")
|
||||
ETobiiProjectileHomingBehavior HomingBehavior;
|
||||
|
||||
//This is the fastest the projectile is able to turn when using the steering homing behavior.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Homing")
|
||||
float SteeringMaxTurnSpeedDegPerSec;
|
||||
|
||||
public:
|
||||
//Allows you to customize the targeting part of the homing behavior. The different options generally provide different trade offs between performance and accuracy. Good accuracy also helps to avoid orbiting projectiles.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Guidance System")
|
||||
ETobiiProjectileGuidanceSystem GuidanceSystem;
|
||||
|
||||
//This is how often the guidance system will update it's target location. A higher frequency will be more expensive but more accurate and vice versa. The guidance system will never update more than once per frame. 0 means every frame.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Guidance System")
|
||||
float GuidanceSystemUpdateFreq;
|
||||
|
||||
//Sometimes you might not want the homing behavior to track targets that are too far off course. This is the maximium angle allowed between the projectile forward vector and the vector towards the target. If this threshold is breached, the homing will stop. 0 means there is no threshold.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Guidance System")
|
||||
float GuidanceSystemMaximumTargetAngleDeg;
|
||||
|
||||
public:
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Guidance System")
|
||||
FVector GuidanceSystemTarget;
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Guidance System")
|
||||
FVector AccelerationVectorTowardsTarget;
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Guidance System")
|
||||
bool bTargetOffCourse;
|
||||
|
||||
public:
|
||||
//This function will attempt to set up the actor to start homing. This entails disabling physics simulation etc. Please note that if the actor is intersecting the ground or other geometry, the simulation might stop immediately since it will "hit" it. To avoid this, set the appropriate collision masks or turn off collision during launch.
|
||||
UFUNCTION(BlueprintCallable, Category = "Homing")
|
||||
void StartHoming(USceneComponent* NewHomingTargetComponent);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Homing")
|
||||
void StopHoming();
|
||||
|
||||
public:
|
||||
UTobiiProjectileComponent();
|
||||
|
||||
public:
|
||||
virtual void BeginPlay() override;
|
||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||
|
||||
virtual FVector ComputeAcceleration(const FVector& InVelocity, float DeltaTime) const override;
|
||||
virtual void SimulateGuidanceSystem();
|
||||
|
||||
private:
|
||||
bool bCanThrust;
|
||||
bool bUsesFuel;
|
||||
float CurrentFuelSecs;
|
||||
float CurrentLifeTime;
|
||||
float GuidanceSystemUpdateTimerSecsLeft;
|
||||
FVector LastTargetVelocity;
|
||||
FVector TargetAcceleration;
|
||||
};
|
||||
@@ -0,0 +1,169 @@
|
||||
/******************************************************************************
|
||||
* Copyright 2017- Tobii Technology AB. All rights reserved.
|
||||
*
|
||||
* @author Temaran | Fredrik Lindh | fredrik.lindh@tobii.com | https://github.com/Temaran
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "TobiiInteractionsTypes.h"
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/ActorComponent.h"
|
||||
#include "Components/PrimitiveComponent.h"
|
||||
|
||||
#include "TobiiThrowAtGazeComponent.generated.h"
|
||||
|
||||
/**
|
||||
* This component will generate gaze contingent throw vectors on demand.
|
||||
* You can use this vector to either simulate a trajectory yourself, or simply apply it to the rigid body of some object.
|
||||
*/
|
||||
UCLASS(BlueprintType, Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = (Tobii))
|
||||
class TOBIIINTERACTIONS_API UTobiiThrowAtGazeComponent : public UActorComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UTobiiThrowAtGazeComponent();
|
||||
|
||||
public:
|
||||
// This is the component that you're trying to hit with the throw. You can set this on the same frame you are trying to throw, but setting it earlier will allow the component to "aim" a bit better. If this is not set, you can still use the component, but it will then try to simply use the gaze vector instead.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Throw@gaze")
|
||||
TWeakObjectPtr<UPrimitiveComponent> ThrowTarget;
|
||||
|
||||
// Throw force applied to the throw vector can never be greater than this value.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Throw@gaze")
|
||||
float MaxThrowSpeedCmPerSecs;
|
||||
|
||||
// This is how high above the thrower the arc apex will be.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Throw@gaze")
|
||||
float ThrowApexOffsetCm;
|
||||
|
||||
// This is how many times we will run the angle finding code. More iterations will mean more tested apexes between the limits below. Setting this to 0 will only run one test using the average of the apexes.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Throw@gaze Configuration")
|
||||
int32 MaxIterations;
|
||||
|
||||
// If this is true, the algorithm will always test low apexes first.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Throw@gaze Configuration")
|
||||
bool bAlwaysPreferLowApex;
|
||||
|
||||
// If this is true, the algorithm will prefer low apexes rather than mid or high ones for a more natural looking throw.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Throw@gaze Configuration")
|
||||
bool bPreferLowApexForTargetsBelowThrower;
|
||||
|
||||
// If this is true, the algorithm will attempt to trace the solution in the world to make sure nothing is in the way.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Throw@gaze Configuration")
|
||||
bool bShouldTraceResult;
|
||||
|
||||
// If bShouldTraceResult is true, an apex smaller than this value will never be tested
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Throw@gaze Configuration")
|
||||
float ThrowApexOffsetMinimumCm;
|
||||
|
||||
// If bShouldTraceResult is true, an apex larger than this value will never be tested
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Throw@gaze Configuration")
|
||||
float ThrowApexOffsetMaximumCm;
|
||||
|
||||
// When testing different apexes, if the delta between the last test and the next one is smaller than this value, tests will be aborted
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Throw@gaze Configuration")
|
||||
float MinimumApexDeltaCm;
|
||||
|
||||
// If bShouldTraceResult is true, this is the size that will be used for tracing. Should be larger or equal to the projectile size.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Throw@gaze Configuration")
|
||||
float TraceRadiusCm;
|
||||
|
||||
// If bShouldTraceResult is true, this is the length of each trace step done.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Throw@gaze Configuration")
|
||||
int32 MaxNrTraceSteps;
|
||||
|
||||
// If bShouldTraceResult is true, this is the length of each trace step done in seconds.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Throw@gaze Configuration")
|
||||
float TraceStepSizeSecs;
|
||||
|
||||
// We don't allow traces longer than this
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Throw@gaze Configuration")
|
||||
float MaxTraceDistance;
|
||||
|
||||
// If we don't have a ThrowTarget, we will consider hits closer than this distance to the target to be "hits"
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Throw@gaze Configuration")
|
||||
float NoTargetAcceptanceThreshold;
|
||||
|
||||
// This is the channel that will be used when tracing.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Throw@gaze Configuration")
|
||||
TEnumAsByte<ECollisionChannel> TraceChannel;
|
||||
|
||||
// If you have any additional actors that should be ignored by the tracing
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Throw@gaze Configuration")
|
||||
TArray<AActor*> TraceIgnoreActors;
|
||||
|
||||
// Let's you ignore this component's owner collision when tracing.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Throw@gaze Configuration")
|
||||
bool bShouldTraceIgnoreOwner;
|
||||
|
||||
// If this is false, the world gravity is used for calculations. If this is true, CustomProjectileGravity is used instead.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Throw@gaze Gravity")
|
||||
bool bUseCustomGravity;
|
||||
|
||||
// If bUseCustomGravity is true, this is the gravity that will be used in calculations
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Throw@gaze Gravity")
|
||||
FVector CustomProjectileGravity;
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintPure, Category = "Fire@gaze")
|
||||
FVector CalculateProjectileGravityVector();
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Fire@gaze")
|
||||
bool ThrowAtGazeAvailable();
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Fire@gaze")
|
||||
bool TraceBallisticProjectilePath(FVector ProjectileOrigin, FVector ProjectileInitialVelocity, TArray<FVector>& OutTracedPath);
|
||||
|
||||
/**
|
||||
* This function is useful when throwing things in XR and you have a throw vector from the player's attempt to throw something.
|
||||
* Don't forget to set collision on the thing you're throwing etc before using this though, otherwise tracing might not work.
|
||||
* It will only correct trajectories where we can expect a direct hit, or where we are simply out of range.
|
||||
*
|
||||
* @param ThrowOrigin This is where the projectile will start.
|
||||
* @param OriginalThrowVector This is the throw vector supplied by the developer to correct.
|
||||
* @param ThrowAngleThresholdDeg If the angle difference between the OriginalThrowVector and the suggested vector is greater than this parameter, the vector will not be corrected. This is not applied if it is 0.
|
||||
* @param ThrowSpeedThreshold If the OriginalThrowVector speed is lower than the suggested vector's speed by at least this amount, the vector will not be corrected. This is measured in centimeters per second. This is not applied if it is 0.
|
||||
* @param bUseSimple If this is true, CalculateThrowAtGazeVectorSimple is used in favor of the Complex version internally
|
||||
* @return The potentially corrected throw vector
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "Throw@gaze")
|
||||
FVector CorrectThrow(const FVector& ThrowOrigin, const FVector& OriginalThrowVector, float ThrowAngleThresholdDeg, float ThrowSpeedThresholdCmPerSec);
|
||||
|
||||
/**
|
||||
* Call this function to request an impulse vector to use for gaze throwing.
|
||||
* This function will start by testing the standard apex and force, and if that works it will just return it.
|
||||
* If no solution is found, the algorithm will test other apex heights until either MaxNrIterations is reached or a result is found.
|
||||
*
|
||||
* @param ThrowOrigin This is where the projectile will start.
|
||||
* @param OutBallisticResult This are our results.
|
||||
* @param OutTracedPath If path tracing is on, this will contain the traced path.
|
||||
* @return The result of the calculation. Please note that in the case of OutOfRange, the best solution will still be returned in OutGazeThrowVector, adjusted to your max throw speed
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "Throw@gaze")
|
||||
ETobiiThrowAtGazeResult CalculateThrowAtGazeVector(const FVector& ThrowOrigin, FTobiiBallisticResult& OutBallisticResult, TArray<FVector>& OutTracedPath);
|
||||
|
||||
/**
|
||||
* This is a companion function to CalculateThrowAtGazeVectorComplex that lets you calculate a throw vector towards a world location.
|
||||
* You can specify target velocity and acceleration if you would like to.
|
||||
*
|
||||
* @param ThrowOrigin This is where the projectile will start.
|
||||
* @param TargetLocation This is where the target is.
|
||||
* @param TargetVelocity This is the target's velocity. Can be zero.
|
||||
* @param TargetAcceleration This is the target's acceleration. Can be zero.
|
||||
* @param OutBallisticResult This are our results.
|
||||
* @param OutTracedPath If path tracing is on, this will contain the traced path.
|
||||
* @return The result of the calculation. Please note that in the case of OutOfRange, the best solution will still be returned in OutGazeThrowVector, adjusted to your max throw speed
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "Throw@gaze")
|
||||
ETobiiThrowAtGazeResult CalculateThrowArc(const FVector& ThrowOrigin, const FVector& TargetLocation, const FVector& TargetVelocity, const FVector& TargetAcceleration, FTobiiBallisticResult& OutBallisticResult, TArray<FVector>& OutTracedPath);
|
||||
|
||||
public:
|
||||
void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
|
||||
|
||||
private:
|
||||
FVector LastTargetVelocity;
|
||||
FVector CalculatedTargetAcceleration;
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
/******************************************************************************
|
||||
* Copyright 2017- Tobii Technology AB. All rights reserved.
|
||||
*
|
||||
* @author Temaran | Fredrik Lindh | fredrik.lindh@tobii.com | https://github.com/Temaran
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/ActorComponent.h"
|
||||
|
||||
#include "TobiiAimAtGazeComponent.generated.h"
|
||||
|
||||
UCLASS(BlueprintType, Blueprintable, meta = (BlueprintSpawnableComponent))
|
||||
class TOBIIINTERACTIONS_API UTobiiAimAtGazeComponent : public UActorComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UTobiiAimAtGazeComponent();
|
||||
|
||||
public:
|
||||
//This controls how the filters in FocusFilterList are used. If this is true, only focusables with a layer that is in the FocusFilterList will be considered. If this is false, the FocusFilterList will act like a black list, excluding any focusables whos layer can be found in the array.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Gaze Focus Management")
|
||||
bool bIsWhiteList;
|
||||
|
||||
//These are the filters that will determine what focus data you will receive. The behavior of the filters are controlled by bIsWhiteList.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Gaze Focus Management")
|
||||
TArray<FName> FocusLayerFilters;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Aim@gaze")
|
||||
bool bAllowRetarget;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Aim@gaze")
|
||||
float AimSpeed;
|
||||
|
||||
public:
|
||||
//Use this to test if the user has turned aim@gaze on and it is available.
|
||||
UFUNCTION(BlueprintPure, Category = "Aim@gaze")
|
||||
bool AimAtGazeAvailable();
|
||||
|
||||
//Trigger an aim@gaze
|
||||
UFUNCTION(BlueprintCallable, Category = "Aim@gaze")
|
||||
void AimAtGaze();
|
||||
|
||||
//Call this every frame you want to continually track the aim@gaze target
|
||||
UFUNCTION(BlueprintCallable, Category = "Aim@gaze")
|
||||
void ContinuousAimAtGaze();
|
||||
|
||||
/************************************************************************/
|
||||
/* UActorComponent */
|
||||
/************************************************************************/
|
||||
public:
|
||||
virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
|
||||
|
||||
private:
|
||||
TWeakObjectPtr<class UPrimitiveComponent> CurrentFocusComponent;
|
||||
FVector CurrentAimTarget;
|
||||
bool bIsGazeAiming;
|
||||
};
|
||||
@@ -0,0 +1,68 @@
|
||||
/******************************************************************************
|
||||
* Copyright 2017- Tobii Technology AB. All rights reserved.
|
||||
*
|
||||
* @author Temaran | Fredrik Lindh | fredrik.lindh@tobii.com | https://github.com/Temaran
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/ActorComponent.h"
|
||||
|
||||
#include "TobiiFireAtGazeComponent.generated.h"
|
||||
|
||||
UENUM(BlueprintType)
|
||||
enum class ETobiiFireAtGazeNoTargetBehavior : uint8
|
||||
{
|
||||
PointGunForward,
|
||||
PointGunToGaze
|
||||
};
|
||||
|
||||
UCLASS(BlueprintType, Blueprintable, meta = (BlueprintSpawnableComponent))
|
||||
class TOBIIINTERACTIONS_API UTobiiFireAtGazeComponent : public UActorComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UTobiiFireAtGazeComponent();
|
||||
|
||||
public:
|
||||
//This controls how the filters in FocusFilterList are used. If this is true, only focusables with a layer that is in the FocusFilterList will be considered. If this is false, the FocusFilterList will act like a black list, excluding any focusables whos layer can be found in the array.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Gaze Focus Management")
|
||||
bool bIsWhiteList;
|
||||
|
||||
//These are the filters that will determine what focus data you will receive. The behavior of the filters are controlled by bIsWhiteList.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Gaze Focus Management")
|
||||
TArray<FName> FocusLayerFilters;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Fire@gaze")
|
||||
class UCameraComponent* CameraComponent;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Fire@gaze")
|
||||
TWeakObjectPtr<AActor> FireAtGazeTargetActor;
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Fire@gaze")
|
||||
TWeakObjectPtr<UPrimitiveComponent> FireAtGazeTargetComponent;
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Fire@gaze")
|
||||
FVector FireAtGazeTargetLocation;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Fire@gaze Settings")
|
||||
float MaxDistance;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Fire@gaze Settings")
|
||||
ETobiiFireAtGazeNoTargetBehavior NoTargetBehavior;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Fire@gaze Settings")
|
||||
TEnumAsByte<ECollisionChannel> TraceChannel;
|
||||
|
||||
public:
|
||||
//Use this to test if the user has turned fire@gaze on and it is available.
|
||||
UFUNCTION(BlueprintPure, Category = "Fire@gaze")
|
||||
bool FireAtGazeAvailable();
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Fire@gaze")
|
||||
bool WantsCrosshair();
|
||||
|
||||
/************************************************************************/
|
||||
/* UActorComponent */
|
||||
/************************************************************************/
|
||||
public:
|
||||
virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
|
||||
};
|
||||
@@ -0,0 +1,103 @@
|
||||
/******************************************************************************
|
||||
* Copyright 2017- Tobii Technology AB. All rights reserved.
|
||||
*
|
||||
* @author Temaran | Fredrik Lindh | fredrik.lindh@tobii.com | https://github.com/Temaran
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "TobiiInteractionsTypes.h"
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "Kismet/BlueprintFunctionLibrary.h"
|
||||
|
||||
#include "TobiiInteractionsBlueprintLibrary.generated.h"
|
||||
|
||||
/**
|
||||
* Simplified interface for blueprint use. Only exposes the features most likely to be consumed from BP.
|
||||
*/
|
||||
UCLASS()
|
||||
class TOBIIINTERACTIONS_API UTobiiInteractionsBlueprintLibrary : public UBlueprintFunctionLibrary
|
||||
{
|
||||
GENERATED_UCLASS_BODY()
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintPure, Category = "Tobii Desktop Interaction")
|
||||
static bool IsInfiniteScreenEnabled();
|
||||
|
||||
//Util functions to see if the feature can be considered enabled by the user.
|
||||
UFUNCTION(BlueprintPure, Category = "Tobii Desktop Interaction")
|
||||
static bool IsCleanUIEnabled();
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Tobii Desktop Interaction")
|
||||
static bool IsAimAtGazeEnabled();
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Tobii Desktop Interaction")
|
||||
static bool IsFireAtGazeEnabled();
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Tobii Desktop Interaction")
|
||||
static bool IsThrowAtGazeEnabled();
|
||||
|
||||
public:
|
||||
/**
|
||||
* This function will determine an appropriate amount to dampen infinite screen depending on view pitch.
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "Tobii Infinite Screen")
|
||||
static float CalculateSmoothPitchStep(float ViewPitch);
|
||||
|
||||
/**
|
||||
* This function will determine an appropriate amount to dampen infinite screen depending on view pitch.
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "Tobii Infinite Screen")
|
||||
static FRotator MakeInfiniteScreenCameraRotator(FRotator OriginalCameraRotation, FRotator InfiniteScreenAngles);
|
||||
|
||||
public:
|
||||
/*
|
||||
* Render UI to a texture so we can use it on arbitrary meshes.
|
||||
* Thanks to https://answers.unrealengine.com/questions/353532/rendering-a-umg-widget-on-a-static-mesh.html for this.
|
||||
*/
|
||||
UTexture2D* TextureFromWidget(UUserWidget* const Widget, const FVector2D& DrawSize);
|
||||
|
||||
/**
|
||||
* This function will find and return all real roots to the square equation Ax^2 + Bx + C = 0
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "Tobii Math Utils")
|
||||
static void FindRealSquareRoots(float A, float B, float C, TArray<float>& OutRealRoots);
|
||||
|
||||
/**
|
||||
* This function will find and return all real roots to the cubic equation Ax^3 + Bx^2 + Cx + D = 0
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "Tobii Math Utils")
|
||||
static void FindRealCubicRoots(float A, float B, float C, float D, TArray<float>& OutRealRoots);
|
||||
|
||||
/**
|
||||
* This function will find and return all real roots to the quartic equation Ax^4 + Bx^3 + Cx^2 + Dx + E = 0
|
||||
* WARNING: The roots of a full degree quartic are generally not cheap to compute. Use with care.
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "Tobii Math Utils")
|
||||
static void FindRealQuarticRoots(float A, float B, float C, float D, float E, TArray<float>& OutRealRoots);
|
||||
|
||||
/**
|
||||
* This function will try to find which acceleration you will need for the current frame to hit a certain target given a homing projectile that uses acceleration for it's movement behavior.
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "Tobii Math Utils")
|
||||
static bool FindNeededAccelerationForAccelerationBasedHomingProjectile(const FTobiiAccelerationBasedHomingData& InputData, FTobiiAccelerationBasedHomingResult& BestResult);
|
||||
|
||||
/**
|
||||
* This function will try to find the initial velocity needed to hit a moving target with a ballistic projectile that passes through a selected apex point.
|
||||
* To find an arc that works with your environment and thrower you might have to call this function multiple times and trace the results in your scene.
|
||||
*
|
||||
* @return Whether a valid velocity could be found. If this is false, it usually means that SourceZ + ProjectileApexOffset was smaller than TargetZ. Try increasing the apex offset and try again.
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "Tobii Math Utils")
|
||||
static bool FindNeededInitialVelocityForBallisticProjectile(const FTobiiBallisticData& InputData, TArray<FTobiiBallisticResult>& Results);
|
||||
|
||||
/**
|
||||
* This function will trace along a ballistic path until it hits something. It will then return the traced path as well as what it hit.
|
||||
*
|
||||
* @return Whether anything was hit tracing the path
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "Tobii Math Utils", meta = (WorldContext = "WorldContextObject"))
|
||||
static bool TraceBallisticProjectilePath(UObject* WorldContextObject, const FTobiiProjectileTraceData& InputData, TArray<FVector>& OutTracedPath, FHitResult& OutHitResult);
|
||||
};
|
||||
146
Source/TobiiInteractions/Public/TobiiInteractionsTypes.h
Normal file
146
Source/TobiiInteractions/Public/TobiiInteractionsTypes.h
Normal file
@@ -0,0 +1,146 @@
|
||||
/******************************************************************************
|
||||
* Copyright 2017- Tobii Technology AB. All rights reserved.
|
||||
*
|
||||
* @author Temaran | Fredrik Lindh | fredrik.lindh@tobii.com | https://github.com/Temaran
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "CollisionQueryParams.h"
|
||||
|
||||
#include "TobiiInteractionsTypes.generated.h"
|
||||
|
||||
UENUM(BlueprintType)
|
||||
enum class ETobiiInterceptType : uint8
|
||||
{
|
||||
ClosestApproach,
|
||||
DirectHit
|
||||
};
|
||||
|
||||
UENUM(BlueprintType)
|
||||
enum class ETobiiThrowAtGazeResult : uint8
|
||||
{
|
||||
// Bad input in some way
|
||||
UnknownError,
|
||||
|
||||
// Neither a throw target, nor gaze input is available
|
||||
NoEyetrackingInput,
|
||||
|
||||
// If no valid path could be found
|
||||
NoPath,
|
||||
|
||||
// A path is mathematically possible, but it is blocked by something and out of range.
|
||||
BlockedByWorldAndOutOfRange,
|
||||
|
||||
// A path is mathematically possible and is within range, but it is blocked by something.
|
||||
BlockedByWorldInRange,
|
||||
|
||||
// If a valid path could be found, but it requires more throw force than allowed
|
||||
OutOfRange,
|
||||
|
||||
// If a valid path exists and the force requirement is within limits
|
||||
DirectHit
|
||||
};
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct FTobiiAccelerationBasedHomingData
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "General Data")
|
||||
bool bAttemptClosestApproachSolution;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Source Data")
|
||||
FVector ProjectilePosition;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Source Data")
|
||||
FVector ProjectileVelocity;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Source Data")
|
||||
float ProjectileAccelerationMagnitude;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Target Data")
|
||||
FVector TargetPosition;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Target Data")
|
||||
FVector TargetVelocity;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Target Data")
|
||||
FVector TargetAcceleration;
|
||||
};
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct FTobiiBallisticData
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
//This is how high the projectile should be above the initial position at it's midpoint
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "General Data")
|
||||
float ProjectileApexOffsetCm;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Source Data")
|
||||
FVector ProjectileInitialPosition;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Source Data")
|
||||
FVector ProjectileAcceleration;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Target Data")
|
||||
FVector TargetPosition;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Target Data")
|
||||
FVector TargetVelocity;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Target Data")
|
||||
FVector TargetAcceleration;
|
||||
};
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct FTobiiAccelerationBasedHomingResult
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Intercept Data")
|
||||
ETobiiInterceptType Type;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Intercept Data")
|
||||
FVector SuggestedAcceleration;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Intercept Data")
|
||||
FVector ExpectedInterceptLocation;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Intercept Data")
|
||||
float ExpectedInterceptTimeSecs;
|
||||
};
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct FTobiiBallisticResult
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Intercept Data")
|
||||
FVector SuggestedInitialVelocity;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Intercept Data")
|
||||
FVector ExpectedInterceptLocation;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Intercept Data")
|
||||
float ExpectedInterceptTimeSecs;
|
||||
};
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct FTobiiProjectileTraceData
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "General Data")
|
||||
TEnumAsByte<ECollisionChannel> TraceChannel;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "General Data")
|
||||
TArray<AActor*> IgnoredActors;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "General Data")
|
||||
int32 MaxNrSteps;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "General Data")
|
||||
float StepSizeSecs;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "General Data")
|
||||
float TraceRadiusCm;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Source Data")
|
||||
FVector ProjectileInitialPosition;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Source Data")
|
||||
FVector ProjectileVelocity;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Source Data")
|
||||
FVector ProjectileAcceleration;
|
||||
};
|
||||
Reference in New Issue
Block a user