Added Tobii from 4.23 + updated

This commit is contained in:
2023-03-04 04:19:09 +11:00
parent 2d5b9008e5
commit 1cde391516
521 changed files with 11735 additions and 0 deletions

View File

@@ -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;
};

View File

@@ -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;
};