【发布时间】:2020-09-13 18:28:35
【问题描述】:
如何为actor AMySphere设置带有材质的网格?
void AMyActor::DrawSpheresAtLevel(int level_)
{
// 1. Generate parameters...
if (0 != level_)
{
spheres_count += spheres_count / 100 * factor;
radius += radius / 100 * rad_factor; // radius of a circle with a player placed at the center
}
// 2. Generate spheres.
FVector location;
GetPlayerLocation(location);
float x = location.X + radius;
FVector previous_scenter;
for (int j = 0; j <= spheres_count; ++j)
{
float y = std::sqrt(pow(radius, 2) - pow(x, 2));
FVector sphere_center = { x, y, 100 };
FRotator rot = FRotator::ZeroRotator;
if (j != 0) // calculate distance between previous sphere and current sphere
{ // centers until it becomes less, or equal to 80
float deg = 1.f;
do
{
rot.SetComponentForAxis(EAxis::Type::Z, deg++);
sphere_center = rot.RotateVector(previous_scenter);
} while (Distance(previous_scenter, sphere_center) < 80.f);
}
// Draw a sphere.
FActorSpawnParameters SpawnParams;
AMySphere* sphere_ptr = GetWorld()->SpawnActor<AMySphere>(sphere_center, rot, SpawnParams);
if (nullptr == sphere_ptr)
{
std::cout << "nullptr\n";
}
else
{
sphere_ptr->SetObserver(this);
sphere_ptr->SetIndex_(spheres.size());
spheres.push_back(sphere_ptr);
}
previous_scenter = sphere_center;
}
}
【问题讨论】:
标签: c++ unreal-engine4