Commit 63905fe4 authored by Jan Kremer's avatar Jan Kremer

Added C++ RenderTarget implementation.

parent ab1bdbd9
No preview for this file type
No preview for this file type
// Fill out your copyright notice in the Description page of Project Settings.
#include "PawnBase.h"
#include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"
#include "Plot3D.h"
// Sets default values
APawnBase::APawnBase()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void APawnBase::BeginPlay()
{
Super::BeginPlay();
TArray<AActor*> AllActors;
UGameplayStatics::GetAllActorsWithTag(this, TEXT("Plot3D"), AllActors);
Plot3D = Cast<APlot3D>(AllActors[0]);
}
// Called every frame
void APawnBase::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void APawnBase::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "PawnBase.generated.h"
class APlot3D;
UCLASS()
class IMMERSIVEANALYTICS_API APawnBase : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
APawnBase();
UPROPERTY(EditAnywhere, BlueprintReadOnly)
APlot3D* Plot3D;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "PlotRenderTarget.h"
#include "PawnBase.h"
#include "Plot3D.h"
#include "Runtime/Engine/Classes/Engine/Canvas.h"
#include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"
UPlotRenderTarget::UPlotRenderTarget()
{
TScriptDelegate <FWeakObjectPtr> MyDelegate;
MyDelegate.BindUFunction(this, "OnUpdate");
OnCanvasRenderTargetUpdate.Add(MyDelegate);
}
void UPlotRenderTarget::OnUpdate(UCanvas * Canvas, int32 Width, int32 Height)
{
if (!MaterialDot)
{
return;
}
APawn* Pawn = UGameplayStatics::GetPlayerPawn(this, 0);
APawnBase* PawnBase = Cast<APawnBase>(Pawn);
for (int i = 0; i < PawnBase->Plot3D->Points.Num(); ++i)
{
FVector2D Location = FVector2D(PawnBase->Plot3D->Points[i].Location.X * 10000 + Width / 2, PawnBase->Plot3D->U[i] * 5 + Height / 2);
//Canvas->K2_DrawBox(Location, FVector2D(10, 10), 5);
Canvas->K2_DrawLine(Location, Location + FVector2D(0, 100), 2);
//Canvas->K2_DrawMaterial(MaterialDot, Location, FVector2D(10, 10), FVector2D(0, 0), FVector2D(1, 1), 0, FVector2D(0.5, 0.5));
}
}
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Engine/CanvasRenderTarget2D.h"
#include "PlotRenderTarget.generated.h"
/**
*
*/
UCLASS()
class IMMERSIVEANALYTICS_API UPlotRenderTarget : public UCanvasRenderTarget2D
{
GENERATED_BODY()
public:
UPlotRenderTarget();
UFUNCTION()
void OnUpdate(UCanvas* Canvas, int32 Width, int32 Height);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Default)
UMaterialInterface* MaterialDot;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment