void GetVariableTraverser::setTypeSpecificInfo( const TType &type, const TString& name, Varying *variable) { ASSERT(variable); switch (type.getQualifier()) { case EvqVaryingIn: case EvqVaryingOut: case EvqVertexOut: case EvqSmoothOut: case EvqFlatOut: case EvqCentroidOut: if (mSymbolTable.isVaryingInvariant(std::string(name.c_str())) || type.isInvariant()) { variable->isInvariant = true; } break; default: break; } variable->interpolation = GetInterpolationType(type.getQualifier()); }
void FAnimNode_LookAt::EvaluateBoneTransforms(USkeletalMeshComponent* SkelComp, FCSPose<FCompactPose>& MeshBases, TArray<FBoneTransform>& OutBoneTransforms) { check(OutBoneTransforms.Num() == 0); const FBoneContainer& BoneContainer = MeshBases.GetPose().GetBoneContainer(); const FCompactPoseBoneIndex ModifyBoneIndex = BoneToModify.GetCompactPoseIndex(BoneContainer); FTransform ComponentBoneTransform = MeshBases.GetComponentSpaceTransform(ModifyBoneIndex); // get target location FVector TargetLocationInComponentSpace; if (LookAtBone.IsValid(BoneContainer)) { const FTransform& LookAtTransform = MeshBases.GetComponentSpaceTransform(LookAtBone.GetCompactPoseIndex(BoneContainer)); TargetLocationInComponentSpace = LookAtTransform.GetLocation(); } else { TargetLocationInComponentSpace = SkelComp->ComponentToWorld.InverseTransformPosition(LookAtLocation); } FVector OldCurrentTargetLocation = CurrentTargetLocation; FVector NewCurrentTargetLocation = TargetLocationInComponentSpace; if ((NewCurrentTargetLocation - OldCurrentTargetLocation).SizeSquared() > InterpolationTriggerThreashold*InterpolationTriggerThreashold) { if (AccumulatedInterpoolationTime >= InterpolationTime) { // reset current Alpha, we're starting to move AccumulatedInterpoolationTime = 0.f; } PreviousTargetLocation = OldCurrentTargetLocation; CurrentTargetLocation = NewCurrentTargetLocation; } else if (InterpolationTriggerThreashold == 0.f) { CurrentTargetLocation = NewCurrentTargetLocation; } if (InterpolationTime > 0.f) { float CurrentAlpha = AccumulatedInterpoolationTime/InterpolationTime; if (CurrentAlpha < 1.f) { float BlendAlpha = AlphaToBlendType(CurrentAlpha, GetInterpolationType()); CurrentLookAtLocation = FMath::Lerp(PreviousTargetLocation, CurrentTargetLocation, BlendAlpha); } } else { CurrentLookAtLocation = CurrentTargetLocation; } if (bEnableDebug) { UWorld* World = SkelComp->GetWorld(); DrawDebugData(World, SkelComp->GetComponentToWorld(), ComponentBoneTransform.GetLocation(), PreviousTargetLocation, FColor(0, 255, 0)); DrawDebugData(World, SkelComp->GetComponentToWorld(), ComponentBoneTransform.GetLocation(), CurrentTargetLocation, FColor(255, 0, 0)); DrawDebugData(World, SkelComp->GetComponentToWorld(), ComponentBoneTransform.GetLocation(), CurrentLookAtLocation, FColor(0, 0, 255)); } // lookat vector FVector LookAtVector = GetAlignVector(ComponentBoneTransform, LookAtAxis); // flip to target vector if it wasnt negative bool bShouldFlip = LookAtAxis == EAxisOption::X_Neg || LookAtAxis == EAxisOption::Y_Neg || LookAtAxis == EAxisOption::Z_Neg; FVector ToTarget = CurrentLookAtLocation - ComponentBoneTransform.GetLocation(); ToTarget.Normalize(); if (bShouldFlip) { ToTarget *= -1.f; } if ( LookAtClamp > ZERO_ANIMWEIGHT_THRESH ) { float LookAtClampInRadians = FMath::DegreesToRadians(LookAtClamp); float DiffAngle = FMath::Acos(FVector::DotProduct(LookAtVector, ToTarget)); if (LookAtClampInRadians > 0.f && DiffAngle > LookAtClampInRadians) { FVector OldToTarget = ToTarget; FVector DeltaTarget = ToTarget-LookAtVector; float Ratio = LookAtClampInRadians/DiffAngle; DeltaTarget *= Ratio; ToTarget = LookAtVector + DeltaTarget; ToTarget.Normalize(); // UE_LOG(LogAnimation, Warning, TEXT("Recalculation required - old target %f, new target %f"), // FMath::RadiansToDegrees(FMath::Acos(FVector::DotProduct(LookAtVector, OldToTarget))), FMath::RadiansToDegrees(FMath::Acos(FVector::DotProduct(LookAtVector, ToTarget)))); } } FQuat DeltaRot; // if want to use look up, if (bUseLookUpAxis) { // find look up vector in local space FVector LookUpVector = GetAlignVector(ComponentBoneTransform, LookUpAxis); // project target to the plane FVector NewTarget = FVector::VectorPlaneProject(ToTarget, LookUpVector); NewTarget.Normalize(); DeltaRot = FQuat::FindBetween(LookAtVector, NewTarget); } else { DeltaRot = FQuat::FindBetween(LookAtVector, ToTarget); } // transform current rotation to delta rotation FQuat CurrentRot = ComponentBoneTransform.GetRotation(); FQuat NewRotation = DeltaRot * CurrentRot; ComponentBoneTransform.SetRotation(NewRotation); OutBoneTransforms.Add(FBoneTransform(ModifyBoneIndex, ComponentBoneTransform)); }