TraceFinger
unknown
c_cpp
a year ago
1.8 kB
3
Indexable
float AVRCharacterBase::TraceFingerSegment(EVRHandType HandType, EVRHandFingerType FingerType, UPrimitiveComponent* GrabComponent) { USceneComponent* HandComponent = HandType == EHT_Left ? L_HandMeshComponent : R_HandMeshComponent; TMap<EVRHandFingerType, FVRHandFingerMapEntries> FingersCacheMap = HandType == EHT_Left ? L_FingersCacheMap : R_FingersCacheMap; FVRHandFingerMapEntries* FingerCacheMap = FingersCacheMap.Find(FingerType); if (FingerCacheMap) { TArray<FVector> ArrayOfFingerPoints = FingerCacheMap->Entries; float TotalLength; float HitLength; bool bIsHit = false; FTransform HandTransform = HandComponent->GetComponentTransform(); for (int Index = 0; Index < ArrayOfFingerPoints.Num() - 1; Index++) { FVector FingerPointCurrentLocation = UKismetMathLibrary::TransformLocation(HandTransform, ArrayOfFingerPoints[Index]); FVector FingerPointNextLocation = UKismetMathLibrary::TransformLocation( HandTransform, ArrayOfFingerPoints[Index + 1]); if (!bIsHit) { FHitResult HitResult; FCollisionQueryParams CollisionParams; CollisionParams.bTraceComplex = true; if (GrabComponent->LineTraceComponent(HitResult, FingerPointCurrentLocation, FingerPointNextLocation, CollisionParams)) { bIsHit = true; HitLength = TotalLength + HitResult.Distance; } } TotalLength += FVector::Distance(FingerPointCurrentLocation, FingerPointNextLocation); if (!bIsHit) { HitLength = TotalLength; } } float Result = FMath::Clamp(HitLength / TotalLength, 0, 1); return Result; } return 0; }
Editor is loading...