Download

Custom blueprint node that gets the centers of a camera's frustums

I created a custom blueprint node for that returns the world coordinates for the centers of the top, left, bottom and right frustum planes of an orthographic camera. I’m using it to spawn some actors at right at the edge of the screen. Maybe it’ll come in handy to someone else.

To test it I’ve made it so that at game start a fire particle is initiated at the center of each of the planes. The cube represents the camera position.

Camera frusta visualized

Fire spawned at the center of each plane

Blueprint node usage

To use it add these files to your C++ classes folder

CameraUtils.h



#pragma once

#include "Camera/CameraActor.h"
#include "CameraUtils.generated.h"

/**
 * 
 */
UCLASS()
class PROJECTNAME_API ACameraUtils : public ACameraActor
{
    GENERATED_BODY()


public:

    UFUNCTION(BlueprintPure,
        meta = (
            DisplayName = "Get Camera Edges from Frustum",
            Keywords = "Camera Edges Frustum"
            ),
        Category = "Camera|Utility")
        static void GetCameraFrustumEdges(UCameraComponent* camera, FVector& topCenter, FVector& leftCenter, FVector& bottomCenter, FVector& rightCenter);


};

CameraUtils.cpp
Note: Change “ProjectName.h” to whatever your project is called.



#include "ProjectName.h"
#include "CameraUtils.h"


void ACameraUtils::GetCameraFrustumEdges(UCameraComponent* camera, FVector& topCenter, FVector& leftCenter, FVector& bottomCenter, FVector& rightCenter)
{
    // Assumptions: Camera is orthographic, Z axis is upwards, Y axis is right, X is forward

    FMinimalViewInfo cameraView;
    camera->GetCameraView(0.0f, cameraView);

    float width = cameraView.OrthoWidth;
    float height = width / cameraView.AspectRatio;

    topCenter.Set(cameraView.Location.X,
                  cameraView.Location.Y,
                  cameraView.Location.Z + height/2.0f);

    bottomCenter.Set(cameraView.Location.X,
                     cameraView.Location.Y,
                     cameraView.Location.Z - height / 2.0f);

    leftCenter.Set(cameraView.Location.X,
                   cameraView.Location.Y - width / 2.0f,
                   cameraView.Location.Z);

    rightCenter.Set(cameraView.Location.X,
                    cameraView.Location.Y + width / 2.0f,
                    cameraView.Location.Z);

}


I also made entry in the wiki.