Add Basic Spell System (#9)
Co-authored-by: alhashij <alhashimy.janna@gmail.com> Reviewed-on: #9 Co-authored-by: Lance1416 <lanceli1416@gmail.com> Co-committed-by: Lance1416 <lanceli1416@gmail.com>
This commit was merged in pull request #9.
This commit is contained in:
@@ -12,16 +12,13 @@ FUniStrokeRecognizer::~FUniStrokeRecognizer()
|
||||
|
||||
// TODO: Review this function
|
||||
FUniStrokeResult
|
||||
FUniStrokeRecognizer::Recognize(const TArray<FVector2D>& VectorPoints,
|
||||
const bool& UseProtractor)
|
||||
FUniStrokeRecognizer::Recognize(const TArray<FVector2D>& VectorPoints)
|
||||
{
|
||||
TArray<FUniStrokePoint> Points = FUniStrokePoint::From(VectorPoints);
|
||||
|
||||
// Edge case: Not enough points
|
||||
if (Points.Num() < 2 || FUniStrokePoint::PathLength(Points) < 100.0f)
|
||||
{
|
||||
return FUniStrokeResult("Too few points made", 0.0);
|
||||
}
|
||||
|
||||
const FUniStrokeTemplate Candidate = FUniStrokeTemplate("", Points);
|
||||
int TemplateIndex = -1;
|
||||
@@ -33,18 +30,13 @@ FUniStrokeRecognizer::Recognize(const TArray<FVector2D>& VectorPoints,
|
||||
for (int i = 0; i < Templates.Num(); i++)
|
||||
{
|
||||
// d <- DistanceAtBestAngle(points, T, -theta, theta, threshold)
|
||||
const float d = UseProtractor
|
||||
? FUniStrokePoint::OptimalCosineDistance(
|
||||
Templates[i].Vector,
|
||||
Candidate.Vector
|
||||
)
|
||||
: FUniStrokePoint::DistanceAtBestAngle(
|
||||
Candidate.Points,
|
||||
Templates[i].Points,
|
||||
-AngleRange,
|
||||
AngleRange,
|
||||
AnglePrecision
|
||||
);
|
||||
const float d = FUniStrokePoint::DistanceAtBestAngle(
|
||||
Candidate.Points,
|
||||
Templates[i].Points,
|
||||
-AngleRange,
|
||||
AngleRange,
|
||||
AnglePrecision
|
||||
);
|
||||
|
||||
// if d < b then
|
||||
if (d < b)
|
||||
@@ -57,7 +49,8 @@ FUniStrokeRecognizer::Recognize(const TArray<FVector2D>& VectorPoints,
|
||||
}
|
||||
|
||||
// score <- 1 – b / 0.5 sqrt(size^2 + size^2)
|
||||
const float Score = UseProtractor ? 1.0 - b : 1.0 - b / HalfDiagonal;
|
||||
static const float HalfDiagonal = 0.5 * FMath::Sqrt(2 * FMath::Square(SquareSize));
|
||||
const float Score = 1.0 - b / HalfDiagonal;
|
||||
|
||||
// return <T', score>
|
||||
return TemplateIndex == -1
|
||||
|
||||
Reference in New Issue
Block a user