Skip to content

Instantly share code, notes, and snippets.

@Pranavpaharia
Created December 4, 2019 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pranavpaharia/ef74336ef790d9d01a71bb127b066cb2 to your computer and use it in GitHub Desktop.
Save Pranavpaharia/ef74336ef790d9d01a71bb127b066cb2 to your computer and use it in GitHub Desktop.
maptilemanager.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "ASWP_HUD.h"
#include "Runtime/Online/HTTP/Public/Http.h"
#include "SWP_SaveManager.h"
#include "SWP_MapTileManager.generated.h"
class UStaticMeshComponent;
class USWP_SaveManager;
class ASWP_WorldPlayerPawn;
/*Constants needed to calculate Mercarter Equations*/
const int TileSize = 256;
const long EarthRadius = 6378137;
const double InitialResolution = 2* PI * EarthRadius/TileSize;
const double OriginShift = 2 * PI * EarthRadius/ 2;
const double Deg2Rad = 0.0174532924f;
#define DEBUG_ON 1;
#define DEBUG_OFF 0;
const int DEBUG_TILECOMPONENTS = DEBUG_OFF;
const int DEBUG_TILEAPIREQUEST = DEBUG_OFF;
const int DEBUG_TILEINITIALIZE = DEBUG_OFF;
const int DEBUG_TILEZOOMUPDATE = DEBUG_OFF;
const int DEBUG_TILEPANUPDATE = DEBUG_OFF;
const int DEBUG_TILEPOINTCLICK = DEBUG_OFF;
const int DEBUG_TILETEXTURE = DEBUG_OFF;
/* This structure holds the infomation which each Static Mesh Plane component needs to have.
TileID X and TileID Y and ZoomLevel is affected by each lat long and zoom level change
*/
USTRUCT(BlueprintType)
struct FTileIDStruct
{
GENERATED_USTRUCT_BODY();
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = GeoLocation)
int32 TileX;
/* True North */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = GeoLocation)
int32 TileY;
/* Calibrated */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = GeoLocation)
int32 ZoomLevel;
FTileIDStruct()
{
TileX = 0;
TileY = 0;
ZoomLevel = 0;
}
};
/*Structure to hold the Pixel to Meters Value in Min, Max, Center and Size */
USTRUCT(BlueprintType)
struct FRectD
{
GENERATED_USTRUCT_BODY();
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = GeoLocation)
FVector2D Min;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = GeoLocation)
FVector2D Max;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = GeoLocation)
FVector2D Size;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = GeoLocation)
FVector2D Center;
FRectD()
{
Min = Max = Size = Center = FVector2D::ZeroVector;
}
FRectD(FVector2D min, FVector2D size)
{
Min = min;
Max = min + size;
Center = FVector2D(Min.X + size.X / 2, Min.Y + size.Y / 2);
Size = FVector2D(FMath::Abs(size.X), FMath::Abs(size.Y));
}
FRectD ReverseXY(FRectD tRectd)
{
FVector2D tMin = tRectd.Min, tMax = tRectd.Max, tSize = tRectd.Size, tCenter = tRectd.Center;
tRectd.Min.X = tMin.Y;
tRectd.Min.Y = tMin.X;
tRectd.Max.X = tMax.Y;
tRectd.Max.X = tMax.Y;
tRectd.Center.X = tCenter.Y;
tRectd.Center.Y = tCenter.X;
tRectd.Size.X = tSize.Y;
tRectd.Size.Y = tSize.X;
return tRectd;
}
};
/*Structure to Hold Direction Bounds*/
USTRUCT(BlueprintType)
struct FDirectionBounds
{
GENERATED_USTRUCT_BODY();
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = GeoLocation)
FVector2D SouthWest;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = GeoLocation)
FVector2D NorthEast;
FDirectionBounds()
{
SouthWest = FVector2D::ZeroVector;
NorthEast = FVector2D::ZeroVector;
};
FDirectionBounds(FVector2D sw, FVector2D ne)
{
SouthWest = sw;
NorthEast = ne;
};
double GetSouth()
{
return SouthWest.X;
}
double GetWest()
{
return SouthWest.Y;
}
double GetNorth()
{
return NorthEast.X;
}
double GetEast()
{
return NorthEast.Y;
}
FVector2D Center()
{
auto Tlatitude = (SouthWest.X + NorthEast.X) / 2;
auto Tlongitude = (SouthWest.Y + NorthEast.Y) / 2;
return FVector2D(Tlatitude, Tlongitude);
}
};
UCLASS(BlueprintType)
class SMARTWORLDPRO_API ASWP_MapTileManager : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ASWP_MapTileManager();
//Add Tile Static Mesh Components.
//Each Static Mesh will be responsible for a Material Instance of its own.
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane00;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane01;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane02;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane03;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane04;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane10;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane11;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane12;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane13;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane14;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane20;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane21;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane22;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane23;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane24;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane30;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane31;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane32;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane33;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane34;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane40;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane41;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane42;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane43;
UPROPERTY(VisibleAnywhere)
class UStaticMeshComponent* plane44;
UPROPERTY(VisibleAnywhere)
class USceneComponent* ManagerRoot;
/*Collection of Spawnable Tiles*/
TArray<UStaticMeshComponent*> planes;
/*Map to combine Tile ID Structure with each Static Mesh Plane Component*/
TMap<UStaticMeshComponent*, FTileIDStruct*> tileStructureMap;
/*Map to combine Tile ID Structure with each Mesh Texture2D*/
TMap<FTileIDStruct*, UTexture2D> cacheTileMap;
FTileIDStruct centerTileIDStruct;
/**
* Here we can act on initialized components. We need not to wait for BeginPlay()
*/
virtual void PostInitializeComponents() override;
/* Here we set the code instructions to setup position and other variables needs when the object is spawned*/
virtual void BeginPlay() override;
//Material object which will be used to get the material from Engine Content for Testing purpose
class UMaterial* mStaticMesh;
//Material to get the Required Material Instance from Content
class UMaterialInstance* mTileInst;
//Runtime Material Instance Object needed to get Current Object material and change its properties
class UMaterialInstanceDynamic* mTileInstDyn;
/* This function gives the Tile ID details based on latitude and longitude and zoomlevel */
FTileIDStruct CalculateTileIDForCenterGridElement(float latitude, float longitude, int zoomLevel);
/*These are the individual textures object which will hold the texture data coming from
HTTP Request for each static mesh plane component*/
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTex;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane00;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane01;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane02;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane03;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane04;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane10;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane11;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane12;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane13;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane14;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane20;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane21;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane22;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane23;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane24;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane30;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane31;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane32;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane33;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane34;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane40;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane41;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane42;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane43;
UPROPERTY(VisibleAnywhere)
UTexture2D* ImageTexPlane44;
/*Number of Rows in Grid. Put the value in constructor*/
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
int32 rows;
/*Number of Columns in Grid. Put the value in constructor*/
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
int32 columns;
/*Added Static Mesh Length Value*/
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
float blocklength;
/*Zoom Level to keep check on how much we need*/
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
int32 zoomLevel;
/*This will send the quality level to REST API*/
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
int32 qualityLevel;
int zoomLvlPrev = 0;
/*Craete the Grid based on Row and Col values and Allocate the material instance */
void CreateMapGrid(int row, int col);
/*Zoom Level Changes fetches new textures for the tiles generated*/
void GetTileIDsBasedOnZoomLevel(int zoomLevel);
void GetTileIDsBasedOnZoomLevel(int zoomLevel, FVector2D& LatLongVector);
/*A blueprint callable function which creates webrequest for all the tiles*/
UFUNCTION(BlueprintCallable)
void CreateWebRequestForTiles();
/*Creating Tile ID Based on Center Grid. Its hard coded from 3x3 grid*/
UFUNCTION(BlueprintCallable)
void GenerateTileIDForGridElements(FTileIDStruct idInfo);
protected:
/**/
/*Component Strings*/
FString tileName00 = TEXT("");
FString tileName01 = TEXT("");
FString tileName02 = TEXT("");
FString tileName03 = TEXT("");
FString tileName04 = TEXT("");
FString tileName10 = TEXT("");
FString tileName11 = TEXT("");
FString tileName12 = TEXT("");
FString tileName13 = TEXT("");
FString tileName14 = TEXT("");
FString tileName20 = TEXT("");
FString tileName21 = TEXT("");
FString tileName22 = TEXT("");
FString tileName23 = TEXT("");
FString tileName24 = TEXT("");
FString tileName30 = TEXT("");
FString tileName31 = TEXT("");
FString tileName32 = TEXT("");
FString tileName33 = TEXT("");
FString tileName34 = TEXT("");
FString tileName40 = TEXT("");
FString tileName41 = TEXT("");
FString tileName42 = TEXT("");
FString tileName43 = TEXT("");
FString tileName44 = TEXT("");
FTileIDStruct* plane00Struct = new FTileIDStruct();
FTileIDStruct* plane01Struct = new FTileIDStruct();
FTileIDStruct* plane02Struct = new FTileIDStruct();
FTileIDStruct* plane03Struct = new FTileIDStruct();
FTileIDStruct* plane04Struct = new FTileIDStruct();
FTileIDStruct* plane10Struct = new FTileIDStruct();
FTileIDStruct* plane11Struct = new FTileIDStruct();
FTileIDStruct* plane12Struct = new FTileIDStruct();
FTileIDStruct* plane13Struct = new FTileIDStruct();
FTileIDStruct* plane14Struct = new FTileIDStruct();
FTileIDStruct* plane20Struct = new FTileIDStruct();
FTileIDStruct* plane21Struct = new FTileIDStruct();
FTileIDStruct* plane22Struct = new FTileIDStruct();
FTileIDStruct* plane23Struct = new FTileIDStruct();
FTileIDStruct* plane24Struct = new FTileIDStruct();
FTileIDStruct* plane30Struct = new FTileIDStruct();
FTileIDStruct* plane31Struct = new FTileIDStruct();
FTileIDStruct* plane32Struct = new FTileIDStruct();
FTileIDStruct* plane33Struct = new FTileIDStruct();
FTileIDStruct* plane34Struct = new FTileIDStruct();
FTileIDStruct* plane40Struct = new FTileIDStruct();
FTileIDStruct* plane41Struct = new FTileIDStruct();
FTileIDStruct* plane42Struct = new FTileIDStruct();
FTileIDStruct* plane43Struct = new FTileIDStruct();
FTileIDStruct* plane44Struct = new FTileIDStruct();
/*Create Web Request for Each Plane Based on the TileX, TileY, Zoom And Quality Parameters*/
void CreateWebRequestPlane00(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane01(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane02(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane03(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane04(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane10(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane11(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane12(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane13(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane14(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane20(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane21(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane22(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane23(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane24(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane30(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane31(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane32(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane33(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane34(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane40(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane41(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane42(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane43(int zoomLevel, int XValue, int YValue, int QualityValue);
void CreateWebRequestPlane44(int zoomLevel, int XValue, int YValue, int QualityValue);
/*Load and Parse 2D Texture from ByteArray coming from server*/
void OnLoadWebRequestFinishedPlane00(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane01(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane02(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane03(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane04(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane10(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane11(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane12(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane13(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane14(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane20(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane21(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane22(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane23(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane24(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane30(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane31(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane32(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane33(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane34(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane40(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane41(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane42(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane43(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnLoadWebRequestFinishedPlane44(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
/*Set the Newly loaded texture to current texture of each Tile Plane */
void UpdateTextureDatatoPlane00(const UTexture2D* img);
void UpdateTextureDatatoPlane01(const UTexture2D* img);
void UpdateTextureDatatoPlane02(const UTexture2D* img);
void UpdateTextureDatatoPlane03(const UTexture2D* img);
void UpdateTextureDatatoPlane04(const UTexture2D* img);
void UpdateTextureDatatoPlane10(const UTexture2D* img);
void UpdateTextureDatatoPlane11(const UTexture2D* img);
void UpdateTextureDatatoPlane12(const UTexture2D* img);
void UpdateTextureDatatoPlane13(const UTexture2D* img);
void UpdateTextureDatatoPlane14(const UTexture2D* img);
void UpdateTextureDatatoPlane20(const UTexture2D* img);
void UpdateTextureDatatoPlane21(const UTexture2D* img);
void UpdateTextureDatatoPlane22(const UTexture2D* img);
void UpdateTextureDatatoPlane23(const UTexture2D* img);
void UpdateTextureDatatoPlane24(const UTexture2D* img);
void UpdateTextureDatatoPlane30(const UTexture2D* img);
void UpdateTextureDatatoPlane31(const UTexture2D* img);
void UpdateTextureDatatoPlane32(const UTexture2D* img);
void UpdateTextureDatatoPlane33(const UTexture2D* img);
void UpdateTextureDatatoPlane34(const UTexture2D* img);
void UpdateTextureDatatoPlane40(const UTexture2D* img);
void UpdateTextureDatatoPlane41(const UTexture2D* img);
void UpdateTextureDatatoPlane42(const UTexture2D* img);
void UpdateTextureDatatoPlane43(const UTexture2D* img);
void UpdateTextureDatatoPlane44(const UTexture2D* img);
void LoadSavedTexturePlane00(FString loadStr);
void LoadSavedTexturePlane01(FString loadStr);
void LoadSavedTexturePlane02(FString loadStr);
void LoadSavedTexturePlane03(FString loadStr);
void LoadSavedTexturePlane04(FString loadStr);
void LoadSavedTexturePlane10(FString loadStr);
void LoadSavedTexturePlane11(FString loadStr);
void LoadSavedTexturePlane12(FString loadStr);
void LoadSavedTexturePlane13(FString loadStr);
void LoadSavedTexturePlane14(FString loadStr);
void LoadSavedTexturePlane20(FString loadStr);
void LoadSavedTexturePlane21(FString loadStr);
void LoadSavedTexturePlane22(FString loadStr);
void LoadSavedTexturePlane23(FString loadStr);
void LoadSavedTexturePlane24(FString loadStr);
void LoadSavedTexturePlane30(FString loadStr);
void LoadSavedTexturePlane31(FString loadStr);
void LoadSavedTexturePlane32(FString loadStr);
void LoadSavedTexturePlane33(FString loadStr);
void LoadSavedTexturePlane34(FString loadStr);
void LoadSavedTexturePlane40(FString loadStr);
void LoadSavedTexturePlane41(FString loadStr);
void LoadSavedTexturePlane42(FString loadStr);
void LoadSavedTexturePlane43(FString loadStr);
void LoadSavedTexturePlane44(FString loadStr);
/*
*/
/*Get the x and y position of the object with respect to */
FVector2D GeoToWorldPosition(double latitude, double longitude, FVector2D refPoint, float Scale = 1);
/*Get the Tile Scale in Meters*/
float GetTileScaleInMeters(float latitude, int zoom);
/*Get Tile Scale in Degrees*/
float GetTileScaleInDegrees(float latitude, int zoom);
/*Calculating Mercator Constant*/
FVector2D LatLonToMeters(double latitude, double longitude);
/*Get Resolution Constant Based on Zoom*/
FORCEINLINE double Resolution(int zoom)
{
return InitialResolution / FMath::Pow(2, zoom);
}
/*
double TileYtoNWLatitude(int y, int zoom);
double TileXtoNWLongitude(int x, int zoom);
FDirectionBounds TileIDToBounds(int x, int y, int zoom);
FVector2D TileIDToCenterLatitudeLongitude(int x, int y, int zoom);
*/
FVector2D PixelsToMeters(FVector2D p, int zoom);
FRectD TileBounds(FVector2D tileCoordinate, int zoom);
void RearrangeGridElements(double latitude,double longitude, int CenterX, int CenterY);
void GetNewLocation(UStaticMeshComponent& mesh, int x, int y, int z);
FVector2D MapCenterLatLong;
FRectD ReferenceTileRect;
FVector2D CenterMerc;
float panSpeed = 50.0f;
double mapLat = 28.507878f;//77.085348;
double mapLon = 77.085348f;
double mapLatMax = 85.0511f;
double mapLonMax = 180.f;
UPROPERTY(VisibleAnywhere, Category = Basic)
float SaveTimer = 1.f;
UPROPERTY(VisibleAnywhere, Category = Basic)
float currentSaveTimer = 0.f;
FVector2D mapCenterLatLong;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
/*Pan Method with Horizontal and vertical values*/
void PanMapUsingKeyboard(float hValue, float vValue);
/*Pan Method with Mouse Delta*/
void PanMapUsingMouse(const FVector2D& delMousePos);
/* Convert Vect3 Position into Lat and Long*/
FVector2D WorldToGeographyPosition(FVector realWorldPosition);//, FVector2D refPoint, float scale = 1);
FVector2D MetersToLatLon(FVector2D MeterPosition);
void ResetPawnPosition(FVector Position);
void CheckTileVisibleTimer();
AASWP_HUD* HUDRef;
FTimerHandle tileViewTimerHandle;
FTimerDelegate tileViewTimerDelegate;
void SaveTileInDatabase(int TileX,int TileY,int zoomL,UTexture2D* tex2D);
void SaveTileTexture(int TileX, int TileY, int zoomL, UTexture2D* tex2D);
void SaveTextureToDisk(UTexture2D* texture, const FString& file);
bool InstantiateSaveGameObject();
bool FindTileMapInDatabase(FString texName);
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = Basic)
USWP_SaveManager* mSaveGameSlot;
bool AddTileIDinSaveGameObject(FString texName);
bool SaveTileData();
bool bCheckSaveTimer = false;
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = Basic)
TArray<FString> ManagerTileList;
FName MapActorTag = TEXT("MapActor");
//UObjectLibrary* ObjectLibrary;
ASWP_WorldPlayerPawn* worldPawn;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment