diff --git a/mta-mono/src/CResourceManager.cpp b/mta-mono/src/CResourceManager.cpp new file mode 100644 index 0000000..2727c22 --- /dev/null +++ b/mta-mono/src/CResourceManager.cpp @@ -0,0 +1,102 @@ +/********************************************************* +* +* Copyright © 2013, Innovation Roleplay Engine. +* +* All Rights Reserved. +* +* Redistribution and use in source and binary forms, +* with or without modification, +* is permitted only for authors. +* +*********************************************************/ + +#include "CResourceManager.h" + +CResourceManager::CResourceManager( void ) +{ + mono_set_dirs( "mods/deathmatch/mono/lib", "mods/deathmatch/mono/etc" ); + + this->m_pMonoDomain = mono_jit_init_version( "Mono Root", "v4.0.30319" ); + + CMonoFunctions::AddInternals(); +} + +CResourceManager::~CResourceManager( void ) +{ + for( auto iter : this->m_List ) + { + delete iter; + } + + mono_jit_cleanup( this->m_pMonoDomain ); +} + +CResource* CResourceManager::Create( lua_State* luaVM, string strName ) +{ + if( !this->GetFromList( luaVM ) ) + { + string sPath( "mods/deathmatch/resources/[ire]/" + strName + "/" + strName + ".dll" ); + + struct stat buf; + + if( stat( sPath.c_str(), &buf ) == -1 ) + { + return nullptr; + } + + CResource *pResource = new CResource( luaVM, strName ); + + this->AddToList( pResource ); + + return pResource; + } + + return nullptr; +} + +void CResourceManager::AddToList( CResource* pResource ) +{ + this->m_List.push_back( pResource ); +} + +CResource* CResourceManager::GetFromList( lua_State* pLuaVM ) +{ + for( auto iter : this->m_List ) + { + if( iter->m_pLuaVM == pLuaVM ) + { + return iter; + } + } + + return nullptr; +} + +CResource* CResourceManager::GetFromList( MonoDomain* pDomain ) +{ + for( auto iter : this->m_List ) + { + if( iter->m_pMonoDomain == pDomain ) + { + return iter; + } + } + + return nullptr; +} + +void CResourceManager::RemoveFromList( CResource* pResource ) +{ + if( !this->m_List.empty() ) + { + this->m_List.remove( pResource ); + } +} + +void CResourceManager::DoPulse( void ) +{ + for( auto iter : this->m_List ) + { + iter->DoPulse(); + } +} \ No newline at end of file diff --git a/mta-mono/src/CResourceManager.h b/mta-mono/src/CResourceManager.h index bfd9955..d5d7b73 100644 --- a/mta-mono/src/CResourceManager.h +++ b/mta-mono/src/CResourceManager.h @@ -1,137 +1,40 @@ -/********************************************************* -* -* Copyright © 2013, Innovation Roleplay Engine. -* -* All Rights Reserved. -* -* Redistribution and use in source and binary forms, -* with or without modification, -* is permitted only for authors. -* -*********************************************************/ +/********************************************************* +* +* Copyright © 2013, Innovation Roleplay Engine. +* +* All Rights Reserved. +* +* Redistribution and use in source and binary forms, +* with or without modification, +* is permitted only for authors. +* +*********************************************************/ class CResourceManager; #ifndef __CRESOURCEMANAGER_H #define __CRESOURCEMANAGER_H - -#include "CMonoFunctions.h" - + +#include "CMonoFunctions.h" + extern ILuaModuleManager10 *g_pModuleManager; class CResourceManager { private: - std::list< CResource* > m_List; + list< CResource* > m_List; - MonoDomain *m_pMonoDomain; + MonoDomain *m_pMonoDomain; public: - CResourceManager( void ) - { - // #ifdef _WIN32 - mono_set_dirs( "mods/deathmatch/mono/lib", "mods/deathmatch/mono/etc" ); - // #endif + CResourceManager ( void ); + ~CResourceManager ( void ); - // mono_config_parse( NULL ); - - // mono_debug_init( MONO_DEBUG_FORMAT_MONO ); - - this->m_pMonoDomain = mono_jit_init_version( "Mono Root", "v4.0.30319" ); - - CMonoFunctions::AddInternals(); - } - - ~CResourceManager( void ) - { - std::list< CResource* >::const_iterator iter = this->m_List.begin(); - - for( ; iter != this->m_List.end(); iter++ ) - { - delete *iter; - } - - mono_jit_cleanup( this->m_pMonoDomain ); - } - - CResource* Create( lua_State* luaVM ) - { - if( !this->GetFromList( luaVM ) ) - { - string sName = ""; - - g_pModuleManager->GetResourceName( luaVM, sName ); - - string sPath( "mods/deathmatch/resources/[ire]/" + sName + "/" + sName + ".dll" ); - - struct stat buf; - - if( stat( sPath.c_str(), &buf ) == -1 ) - { - return NULL; - } - - CResource *pResource = new CResource( luaVM, sName ); - - this->AddToList( pResource ); - - return pResource; - } - - return NULL; - } - - void AddToList( CResource* pResource ) - { - this->m_List.push_back( pResource ); - } - - CResource* GetFromList( lua_State* pLuaVM ) - { - std::list< CResource* >::const_iterator iter = this->m_List.begin(); - - for( ; iter != this->m_List.end(); iter++ ) - { - if( (*iter)->m_pLuaVM == pLuaVM ) - { - return *iter; - } - } - - return NULL; - } - - CResource* GetFromList( MonoDomain* pDomain ) - { - std::list< CResource* >::const_iterator iter = this->m_List.begin(); - - for( ; iter != this->m_List.end(); iter++ ) - { - if( (*iter)->m_pMonoDomain == pDomain ) - { - return *iter; - } - } - - return NULL; - } - - void RemoveFromList( CResource* pResource ) - { - if( !this->m_List.empty() ) - { - this->m_List.remove( pResource ); - } - } - - void DoPulse( void ) - { - std::list< CResource* >::const_iterator iter = this->m_List.begin(); - - for( ; iter != this->m_List.end(); iter++ ) - { - (*iter)->DoPulse(); - } - } + CResource* Create ( lua_State* luaVM, string strName ); + void AddToList ( CResource* pResource ); + CResource* GetFromList ( lua_State* pLuaVM ); + CResource* GetFromList ( MonoDomain* pDomain ); + void RemoveFromList ( CResource* pResource ); + void DoPulse ( void ); }; #endif diff --git a/mta-mono/src/extra/Vector2.cpp b/mta-mono/src/extra/Vector2.cpp new file mode 100644 index 0000000..adf2b05 --- /dev/null +++ b/mta-mono/src/extra/Vector2.cpp @@ -0,0 +1,134 @@ +#include "Vector2.h" + +Vector2::Vector2( void ) +{ + fX = 0; + fY = 0; +} + +Vector2::Vector2( float _fX, float _fY ) +{ + fX = _fX; + fY = _fY; +} + +Vector2::Vector2( MonoObject* pObject ) +{ + this->fX = CMonoObject::GetPropertyValue< float >( pObject, "X" ); + this->fY = CMonoObject::GetPropertyValue< float >( pObject, "Y" ); +} + +float Vector2::DotProduct( Vector2& other ) const +{ + return fX*other.fX + fY*other.fY; +} + +float Vector2::Length() const +{ + return sqrt( fX * fX + fY * fY ); +} + +float Vector2::LengthSquared( void ) const +{ + return ( fX*fX ) + ( fY*fY ); +} + +void Vector2::Normalize( void ) +{ + float fLength = Length(); + if( fLength > 0.0f ) + { + fX /= fLength; + fY /= fLength; + } +} + +Vector2 Vector2::operator * ( float fRight ) const +{ + return Vector2( fX * fRight, fY * fRight ); +} + +Vector2 Vector2::operator / ( float fRight ) const +{ + float fRcpValue = 1 / fRight; + + return Vector2( fX * fRcpValue, fY * fRcpValue ); +} + +Vector2 Vector2::operator + ( const Vector2& vecRight ) const +{ + return Vector2( fX + vecRight.fX, fY + vecRight.fY ); +} + +Vector2 Vector2::operator - ( const Vector2& vecRight ) const +{ + return Vector2( fX - vecRight.fX, fY - vecRight.fY ); +} + +Vector2 Vector2::operator * ( const Vector2& vecRight ) const +{ + return Vector2( fX * vecRight.fX, fY * vecRight.fY ); +} + +Vector2 Vector2::operator / ( const Vector2& vecRight ) const +{ + return Vector2( fX / vecRight.fX, fY / vecRight.fY ); +} + +void Vector2::operator += ( float fRight ) +{ + fX += fRight; + fY += fRight; +} + +void Vector2::operator += ( const Vector2& vecRight ) +{ + fX += vecRight.fX; + fY += vecRight.fY; +} + +void Vector2::operator -= ( float fRight ) +{ + fX -= fRight; + fY -= fRight; +} + +void Vector2::operator -= ( const Vector2& vecRight ) +{ + fX -= vecRight.fX; + fY -= vecRight.fY; +} + +void Vector2::operator *= ( float fRight ) +{ + fX *= fRight; + fY *= fRight; +} + +void Vector2::operator *= ( const Vector2& vecRight ) +{ + fX *= vecRight.fX; + fY *= vecRight.fY; +} + +void Vector2::operator /= ( float fRight ) +{ + fX /= fRight; + fY /= fRight; +} + +void Vector2::operator /= ( const Vector2& vecRight ) +{ + fX /= vecRight.fX; + fY /= vecRight.fY; +} + +bool Vector2::operator == ( const Vector2& param ) const +{ + return ( ( fabs( fX - param.fX ) < FLOAT_EPSILON ) && ( fabs( fY - param.fY ) < FLOAT_EPSILON ) ); +} + +bool Vector2::operator != ( const Vector2& param ) const +{ + return ( ( fabs( fX - param.fX ) >= FLOAT_EPSILON ) || ( fabs( fY - param.fY ) >= FLOAT_EPSILON ) ); +} \ No newline at end of file diff --git a/mta-mono/src/extra/Vector2.h b/mta-mono/src/extra/Vector2.h index 903002c..403851d 100644 --- a/mta-mono/src/extra/Vector2.h +++ b/mta-mono/src/extra/Vector2.h @@ -1,157 +1,57 @@ -/***************************************************************************** -* -* PROJECT: Multi Theft Auto v1.0 -* LICENSE: See LICENSE in the top level directory -* FILE: sdk/CVector2D.h -* PURPOSE: 2D vector class -* -* Multi Theft Auto is available from http://www.multitheftauto.com/ -* -*****************************************************************************/ - -#ifndef __CVector2D_H -#define __CVector2D_H - -#include -#include "Vector3.h" - -/** - * CVector2D Structure used to store a 2D vertex. - */ -class Vector2 -{ -public: - Vector2 ( void ) - { - fX = 0; - fY = 0; - } - - Vector2 ( float _fX, float _fY ) - { - fX = _fX; - fY = _fY; - } - - float DotProduct ( Vector2& other ) const - { - return fX*other.fX + fY*other.fY; - } - - float Length () const - { - return sqrt ( fX * fX + fY * fY ); - } - - float LengthSquared ( void ) const - { - return (fX*fX) + (fY*fY); - } - - void Normalize ( void ) - { - float fLength = Length (); - if ( fLength > 0.0f ) - { - fX /= fLength; - fY /= fLength; - } - } - - Vector2 operator * ( float fRight ) const - { - return Vector2 ( fX * fRight, fY * fRight ); - } - - Vector2 operator / ( float fRight ) const - { - float fRcpValue = 1 / fRight; - return Vector2 ( fX * fRcpValue, fY * fRcpValue ); - } - - Vector2 operator + ( const Vector2& vecRight ) const - { - return Vector2 ( fX + vecRight.fX, fY + vecRight.fY ); - } - - Vector2 operator - ( const Vector2& vecRight ) const - { - return Vector2 ( fX - vecRight.fX, fY - vecRight.fY ); - } - - Vector2 operator * ( const Vector2& vecRight ) const - { - return Vector2 ( fX * vecRight.fX, fY * vecRight.fY ); - } - - Vector2 operator / ( const Vector2& vecRight ) const - { - return Vector2 ( fX / vecRight.fX, fY / vecRight.fY ); - } - - void operator += ( float fRight ) - { - fX += fRight; - fY += fRight; - } - - void operator += ( const Vector2& vecRight ) - { - fX += vecRight.fX; - fY += vecRight.fY; - } - - void operator -= ( float fRight ) - { - fX -= fRight; - fY -= fRight; - } - - void operator -= ( const Vector2& vecRight ) - { - fX -= vecRight.fX; - fY -= vecRight.fY; - } - - void operator *= ( float fRight ) - { - fX *= fRight; - fY *= fRight; - } - - void operator *= ( const Vector2& vecRight ) - { - fX *= vecRight.fX; - fY *= vecRight.fY; - } - - void operator /= ( float fRight ) - { - fX /= fRight; - fY /= fRight; - } - - void operator /= ( const Vector2& vecRight ) - { - fX /= vecRight.fX; - fY /= vecRight.fY; - } - - bool operator== ( const Vector2& param ) const - { - return ( ( fabs ( fX - param.fX ) < FLOAT_EPSILON ) && - ( fabs ( fY - param.fY ) < FLOAT_EPSILON ) ); - } - - bool operator!= ( const Vector2& param ) const - { - return ( ( fabs ( fX - param.fX ) >= FLOAT_EPSILON ) || - ( fabs ( fY - param.fY ) >= FLOAT_EPSILON ) ); - } - - float fX; - float fY; -}; - - -#endif +/***************************************************************************** +* +* PROJECT: Multi Theft Auto v1.0 +* LICENSE: See LICENSE in the top level directory +* FILE: sdk/CVector2D.h +* PURPOSE: 2D vector class +* +* Multi Theft Auto is available from http://www.multitheftauto.com/ +* +*****************************************************************************/ + +#ifndef __CVector2D_H +#define __CVector2D_H + +#include +#include "Vector3.h" +#include "../CMonoObject.h" + +/** + * CVector2D Structure used to store a 2D vertex. + */ +class Vector2 +{ +public: + float fX; + float fY; + + Vector2( void ); + Vector2( float _fX, float _fY ); + Vector2( MonoObject* pObject ); + + float DotProduct ( Vector2& other ) const; + float Length ( void ) const; + float LengthSquared ( void ) const; + void Normalize ( void ); + + Vector2 operator * ( float fRight ) const; + Vector2 operator / ( float fRight ) const; + Vector2 operator + ( const Vector2& vecRight ) const; + Vector2 operator - ( const Vector2& vecRight ) const; + Vector2 operator * ( const Vector2& vecRight ) const; + Vector2 operator / ( const Vector2& vecRight ) const; + + void operator += ( float fRight ); + void operator += ( const Vector2& vecRight ); + void operator -= ( float fRight ); + void operator -= ( const Vector2& vecRight ); + void operator *= ( float fRight ); + void operator *= ( const Vector2& vecRight ); + void operator /= ( float fRight ); + void operator /= ( const Vector2& vecRight ); + bool operator == ( const Vector2& param ) const; + bool operator != ( const Vector2& param ) const; +}; + + +#endif diff --git a/mta-mono/src/extra/Vector3.cpp b/mta-mono/src/extra/Vector3.cpp new file mode 100644 index 0000000..3c37f08 --- /dev/null +++ b/mta-mono/src/extra/Vector3.cpp @@ -0,0 +1,203 @@ +#include "Vector3.h" + +Vector3::Vector3( void ) +{ + this->fX = 0; + this->fY = 0; + this->fZ = 0; +}; + +Vector3::Vector3( float fX, float fY, float fZ ) +{ + this->fX = fX; + this->fY = fY; + this->fZ = fZ; +} + +Vector3::Vector3( MonoObject *pObject ) +{ + this->fX = CMonoObject::GetPropertyValue< float >( pObject, "X" ); + this->fY = CMonoObject::GetPropertyValue< float >( pObject, "Y" ); + this->fZ = CMonoObject::GetPropertyValue< float >( pObject, "Z" ); +} + +float Vector3::Normalize( void ) +{ + float t = sqrt( this->fX * this->fX + this->fY * this->fY + this->fZ * this->fZ ); + + if( t > FLOAT_EPSILON ) + { + float fRcpt = 1 / t; + + this->fX *= fRcpt; + this->fY *= fRcpt; + this->fZ *= fRcpt; + } + else + { + t = 0; + } + + return t; +} + +float Vector3::Length( void ) const +{ + return sqrt( ( fX*fX ) + ( fY*fY ) + ( fZ*fZ ) ); +} + +float Vector3::LengthSquared( void ) const +{ + return ( fX*fX ) + ( fY*fY ) + ( fZ*fZ ); +} + +float Vector3::DotProduct( const Vector3 * param ) const +{ + return fX*param->fX + fY*param->fY + fZ*param->fZ; +} + +void Vector3::CrossProduct( const Vector3 * param ) +{ + float _fX = fX, _fY = fY, _fZ = fZ; + + fX = _fY * param->fZ - param->fY * _fZ; + fY = _fZ * param->fX - param->fZ * _fX; + fZ = _fX * param->fY - param->fX * _fY; +} + +Vector3 Vector3::ToRotation( void ) const +{ + Vector3 vecRotation; + + vecRotation.fZ = atan2( fY, fX ); + + Vector3 vecTemp( sqrt( fX * fX + fY * fY ), fZ, 0 ); + + vecTemp.Normalize(); + + vecRotation.fY = atan2( vecTemp.fX, vecTemp.fY ) - PI / 2; + + return vecRotation; +} + +Vector3 Vector3::GetOtherAxis( void ) const +{ + Vector3 vecResult; + + if( abs( fX ) > abs( fY ) ) + { + vecResult = Vector3( fZ, 0, -fX ); + } + else + { + vecResult = Vector3( 0, -fZ, fY ); + } + + vecResult.Normalize(); + + return vecResult; +} + +Vector3 Vector3::operator + ( const Vector3& vecRight ) const +{ + return Vector3( fX + vecRight.fX, fY + vecRight.fY, fZ + vecRight.fZ ); +} + +Vector3 Vector3::operator - ( const Vector3& vecRight ) const +{ + return Vector3( fX - vecRight.fX, fY - vecRight.fY, fZ - vecRight.fZ ); +} + +Vector3 Vector3::operator * ( const Vector3& vecRight ) const +{ + return Vector3( fX * vecRight.fX, fY * vecRight.fY, fZ * vecRight.fZ ); +} + +Vector3 Vector3::operator * ( float fRight ) const +{ + return Vector3( fX * fRight, fY * fRight, fZ * fRight ); +} + +Vector3 Vector3::operator / ( const Vector3& vecRight ) const +{ + return Vector3( fX / vecRight.fX, fY / vecRight.fY, fZ / vecRight.fZ ); +} + +Vector3 Vector3::operator / ( float fRight ) const +{ + float fRcpValue = 1 / fRight; + + return Vector3( fX * fRcpValue, fY * fRcpValue, fZ * fRcpValue ); +} + +Vector3 Vector3::operator - ( ) const +{ + return Vector3( -fX, -fY, -fZ ); +} + +void Vector3::operator += ( float fRight ) +{ + fX += fRight; + fY += fRight; + fZ += fRight; +} + +void Vector3::operator += ( const Vector3& vecRight ) +{ + fX += vecRight.fX; + fY += vecRight.fY; + fZ += vecRight.fZ; +} + +void Vector3::operator -= ( float fRight ) +{ + fX -= fRight; + fY -= fRight; + fZ -= fRight; +} + +void Vector3::operator -= ( const Vector3& vecRight ) +{ + fX -= vecRight.fX; + fY -= vecRight.fY; + fZ -= vecRight.fZ; +} + +void Vector3::operator *= ( float fRight ) +{ + fX *= fRight; + fY *= fRight; + fZ *= fRight; +} + +void Vector3::operator *= ( const Vector3& vecRight ) +{ + fX *= vecRight.fX; + fY *= vecRight.fY; + fZ *= vecRight.fZ; +} + +void Vector3::operator /= ( float fRight ) +{ + float fRcpValue = 1 / fRight; + fX *= fRcpValue; + fY *= fRcpValue; + fZ *= fRcpValue; +} + +void Vector3::operator /= ( const Vector3& vecRight ) +{ + fX /= vecRight.fX; + fY /= vecRight.fY; + fZ /= vecRight.fZ; +} + +bool Vector3::operator== ( const Vector3& param ) const +{ + return ( ( fabs( fX - param.fX ) < FLOAT_EPSILON ) && ( fabs( fY - param.fY ) < FLOAT_EPSILON ) && ( fabs( fZ - param.fZ ) < FLOAT_EPSILON ) ); +} + +bool Vector3::operator!= ( const Vector3& param ) const +{ + return ( ( fabs( fX - param.fX ) >= FLOAT_EPSILON ) || ( fabs( fY - param.fY ) >= FLOAT_EPSILON ) || ( fabs( fZ - param.fZ ) >= FLOAT_EPSILON ) ); +} diff --git a/mta-mono/src/extra/Vector3.h b/mta-mono/src/extra/Vector3.h index f1f5894..00e4a94 100644 --- a/mta-mono/src/extra/Vector3.h +++ b/mta-mono/src/extra/Vector3.h @@ -1,214 +1,72 @@ -/***************************************************************************** -* -* PROJECT: Multi Theft Auto v1.0 -* LICENSE: See LICENSE in the top level directory -* FILE: sdk/CVector.h -* PURPOSE: 3D vector math implementation -* -* Multi Theft Auto is available from http://www.multitheftauto.com/ -* -*****************************************************************************/ - -#ifndef __CVector_H -#define __CVector_H - -#ifdef WIN32 -#include -#endif - -#include - -#define FLOAT_EPSILON 0.0001f -#define PI (3.14159265358979323846f) -/** - * CVector Structure used to store a 3D vertex. - */ -class Vector3 -{ -public: - float fX, fY, fZ; - - Vector3 () - { - this->fX = 0; - this->fY = 0; - this->fZ = 0; - }; - - Vector3 ( float fX, float fY, float fZ) - { - this->fX = fX; - this->fY = fY; - this->fZ = fZ; - } - - float Normalize ( void ) - { - float t = sqrt(fX*fX + fY*fY + fZ*fZ); - if ( t > FLOAT_EPSILON ) - { - float fRcpt = 1 / t; - fX *= fRcpt; - fY *= fRcpt; - fZ *= fRcpt; - } - else - t = 0; - return t; - } - - float Length ( void ) const - { - return sqrt ( (fX*fX) + (fY*fY) + (fZ*fZ) ); - } - - float LengthSquared ( void ) const - { - return (fX*fX) + (fY*fY) + (fZ*fZ); - } - - float DotProduct ( const Vector3 * param ) const - { - return fX*param->fX + fY*param->fY + fZ*param->fZ; - } - - void CrossProduct ( const Vector3 * param ) - { - float _fX = fX, _fY = fY, _fZ = fZ; - fX = _fY * param->fZ - param->fY * _fZ; - fY = _fZ * param->fX - param->fZ * _fX; - fZ = _fX * param->fY - param->fX * _fY; - } - - // Convert (direction) to rotation - Vector3 ToRotation ( void ) const - { - Vector3 vecRotation; - vecRotation.fZ = atan2 ( fY, fX ); - Vector3 vecTemp ( sqrt ( fX * fX + fY * fY ), fZ, 0 ); - vecTemp.Normalize (); - vecRotation.fY = atan2 ( vecTemp.fX, vecTemp.fY ) - PI / 2; - return vecRotation; - } - - // Return a perpendicular direction - Vector3 GetOtherAxis ( void ) const - { - Vector3 vecResult; - if ( abs( fX ) > abs( fY ) ) - vecResult = Vector3( fZ, 0, -fX ); - else - vecResult = Vector3( 0, -fZ, fY ); - vecResult.Normalize(); - return vecResult; - } - - Vector3 operator + ( const Vector3& vecRight ) const - { - return Vector3 ( fX + vecRight.fX, fY + vecRight.fY, fZ + vecRight.fZ ); - } - - Vector3 operator - ( const Vector3& vecRight ) const - { - return Vector3 ( fX - vecRight.fX, fY - vecRight.fY, fZ - vecRight.fZ ); - } - - Vector3 operator * ( const Vector3& vecRight ) const - { - return Vector3 ( fX * vecRight.fX, fY * vecRight.fY, fZ * vecRight.fZ ); - } - - Vector3 operator * ( float fRight ) const - { - return Vector3 ( fX * fRight, fY * fRight, fZ * fRight ); - } - - Vector3 operator / ( const Vector3& vecRight ) const - { - return Vector3 ( fX / vecRight.fX, fY / vecRight.fY, fZ / vecRight.fZ ); - } - - Vector3 operator / ( float fRight ) const - { - float fRcpValue = 1 / fRight; - return Vector3 ( fX * fRcpValue, fY * fRcpValue, fZ * fRcpValue ); - } - - Vector3 operator - () const - { - return Vector3 ( -fX, -fY, -fZ ); - } - - void operator += ( float fRight ) - { - fX += fRight; - fY += fRight; - fZ += fRight; - } - - void operator += ( const Vector3& vecRight ) - { - fX += vecRight.fX; - fY += vecRight.fY; - fZ += vecRight.fZ; - } - - void operator -= ( float fRight ) - { - fX -= fRight; - fY -= fRight; - fZ -= fRight; - } - - void operator -= ( const Vector3& vecRight ) - { - fX -= vecRight.fX; - fY -= vecRight.fY; - fZ -= vecRight.fZ; - } - - void operator *= ( float fRight ) - { - fX *= fRight; - fY *= fRight; - fZ *= fRight; - } - - void operator *= ( const Vector3& vecRight ) - { - fX *= vecRight.fX; - fY *= vecRight.fY; - fZ *= vecRight.fZ; - } - - void operator /= ( float fRight ) - { - float fRcpValue = 1 / fRight; - fX *= fRcpValue; - fY *= fRcpValue; - fZ *= fRcpValue; - } - - void operator /= ( const Vector3& vecRight ) - { - fX /= vecRight.fX; - fY /= vecRight.fY; - fZ /= vecRight.fZ; - } - - bool operator== ( const Vector3& param ) const - { - return ( ( fabs ( fX - param.fX ) < FLOAT_EPSILON ) && - ( fabs ( fY - param.fY ) < FLOAT_EPSILON ) && - ( fabs ( fZ - param.fZ ) < FLOAT_EPSILON ) ); - } - - bool operator!= ( const Vector3& param ) const - { - return ( ( fabs ( fX - param.fX ) >= FLOAT_EPSILON ) || - ( fabs ( fY - param.fY ) >= FLOAT_EPSILON ) || - ( fabs ( fZ - param.fZ ) >= FLOAT_EPSILON ) ); - } -}; - -#endif +/***************************************************************************** +* +* PROJECT: Multi Theft Auto v1.0 +* LICENSE: See LICENSE in the top level directory +* FILE: sdk/CVector.h +* PURPOSE: 3D vector math implementation +* +* Multi Theft Auto is available from http://www.multitheftauto.com/ +* +*****************************************************************************/ + +#ifndef __CVector_H +#define __CVector_H + +#ifdef WIN32 +#include +#endif + +#include +#include "../CMonoObject.h" + +#define FLOAT_EPSILON 0.0001f +#define PI 3.14159265358979323846f +/** + * CVector Structure used to store a 3D vertex. + */ +class Vector3 +{ +public: + float fX, fY, fZ; + + Vector3 ( void ); + Vector3 ( float fX, float fY, float fZ ); + Vector3 ( MonoObject *pObject ); + + float Normalize ( void ); + float Length ( void ) const; + float LengthSquared ( void ) const; + float DotProduct ( const Vector3 * param ) const; + void CrossProduct ( const Vector3 * param ); + + // Convert (direction) to rotation + Vector3 ToRotation ( void ) const; + + // Return a perpendicular direction + Vector3 GetOtherAxis ( void ) const; + + Vector3 operator + ( const Vector3& vecRight ) const; + Vector3 operator - ( const Vector3& vecRight ) const; + Vector3 operator * ( const Vector3& vecRight ) const; + Vector3 operator * ( float fRight ) const; + Vector3 operator / ( const Vector3& vecRight ) const; + Vector3 operator / ( float fRight ) const; + Vector3 operator - () const; + + void operator += ( float fRight ); + void operator += ( const Vector3& vecRight ); + + void operator -= ( float fRight ); + void operator -= ( const Vector3& vecRight ); + + void operator *= ( float fRight ); + void operator *= ( const Vector3& vecRight ); + + void operator /= ( float fRight ); + void operator /= ( const Vector3& vecRight ); + + bool operator == ( const Vector3& param ) const; + bool operator != ( const Vector3& param ) const; +}; + +#endif