Skip to content
Snippets Groups Projects
Commit 2f151103 authored by Timon Römer's avatar Timon Römer
Browse files

Adds documentation for Scoring Behaviours

parent 9b6c72e9
No related branches found
No related tags found
1 merge request!87Merge IntenSelect into dev5.3
Showing
with 324 additions and 3 deletions
...@@ -12,37 +12,62 @@ class UClickBehaviour; ...@@ -12,37 +12,62 @@ class UClickBehaviour;
class USelectionBehaviour; class USelectionBehaviour;
class UIntenSelectComponent; class UIntenSelectComponent;
/**
* A component designed to make an actor selectable within IntenSelect, handling various aspects
* of interaction including scoring, hover, and action behaviors.
*/
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent)) UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class RWTHVRTOOLKIT_API UIntenSelectable : public UActorComponent class RWTHVRTOOLKIT_API UIntenSelectable : public UActorComponent
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
/** Whether the actor can be selected. */
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool IsSelectable = true; bool IsSelectable = true;
/** Collection of scoring behaviors that define how selection scores are calculated for this actor. */
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<UIntenSelectableScoring*> ScoringBehaviours; TArray<UIntenSelectableScoring*> ScoringBehaviours;
/** Collection of behaviors that define what happens when this actor is hovered over. */
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<UHoverBehaviour*> OnHoverBehaviours; TArray<UHoverBehaviour*> OnHoverBehaviours;
/** Collection of behaviors that define what happens when an action is performed on this actor. */
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<UActionBehaviour*> OnActionBehaviours; TArray<UActionBehaviour*> OnActionBehaviours;
public:
UIntenSelectable(); UIntenSelectable();
/**
* Computes the best point and score for selection based on defined criteria and behaviors.
*
* @param ConeOrigin The origin point of the selection cone.
* @param ConeForwardDirection The forward direction of the selection cone.
* @param ConeBackwardShiftDistance The distance to shift the cone's origin backwards.
* @param ConeAngle The angle of the selection cone.
* @param LastValue The last score value calculated for ongoing adjustments.
* @param DeltaTime Time elapsed since the last score calculation.
* @return A pair containing the best hit result and its corresponding score.
*/
TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin, const FVector& ConeForwardDirection, TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle, const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime) const; const float LastValue, const float DeltaTime) const;
/** Handles events when hover starts over this actor. */
void HandleOnHoverStartEvents(const UIntenSelectComponent* IntenSelect, const FHitResult& HitResult); void HandleOnHoverStartEvents(const UIntenSelectComponent* IntenSelect, const FHitResult& HitResult);
/** Handles events when hover ends over this actor. */
void HandleOnHoverEndEvents(const UIntenSelectComponent* IntenSelect); void HandleOnHoverEndEvents(const UIntenSelectComponent* IntenSelect);
/** Handles events when an action starts on this actor. */
void HandleOnActionStartEvents(UIntenSelectComponent* IntenSelect); void HandleOnActionStartEvents(UIntenSelectComponent* IntenSelect);
/** Handles events when an action ends on this actor. */
void HandleOnActionEndEvents(UIntenSelectComponent* IntenSelect, FInputActionValue& InputValue); void HandleOnActionEndEvents(UIntenSelectComponent* IntenSelect, FInputActionValue& InputValue);
/** Initializes default references for the component's behaviors. Useful for setting up initial states. */
void InitDefaultBehaviourReferences(); void InitDefaultBehaviourReferences();
protected: protected:
......
...@@ -4,23 +4,48 @@ ...@@ -4,23 +4,48 @@
#include "IntenSelectableScoring.h" #include "IntenSelectableScoring.h"
#include "IntenSelectableCircleScoring.generated.h" #include "IntenSelectableCircleScoring.generated.h"
/**
* A component for calculating and managing scores for selectable objects within a circular area.
*/
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent)) UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class RWTHVRTOOLKIT_API UIntenSelectableCircleScoring : public UIntenSelectableScoring class RWTHVRTOOLKIT_API UIntenSelectableCircleScoring : public UIntenSelectableScoring
{ {
GENERATED_BODY() GENERATED_BODY()
protected: protected:
/**
* Determines the closest point within a circle to a given point, taking into account the direction of selection.
*
* @param Point The point from which to find the closest selection point.
* @param Direction The direction in which the selection is being made.
* @return The closest point within the circle to the specified point, considering the given direction.
*/
FVector GetClosestSelectionPointTo(const FVector& Point, const FVector& Direction) const; FVector GetClosestSelectionPointTo(const FVector& Point, const FVector& Direction) const;
public: public:
UIntenSelectableCircleScoring(); UIntenSelectableCircleScoring();
/** If true, selection scoring is only considered on the outline of the circle. Otherwise, the entire area is
* considered. */
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
bool OnlyOutline = true; bool OnlyOutline = true;
/** The radius of the circle used for selection scoring. */
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
float Radius = 50; float Radius = 50;
/**
* Overrides the parent class's method to calculate the best point and score pair for selection within a circular
* area.
*
* @param ConeOrigin The origin point of the cone used for selection.
* @param ConeForwardDirection The forward direction of the cone used for selection.
* @param ConeBackwardShiftDistance The distance to shift the cone's origin backwards, for selection purposes.
* @param ConeAngle The angle of the cone in degrees, used for selection.
* @param LastValue The last score value calculated for this point, used for selection.
* @param DeltaTime The time elapsed since the last score calculation, used for selection.
* @return A pair containing the hit result and the score for the best point within the circular area.
*/
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin, virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle, const float ConeBackwardShiftDistance, const float ConeAngle,
......
...@@ -4,15 +4,37 @@ ...@@ -4,15 +4,37 @@
#include "IntenSelectableScoring.h" #include "IntenSelectableScoring.h"
#include "IntenSelectableCubeScoring.generated.h" #include "IntenSelectableCubeScoring.generated.h"
/**
* A component that specializes in calculating and managing selection scores within a cubic area.
*/
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent)) UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class RWTHVRTOOLKIT_API UIntenSelectableCubeScoring : public UIntenSelectableScoring class RWTHVRTOOLKIT_API UIntenSelectableCubeScoring : public UIntenSelectableScoring
{ {
GENERATED_BODY() GENERATED_BODY()
protected: protected:
/**
* Determines if two lines intersect, which is critical for calculating selection boundaries
* and interactions within or around the cube.
*
* @param FromA The starting point of the first line.
* @param FromB The ending point of the first line.
* @param ToA The starting point of the second line.
* @param ToB The ending point of the second line.
* @param OutIntersection Output parameter that will be filled with the intersection point if an intersection
* occurs.
* @return true if the lines intersect; otherwise, false.
*/
static bool LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA, static bool LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA,
const FVector& ToB, FVector& OutIntersection); const FVector& ToB, FVector& OutIntersection);
/**
* Calculates the closest point within the cube to a given ray, which is essential for selection scoring.
*
* @param RayOrigin The origin of the ray.
* @param RayDirection The direction of the ray.
* @return The closest point within the cube to the specified ray.
*/
FVector GetClosestSelectionPointTo(const FVector& RayOrigin, const FVector& RayDirection) const; FVector GetClosestSelectionPointTo(const FVector& RayOrigin, const FVector& RayDirection) const;
virtual void TickComponent(float DeltaTime, ELevelTick TickType, virtual void TickComponent(float DeltaTime, ELevelTick TickType,
...@@ -21,17 +43,42 @@ protected: ...@@ -21,17 +43,42 @@ protected:
public: public:
UIntenSelectableCubeScoring(); UIntenSelectableCubeScoring();
/** Whether back faces of the cube should be considered in the selection process. */
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
bool BackFaceCulling = false; bool BackFaceCulling = false;
/** If true, selection scoring is only considered on the outline of the cube, not the volume. */
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
bool OnlyOutline = false; bool OnlyOutline = false;
/**
* Overrides the base class method to compute the best point and score pair for selection within a cubic volume,
* considering the unique properties and geometry of the cube.
*
* @param ConeOrigin The origin point of the cone used for selection.
* @param ConeForwardDirection The forward direction of the cone.
* @param ConeBackwardShiftDistance How far to shift the cone's origin backward for selection purposes.
* @param ConeAngle The angle of the cone in degrees, used to define the selection area.
* @param LastValue The last score value calculated, useful for continuous adjustments of the selection score.
* @param DeltaTime Time since the last score calculation.
* @return A pair containing the hit result and the score for the best point within the cubic volume.
*/
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin, virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle, const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime) override; const float LastValue, const float DeltaTime) override;
/**
* Finds the closest point on a rectangle, part of the cube, to a given start point, projecting in a specified
* direction. This function is useful for determining interaction points on the cube's surface.
*
* @param StartPoint The point from which closeness is measured.
* @param Direction The direction in which the closeness is projected.
* @param Corner00 One corner of the rectangle.
* @param Corner01 Adjacent corner to Corner00.
* @param Corner10 Adjacent corner to Corner00, opposite to Corner01.
* @return The closest point on the rectangle to the given start point.
*/
FVector GetClosestPointToRectangle(const FVector& StartPoint, const FVector& Direction, const FVector& Corner00, FVector GetClosestPointToRectangle(const FVector& StartPoint, const FVector& Direction, const FVector& Corner00,
const FVector& Corner01, const FVector& Corner10) const; const FVector& Corner01, const FVector& Corner10) const;
}; };
...@@ -4,15 +4,37 @@ ...@@ -4,15 +4,37 @@
#include "IntenSelectableScoring.h" #include "IntenSelectableScoring.h"
#include "IntenSelectableCylinderScoring.generated.h" #include "IntenSelectableCylinderScoring.generated.h"
/**
* A component for calculating and managing scores for selectable objects within a cylindrical area.
*/
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent)) UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class RWTHVRTOOLKIT_API UIntenSelectableCylinderScoring : public UIntenSelectableScoring class RWTHVRTOOLKIT_API UIntenSelectableCylinderScoring : public UIntenSelectableScoring
{ {
GENERATED_BODY() GENERATED_BODY()
protected: protected:
/**
* Checks for intersection between two lines, which is useful for calculations involving
* the cylinder's geometry and selection logic.
*
* @param FromA The starting point of the first line.
* @param FromB The ending point of the first line.
* @param ToA The starting point of the second line.
* @param ToB The ending point of the second line.
* @param OutIntersection If an intersection exists, this parameter will be filled with the point of intersection.
* @return true if there is an intersection; false otherwise.
*/
static bool LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA, static bool LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA,
const FVector& ToB, FVector& OutIntersection); const FVector& ToB, FVector& OutIntersection);
/**
* Determines the closest point on the cylinder to a given ray, which can be used to calculate
* selection scores based on proximity and directionality.
*
* @param Point The origin point of the ray.
* @param Direction The direction of the ray.
* @return The closest point on the cylinder to the specified ray.
*/
FVector GetClosestSelectionPointTo(const FVector& Point, const FVector& Direction) const; FVector GetClosestSelectionPointTo(const FVector& Point, const FVector& Direction) const;
virtual void TickComponent(float DeltaTime, ELevelTick TickType, virtual void TickComponent(float DeltaTime, ELevelTick TickType,
...@@ -21,14 +43,28 @@ protected: ...@@ -21,14 +43,28 @@ protected:
public: public:
UIntenSelectableCylinderScoring(); UIntenSelectableCylinderScoring();
/**
* Overrides the parent class method to calculate the best point and score pair for selection
* within a cylindrical volume, taking into account the unique geometry of a cylinder.
*
* @param ConeOrigin The origin point of the cone used for selection.
* @param ConeForwardDirection The forward direction of the cone.
* @param ConeBackwardShiftDistance How far to shift the cone's origin backward for selection.
* @param ConeAngle The angle of the cone, in degrees, used for determining the selection area.
* @param LastValue The last score value calculated, used for continuous adjustments.
* @param DeltaTime Time since the last score calculation.
* @return A pair containing the hit result and score for the best selection point.
*/
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin, virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle, const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime) override; const float LastValue, const float DeltaTime) override;
/** Defines the end points of the cylinder's central axis, used in selection calculations. */
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
TArray<FVector> LinePoints{FVector::UpVector * 50, FVector::DownVector * 50}; TArray<FVector> LinePoints{FVector::UpVector * 50, FVector::DownVector * 50};
/** The radius of the cylinder, important for determining the cylindrical selection area. */
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
float Radius = 50; float Radius = 50;
}; };
...@@ -4,15 +4,37 @@ ...@@ -4,15 +4,37 @@
#include "IntenSelectableScoring.h" #include "IntenSelectableScoring.h"
#include "IntenSelectableLineScoring.generated.h" #include "IntenSelectableLineScoring.generated.h"
/**
* A component that specializes in calculating and managing scores for selectable objects along a line.
*/
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent)) UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class RWTHVRTOOLKIT_API UIntenSelectableLineScoring : public UIntenSelectableScoring class RWTHVRTOOLKIT_API UIntenSelectableLineScoring : public UIntenSelectableScoring
{ {
GENERATED_BODY() GENERATED_BODY()
protected: protected:
/**
* Checks for the intersection between two lines, which is crucial for determining
* the selection points and scoring along lines.
*
* @param FromA Starting point of the first line.
* @param FromB Ending point of the first line.
* @param ToA Starting point of the second line.
* @param ToB Ending point of the second line.
* @param OutIntersection Output parameter that will be populated with the intersection point, if it exists.
* @return true if an intersection occurs; false otherwise.
*/
static bool LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA, static bool LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA,
const FVector& ToB, FVector& OutIntersection); const FVector& ToB, FVector& OutIntersection);
/**
* Determines the closest point on the line to a given point, considering a specific direction.
* This method is pivotal for line-based selection scoring calculations.
*
* @param Point The reference point from which to find the closest point on the line.
* @param Direction The direction from the reference point towards the line.
* @return The closest point on the line to the specified point and direction.
*/
FVector GetClosestSelectionPointTo(const FVector& Point, const FVector& Direction) const; FVector GetClosestSelectionPointTo(const FVector& Point, const FVector& Direction) const;
virtual void TickComponent(float DeltaTime, ELevelTick TickType, virtual void TickComponent(float DeltaTime, ELevelTick TickType,
...@@ -21,11 +43,27 @@ protected: ...@@ -21,11 +43,27 @@ protected:
public: public:
UIntenSelectableLineScoring(); UIntenSelectableLineScoring();
/**
* Overrides the parent class's method to calculate the best point and score pair for selection
* within a line, accounting for the unique linear geometry.
*
* @param ConeOrigin The origin point of the cone used for selection.
* @param ConeForwardDirection The forward direction of the cone.
* @param ConeBackwardShiftDistance The distance to shift the cone's origin backward for selection purposes.
* @param ConeAngle The angle of the cone in degrees, defining the selection area.
* @param LastValue The last score value calculated, for continuous selection logic adjustments.
* @param DeltaTime Time elapsed since the last score calculation.
* @return A pair containing the hit result and the score for the best point along the line.
*/
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin, virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle, const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime) override; const float LastValue, const float DeltaTime) override;
/**
* Defines the endpoints of the line used for selection scoring. The selection logic will
* consider these points to calculate the closest point and score along the line.
*/
UPROPERTY(EditAnywhere, meta = (EditFixedSize)) UPROPERTY(EditAnywhere, meta = (EditFixedSize))
TArray<FVector> LinePoints{FVector::RightVector * 50, FVector::LeftVector * 50}; TArray<FVector> LinePoints{FVector::RightVector * 50, FVector::LeftVector * 50};
}; };
...@@ -4,24 +4,53 @@ ...@@ -4,24 +4,53 @@
#include "IntenSelectableScoring.h" #include "IntenSelectableScoring.h"
#include "IntenSelectableMultiPointScoring.generated.h" #include "IntenSelectableMultiPointScoring.generated.h"
/**
* A component that specializes in calculating and managing selection scores based on multiple points.
*/
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent)) UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class RWTHVRTOOLKIT_API UIntenSelectableMultiPointScoring : public UIntenSelectableScoring class RWTHVRTOOLKIT_API UIntenSelectableMultiPointScoring : public UIntenSelectableScoring
{ {
GENERATED_BODY() GENERATED_BODY()
protected: protected:
/**
* Calculates the closest selection point to a given reference point, factoring in a specific direction.
* This function is crucial for multi-point selection scenarios, where the closest point
* within a set needs to be determined based on proximity and direction.
*
* @param Point The reference point from which to find the closest selection point.
* @param Direction The direction from the reference point towards the selection points.
* @return The closest point from the provided set to the specified reference point and direction.
*/
FVector GetClosestSelectionPointTo(const FVector& Point, const FVector& Direction) const; FVector GetClosestSelectionPointTo(const FVector& Point, const FVector& Direction) const;
public: public:
UIntenSelectableMultiPointScoring(); UIntenSelectableMultiPointScoring();
/**
* Overrides the base class method to calculate the best point and score pair from among multiple points,
* based on the specified selection criteria.
*
* @param ConeOrigin The origin point of the cone used for selection.
* @param ConeForwardDirection The forward direction of the cone.
* @param ConeBackwardShiftDistance The distance to shift the cone's origin backward for selection purposes.
* @param ConeAngle The angle of the cone in degrees, defining the selection area.
* @param LastValue The last score value calculated, for continuous adjustments of the selection score.
* @param DeltaTime Time elapsed since the last score calculation.
* @return A pair containing the hit result and the score for the best point among the multiple points.
*/
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin, virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle, const float ConeBackwardShiftDistance, const float ConeAngle,
const float LastValue, const float DeltaTime) override; const float LastValue, const float DeltaTime) override;
/**
* Updates the set of points to be considered for selection. This can be used to dynamically
* change the points that are eligible for selection, based on gameplay or application logic.
*/
void UpdatePoints(); void UpdatePoints();
/** The set of points to consider for selection. These points are evaluated to find the best selection score. */
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<FVector> PointsToSelect; TArray<FVector> PointsToSelect;
}; };
...@@ -4,15 +4,37 @@ ...@@ -4,15 +4,37 @@
#include "IntenSelectableScoring.h" #include "IntenSelectableScoring.h"
#include "IntenSelectableRectangleScoring.generated.h" #include "IntenSelectableRectangleScoring.generated.h"
/**
* A component for calculating and managing scores for selectable objects within a rectangular area.
*/
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent)) UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class RWTHVRTOOLKIT_API UIntenSelectableRectangleScoring : public UIntenSelectableScoring class RWTHVRTOOLKIT_API UIntenSelectableRectangleScoring : public UIntenSelectableScoring
{ {
GENERATED_BODY() GENERATED_BODY()
protected: protected:
/**
* Determines if two lines intersect, which is particularly useful in calculating
* selection boundaries and points within the rectangle.
*
* @param FromA Starting point of the first line.
* @param FromB Ending point of the first line.
* @param ToA Starting point of the second line.
* @param ToB Ending point of the second line.
* @param OutIntersection Output parameter filled with the intersection point, if any.
* @return true if the lines intersect, false otherwise.
*/
static bool LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA, static bool LineToLineIntersection(const FVector& FromA, const FVector& FromB, const FVector& ToA,
const FVector& ToB, FVector& OutIntersection); const FVector& ToB, FVector& OutIntersection);
/**
* Calculates the closest point within the rectangle to a given ray, which is essential
* for determining selection scores based on the geometry of rectangular areas.
*
* @param Point The origin point of the ray.
* @param Direction The direction of the ray.
* @return The closest point within the rectangle to the specified ray.
*/
FVector GetClosestSelectionPointTo(const FVector& Point, const FVector& Direction) const; FVector GetClosestSelectionPointTo(const FVector& Point, const FVector& Direction) const;
virtual void TickComponent(float DeltaTime, ELevelTick TickType, virtual void TickComponent(float DeltaTime, ELevelTick TickType,
...@@ -21,17 +43,32 @@ protected: ...@@ -21,17 +43,32 @@ protected:
public: public:
UIntenSelectableRectangleScoring(); UIntenSelectableRectangleScoring();
/** If true, only the outline of the rectangle is considered for selection scoring. */
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
bool OnlyOutline = false; bool OnlyOutline = false;
/** The length of the rectangle along the X-axis. */
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
float XLength = 100; float XLength = 100;
/** The length of the rectangle along the Y-axis. */
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
float YLength = 100; float YLength = 100;
/**
* Calculates the best point and score pair for selection within a rectangular area,
* taking into account the unique properties and dimensions of the rectangle.
*
* @param ConeOrigin Origin point of the cone used for selection.
* @param ConeForwardDirection Forward direction of the cone used for selection.
* @param ConeBackwardShiftDistance Distance to shift the cone's origin backward for selection purposes.
* @param ConeAngle Angle of the cone in degrees, used to define the selection area.
* @param LastValue Last score value calculated, useful for continuous selection logic.
* @param DeltaTime Time elapsed since the last score calculation.
* @return A pair containing the hit result and the score for the best selection point within the rectangle.
*/
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin, virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle, const float ConeBackwardShiftDistance, float ConeAngle,
const float LastValue, const float DeltaTime) override; const float LastValue, const float DeltaTime) override;
}; };
...@@ -4,12 +4,27 @@ ...@@ -4,12 +4,27 @@
#include "Components/SceneComponent.h" #include "Components/SceneComponent.h"
#include "IntenSelectableScoring.generated.h" #include "IntenSelectableScoring.generated.h"
/**
* A component for calculating and managing scores for selectable objects.
*/
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent)) UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class RWTHVRTOOLKIT_API UIntenSelectableScoring : public USceneComponent class RWTHVRTOOLKIT_API UIntenSelectableScoring : public USceneComponent
{ {
GENERATED_BODY() GENERATED_BODY()
protected: protected:
/**
* Calculates a score based on the position and orientation of a cone, and a test point within the environment.
*
* @param ConeOrigin The origin point of the cone.
* @param ConeForwardDirection The forward direction of the cone.
* @param ConeBackwardShiftDistance The distance to shift the cone's origin backwards.
* @param ConeAngle The angle of the cone in degrees.
* @param TestPoint The point in the environment to test against the cone.
* @param LastValue The last score value calculated for this point.
* @param DeltaTime The time elapsed since the last score calculation.
* @return The calculated score for the test point.
*/
float GetScore(const FVector& ConeOrigin, const FVector& ConeForwardDirection, float GetScore(const FVector& ConeOrigin, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle, const FVector& TestPoint, const float ConeBackwardShiftDistance, const float ConeAngle, const FVector& TestPoint,
const float LastValue, const float DeltaTime); const float LastValue, const float DeltaTime);
...@@ -17,28 +32,47 @@ protected: ...@@ -17,28 +32,47 @@ protected:
public: public:
UIntenSelectableScoring(); UIntenSelectableScoring();
/** Whether to draw debug information in the editor. */
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
bool DrawDebug = true; bool DrawDebug = true;
/** The current score of the component. */
UPROPERTY(BlueprintReadOnly) UPROPERTY(BlueprintReadOnly)
float CurrentScore = 0; float CurrentScore = 0;
/** Whether the component is selectable. */
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
bool bIsSelectable = true; bool bIsSelectable = true;
/** The stickiness of selection. Higher values make selection more 'sticky'. */
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
float Stickiness = 10; float Stickiness = 10;
/** The snappiness of selection. Higher values make selection 'snap' more aggressively. */
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
float Snappiness = 15; float Snappiness = 15;
/** A constant used for compensating the score calculation. */
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
float CompensationConstant = 0.8; float CompensationConstant = 0.8;
/** Whether to overwrite the contribution of this component towards the final score. */
bool bOverwritingContrib = false; bool bOverwritingContrib = false;
/** The contribution of this component towards the final score. */
float Contrib = 0; float Contrib = 0;
/**
* Gets the best point and score pair based on the input parameters.
*
* @param ConeOrigin The origin point of the cone.
* @param ConeForwardDirection The forward direction of the cone.
* @param ConeBackwardShiftDistance The distance to shift the cone's origin backwards.
* @param ConeAngle The angle of the cone in degrees.
* @param LastValue The last score value calculated for this point.
* @param DeltaTime The time elapsed since the last score calculation.
* @return A pair containing the hit result and the score for the best point.
*/
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin, virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle, const float ConeBackwardShiftDistance, const float ConeAngle,
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include "IntenSelectableScoring.h" #include "IntenSelectableScoring.h"
#include "IntenSelectableSinglePointScoring.generated.h" #include "IntenSelectableSinglePointScoring.generated.h"
/**
* A component specifically designed for calculating and managing scores for selectable objects at a single point.
*/
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent)) UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class RWTHVRTOOLKIT_API UIntenSelectableSinglePointScoring : public UIntenSelectableScoring class RWTHVRTOOLKIT_API UIntenSelectableSinglePointScoring : public UIntenSelectableScoring
{ {
...@@ -12,6 +15,19 @@ class RWTHVRTOOLKIT_API UIntenSelectableSinglePointScoring : public UIntenSelect ...@@ -12,6 +15,19 @@ class RWTHVRTOOLKIT_API UIntenSelectableSinglePointScoring : public UIntenSelect
public: public:
UIntenSelectableSinglePointScoring(); UIntenSelectableSinglePointScoring();
/**
* Overrides the base class method to calculate the best point and score pair for a single point selection.
* This method is crucial for determining the effectiveness of selection based on the specified criteria.
*
* @param ConeOrigin The origin point of the cone used for selection.
* @param ConeForwardDirection The forward direction of the cone.
* @param ConeBackwardShiftDistance The distance to shift the cone's origin backward for selection purposes.
* @param ConeAngle The angle of the cone in degrees, defining the selection area.
* @param LastValue The last score value calculated, for continuous adjustments of the selection score.
* @param DeltaTime Time elapsed since the last score calculation.
* @return A pair containing the hit result and the score for the best selection point, which in this case is
* predetermined.
*/
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin, virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle, const float ConeBackwardShiftDistance, const float ConeAngle,
......
...@@ -4,26 +4,60 @@ ...@@ -4,26 +4,60 @@
#include "IntenSelectableScoring.h" #include "IntenSelectableScoring.h"
#include "IntenSelectableSphereScoring.generated.h" #include "IntenSelectableSphereScoring.generated.h"
/**
* A component designed for calculating and managing selection scores within a spherical area.
*/
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent)) UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class RWTHVRTOOLKIT_API UIntenSelectableSphereScoring : public UIntenSelectableScoring class RWTHVRTOOLKIT_API UIntenSelectableSphereScoring : public UIntenSelectableScoring
{ {
GENERATED_BODY() GENERATED_BODY()
protected: protected:
/**
* Determines the closest point within the sphere to a given point and direction, which is essential
* for calculating selection scores that are based on proximity to a spherical surface or volume.
*
* @param Point The reference point from which to find the closest point on the sphere.
* @param Direction The direction from the reference point to project towards the sphere.
* @return The closest point on the sphere to the given reference point and direction.
*/
FVector GetClosestSelectionPointTo(const FVector& Point, const FVector& Direction) const; FVector GetClosestSelectionPointTo(const FVector& Point, const FVector& Direction) const;
public: public:
UIntenSelectableSphereScoring(); UIntenSelectableSphereScoring();
/**
* Optional debug material to visualize the selection scoring area in the Unreal Editor or during gameplay.
* This material can be applied to a sphere mesh to aid in debugging and visualizing the scoring volume.
*/
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
UMaterialInstance* DebugMaterial; UMaterialInstance* DebugMaterial;
/**
* Determines whether the scoring calculation should only consider the outline of the sphere.
* If true, only the surface area of the sphere is considered for scoring. Otherwise, the entire
* volume of the sphere is used in the scoring calculations.
*/
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
bool OnlyOutline = false; bool OnlyOutline = false;
/** The radius of the sphere used in the selection scoring calculations. */
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
float Radius = 50; float Radius = 50;
/**
* Overrides the base class method to calculate the best point and score pair for selections
* within a spherical volume, taking into account the sphere's radius and whether to consider
* just the outline or the entire volume for scoring.
*
* @param ConeOrigin The origin point of the cone used for selection.
* @param ConeForwardDirection The forward direction of the cone.
* @param ConeBackwardShiftDistance How far to shift the cone's origin backward for selection purposes.
* @param ConeAngle The angle of the cone in degrees, used to determine the selection area.
* @param LastValue The last score value calculated, for continuous adjustment of selection scoring.
* @param DeltaTime Time since the last score calculation.
* @return A pair containing the hit result and the score for the best point within or on the surface of the sphere.
*/
virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin, virtual TPair<FHitResult, float> GetBestPointScorePair(const FVector& ConeOrigin,
const FVector& ConeForwardDirection, const FVector& ConeForwardDirection,
const float ConeBackwardShiftDistance, const float ConeAngle, const float ConeBackwardShiftDistance, const float ConeAngle,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment