Advertisement
Guest User

Untitled

a guest
May 21st, 2017
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.01 KB | None | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3. #include "WaveworksTester.h"
  4. #include "FloatingSphere.h"
  5.  
  6. // Sets default values for this component's properties
  7. UFloatingSphere::UFloatingSphere()
  8. {
  9.     // Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
  10.     // off to improve performance if you don't need them.
  11.     bWantsBeginPlay = true;
  12.     PrimaryComponentTick.bCanEverTick = true;
  13. }
  14.  
  15.  
  16. // Called when the game starts
  17. void UFloatingSphere::BeginPlay()
  18. {
  19.     Super::BeginPlay();
  20.  
  21.     // ...
  22.     UActorComponent* pComponent = WaveWorksActor->GetComponentByClass(UWaveWorksComponent::StaticClass());
  23.     WaveWorksComponent = Cast<UWaveWorksComponent>(pComponent);
  24.     InitialPosition = GetOwner()->GetActorLocation();
  25.  
  26.     WaveWorksRecieveDisplacementDelegate = FVectorArrayDelegate::CreateUObject(this, &UFloatingSphere::OnRecievedWaveWorksDisplacement);
  27. }
  28.  
  29. DECLARE_DELEGATE_OneParam(FStringDelegate, FString);
  30. DECLARE_DELEGATE_OneParam(FArrayDelegate, TArray<FVector4>);
  31.  
  32. // Called every frame
  33. void UFloatingSphere::TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction )
  34. {
  35.     Super::TickComponent( DeltaTime, TickType, ThisTickFunction );
  36.  
  37.     TArray<FVector2D> samplePoints;
  38.     FVector2D samplePos(InitialPosition.X / 100.0f, InitialPosition.Y / 100.0f);
  39.     samplePoints.Add(samplePos);
  40.    
  41.     WaveWorksComponent->SampleDisplacements(samplePoints, WaveWorksRecieveDisplacementDelegate);
  42.    
  43.     FVector newActorPosition;
  44.     newActorPosition.X = WaveWorksOutDisplacement.X * 100.0f + InitialPosition.X;
  45.     newActorPosition.Y = WaveWorksOutDisplacement.Y * 100.0f + InitialPosition.Y;
  46.     newActorPosition.Z = WaveWorksOutDisplacement.Z * 100.0f + WaveWorksComponent->SeaLevel;
  47.     GetOwner()->SetActorLocation(newActorPosition);
  48. }
  49.  
  50. void UFloatingSphere::OnRecievedWaveWorksDisplacement(TArray<FVector4> OutDisplacements)
  51. {
  52.     if (OutDisplacements.Num() > 0)
  53.     {
  54.         WaveWorksOutDisplacement = OutDisplacements[0];
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement