Advertisement
Guest User

BlackHoleSkill.h

a guest
Apr 12th, 2021
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.46 KB | None | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3. #pragma once
  4.  
  5. #include "CoreMinimal.h"
  6. #include "GameFramework/Actor.h"
  7. #include "BlackHoleSkill.generated.h"
  8.  
  9. class AParticleMovementSpline;
  10. class UMaterialInstanceDynamic;
  11. class UNiagaraComponent;
  12. class UNiagaraSystem;
  13. class UProjectileMovementComponent;
  14. class USphereComponent;
  15. class USplineComponent;
  16.  
  17. /** Enumaration containing values for possible axis in a Euclidian space */
  18. namespace EAxisSet
  19. {
  20.     UENUM()
  21.     enum Type
  22.     {
  23.         X = 0,
  24.         Y = 1,
  25.         Z = 2,
  26.  
  27.         XY = 3,
  28.         MinusXY = 4,
  29.         XZ = 5,
  30.         MinusXZ = 6,
  31.         YZ = 7,
  32.         MinusYZ = 8,
  33.         XYZ = 9
  34.     };
  35. }
  36.  
  37. /** Enumaration containing values for possible planes in a Euclidian space */
  38. namespace EPlane {
  39.  
  40.     UENUM()
  41.     enum Type
  42.     {
  43.         YZ = 1,
  44.         XZ = 2,
  45.         XY = 3
  46.     };
  47.  
  48. }
  49.  
  50. struct FBlackHoleOrbitData
  51. {      
  52.     /** Value used to notify that an orbit data was perfectly initialized */
  53.     bool OrbitFlag = false;
  54.    
  55.     /** Value used to define the orbit pitch angle */
  56.     float OrbitPitch;
  57.  
  58.     /** Value used to define the orbit roll angle */   
  59.     float OrbitRoll;
  60.  
  61.     /** Value of the elliptic orbit semi major axis */ 
  62.     float OrbitSemiMajorAxis;
  63.  
  64.     /** Value used to define the orbit yaw angle */
  65.     float OrbitYaw;
  66.        
  67.     float ProportionalityFactor = 0.f;
  68.        
  69.     float StretchFactor;
  70.  
  71.     /**
  72.      * Value used to store the angle between the black hole and a orbiting
  73.      * actor, projected in the YZ plane
  74.      */
  75.     float YZAngle;
  76.  
  77.     /**
  78.      * Value used to store the angle between the black hole and a orbiting
  79.      * actor, projected in the XY plane
  80.      */
  81.     float XYAngle;
  82.  
  83.     /**
  84.      * Value used to store the angle between the black hole and a orbiting
  85.      * actor, projected in the XZ plane
  86.      */
  87.     float XZAngle;     
  88.  
  89.     /**
  90.      * The conjugate of the quaternion representing the orientation in
  91.      * the X-axis
  92.      */
  93.     FQuat InversedOrientationX;
  94.  
  95.     /**
  96.      * The conjugate of the quaternion representing the orientation in
  97.      * the Y-axis
  98.      */
  99.     FQuat InversedOrientationY;
  100.  
  101.     /**
  102.      * The conjugate of the quaternion representing the orientation in
  103.      * the Z-axis
  104.      */
  105.     FQuat InversedOrientationZ;
  106.  
  107.     /** Quaternion representing the orientation in the X-axis */   
  108.     FQuat OrientationX;
  109.  
  110.     /** Quaternion representing the orientation in the Y-axis */   
  111.     FQuat OrientationY;
  112.  
  113.     /** Quaternion representing the orientation in the Z-axis */   
  114.     FQuat OrientationZ;
  115.        
  116.     FTimerDelegate StretchTimerDelegate;
  117.        
  118.     FTimerHandle StretchTimer;
  119.        
  120.     uint16 NumPointsToBeSampled = 1;
  121.  
  122.     /** The identification pf the orbit data */
  123.     uint32 OrbitID;    
  124.        
  125.     TArray<TWeakObjectPtr<UMaterialInstanceDynamic>> OrbitingActorDynamicMaterialArr;
  126.  
  127. public:
  128.  
  129.     FBlackHoleOrbitData() {}
  130.  
  131.     ~FBlackHoleOrbitData()
  132.     {
  133.         for(TWeakObjectPtr<UMaterialInstanceDynamic> DynamicMaterialInstance :
  134.             OrbitingActorDynamicMaterialArr)
  135.         {
  136.             if(DynamicMaterialInstance.IsValid())
  137.             {
  138.                 DestructItem(DynamicMaterialInstance.Get());
  139.                 DynamicMaterialInstance = nullptr;
  140.             }
  141.         }      
  142.  
  143.     }
  144.  
  145. };
  146.  
  147. UCLASS()
  148. class PRJ_PROJECTILETESTEX_API ABlackHoleSkill : public AActor     
  149. {
  150.     GENERATED_BODY()
  151.  
  152.     /** The minimun speed that a black hole must have */
  153.     UPROPERTY(EditDefaultsOnly, Category = "Properties", meta = (AllowPrivateAccess = "true"))
  154.     float BlackHoleInitialSpeed;
  155.  
  156.     /**
  157.      * Value used to define how much a black hole life span can be
  158.      * extended
  159.      */
  160.     UPROPERTY(EditDefaultsOnly, Category = "Properties", meta = (AllowPrivateAccess = "true"))
  161.     float BlackHoleLifetimeFactor;
  162.  
  163.     /** The maximum speed that a black hole can achieve */
  164.     UPROPERTY(EditDefaultsOnly, Category = "Properties", meta = (AllowPrivateAccess = "true"))
  165.     float BlackHoleMaxSpeed;
  166.  
  167.     /** Value used to influence an orbiting actor speed */
  168.     UPROPERTY(EditDefaultsOnly, Category = "Properties", meta = (AllowPrivateAccess = "true"))
  169.     float BlackHolePullForce;      
  170.  
  171.     UPROPERTY(EditDefaultsOnly, Category = "Properties", meta = (AllowPrivateAccess = "true"))
  172.     float EllipticalMovementRate;
  173.  
  174.     UPROPERTY(EditDefaultsOnly, Category = "Properties", meta = (AllowPrivateAccess = "true"))
  175.     float SemiMajorAxisFactor;
  176.        
  177.     TArray<TSharedPtr<FBlackHoleOrbitData>> OrbitDataArr;
  178.  
  179.     UPROPERTY()
  180.     TArray<int> CollisionTypeArr;
  181.  
  182.     UPROPERTY()
  183.     TArray<UPrimitiveComponent*> PreviouslyOverlapppedComponentArr;
  184.  
  185.     UPROPERTY()
  186.     UNiagaraComponent* BlackHoleVFXComp = nullptr;
  187.    
  188.     UPROPERTY(EditDefaultsOnly, Category = "Visual Effects", meta = (AllowPrivateAccess = "true"))
  189.     UNiagaraSystem* BlackHoleVFX = nullptr;    
  190.  
  191.     UPROPERTY()
  192.     UProjectileMovementComponent* BlackHoleMovementComp = nullptr;
  193.  
  194.     UPROPERTY(VisibleDefaultsOnly, Category = "Properties", meta = (AllowPrivateAccess = "true"))
  195.     USphereComponent* BlackHoleGravitationalInfluenceSpace = nullptr;  
  196.  
  197.     void CalculateOrbitOrientation(const FVector& OrbitOrigin, const FBlackHoleOrbitData& OrbitData, FVector& OrbitPosition);
  198.    
  199.     FVector CalculateOrbitPosition(const FVector& OrbitOrigin, FBlackHoleOrbitData& OrbitData);
  200.    
  201.     /**
  202.      * Compares two arrays containing UPrimitiveComponent pointers.
  203.      * @param Arr1 - The array that will be compared to
  204.      * @param Arr2 - The base array that will be used to make the comparison
  205.      * @return Confirms the equality between the arrays
  206.      */
  207.     bool Compare(TArray<UPrimitiveComponent*> Arr1, TArray<UPrimitiveComponent*> Arr2);
  208.    
  209.     void DrawPrimaryHelpers(const FVector& BlackHoleLocation);
  210.  
  211.     void DrawSecondaryHelpers(const FVector& BlackHoleLocation, const FVector& OrbitingActorLocation, const FBlackHoleOrbitData& NewOrbitData);
  212.  
  213.     FVector EstimateOrbitPosition(const FVector& OrbitOrigin, const FBlackHoleOrbitData& OrbitData, uint32 AngleMultiplier);
  214.  
  215.     TSharedPtr<FBlackHoleOrbitData> GenerateOrbitData(UPrimitiveComponent* OverlappedComponent);
  216.  
  217.     float GetAngleBetween(const FVector& Vec1, const FVector& Vec2, EPlane::Type ProjectionPlane);
  218.    
  219.     UFUNCTION()
  220.     //void UpdateMaterials(uint16& FibonacciTerm, TArray<UMaterialInstanceDynamic*>& DynamicMaterialArr);
  221.     void UpdateDisplacementEffect(const FVector& OrbitOrigin, FBlackHoleOrbitData& OrbitData);
  222.    
  223. public:
  224.     // Sets default values for this actor's properties
  225.     ABlackHoleSkill(const FObjectInitializer& ObjectInitializer);
  226.  
  227. protected:
  228.     // Called when the game starts or when spawned
  229.     virtual void BeginPlay() override; 
  230.  
  231.     virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;   
  232.    
  233. public:
  234.     void MoveInDirection(FVector Direction);
  235.  
  236.     virtual void PostInitializeComponents();   
  237.  
  238.     // Called every frame
  239.     virtual void Tick(float DeltaTime) override;
  240.  
  241. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement