Untitled
unknown
c_cpp
22 days ago
1.9 kB
2
Indexable
Never
void ACustomARPawn::DetectCircleGesture(const ETouchIndex::Type FingerIndex, const FVector screenCenter, float Delta) //Detects a circular motion gesture in the screen with touch input { FVector2D prevVec, currentVec; circleTimer += Delta; float angle = 0; float totalAngle = 0; prevVec = FVector2D(0, 0); //prevVec should also be initialized to the touch currentVec = FVector2D(0, 0); //CurrVector should be the fingers position - screen center //Here i should add a while loop - while finger is in contact with screen if(circleTimer < 5) //before 5 frames elapsed { prevVec = currentVec; //Store the current vectors position in previous vector } else //If 5 frames elapsed { //Calculate angle between previous vector and current vector angle = UKismetMathLibrary::Min(1, prevVec.Dot(currentVec) / (prevVec.Length() * currentVec.Length())); angle = UKismetMathLibrary::Acos(angle); //Acos produces NaN if input > 1 so we use min. Rounding inaccuracies can cause this. circleTimer = 0; //Reset timer } //Check the direction of the rotation (cw vs ccw) float dir = UKismetMathLibrary::CrossProduct2D(prevVec, currentVec) > 0 ? 1 : -1; //If it's positive its cw, negative is ccw totalAngle += dir * angle; //Check if total angle > 360 if(totalAngle > 360) { //Do the functionality. In this case it'd probably add a value to a variable per circle completed GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Orange, FString::Printf(TEXT("CIRCLE MADE!"))); //Reset total angle totalAngle = 0; } //I have to check if the magnitudes of the previous and current vectors are within a certain radius/proximity to the center so the user doesnt circle too far or too close to it //Something like if(prevVec.Length() > screenWidth || currentVec.Length() > screenWidth) }
Leave a Comment