本文整理汇总了C++中FVector::GetClampedToMaxSize2D方法的典型用法代码示例。如果您正苦于以下问题:C++ FVector::GetClampedToMaxSize2D方法的具体用法?C++ FVector::GetClampedToMaxSize2D怎么用?C++ FVector::GetClampedToMaxSize2D使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FVector
的用法示例。
在下文中一共展示了FVector::GetClampedToMaxSize2D方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Tick
void ADynamicCarController::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
if (play) {
float deltaSec = GWorld->GetWorld()->GetDeltaSeconds();
updateTarget();
if (first) {
first = false;
FRotator rotation = agent->GetActorRotation();
rotation.Yaw = getRotation(agent->GetActorLocation(), target);
agent->SetActorRotation(rotation);
if (followPath) {
waypoints = DubinsPath::getPath(waypoints, to2D(agent->GetActorLocation()), rotation.Yaw, maxAngle, L, graph, errorTolerance);
writeWaypointsToFile("Waypoints2.txt");
if (waypoints.Num() > 0) {
target = waypoints[0];
}
}
}
if (waypointReached()) {
bool t35 = followPath && waypointsIndex >= waypoints.Num();
bool t4 = avoidAgents && !followPath;
if (t35 || t4) {
play = false;
GEngine->AddOnScreenDebugMessage(-1, 50.f, FColor::Green, FString::Printf(TEXT("Time: %f\r\n"), totalTime));
}
return;
}
float a = getAcceleration(deltaSec);
v += a;
v = UKismetMathLibrary::FClamp(v, -vMax, vMax);
float rotation = rotate(deltaSec);
FVector vPref = FVector(v * UKismetMathLibrary::DegCos(rotation) * deltaSec, v * UKismetMathLibrary::DegSin(rotation) * deltaSec, 0);
vPref = vPref.GetClampedToMaxSize2D(UKismetMathLibrary::FMin(v * deltaSec, FVector2D::Distance(to2D(agent->GetActorLocation()), target)));
FVector oldVel = velocity;
if (avoidAgents) {
adjustVelocity(to2D(vPref), deltaSec);
//velocity = vPref;
} else {
velocity = vPref;
}
FVector2D q = to2D(velocity - oldVel);
float dv = FMath::Sqrt(FVector2D::DotProduct(q, q));
if (dv > aMax * deltaSec) {
float f = aMax * deltaSec / dv;
velocity = (1 - f) * oldVel + f * velocity;
}
float rot = agent->GetActorRotation().Yaw;
if (velocity.Size2D() != 0) {
if (angleDiff(rot, velocity.Rotation().Yaw) > 90) {
velocity = -velocity;
setRotation();
velocity = -velocity;
} else {
setRotation();
}
}
/*
if (UKismetMathLibrary::Abs(angleDiff(rot, agent->GetActorRotation().Yaw)) / deltaSec > maxAngle * (v / L) + 5) {
GEngine->AddOnScreenDebugMessage(-1, 50.f, FColor::Red, FString::Printf(TEXT("rot: %f yaw: %f -> %f (%f) %d %s -> %s"), rot, agent->GetActorRotation().Yaw, angleDiff(rot, agent->GetActorRotation().Yaw), UKismetMathLibrary::Abs(angleDiff(rot, agent->GetActorRotation().Yaw)) / deltaSec, vPref.Equals(velocity), *to2D(vPref).ToString(), *to2D(velocity).ToString()));
DrawDebugLine(GWorld->GetWorld(), FVector(to2D(agent->GetActorLocation()), 20), FVector(to2D(agent->GetActorLocation()), 30), FColor::Red, false, 0.5, 0, 1);
GEngine->DeferredCommands.Add(TEXT("pause"));
}*/
agent->SetActorLocation(agent->GetActorLocation() + velocity);
/*
DrawDebugLine(GWorld->GetWorld(), to3D(target), to3D(target) + collisionSize, collisionColor, false, 0.1, 0, 1);
float a = getAcceleration(deltaSec);
v += a;
v = UKismetMathLibrary::FClamp(v, -vMax, vMax);
float rotation = rotate(deltaSec);
acceleration.X = a * UKismetMathLibrary::DegCos(rotation);
//.........这里部分代码省略.........