diff --git a/src/common/Util/UtilMath.cpp b/src/common/Util/UtilMath.cpp index 6a162d64..93b45624 100644 --- a/src/common/Util/UtilMath.cpp +++ b/src/common/Util/UtilMath.cpp @@ -80,6 +80,25 @@ uint8_t Util::floatToUInt8Rot( float val ) return static_cast< uint8_t >( 0x80 * ( ( val + PI ) ) / PI ); } +FFXIVARR_POSITION3 Util::getOffsettedPosition( const FFXIVARR_POSITION3& pos, float rot, float left, float up, float forward ) +{ + FFXIVARR_POSITION3 ret{ pos }; + + // height + ret.y += up; + + // forward + float angle = rot + ( PI / 2 ); + ret.x -= forward * cos( angle ); + ret.z += forward * sin( angle ); + + // side + ret.x += left * cos( rot ); + ret.z += left * sin( rot ); + + return ret; +} + FFXIVARR_POSITION3 Util::transform( const FFXIVARR_POSITION3& vector, const Matrix33& matrix ) { FFXIVARR_POSITION3 dst{}; diff --git a/src/common/Util/UtilMath.h b/src/common/Util/UtilMath.h index 1f6ddd50..e245892d 100644 --- a/src/common/Util/UtilMath.h +++ b/src/common/Util/UtilMath.h @@ -29,6 +29,8 @@ namespace Sapphire::Common::Util uint8_t floatToUInt8Rot( float val ); + FFXIVARR_POSITION3 getOffsettedPosition( const FFXIVARR_POSITION3& pos, float rotation, float left, float up, float forward ); + template < typename T > T clamp( T val, T minimum, T maximum ) {