❗ NormalizeAngle is fine ?

Posts 1–8 of 8 · Page 1 of 1
❗ NormalizeAngle is fine ?
Code:
#include "Math.h"
#include <iostream>
 
CMath Math;
 
Vector3 CMath::NormalizeAngle(const Vector3 Angle1) {
	Vector3 Angle = Angle1;
 
	if (!std::isfinite(Angle.x)) {
		Angle.x = 0;
	}
	if (!std::isfinite(Angle.y)) {
		Angle.y = 0;
	}
 
	while (Angle.y < -180.0f)
		Angle.y += 360.0f;
	while (Angle.y > 180.0f)
		Angle.y -= 360.0f;
 
	if (Angle.x > 89.0f)
		Angle.x = 89.0f;
	if (Angle.x < -89.0f)
		Angle.x = -89.0f;
 
	Angle.z = 0;
 
	return Angle;
}
 
Vector3 CMath::SmoothAngle(const Vector3 Angle1, const Vector3 Angle2, float Smooth) {
	Vector3 Delta = { Angle2.x - Angle1.x, Angle2.y - Angle1.y, 0 };
 
	Delta = NormalizeAngle(Delta);
 
	Delta.x = (Delta.x / Smooth) + Angle1.x;
	Delta.y = (Delta.y / Smooth) + Angle1.y;
 
	return Delta;
}
 
float CMath::FOV(const Vector3 Angle1, const Vector3 Angle2) {
	Vector3 Delta = { Angle1.x - Angle2.x, Angle1.y - Angle2.y, 0 };
	Delta = NormalizeAngle(Delta);
 
	return sqrt((Delta.x * Delta.x) + (Delta.y * Delta.y));
}
/moved to coding & resources
Code:
        public static Vector3 NormalizeAngle(this Vector3 angle)
        {
            while (angle.X > 89.0f)
            {
                angle.X -= 180f;
            }

            while (angle.X < -89.0f)
            {
                angle.X += 180f;
            }

            while (angle.Y > 180f)
            {
                angle.Y -= 360f;
            }

            while (angle.Y < -180f)
            {
                angle.Y += 360f;
            }
            return angle;
        }
Code:
virtual bool NormalizeVector( ) override
{
	if ( std::isfinite( m_X ) && 
	     std::isfinite( m_Y ) && 
	     std::isfinite( m_Z ) )
	{
		m_X = std::remainderf( m_X, 360.f );
		m_Y = std::remainderf( m_Y, 360.f );
		return true;
	}
	return false;
}
Code:
bool ClampAngles( )
{
	if ( std::isfinite( m_X ) && 
	     std::isfinite( m_Y ) && 
	     std::isfinite( m_Z ) )
	{
		m_X = std::fmax( std::fmin( m_X, 90.f ), -90.f );
		m_Z = std::fmax( std::fmin( m_X, 50.f ), -50.f );;		
		return true;
	}
	return false;
}
Quote Originally Posted by WasserEsser View Post
Code:
virtual bool NormalizeVector( ) override
{
	if ( std::isfinite( m_X ) && 
	     std::isfinite( m_Y ) && 
	     std::isfinite( m_Z ) )
	{
		m_X = std::remainderf( m_X, 360.f );
		m_Y = std::remainderf( m_Y, 360.f );
		return true;
	}
	return false;
}
Code:
bool ClampAngles( )
{
	if ( std::isfinite( m_X ) && 
	     std::isfinite( m_Y ) && 
	     std::isfinite( m_Z ) )
	{
		m_X = std::fmax( std::fmin( m_X, 90.f ), -90.f );
		m_Z = std::fmax( std::fmin( m_X, 50.f ), -50.f );;		
		return true;
	}
	return false;
}

Thanks btw this is very nicely formatted.
Quote Originally Posted by Mixtape View Post

Thanks btw this is very nicely formatted.
If you copy this, make sure you correct this mistake:

m_Z = std::fmax( std::fmin( m_X, 50.f ), -50.f );;

to

m_Z = std::fmax( std::fmin( m_Z, 50.f ), -50.f );
Quote Originally Posted by WasserEsser View Post
If you copy this, make sure you correct this mistake:

m_Z = std::fmax( std::fmin( m_X, 50.f ), -50.f );;

to

m_Z = std::fmax( std::fmin( m_Z, 50.f ), -50.f );
Yeah thanks I caught that too. (But I was thinking it over because I'm kinda new too making an aimbot)
Posts 1–8 of 8 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us