void AGameplayDebuggerReplicator::DrawDebugDataDelegate(class UCanvas* Canvas, class APlayerController* PC) { #if ENABLED_GAMEPLAY_DEBUGGER if (GetWorld() == nullptr || IsPendingKill() || Canvas == nullptr || Canvas->IsPendingKill()) { return; } if (!LocalPlayerOwner || !IsActorTickEnabled()) { return; } if (Canvas->SceneView != nullptr && !Canvas->SceneView->bIsGameView) { return; } if (GetWorld()->bPlayersOnly && Role == ROLE_Authority) { for (FConstPawnIterator Iterator = GetWorld()->GetPawnIterator(); Iterator; ++Iterator) { AActor* NewTarget = Cast<AActor>(*Iterator); if (NewTarget->IsSelected() && GetSelectedActorToDebug() != NewTarget) { ServerSetActorToDebug(NewTarget); } } } DrawDebugData(Canvas, PC); #endif }
void AGameplayDebuggerReplicator::OnDebugAIDelegate(class UCanvas* Canvas, class APlayerController* PC) { #if WITH_EDITOR && ENABLED_GAMEPLAY_DEBUGGER if (!GIsEditor) { return; } if (!LocalPlayerOwner) { return; } UEditorEngine* EEngine = Cast<UEditorEngine>(GEngine); if (!EEngine || !EEngine->bIsSimulatingInEditor) { return; } if (!Canvas || !Canvas->SceneView || Canvas->SceneView->bIsGameView == false) { return; } FEngineShowFlags EngineShowFlags = Canvas && Canvas->SceneView && Canvas->SceneView->Family ? Canvas->SceneView->Family->EngineShowFlags : FEngineShowFlags(GIsEditor ? EShowFlagInitMode::ESFIM_Editor : EShowFlagInitMode::ESFIM_Game); if (!EngineShowFlags.DebugAI) { return; } EnableDraw(true); UWorld* World = GetWorld(); if (World && Role == ROLE_Authority) { if (IsActorTickEnabled() == false) { SetActorTickEnabled(true); } // looks like Simulate in UE4 Editor - let's find selected Pawn to debug AActor* SelectedActor = nullptr; for (FSelectionIterator It = EEngine->GetSelectedActorIterator(); It; ++It) { SelectedActor = Cast<APawn>(*It); //we only work with pawns for now if (SelectedActor) { break; } } if (LastSelectedActorToDebug != SelectedActor) { MarkComponentsRenderStateDirty(); } ServerSetActorToDebug(SelectedActor); DrawDebugData(Canvas, PC, true); } #endif }
void AGameplayDebuggingReplicator::DrawDebugDataDelegate(class UCanvas* Canvas, class APlayerController* PC) { #if !(UE_BUILD_SHIPPING || UE_BUILD_TEST) if (GetWorld() == NULL || IsPendingKill() || Canvas == NULL || Canvas->IsPendingKill()) { return; } if (!LocalPlayerOwner || IsGlobalInWorld() || !IsDrawEnabled()) { return; } if (Canvas->SceneView != NULL && !Canvas->SceneView->bIsGameView) { return; } if (GFrameNumber == LastDrawAtFrame) { return; } LastDrawAtFrame = GFrameNumber; const UGameplayDebuggingControllerComponent* GDC = FindComponentByClass<UGameplayDebuggingControllerComponent>(); if (!GDC) { return; } if (GetWorld()->bPlayersOnly && Role == ROLE_Authority) { for (FConstPawnIterator Iterator = GetWorld()->GetPawnIterator(); Iterator; ++Iterator) { AActor* NewTarget = Cast<AActor>(*Iterator); if (NewTarget->IsSelected() && GetSelectedActorToDebug() != NewTarget) { ServerSetActorToDebug(NewTarget); } GetDebugComponent()->SetActorToDebug(NewTarget); GetDebugComponent()->CollectDataToReplicate(true); } } DrawDebugData(Canvas, PC); #endif }
//MIGUEL MODIFICATION: RESET FORCES TRIGGERING void b2World::Step(float32 dt, int32 velocityIterations, int32 positionIterations, bool resetForces) { m_lock = true; b2TimeStep step; step.dt = dt; step.velocityIterations = velocityIterations; step.positionIterations = positionIterations; step.resetForces = resetForces; //MIGUEL MODIFICATION: RESET FORCES TRIGGERING if (dt > 0.0f) { step.inv_dt = 1.0f / dt; } else { step.inv_dt = 0.0f; } step.dtRatio = m_inv_dt0 * dt; step.warmStarting = m_warmStarting; // Update contacts. m_contactManager.Collide(); // Integrate velocities, solve velocity constraints, and integrate positions. if (step.dt > 0.0f) { Solve(step); } // Handle TOI events. if (m_continuousPhysics && step.dt > 0.0f) { SolveTOI(step); } // Draw debug information. DrawDebugData(); m_inv_dt0 = step.inv_dt; m_lock = false; }
void b2World::Step(float32 dt, int32 iterations) { m_lock = true; b2TimeStep step; step.dt = dt; step.maxIterations = iterations; if (dt > 0.0f) { step.inv_dt = 1.0f / dt; } else { step.inv_dt = 0.0f; } step.dtRatio = m_inv_dt0 * dt; step.positionCorrection = m_positionCorrection; step.warmStarting = m_warmStarting; // Update contacts. m_contactManager.Collide(); // Integrate velocities, solve velocity constraints, and integrate positions. if (step.dt > 0.0f) { Solve(step); } // Handle TOI events. if (m_continuousPhysics && step.dt > 0.0f) { SolveTOI(step); } // Draw debug information. DrawDebugData(); m_inv_dt0 = step.inv_dt; m_lock = false; }
void b2World::Step(float32 dt, int32 iterations) { m_lock = true; b2TimeStep step; step.dt = dt; step.maxIterations = iterations; if (dt > 0.0f) { step.inv_dt = 1.0f / dt; } else { step.inv_dt = 0.0f; } // Update contacts. m_contactManager.Collide(); // Integrate velocities, solve velocity constraints, and integrate positions. if (step.dt > 0.0f) { Solve(step); } // Handle TOI events. if (s_enableTOI && step.dt > 0.0f) { SolveTOI(step); } // Draw debug information. DrawDebugData(); m_lock = false; }
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)); }
void World::RunWorld() { std::srand(static_cast<unsigned int>(std::time(NULL))); uint32 flags = 0; flags += b2Draw::e_shapeBit; flags += b2Draw::e_jointBit; flags += b2Draw::e_aabbBit; flags += b2Draw::e_pairBit; flags += b2Draw::e_centerOfMassBit; WindowManager::I().GetDebugDraw().SetFlags(flags); SetDebugDraw(&WindowManager::I().GetDebugDraw()); // Since the Box2D world is tuned for meters, and works with averagely sized objects, // we'll zoom in with the view. sf::View view; view.setSize(sf::Vector2f(80, 60)); view.setCenter(sf::Vector2f(40, 30)); WindowManager::I().setView(view); auto obj = std::make_shared<ObjectBase>(OSTCircle, 1.0f, true); auto obj2 = std::make_shared<ObjectBase>(OSTRectangle, 15.0f, false); auto obj3 = std::make_shared<ObjectBase>(OSTRectangle, 15.0f, false); auto obj4 = std::make_shared<ObjectBase>(OSTRectangle, 15.0f, false); obj->SetPosition(40, 10); obj2->SetPosition(40, 51.5); obj3->SetPosition(70, 43); obj3->SetRotation(b2_pi / 4.0f); obj4->SetPosition(10, 45); obj4->SetRotation(b2_pi / 8.0f + b2_pi); while (WindowManager::I().isOpen()) { // Handle events sf::Event event; while (WindowManager::I().pollEvent(event)) { // Window closed or escape key pressed: exit if ((event.type == sf::Event::Closed) || ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))) { WindowManager::I().close(); break; } } float32 timeStep = 1.0f / 60.0f; int32 velocityIterations = 6; int32 positionIterations = 2; Step(timeStep, velocityIterations, positionIterations); obj->Move(); WindowManager::I().clear(sf::Color::Black); DrawDebugData(); WindowManager::I().display(); } }
void AGameplayDebuggingReplicator::OnDebugAIDelegate(class UCanvas* Canvas, class APlayerController* PC) { #if WITH_EDITOR && !(UE_BUILD_SHIPPING || UE_BUILD_TEST) if (!GIsEditor) { return; } if (!LocalPlayerOwner || IsGlobalInWorld()) { return; } UEditorEngine* EEngine = Cast<UEditorEngine>(GEngine); if (GFrameNumber == LastDrawAtFrame || !EEngine || !EEngine->bIsSimulatingInEditor) { return; } if (!Canvas || !Canvas->SceneView || Canvas->SceneView->bIsGameView == false) { return; } LastDrawAtFrame = GFrameNumber; FEngineShowFlags EngineShowFlags = Canvas && Canvas->SceneView && Canvas->SceneView->Family ? Canvas->SceneView->Family->EngineShowFlags : FEngineShowFlags(GIsEditor ? EShowFlagInitMode::ESFIM_Editor : EShowFlagInitMode::ESFIM_Game); if (!EngineShowFlags.DebugAI) { return; } EnableDraw(true); UWorld* World = GetWorld(); UGameplayDebuggingComponent* DebuggingComponent = GetDebugComponent(); if (World && DebuggingComponent && DebuggingComponent->GetOwnerRole() == ROLE_Authority) { UGameplayDebuggingControllerComponent* GDC = FindComponentByClass<UGameplayDebuggingControllerComponent>(); TArray<int32> OryginalReplicateViewDataCounters; OryginalReplicateViewDataCounters = DebuggingComponent->ReplicateViewDataCounters; for (uint32 Index = 0; Index < EAIDebugDrawDataView::MAX; ++Index) { DebuggingComponent->ReplicateViewDataCounters[Index] = GameplayDebuggerSettings(this).CheckFlag((EAIDebugDrawDataView::Type)Index) ? 1 : 0; } // looks like Simulate in UE4 Editor - let's find selected Pawn to debug AActor* FullSelectedTarget = NULL; for (FConstPawnIterator Iterator = World->GetPawnIterator(); Iterator; ++Iterator) { AActor* NewTarget = Cast<AActor>(*Iterator); if (NewTarget->IsSelected() && !FullSelectedTarget) { FullSelectedTarget = NewTarget; continue; } //We needs to collect data manually in Simulate DebuggingComponent->SetActorToDebug(NewTarget); DebuggingComponent->CollectDataToReplicate(NewTarget->IsSelected()); DrawDebugData(Canvas, PC); } const AActor* OldActor = LastSelectedActorToDebug; ServerSetActorToDebug(FullSelectedTarget); if (FullSelectedTarget) { DebuggingComponent->CollectDataToReplicate(true); DebuggingComponent->SetEQSIndex(ActiveEQSIndex); DrawDebugData(Canvas, PC); } if (GetSelectedActorToDebug() != OldActor) { DebuggingComponent->MarkRenderStateDirty(); } DebuggingComponent->ReplicateViewDataCounters = OryginalReplicateViewDataCounters; } #endif }