Yes openSSN has alot of the functions I’ll need for newer tech which are very similar and I can do the 2D math no problem (atan2 y-y, dot(x-x, y-y, x-x)) its going to 3d vectors and using FRotators or floats as degrees that gets me. The whole 0-180-0 kills me.
I’m trying to get the angle from north/south line (ship moving to the left of the screen is travelling north) to the current rotation yaw of the camera on the ship 0-360d (So the camera rotation is relative to the ships forward vector, but I dont tihnk that affects the math for B or Br) . Thats Br (bearing relative to the world) 0-360d, left of 0 being 359.999 and down to 0 and camera rotating right (clockwise) being 0.0001 up to 360.
More importantly, I need the bearing B which is the same thing but replace north/south with the forward/aft (bow/stern) line of the boat. Then I can get gyro angle and have a firing solution with 3 moving targets.
I managed to get the angle on the bow, which is the exact same math this way with 2 pawns, but now that im using camera views and now two points its not working for me…
//Returns the angle on the bow
float UBPFuncLib_TDChelper::AngleOnBow(APawn* TargetShip, APawn* PlyrShip)
{
FVector LineSight = (PlyrShip->GetActorLocation() - TargetShip->GetActorLocation());
LineSight.Normalize();
float BowAngleInDeg = FMath::RadiansToDegrees(FGenericPlatformMath::Acos(FVector::DotProduct(TargetShip->GetActorForwardVector(), LineSight)));
if (FVector::DotProduct(TargetShip->GetActorRightVector(), LineSight) < 0.0f) // We need one more dot product to actually figure out our winding
{
//BowAngleInDeg *= -1;
//If pos then sub is to the left or starboard
//bIsAoBToPort = true;
return BowAngleInDeg *= -1;
}
if (BowAngleInDeg < 0.1f && BowAngleInDeg >-0.1f)
{
return BowAngleInDeg = 180.0f;
}
else
{
return BowAngleInDeg;
}
}
//Tells if the player is to port or starboard aka if AoB is negative or not
bool UBPFuncLib_TDChelper::IsPlayerToPort(float AoB)
{
if (AoB < 0.0f)
{
return true;
}
else
{
return false;
}
}
Unfortunatly it gives me 0-180 +/- for left/right (port/starboard) I need 0-360… Cartesian Euler or watever you call it.