I don’t have any practical usage at the moment for placing points in a sphere. I had a thought, and thought it would be pretty cool to make some functions for the future…you never know. This could potentially be more exciting using Niagara, like exploding sphere VFX.
FCageVectorSphereParams
USTRUCT(BlueprintType) struct FCageVectorSphereParams { GENERATED_BODY() UPROPERTY(BlueprintReadWrite, EditAnywhere) int32 LatitudeSegments; UPROPERTY(BlueprintReadWrite, EditAnywhere) int32 LongitudeSegments; UPROPERTY(BlueprintReadWrite, EditAnywhere) float Radius; UPROPERTY(BlueprintReadWrite, EditAnywhere) bool bTop; UPROPERTY(BlueprintReadWrite, EditAnywhere) bool bBottom; };
UCageUtilities::CreateVectorSphere
/** Create Vector Sphere */ UFUNCTION(BlueprintCallable, BlueprintPure, meta=(DisplayName = "Create Vector Sphere"), Category="CageTools|Object Placement") static TArrayCreateVectorSphere(int32 LatitudeSegments, int32 LongitudeSegments, float Radius, bool bTop, bool bBottom); }
C++
TArrayUCageUtilities::CreateVectorSphere(int32 LatitudeSegments, int32 LongitudeSegments, float Radius, bool bTop, bool bBottom) { TArray SphereTransforms; for (int32 lat = 0; lat <= LatitudeSegments; ++lat) { for (int32 lon = 0; lon <= LongitudeSegments; ++lon) { // Calculate the spherical coordinates float Theta = 2 * PI * float(lon) / float(LongitudeSegments); float Phi = PI * float(lat) / float(LatitudeSegments); // Convert to Cartesian coordinates float X = Radius * sin(Phi) * cos(Theta); float Y = Radius * sin(Phi) * sin(Theta); float Z = Radius * cos(Phi); FVector Vertex(X, Y, Z); if ((bTop && Vertex.Z >= 0.0f) || (bBottom && Vertex.Z <= 0.0f) || (!bTop && !bBottom)) { // Create a transform with the forward vector pointing outward on the Z-axis FTransform Transform(FRotator(0.0f, 0.0f, 0.0f), Vertex); SphereTransforms.Add(Transform); } } } return SphereTransforms; } }