Hello. I am trying to make a SceneViewExtension
that can modify the projection matrix, and hopefully, make a camera component that supports lens shift.
This is what I have now:
// LensShiftCameraComponent.h
#pragma once
#include "CoreMinimal.h"
#include "Camera/CameraComponent.h"
#include "SceneViewExtension.h"
#include "LensShiftCameraComponent.generated.h"
/**
*
*/
class ObliqueProjectionExtension : public FSceneViewExtensionBase
{
private:
float m_x, m_y;
public:
ObliqueProjectionExtension(const FAutoRegister& AutoRegister) : FSceneViewExtensionBase(AutoRegister) {}
~ObliqueProjectionExtension() {}
void SetupViewProjectionMatrix(FSceneViewProjectionData& InOutProjectionData) override {
auto m = InOutProjectionData.ProjectionMatrix.M;
m[0][2] = m_x;
m[1][2] = m_y;
}
void SetObliqueness(float x, float y) { m_x = x; m_y = y; }
void SetupViewFamily(FSceneViewFamily& InViewFamily) override {}
void SetupView(FSceneViewFamily& InViewFamily, FSceneView& InView) override {}
void BeginRenderViewFamily(FSceneViewFamily& InViewFamily) override {}
};
/**
*
*/
UCLASS()
class METALMAX3D_API ULensShiftCameraComponent : public UCameraComponent
{
GENERATED_BODY()
private:
TSharedRef<ObliqueProjectionExtension, ESPMode::ThreadSafe> ope;
public:
UPROPERTY(Category = CameraOptions, EditAnywhere, BlueprintReadWrite)
float LensShiftX;
UPROPERTY(Category = CameraOptions, EditAnywhere, BlueprintReadWrite)
float LensShiftY;
ULensShiftCameraComponent() {
ope = FSceneViewExtensions::NewExtension<ObliqueProjectionExtension>();
PrimaryComponentTick.bCanEverTick = true;
}
void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) {
ope->SetObliqueness(LensShiftX, LensShiftY);
}
};
It does not compile and says C2512: ObliqueProjectionExtension::ObliqueProjectionExtension
does not have a default constructor at line:
ope = FSceneViewExtensions::NewExtension<ObliqueProjectionExtension>();
.
But the example code in SceneViewExtension.h
says “your first argument must be FAutoRegister, and you must pass it to FSceneViewExtensionBase constructor”.
Please help me.