Skip to content

Instantly share code, notes, and snippets.

@Pranavpaharia

Pranavpaharia/cpp

Created Dec 4, 2019
Embed
What would you like to do?
SWP_WorldPlayerPawn.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "SWP_WorldPlayerPawn.h"
#include "EngineUtils.h"
#include "SWP_EarthActor.h"
#include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"
#include "SWP_MapTileManager.h"
#include "DrawDebugHelpers.h"
#include "SmartWorldPro.h"
#include "Runtime/Renderer/Public/PrimitiveSceneInfo.h"
#include "Runtime/Engine/Classes/GameFramework/PawnMovementComponent.h"
#include "GameFramework/GameState.h"
#include "SWP_HelperClass.h"
#include "SWP_WorldGameMode.h"
#include "Camera/CameraComponent.h"
#include "GameFramework/SpringArmComponent.h"
//class UPawnMovementComponent;
class UGameUserSettings;
ASWP_WorldPlayerPawn::ASWP_WorldPlayerPawn(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
/*SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArm0"));
SpringArm->SetupAttachment(RootComponent);
SpringArm->TargetArmLength = 300.0f;
SpringArm->SocketOffset = FVector(0.f, 0.f, 60.f);*/
bOnMouseDown = false;
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera0"));
Camera->SetupAttachment(RootComponent);
PrimaryActorTick.bStartWithTickEnabled = true;
// actorMoveComponent = GetMovementComponent();
/*if (actorMoveComponent != nullptr)
{
GEngine->AddOnScreenDebugMessage(-1, 0.1f, FColor::White, FString::Printf(TEXT("Found Movement Component")));
}*/
}
void ASWP_WorldPlayerPawn::PostInitializeComponents()
{
Super::PostInitializeComponents();
pms_upState = EPMS_UpSide::UpSide_Inside;
pms_downState = EPMS_DownSide::DownSide_Inside;
pms_leftState = EPMS_LeftSide::LeftSide_Inside;
pms_rightState = EPMS_RightSide::RightSide_Inside;
}
void ASWP_WorldPlayerPawn::TurnAtRate(float rate)
{
//GEngine->AddOnScreenDebugMessage(-1, 0.1f, FColor::White, FString::Printf(TEXT("Turn Rate Value: %f"), rate));
}
void ASWP_WorldPlayerPawn::LookUpAtRate(float rate)
{
//GEngine->AddOnScreenDebugMessage(-1, 0.1f, FColor::White, FString::Printf(TEXT("Lookup Rate Value: %f"), rate));
}
void ASWP_WorldPlayerPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
check(PlayerInputComponent);
PlayerInputComponent->BindAxis("DefaultPawn_LookUp", this, &ASWP_WorldPlayerPawn::LookUpAtRate);
PlayerInputComponent->BindAxis("DefaultPawn_Turn", this, &ASWP_WorldPlayerPawn::TurnAtRate);
PlayerInputComponent->BindAxis("ZoomRate", this, &ASWP_WorldPlayerPawn::ZoomingMethod);
PlayerInputComponent->BindAction("SetDestination",IE_Pressed, this, &ASWP_WorldPlayerPawn::ClickedMouseDown);
PlayerInputComponent->BindAction("SetDestination", IE_Released, this, &ASWP_WorldPlayerPawn::ClickedMouseReleased);
PlayerInputComponent->BindAction("MoveUp", IE_Pressed, this, &ASWP_WorldPlayerPawn::GoUpwardsPressed);
PlayerInputComponent->BindAction("MoveUp",IE_Released, this, &ASWP_WorldPlayerPawn::GoUpwardsReleased );
PlayerInputComponent->BindAction("MoveDown",IE_Pressed, this, &ASWP_WorldPlayerPawn::GoDownwardsPressed);
PlayerInputComponent->BindAction("MoveDown", IE_Released, this, &ASWP_WorldPlayerPawn::GoDownwardsReleased);
PlayerInputComponent->BindAction("MoveLeft", IE_Pressed, this, &ASWP_WorldPlayerPawn::GoLeftPressed);
PlayerInputComponent->BindAction("MoveLeft", IE_Released, this, &ASWP_WorldPlayerPawn::GoLeftReleased);
PlayerInputComponent->BindAction("MoveRight", IE_Pressed, this, &ASWP_WorldPlayerPawn::GoRightPressed);
PlayerInputComponent->BindAction("MoveRight", IE_Released, this, &ASWP_WorldPlayerPawn::GoRightReleased);
}
void ASWP_WorldPlayerPawn::GoUpwardsPressed()
{
KeyboardDeltaY = 2.0f;
bMoveKeyboardCamera = true;
}
void ASWP_WorldPlayerPawn::GoUpwardsReleased()
{
KeyboardDeltaY = 0;
bMoveKeyboardCamera = false;
}
void ASWP_WorldPlayerPawn::GoDownwardsPressed()
{
KeyboardDeltaY = -2.0f;
bMoveKeyboardCamera = true;
}
void ASWP_WorldPlayerPawn::GoDownwardsReleased()
{
KeyboardDeltaY = 0;
bMoveKeyboardCamera = false;
}
void ASWP_WorldPlayerPawn::GoLeftPressed()
{
bMoveKeyboardCamera = true;
KeyboardDeltaX = -2.0f;
}
void ASWP_WorldPlayerPawn::GoLeftReleased()
{
KeyboardDeltaX = 0;
bMoveKeyboardCamera = false;
}
void ASWP_WorldPlayerPawn::GoRightPressed()
{
bMoveKeyboardCamera = true;
KeyboardDeltaX = 2.0f;
}
void ASWP_WorldPlayerPawn::GoRightReleased()
{
KeyboardDeltaX = 0;
bMoveKeyboardCamera = false;
}
void ASWP_WorldPlayerPawn::PanMap(FVector2D panVector)
{
FVector movementVec = FVector(panVector.X, panVector.Y, 0);
GetMovementComponent()->AddInputVector(movementVec);
}
void ASWP_WorldPlayerPawn::ClickedMouseDown()
{
bOnMouseDown = true;
//Get to know you clicked on Map Tile
FHitResult OutHit;
FVector Start = GetActorLocation();
// alternatively you can get the camera location
// FVector Start = FirstPersonCameraComponent->GetComponentLocation();
FVector ForwardVector = Camera->GetForwardVector();
FVector End = ((ForwardVector * 1000.f) + Start);
FCollisionQueryParams CollisionParams;
//DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 20, 0, 2);
if (GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_Visibility, CollisionParams))
{
if (OutHit.bBlockingHit)
{
if (GEngine)
{
//FString str192 = OutHit.GetActor()->Tags[0].ToString();
//GEngine->AddOnScreenDebugMessage(-1, 1.f, FColor::Red, FString::Printf(TEXT("You are hitting: %s"), *OutHit.GetActor()->GetName()));
//GEngine->AddOnScreenDebugMessage(-1, 1.f, FColor::Red, FString::Printf(TEXT("Impact Point: %s"), *OutHit.ImpactPoint.ToString()));
//GEngine->AddOnScreenDebugMessage(-1, 1.f, FColor::Red, FString::Printf(TEXT("Normal Point: %s"), *OutHit.ImpactNormal.ToString()));
if (OutHit.Actor->ActorHasTag(TEXT("MapActor")))
{
UE_LOG(LogSmartWorldPro, Warning, TEXT("Found Map Actor"));
EarthRef = Cast<ASWP_MapTileManager>(OutHit.Actor);
bMoveLocalCamera = true;
}
//*OutHit.GetActor()->GetName()
//FString str192 = TEXT("NewString");
//str192 = OutHit.GetActor()->Tags[0].ToString();
}
}
}
//Make Mouse Drag bool On
}
void ASWP_WorldPlayerPawn::GetEarthReference()
{
for (TActorIterator<AActor> ActorItr(GetWorld()); ActorItr; ++ActorItr)
{
// Same as with the Object Iterator, access the subclass instance with the * or -> operators.
if(ActorItr->ActorHasTag(TEXT("MapActor")))
{
UE_LOG(LogSmartWorldPro, Warning, TEXT("Attempt to Find MapTiler Successful"));
EarthRef = Cast<ASWP_MapTileManager>(*ActorItr);
}
//EarthRef = Cast<ASWP_MapTileManager>(*ActorItr);
}
}
void ASWP_WorldPlayerPawn::ClickedMouseReleased()
{
if (bMoveLocalCamera)
{
bMoveLocalCamera = false;
}
bOnMouseDown = false;
FVector2D mousePosition = FVector2D();
playerController->GetMousePosition(mousePosition.X, mousePosition.Y);
/*if (EarthRef == nullptr)
return;*/
float GroundLevel = EarthRef->GetActorLocation().Z;
const FPlane groundPlane = FPlane(FVector(0, 0, GroundLevel), -(FVector::UpVector));
ULocalPlayer* const MyPlayer = Cast<ULocalPlayer>(playerController->Player);
FVector RayOrigin, RayDirection;
SWP_HelperClass::DeprojectiScreenToWorld(mousePosition, MyPlayer, RayOrigin, RayDirection);
FVector WorldPoint = SWP_HelperClass::IntersectRayWithPlane(RayOrigin, RayDirection, groundPlane);
//UE_LOG(LogSmartWorldPro, Warning, TEXT("Value of Intersection Point is %s"), *WorldPoint.ToString());
//DrawDebugLine(GetWorld(), GetActorLocation(), WorldPoint, FColor::Yellow, false, 20,0,2);
FVector WorldDirection, WorldTranceEnd;
if (playerController->DeprojectScreenPositionToWorld(mousePosition.X, mousePosition.Y, WorldPoint, WorldDirection))
{
// UE_LOG(LogSmartWorldPro, Warning, TEXT("Value of Intersection Point From Player Controller DeprojectScreenPositiontoWorld is %s"), *WorldPoint.ToString());
// UE_LOG(LogSmartWorldPro, Warning, TEXT("Value of Intersection Direction From Player Controller DeprojectScreenPositiontoWorld is %s"), *WorldDirection.ToString());
WorldTranceEnd = WorldPoint + WorldDirection * 300;
FName colName = FName("CollisionFname");
FCollisionQueryParams QueryParams(colName, true, NULL);
FCollisionResponseParams ResponseParams(ECollisionResponse::ECR_Overlap);
FHitResult Hit = FHitResult(ForceInit);
if (GetWorld()->LineTraceSingleByChannel(Hit, WorldPoint, WorldTranceEnd, ECollisionChannel::ECC_Camera, QueryParams))//, ResponseParams))
{
// DrawDebugLine(GetWorld(), WorldPoint, WorldTranceEnd, FColor::Magenta, true, 20, 0, 2);
FString ActorName = Hit.Actor->GetFName().ToString();
FString ComponentName = Hit.Component->GetFName().ToString();
//UE_LOG(LogSmartWorldPro, Warning, TEXT("Hit Object Location: %s and Component Name: %s"), *Hit.Component->GetComponentLocation().ToString(), *Hit.Component->GetFName().ToString());
//UE_LOG(LogSmartWorldPro, Warning, TEXT("Hit Location is: %s"), *Hit.Location.ToString());
check(EarthRef)
{
//FVector placeHolder = FVector(40, 0, 0);
//UE_LOG(LogSmartWorldPro, Warning, TEXT("Earth Refernece Found"));
auto vecPos = EarthRef->WorldToGeographyPosition(Hit.Location/100);
//auto vecPos = EarthRef->WorldToGeographyPosition(FVector(0.4,0,0));
//UE_LOG(LogSmartWorldPro, Warning, TEXT("World Location is: %s"), *Hit.Location.ToString());
//UE_LOG(LogSmartWorldPro, Warning, TEXT("Lat Long Location is: %s"), *vecPos.ToString());
MarkerCube->SetActorLocation(FVector(Hit.Location.X, Hit.Location.Y, 0), false, nullptr, ETeleportType::None);
//MarkerCube->SetActorLocation(placeHolder, false, nullptr, ETeleportType::None);
FString str1 = TEXT("Latitude: ") + FString::SanitizeFloat(vecPos.X);// +TEXT(" Longitude: ") + FString::SanitizeFloat(vecPos.Y);
FString str2 = TEXT(" Longitude: ") + FString::SanitizeFloat(vecPos.Y);
HUDRef->DebugStringValue2 = str1;
HUDRef->DebugStringValue3 = str2;
DebugMenuWidget->Latitude = vecPos.X;
DebugMenuWidget->Longitude = vecPos.Y;
//HUDRef->DrawText(vecPos.ToString(), FLinearColor::Blue, 200, 200, NULL, 1, false);
//CalculateMarkerVector();
//PanMapUsingMouse();
}
}
}
//UE_LOG(LogSmartWorldPro, Warning, TEXT("Value of Intersection Point is %s"), *WorldPoint.ToString());
}
void ASWP_WorldPlayerPawn::CalculateCenterLatitudeLongitude(FVector worldPoint)
{
FVector centerTileLocation;
if (EarthRef != nullptr)
{
centerTileLocation = EarthRef->plane22->GetComponentLocation();
if (centerTileLocation.X > worldPoint.X)
{
zoomCenterWorldVector.X = (centerTileLocation.X - worldPoint.X) + worldPoint.X;
}
else if (centerTileLocation.X < worldPoint.X)
{
zoomCenterWorldVector.X = (worldPoint.X - centerTileLocation.X) + worldPoint.X;
}
if (centerTileLocation.Y > worldPoint.Y)
{
zoomCenterWorldVector.Y = (centerTileLocation.Y - worldPoint.Y) + worldPoint.Y;
}
else if (centerTileLocation.Y < worldPoint.Y)
{
zoomCenterWorldVector.Y = (worldPoint.Y - centerTileLocation.Y) + worldPoint.Y;
}
}
}
FVector2D& ASWP_WorldPlayerPawn::GetScreenCenter()
{
if (GEngine != nullptr && GEngine->GameViewport != nullptr)
{
GEngine->GameViewport->GetViewportSize(mapCenterSizeVector);
}
return mapCenterSizeVector;
}
void ASWP_WorldPlayerPawn::ZoomingMethod(float Rate)
{
if (EarthRef == nullptr)
GetEarthReference();
if (!bLookZoomCenter)
return;
bLookZoomCenter = false;
//Get the screen center coordinates
FVector WorldDirection, WorldTranceEnd;
FVector WorldPoint = Camera->GetComponentLocation();
if (playerController->DeprojectScreenPositionToWorld(GetScreenCenter().X, GetScreenCenter().Y, WorldPoint, WorldDirection))
{
WorldTranceEnd = WorldPoint + WorldDirection * 300;
FName colName = FName("CollisionFname");
FCollisionQueryParams QueryParams(colName, true, NULL);
FCollisionResponseParams ResponseParams(ECollisionResponse::ECR_Overlap);
FHitResult Hit = FHitResult(ForceInit);
if (GetWorld()->LineTraceSingleByChannel(Hit, WorldPoint, WorldTranceEnd, ECollisionChannel::ECC_Camera, QueryParams))//, ResponseParams))
{
check(EarthRef)
{
CalculateCenterLatitudeLongitude(Hit.Location);
//zoomCenterLatLonVector = EarthRef->WorldToGeographyPosition(EarthRef->plane22->GetComponentLocation()/100);
zoomCenterLatLonVector = EarthRef->WorldToGeographyPosition(zoomCenterWorldVector / 100);
FString str1 = TEXT("Latitude: ") + FString::SanitizeFloat(zoomCenterLatLonVector.X);
FString str2 = TEXT(" Longitude: ") + FString::SanitizeFloat(zoomCenterLatLonVector.Y);
UE_LOG(LogSmartWorldPro, Warning, TEXT("Zoom in Screen Center, Latitude: %s and Longitude: %s "),*str1,*str2);
//MarkerCube->SetActorLocation(FVector(Hit.ImpactPoint.X, Hit.ImpactPoint.Y, 0), false, nullptr, ETeleportType::None);
bLookZoomCenter = true;
}
}
}
/*float camRange = SpringArm->TargetArmLength;
if (camRange <= 300)
return;
float deltaChange = 100;
if (Rate > 0)
{
SpringArm->TargetArmLength = camRange + deltaChange;
}
else if (Rate < 0)
{
SpringArm->TargetArmLength = camRange - deltaChange;
}*/
//GEngine->AddOnScreenDebugMessage(-1, 0.1f, FColor::White, FString::Printf(TEXT("Cam Range : %f"), camRange));
//GEngine->AddOnScreenDebugMessage(-1, 0.1f, FColor::White, FString::Printf(TEXT("Scroll Value : %f"), Rate));
//UE_LOG(LogSmartWorldPro, Warning, TEXT("Cam Range : %f"), camRange);
if (Rate > 0.2f)
{
zoomPitch++;
if (zoomPitch > 3)
{
//EarthRef->GetTileIDsBasedOnZoomLevel(MapZoomLevel);
if (currentFOV > MinFOV)
{
currentFOV -= deltaFOV;
}
else
{
zoomPitch = 0;
MapZoomLevel++;
if (MapZoomLevel >= 16)
MapZoomLevel = 16;
//EarthRef->GetTileIDsBasedOnZoomLevel(MapZoomLevel);
EarthRef->GetTileIDsBasedOnZoomLevel(MapZoomLevel,zoomCenterLatLonVector);
currentFOV = MaxFOV;
}
Camera->FieldOfView = currentFOV;
}
}
if (Rate < -0.2f)
{
zoomPitch--;
if (zoomPitch < -2)
{
//EarthRef->GetTileIDsBasedOnZoomLevel(MapZoomLevel);
if (currentFOV < MaxFOV)
{
currentFOV += deltaFOV;
}
else
{
zoomPitch = 0;
MapZoomLevel--;
if (MapZoomLevel <= 2)
MapZoomLevel = 2;
//EarthRef->GetTileIDsBasedOnZoomLevel(MapZoomLevel);
EarthRef->GetTileIDsBasedOnZoomLevel(MapZoomLevel,zoomCenterLatLonVector);
currentFOV = MinFOV;
}
Camera->FieldOfView = currentFOV;
}
}
}
void ASWP_WorldPlayerPawn::BeginPlay()
{
Super::BeginPlay();
HUDRef = Cast<AASWP_HUD>(GetWorld()->GetFirstPlayerController()->GetHUD());
Camera->FieldOfView = 70;
currentFOV = Camera->FieldOfView;
MinFOV = 50;
MaxFOV = 72;
deltaFOV = 7.5f;
SetActorRotation(FRotator(-90, 0, 0));
SetActorLocation(FVector(-20, 20, 200));
playerController = Cast<ASWP_WorldPlayerController>(UGameplayStatics::GetPlayerController(GetWorld(), 0));
//Trying to get shared pointer reference of Earth Actor
// TO DO
//TSharedRef<ASWP_EarthActor, ESPMode::Fast> ere = AsShared();
//TSharedRef<ASWP_EarthActor> ere = AsShared();
//TSharedRef<ASWP_EarthActor> EarthRef = class ASWP_EarthActor::earth;
//TSharedRef<ASWP_EarthActor> EarthRef = StaticCastSharedRef(TSharedRef<ASWP_EarthActor>,ESPMode::Fast);
//Get Widget Reference
ASWP_WorldGameMode* gm = Cast<ASWP_WorldGameMode>(GetWorld()->GetAuthGameMode());
DebugMenuWidget = gm->DebugMenuWidget;
//Get Reference of Earth Actor by Tag
for (TActorIterator<AActor> ActorItr(GetWorld()); ActorItr; ++ActorItr)
{
// Same as with the Object Iterator, access the subclass instance with the * or -> operators.
EarthRef = Cast<ASWP_MapTileManager>(*ActorItr);
if(EarthRef != nullptr)
{
//UE_LOG(LogSmartWorldPro, Warning, TEXT("Earth Found in PlayerPawn"));
////Set the Location of Player Pawn to the Earth Actor and Increase the Spring Arm Length
//SetActorLocation(EarthRef->GetActorLocation());
//SpringArm->TargetArmLength = 2250.f;
//if (SpringArm->IsCollisionEnabled())
//{
// UE_LOG(LogSmartWorldPro, Warning, TEXT("Spring Arm Collision Enabled"));
//}
EarthRef->worldPawn = this;
MapZoomLevel = EarthRef->zoomLevel;
}
if (ActorItr->ActorHasTag(TEXT("Marker")))
{
MarkerCube = *ActorItr;
UE_LOG(LogSmartWorldPro, Warning, TEXT("Got Marker Reference"));
}
}
InitialPosition = FVector2D(GetActorLocation().X, GetActorLocation().Y);
}
void ASWP_WorldPlayerPawn::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
//CalculateMovementOffset();
if (bOnMouseDown)
{
playerController->GetInputMouseDelta(MouseDeltaX, MouseDeltaY);
// GEngine->AddOnScreenDebugMessage(-1, 0.1f, FColor::White, FString::Printf(TEXT("Mouse Delta Value: MouseX: %f :: MouseY: %f"), MouseDeltaX, MouseDeltaY));
if (MouseDeltaX > 0)
{
if (MaxMouseDeltaX < MouseDeltaX)
MaxMouseDeltaX = MouseDeltaX;
}
else if (MouseDeltaX < 0)
{
if (MaxMouseDeltaX > MouseDeltaX)
MaxMouseDeltaX = MouseDeltaX;
}
if (MouseDeltaY > 0)
{
if (MaxMouseDeltaY < MouseDeltaY)
MaxMouseDeltaY = MouseDeltaY;
}
else if (MouseDeltaY < 0)
{
if (MaxMouseDeltaY > MouseDeltaY)
MaxMouseDeltaY = MouseDeltaY;
}
}
else
{
// GEngine->AddOnScreenDebugMessage(-1, 0.1f, FColor::White, FString::Printf(TEXT("Mouse Delta Value: MaxMouseX: %f :: MaxMouseY: %f"), MaxMouseDeltaX, MaxMouseDeltaY));
}
if (bMoveKeyboardCamera)
{
CameraPanState();
FVector offPosition = FVector(0, KeyboardDeltaX, KeyboardDeltaY);
Camera->AddLocalOffset(offPosition, false, nullptr, ETeleportType::None);
//UE_LOG(LogSmartWorldPro, Warning, TEXT("OFFSet Vector %s"), *offPosition.ToString());
}
if (bMoveLocalCamera)
{
//UE_LOG(LogSmartWorldPro, Warning, TEXT("BMoveLocalCamera is true"));
CameraPanState();
FVector offPosition = FVector(0, -MouseDeltaX, -MouseDeltaY);
FVector addedOffsetPostion = Camera->RelativeLocation + offPosition;
FVector exactPositionOffset = FVector::ZeroVector;
exactPositionOffset.Y = FMath::Clamp(addedOffsetPostion.X, -2.f, 10.f);
exactPositionOffset.Z = FMath::Clamp(addedOffsetPostion.Z, -2.f, 10.f);
//this->AddActorLocalOffset(offPosition, false, nullptr, ETeleportType::None);
Camera->AddLocalOffset(offPosition, false, nullptr, ETeleportType::None);
// Camera->SetRelativeLocation(exactPositionOffset,)
//UE_LOG(LogSmartWorldPro, Warning, TEXT("OFFSet Vector %s"),*offPosition.ToString());
}
}
bool ASWP_WorldPlayerPawn::ClampLocalPositionY()
{
FVector diffPosition = Camera->RelativeLocation;
if (-7 < diffPosition.Y && diffPosition.Y < 14)
{
return true;
}
return false;
}
bool ASWP_WorldPlayerPawn::ClampLocalPositionZ()
{
FVector diffPosition = Camera->RelativeLocation;
if (-86 < diffPosition.Z && diffPosition.Z < 94)
{
return true;
}
return false;
}
void ASWP_WorldPlayerPawn::CameraPanState()
{
if (Camera->RelativeLocation.Y > MaxLeftX)
{
pms_leftState = EPMS_LeftSide::LeftSide_Inside;
}
else if (Camera->RelativeLocation.Y < -MaxLeftX)
{
pms_leftState = EPMS_LeftSide::LeftSide_Outside;
}
if (Camera->RelativeLocation.Y < MaxRightX)
{
pms_rightState = EPMS_RightSide::RightSide_Inside;
}
else if (Camera->RelativeLocation.Y > MaxRightX)
{
pms_rightState = EPMS_RightSide::RightSide_Outside;
}
if (Camera->RelativeLocation.Z < MaxUpY )
{
pms_upState = EPMS_UpSide::UpSide_Inside;
}
else if (Camera->RelativeLocation.Z > MaxUpY)
{
pms_upState = EPMS_UpSide::UpSide_Outside;
}
if (Camera->RelativeLocation.Z > MaxDownY)
{
pms_downState = EPMS_DownSide::DownSide_Inside;
}
else if (Camera->RelativeLocation.Z < MaxDownY)
{
pms_downState = EPMS_DownSide::DownSide_Outside;
}
if (pms_upState == EPMS_UpSide::UpSide_Inside)
{
if (DEBUG_PAWNMOVEMENT == 1)
{
UE_LOG(LogSmartWorldPro, Warning, TEXT("PMS_UpState = UpSide_Inside "));
}
}
else if (pms_upState == EPMS_UpSide::UpSide_Outside)
{
if (DEBUG_PAWNMOVEMENT == 1)
UE_LOG(LogSmartWorldPro, Warning, TEXT("PMS_UpState = UpSide_Outside "));
if (KeyboardDeltaY > 0)
KeyboardDeltaY = 0;
if (MouseDeltaY < 0)
MouseDeltaY = 0;
// ResetAfterPanLimit();
PanMapUsingMouse();
}
if (pms_downState == EPMS_DownSide::DownSide_Inside)
{
if (DEBUG_PAWNMOVEMENT == 1)
UE_LOG(LogSmartWorldPro, Warning, TEXT("PMS_DownState = DownSide_Inside "));
}
else if (pms_downState == EPMS_DownSide::DownSide_Outside)
{
if (DEBUG_PAWNMOVEMENT == 1)
UE_LOG(LogSmartWorldPro, Warning, TEXT("PMS_DownState = DownSide_Outside "));
if (MouseDeltaY > 0)
MouseDeltaY = 0;
if (KeyboardDeltaY < 0)
KeyboardDeltaY = 0;
//ResetAfterPanLimit();
PanMapUsingMouse();
}
if (pms_leftState == EPMS_LeftSide::LeftSide_Inside)
{
if (DEBUG_PAWNMOVEMENT == 1)
UE_LOG(LogSmartWorldPro, Warning, TEXT("PMS_LeftState = LeftSide_Inside "));
}
else if (pms_leftState == EPMS_LeftSide::LeftSide_Outside)
{
if (DEBUG_PAWNMOVEMENT == 1)
UE_LOG(LogSmartWorldPro, Warning, TEXT("PMS_LeftState = LeftSide_OutSide "));
if (MouseDeltaX > 0)
MouseDeltaX = 0;
if (KeyboardDeltaX < 0)
KeyboardDeltaX = 0;
//ResetAfterPanLimit();
PanMapUsingMouse();
}
if (pms_rightState == EPMS_RightSide::RightSide_Inside)
{
if (DEBUG_PAWNMOVEMENT == 1)
UE_LOG(LogSmartWorldPro, Warning, TEXT("PMS_RightState = RightSide_Inside "));
}
else if (pms_rightState == EPMS_RightSide::RightSide_Outside)
{
if (DEBUG_PAWNMOVEMENT == 1)
UE_LOG(LogSmartWorldPro, Warning, TEXT("PMS_RightState = RightSide_Outside "));
if (MouseDeltaX < 0)
MouseDeltaX = 0;
if (KeyboardDeltaX > 0)
KeyboardDeltaX = 0;
// ResetAfterPanLimit();
PanMapUsingMouse();
}
}
void ASWP_WorldPlayerPawn::CalculateMarkerVector()
{
FVector pos1 = MarkerCube->GetActorLocation();
FVector screenObjectVectorDir = MarkerCube->GetActorLocation() - Camera->GetComponentLocation();
FVector playerVector = (Camera->GetComponentLocation()+ Camera->GetForwardVector() * 200) - Camera->GetComponentLocation();
//FVector playerVector =
FVector posy = Camera->GetComponentLocation() + Camera->GetForwardVector() * 200;
//FirstVector = FirstVector.Normalize();
//SecondVector = SecondVector.Normalize();
screenObjectVectorDir.Normalize();
playerVector.Normalize();
float dot = FVector::DotProduct(screenObjectVectorDir, playerVector);
float degInclination = FMath::Acos(dot);
//HUDRef->DebugStringValue = FString::SanitizeFloat(degInclination, 3);
//DrawDebugLine(GetWorld(), MarkerCube->GetActorLocation(), Camera->GetComponentLocation(), FColor::Magenta, true, 20, 0, 2);
//DrawDebugLine(GetWorld(), Camera->GetComponentLocation(),playerVector, FColor::Blue, true, 20, 0, 2);
//FPrimitiveSceneInfo* sceneInfo = EarthRef->plane11->SceneProxy->GetPrimitiveSceneInfo();
//float floatpointer = sceneInfo->LastRenderTime;
//fptr = sceneInfo->ComponentLastRenderTime;
//float& fptrValue = fptr;
//renderTime = sceneInfo()->ComponentLastRenderTime;
//HUDRef->DebugStringValue = FString::SanitizeFloat(floatpointer);
}
void ASWP_WorldPlayerPawn::CalculateMovementOffset()
{
FVector newLocation = GetActorLocation();
float deltaX = (newLocation.X - InitialPosition.X);
float deltaY = (newLocation.Y - InitialPosition.Y);
// HUDRef->DebugStringValue = TEXT("DeltaX: ") + FString::SanitizeFloat(deltaX);
// HUDRef->DebugStringValue2 = TEXT("DeltaY: ") + FString::SanitizeFloat(deltaY);
CurrentMovementOffset = FVector2D(deltaX, deltaY);
// HUDRef->DebugStringValue = TEXT("Current Movement: ") + CurrentMovementOffset.ToString();
}
//bool ASWP_WorldPlayerPawn::DoesPlayerShouldMove(PlayerMoveState pState)
//{
// bool rBool = false;
// FString boolStr = TEXT("NOTEXT");
// switch (pState)
// {
// case PlayerMoveState::MovingNorth:
// CalculateMovementOffset();
// if (CurrentMovementOffset.X > MovementOffsetMaxLimit.X)
// {
// rBool = false;
// boolStr = TEXT("No");
// }
// else if (CurrentMovementOffset.X < MovementOffsetMaxLimit.X)
// {
// rBool = true;
// boolStr = TEXT("Yes");
// }
// HUDRef->DebugStringValue = TEXT("In Moving North Case: ") + FString::FromInt(pState) + TEXT(" Bool: ") + boolStr;
// break;
// case PlayerMoveState::MovingSouth : HUDRef->DebugStringValue = TEXT("In Switch Case: ") + FString::FromInt(pState);
//
// case PlayerMoveState::MovingLeft: HUDRef->DebugStringValue = TEXT("In Switch Case: ") + FString::FromInt(pState);
//
// case PlayerMoveState::MovingRight: HUDRef->DebugStringValue = TEXT("In Switch Case: ") + FString::FromInt(pState);
// }
//
// return rBool;
//}
void ASWP_WorldPlayerPawn::PanMapUsingMouse()
{
if (EarthRef == nullptr)
GetEarthReference();
//playerController->GetInputMouseDelta(_mouseDelta.X, _mouseDelta.Y);
//_mouseDelta = FVector2D(FMath::Abs(_mouseDelta.X), FMath::Abs(_mouseDelta.Y));
if(bMoveLocalCamera)
_mouseDelta = FVector2D(-MaxMouseDeltaY, -MaxMouseDeltaX );
if(bMoveKeyboardCamera)
_mouseDelta = FVector2D(-KeyboardDeltaY, -KeyboardDeltaX);
HUDRef->DebugStringValue3 = _mouseDelta.ToString();
EarthRef->PanMapUsingMouse(_mouseDelta);
}
void ASWP_WorldPlayerPawn::ResetAfterPanLimit()
{
if (pms_upState == EPMS_UpSide::UpSide_Outside || pms_downState == EPMS_DownSide::DownSide_Outside || pms_leftState == EPMS_LeftSide::LeftSide_Outside || pms_rightState == EPMS_RightSide::RightSide_Outside)
{
if (EarthRef == nullptr)
GetEarthReference();
FVector newLocation = FVector((EarthRef->GetActorLocation().X - 20), (EarthRef->GetActorLocation().Y + 20), (EarthRef->GetActorLocation().Z + 200));
//SetActorLocation(newLocation, false, nullptr, ETeleportType::None);
FVector cameraLocation = FVector((EarthRef->GetActorLocation().X-20), (EarthRef->GetActorLocation().Y - 10), (EarthRef->GetActorLocation().Z + 200));
Camera->SetRelativeLocation(FVector::ZeroVector,false,nullptr,ETeleportType::None);
//PanMapUsingMouse();
bMoveLocalCamera = false;
}
}
//ASWP_MapTileManager* ASWP_WorldPlayerPawn::GetTileMapManager()
//{
//
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.