How Can I Draw Sine Waves on Screen

Hi folks,

I am looking for a way to draw the results from sine waves onto the screen, either in a stream or by offloading the results to an array and passing them to a “graph” to display in a widget. Ideally, there would be a simple way to do either or, but I am not really sure where to even start with this.

Regards

Take a look on WheeledVehicleMovementComponent.cpp DrawTelemetryGraph

especially on

for ( uint32 i = 2; i < 2 * PxVehicleGraph::eMAX_NB_SAMPLES; i += 2 )
	{
		float x1 = PGraphXY[i-2];
		float y1 = PGraphXY[i-1];
		float x2 = PGraphXY[i];
		float y2 = PGraphXY[i+1];

		x1 = FMath::Clamp( x1 + 0.50f, 0.0f, 1.0f );
		x2 = FMath::Clamp( x2 + 0.50f, 0.0f, 1.0f );
		y1 = 1.0f - FMath::Clamp( y1 + 0.50f, 0.0f, 1.0f );
		y2 = 1.0f - FMath::Clamp( y2 + 0.50f, 0.0f, 1.0f );

		FCanvasLineItem LineItem( FVector2D( GraphX + x1 * GraphWidth, LineGraphY + y1 * LineGraphHeight ), FVector2D( GraphX + x2 * GraphWidth, LineGraphY + y2 * LineGraphHeight ) );
		LineItem.SetColor( FLinearColor( 1.0f, 0.5f, 0.0f, 1.0f ) );
		LineItem.Draw( Canvas->Canvas );
	}

this piece of code draw graph with vehicle parameters.

Thanks for that! Going to test it out over the next couple of days and report results before I mark this as answered. I also found this: https://docs.unrealengine.com/latest/INT/Resources/ContentExamples/Blueprint_Splines/index.html

My tinker with splines as well to see if they can perform the task. Thanks for the info, Pierdek

Meantime, I found another nice piece of code:

DrawDebugHelpers.cpp

void DrawDebugFloatHistory(UWorld const & WorldRef, FDebugFloatHistory const & FloatHistory, FTransform const & DrawTransform, FVector2D const & DrawSize, FColor const & DrawColor, bool const & bPersistent, float const & LifeTime, uint8 const & DepthPriority)

Any idea if its possible to do it directly from BP rather then c++ ?
I mean this method is great for visualizing values over time, but what about BP only projects ?

thanks!

I know there is, but I can’t figure out how. There is a snap shot wave in the content examples math level, but I can’t figure out exactly what they are doing or where.