PlotRenderTarget.cpp 1.35 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// 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);
29
		FVector2D LocationB = Location + FVector2D(0, 100);
30

31
32
33
34
35
36
37
38
		/*
		 * Still not fast enough. Using other way to draw the graph.
		 */
		FCanvasLineItem LineItem(Location, LocationB);
		LineItem.LineThickness = 2;
		LineItem.SetColor(FLinearColor(1, 1, 1));
		LineItem.Draw(Canvas->Canvas);
		
39
40
		//Canvas->K2_DrawBox(Location, FVector2D(10, 10), 5);
		//Canvas->K2_DrawMaterial(MaterialDot, Location, FVector2D(10, 10), FVector2D(0, 0), FVector2D(1, 1), 0, FVector2D(0.5, 0.5));
41
		//Canvas->K2_DrawLine(Location, LocationB, 2);
42
43
	}
}