Houstin
01-24-2012, 05:36 AM
I was strolling Object.cpp when I noticed:
Lockable* Object::SetGamePos( unsigned char axis, double pos )
{
Value<double>& data = SAFE_FIND( this->object_Game_Pos, axis )->second;
if ( Utils::DoubleCompare( data.Get(), pos, 0.01 ) )
return NULL;
if ( ( pos != 2048.0 && pos != 128.0 && pos != 0.0 ) )
{
if ( !data.Set( pos ) )
return NULL;
#ifdef VAULTMP_DEBUG
if ( debug != NULL )
debug->PrintFormat( "Object game %s-pos was set to %f (ref: %08X)", true, API::RetrieveAxis_Reverse( axis ).c_str(), ( float ) pos, this->GetReference() );
#endif
return &data;
}
return NULL;
}
Lockable* Object::SetNetworkPos( unsigned char axis, double pos )
{
Value<double>& data = SAFE_FIND( this->object_Network_Pos, axis )->second;
if ( Utils::DoubleCompare( data.Get(), pos, 0.01 ) )
return NULL;
if ( ( pos != 2048.0 && pos != 128.0 && pos != 0.0 ) )
{
if ( !data.Set( pos ) )
return NULL;
#ifdef VAULTMP_DEBUG
if ( debug != NULL )
debug->PrintFormat( "Object network %s-pos was set to %f (ref: %08X)", true, API::RetrieveAxis_Reverse( axis ).c_str(), ( float ) pos, this->GetReference() );
#endif
return &data;
}
return NULL;
}
Lockable* Object::SetAngle( unsigned char axis, double angle )
{
Value<double>& data = SAFE_FIND( this->object_Angle, axis )->second;
if ( Utils::DoubleCompare( data.Get(), angle, 0.01 ) )
return NULL;
if ( ( angle != 2048.0 && angle != 128.0 && angle != 0.0 ) )
{
if ( !data.Set( angle ) )
return NULL;
#ifdef VAULTMP_DEBUG
if ( debug != NULL )
debug->PrintFormat( "Object %s-angle was set to %f (ref: %08X)", true, API::RetrieveAxis_Reverse( axis ).c_str(), ( float ) angle, this->GetReference() );
#endif
return &data;
}
return NULL;
}
What's up with the if ( ( pos != 2048.0 && pos != 128.0 && pos != 0.0 ) ) checks in these functions? Couldn't they be valid values?
And my other .01$, a 3d vector class I've made that might be of use
#include <math.h>
#define CInline inline
#define _prec float
#define M_PI 3.14159265358979323846
class Vector3
{
public:
_prec X;
_prec Y;
_prec Z;
CInline Vector3()
{
X=0;
Y=0;
Z=0;
}
CInline Vector3(_prec f)
{
X=f;
Y=f;
Z=f;
}
CInline Vector3(const Vector3& v)
{
X=v.X;
Y=v.Y;
Z=v.Z;
}
CInline Vector3(_prec x,_prec y,_prec z)
{
X=x;
Y=y;
Z=z;
}
CInline Vector3 operator+ (Vector3 in)
{
Vector3 Temp;
Temp.X=this->X+in.X;
Temp.Y=this->Y+in.Y;
Temp.Z=this->Z+in.Z;
return Temp;
}
CInline Vector3 operator+= (Vector3 in)
{
this->X+=in.X;
this->Y+=in.Y;
this->Z+=in.Z;
return *this;
}
CInline Vector3 operator+ (_prec in)
{
Vector3 Temp;
Temp.X=this->X+in;
Temp.Y=this->Y+in;
Temp.Z=this->Z+in;
return Temp;
}
CInline Vector3 operator+= (_prec in)
{
this->X+=in;
this->Y+=in;
this->Z+=in;
return *this;
}
CInline Vector3 operator- (Vector3 in)
{
Vector3 Temp;
Temp.X=this->X-in.X;
Temp.Y=this->Y-in.Y;
Temp.Z=this->Z-in.Z;
return Temp;
}
CInline Vector3 operator-= (Vector3 in)
{
this->X-=in.X;
this->Y-=in.Y;
this->Z-=in.Z;
return *this;
}
CInline Vector3 operator- (_prec in)
{
Vector3 Temp;
Temp.X=this->X-in;
Temp.Y=this->Y-in;
Temp.Z=this->Z-in;
return Temp;
}
CInline Vector3 operator-= (_prec in)
{
this->X-=in;
this->Y-=in;
this->Z-=in;
return *this;
}
CInline Vector3 operator* (Vector3 in)
{
Vector3 Temp;
Temp.X=this->X*in.X;
Temp.Y=this->Y*in.Y;
Temp.Z=this->Z*in.Z;
return Temp;
}
CInline Vector3 operator*= (Vector3 in)
{
this->X*=in.X;
this->Y*=in.Y;
this->Z*=in.Z;
return *this;
}
CInline Vector3 operator* (_prec in)
{
Vector3 Temp;
Temp.X=this->X*in;
Temp.Y=this->Y*in;
Temp.Z=this->Z*in;
return Temp;
}
CInline Vector3 operator*= (_prec in)
{
this->X*=in;
this->Y*=in;
this->Z*=in;
return *this;
}
CInline Vector3 operator/ (Vector3 in)
{
Vector3 Temp;
Temp.X=this->X/in.X;
Temp.Y=this->Y/in.Y;
Temp.Z=this->Z/in.Z;
return Temp;
}
CInline Vector3 operator/= (Vector3 in)
{
this->X/=in.X;
this->Y/=in.Y;
this->Z/=in.Z;
return *this;
}
CInline Vector3 operator/ (_prec in)
{
Vector3 Temp;
Temp.X=this->X/in;
Temp.Y=this->Y/in;
Temp.Z=this->Z/in;
return Temp;
}
CInline Vector3 operator/= (_prec in)
{
X/=in;
Y/=in;
Z/=in;
return *this;
}
CInline bool operator== (Vector3 in)
{
return (X == in.X && Y == in.Y && Z == in.Z);
}
CInline bool operator== (_prec in)
{
return (X == in && Y == in && Z == in);
}
CInline bool operator> (Vector3 in)
{
return (X > in.X && Y > in.Y && Z > in.Z);
}
CInline bool operator> (_prec in)
{
return (X > in && Y > in && Z > in);
}
CInline bool operator>= (Vector3 in)
{
return (X >= in.X && Y >= in.Y && Z >= in.Z);
}
CInline bool operator>= (_prec in)
{
return (X >= in && Y >= in && Z >= in);
}
CInline bool operator<= (Vector3 in)
{
return (X <= in.X && Y <= in.Y && Z <= in.Z);
}
CInline bool operator<= (_prec in)
{
return (X <= in && Y <= in && Z <= in);
}
CInline bool operator< (Vector3 in)
{
return (X < in.X && Y < in.Y && Z < in.Z);
}
CInline bool operator< (_prec in)
{
return (X < in && Y < in && Z < in);
}
CInline bool operator!= (Vector3 in)
{
return (X != in.X && Y != in.Y && Z != in.Z);
}
CInline bool operator!= (_prec in)
{
return (X != in && Y != in && Z != in);
}
CInline _prec Dot(const Vector3 V1,const Vector3 V2)
{
return ( V1.X*V2.X + V1.Y*V2.Y + V1.Z*V2.Z );
}
CInline _prec Dot(const Vector3 V1,const _prec V2)
{
return ( V1.X*V2 + V1.Y*V2 + V1.Z*V2 );
}
CInline Vector3 Lerp (_prec to, _prec frac)
{
return *this + (((Vector3)to - *this) * frac);
}
CInline Vector3 Lerp (Vector3 to, _prec frac)
{
return *this + ((to - *this) * frac);
}
CInline Vector3 Angles()
{
Vector3 Angles;
_prec forward, yaw, pitch;
if( Y == 0 && X == 0 )
{
yaw = 0;
if ( Z > 0 )
pitch = 90;
else
pitch = 270;
}
else
{
if ( X )
yaw = ( atan2 (Y, X ) * ( 180.0 / M_PI ) );
else if ( Y > 0 )
yaw = 90.0;
else
yaw = 270.0;
if ( yaw < 0.0 )
yaw += 360.0f;
forward = sqrt ( ( X * X ) + ( Y * Y ) );
pitch = ( atan2( Z, forward ) * ( 180.0 / M_PI ) );
if ( pitch < 0.0 )
pitch += 360;
}
Angles.X = -pitch;
Angles.Y = yaw;
Angles.Z = 0;
return Angles;
}
CInline void AngleVectors(Vector3* forward, Vector3* right, Vector3* up)
{
static _prec angle;
static _prec sr, sp, sy, cr, cp, cy;
angle = Z * (M_PI*2 / 360);
sr = sin(angle);
cr = cos(angle);
angle = X * (M_PI*2 / 360);
sp = sin(angle);
cp = cos(angle);
angle = Y * (M_PI*2 / 360);
sy = sin(angle);
cy = cos(angle);
if (right)
{
right->X = (-1*sr*sp*cy+-1*cr*-sy);
right->Y = (-1*sr*sp*sy+-1*cr*cy);
right->Z = -1*sr*cp;
}
if (forward)
{
forward->X = cp*cy;
forward->Y = cp*sy;
forward->Z = -sp;
}
if (up)
{
up->X = (cr*sp*cy+-sr*-sy);
up->Y = (cr*sp*sy+-sr*cy);
up->Z = cr*cp;
}
}
CInline void Normalize180()
{
Normalize360();
if (Y > 180.0)
Y -= 360.0;
if (X > 180.0)
X -= 360.0;
}
CInline void Normalize360()
{
X = ((_prec)(360.0 / 65536) * ((int)(X * (65536 / 360.0)) & 65535));
Y = ((_prec)(360.0 / 65536) * ((int)(Y * (65536 / 360.0)) & 65535));
}
CInline Vector3 UnitVector()
{
return *this / this->Length();
}
CInline bool IsNull()
{
if (*this == 0.0)
return true;
return false;
}
CInline _prec Length()
{
return sqrt(X*X+Y*Y+Z*Z);
}
};
Lockable* Object::SetGamePos( unsigned char axis, double pos )
{
Value<double>& data = SAFE_FIND( this->object_Game_Pos, axis )->second;
if ( Utils::DoubleCompare( data.Get(), pos, 0.01 ) )
return NULL;
if ( ( pos != 2048.0 && pos != 128.0 && pos != 0.0 ) )
{
if ( !data.Set( pos ) )
return NULL;
#ifdef VAULTMP_DEBUG
if ( debug != NULL )
debug->PrintFormat( "Object game %s-pos was set to %f (ref: %08X)", true, API::RetrieveAxis_Reverse( axis ).c_str(), ( float ) pos, this->GetReference() );
#endif
return &data;
}
return NULL;
}
Lockable* Object::SetNetworkPos( unsigned char axis, double pos )
{
Value<double>& data = SAFE_FIND( this->object_Network_Pos, axis )->second;
if ( Utils::DoubleCompare( data.Get(), pos, 0.01 ) )
return NULL;
if ( ( pos != 2048.0 && pos != 128.0 && pos != 0.0 ) )
{
if ( !data.Set( pos ) )
return NULL;
#ifdef VAULTMP_DEBUG
if ( debug != NULL )
debug->PrintFormat( "Object network %s-pos was set to %f (ref: %08X)", true, API::RetrieveAxis_Reverse( axis ).c_str(), ( float ) pos, this->GetReference() );
#endif
return &data;
}
return NULL;
}
Lockable* Object::SetAngle( unsigned char axis, double angle )
{
Value<double>& data = SAFE_FIND( this->object_Angle, axis )->second;
if ( Utils::DoubleCompare( data.Get(), angle, 0.01 ) )
return NULL;
if ( ( angle != 2048.0 && angle != 128.0 && angle != 0.0 ) )
{
if ( !data.Set( angle ) )
return NULL;
#ifdef VAULTMP_DEBUG
if ( debug != NULL )
debug->PrintFormat( "Object %s-angle was set to %f (ref: %08X)", true, API::RetrieveAxis_Reverse( axis ).c_str(), ( float ) angle, this->GetReference() );
#endif
return &data;
}
return NULL;
}
What's up with the if ( ( pos != 2048.0 && pos != 128.0 && pos != 0.0 ) ) checks in these functions? Couldn't they be valid values?
And my other .01$, a 3d vector class I've made that might be of use
#include <math.h>
#define CInline inline
#define _prec float
#define M_PI 3.14159265358979323846
class Vector3
{
public:
_prec X;
_prec Y;
_prec Z;
CInline Vector3()
{
X=0;
Y=0;
Z=0;
}
CInline Vector3(_prec f)
{
X=f;
Y=f;
Z=f;
}
CInline Vector3(const Vector3& v)
{
X=v.X;
Y=v.Y;
Z=v.Z;
}
CInline Vector3(_prec x,_prec y,_prec z)
{
X=x;
Y=y;
Z=z;
}
CInline Vector3 operator+ (Vector3 in)
{
Vector3 Temp;
Temp.X=this->X+in.X;
Temp.Y=this->Y+in.Y;
Temp.Z=this->Z+in.Z;
return Temp;
}
CInline Vector3 operator+= (Vector3 in)
{
this->X+=in.X;
this->Y+=in.Y;
this->Z+=in.Z;
return *this;
}
CInline Vector3 operator+ (_prec in)
{
Vector3 Temp;
Temp.X=this->X+in;
Temp.Y=this->Y+in;
Temp.Z=this->Z+in;
return Temp;
}
CInline Vector3 operator+= (_prec in)
{
this->X+=in;
this->Y+=in;
this->Z+=in;
return *this;
}
CInline Vector3 operator- (Vector3 in)
{
Vector3 Temp;
Temp.X=this->X-in.X;
Temp.Y=this->Y-in.Y;
Temp.Z=this->Z-in.Z;
return Temp;
}
CInline Vector3 operator-= (Vector3 in)
{
this->X-=in.X;
this->Y-=in.Y;
this->Z-=in.Z;
return *this;
}
CInline Vector3 operator- (_prec in)
{
Vector3 Temp;
Temp.X=this->X-in;
Temp.Y=this->Y-in;
Temp.Z=this->Z-in;
return Temp;
}
CInline Vector3 operator-= (_prec in)
{
this->X-=in;
this->Y-=in;
this->Z-=in;
return *this;
}
CInline Vector3 operator* (Vector3 in)
{
Vector3 Temp;
Temp.X=this->X*in.X;
Temp.Y=this->Y*in.Y;
Temp.Z=this->Z*in.Z;
return Temp;
}
CInline Vector3 operator*= (Vector3 in)
{
this->X*=in.X;
this->Y*=in.Y;
this->Z*=in.Z;
return *this;
}
CInline Vector3 operator* (_prec in)
{
Vector3 Temp;
Temp.X=this->X*in;
Temp.Y=this->Y*in;
Temp.Z=this->Z*in;
return Temp;
}
CInline Vector3 operator*= (_prec in)
{
this->X*=in;
this->Y*=in;
this->Z*=in;
return *this;
}
CInline Vector3 operator/ (Vector3 in)
{
Vector3 Temp;
Temp.X=this->X/in.X;
Temp.Y=this->Y/in.Y;
Temp.Z=this->Z/in.Z;
return Temp;
}
CInline Vector3 operator/= (Vector3 in)
{
this->X/=in.X;
this->Y/=in.Y;
this->Z/=in.Z;
return *this;
}
CInline Vector3 operator/ (_prec in)
{
Vector3 Temp;
Temp.X=this->X/in;
Temp.Y=this->Y/in;
Temp.Z=this->Z/in;
return Temp;
}
CInline Vector3 operator/= (_prec in)
{
X/=in;
Y/=in;
Z/=in;
return *this;
}
CInline bool operator== (Vector3 in)
{
return (X == in.X && Y == in.Y && Z == in.Z);
}
CInline bool operator== (_prec in)
{
return (X == in && Y == in && Z == in);
}
CInline bool operator> (Vector3 in)
{
return (X > in.X && Y > in.Y && Z > in.Z);
}
CInline bool operator> (_prec in)
{
return (X > in && Y > in && Z > in);
}
CInline bool operator>= (Vector3 in)
{
return (X >= in.X && Y >= in.Y && Z >= in.Z);
}
CInline bool operator>= (_prec in)
{
return (X >= in && Y >= in && Z >= in);
}
CInline bool operator<= (Vector3 in)
{
return (X <= in.X && Y <= in.Y && Z <= in.Z);
}
CInline bool operator<= (_prec in)
{
return (X <= in && Y <= in && Z <= in);
}
CInline bool operator< (Vector3 in)
{
return (X < in.X && Y < in.Y && Z < in.Z);
}
CInline bool operator< (_prec in)
{
return (X < in && Y < in && Z < in);
}
CInline bool operator!= (Vector3 in)
{
return (X != in.X && Y != in.Y && Z != in.Z);
}
CInline bool operator!= (_prec in)
{
return (X != in && Y != in && Z != in);
}
CInline _prec Dot(const Vector3 V1,const Vector3 V2)
{
return ( V1.X*V2.X + V1.Y*V2.Y + V1.Z*V2.Z );
}
CInline _prec Dot(const Vector3 V1,const _prec V2)
{
return ( V1.X*V2 + V1.Y*V2 + V1.Z*V2 );
}
CInline Vector3 Lerp (_prec to, _prec frac)
{
return *this + (((Vector3)to - *this) * frac);
}
CInline Vector3 Lerp (Vector3 to, _prec frac)
{
return *this + ((to - *this) * frac);
}
CInline Vector3 Angles()
{
Vector3 Angles;
_prec forward, yaw, pitch;
if( Y == 0 && X == 0 )
{
yaw = 0;
if ( Z > 0 )
pitch = 90;
else
pitch = 270;
}
else
{
if ( X )
yaw = ( atan2 (Y, X ) * ( 180.0 / M_PI ) );
else if ( Y > 0 )
yaw = 90.0;
else
yaw = 270.0;
if ( yaw < 0.0 )
yaw += 360.0f;
forward = sqrt ( ( X * X ) + ( Y * Y ) );
pitch = ( atan2( Z, forward ) * ( 180.0 / M_PI ) );
if ( pitch < 0.0 )
pitch += 360;
}
Angles.X = -pitch;
Angles.Y = yaw;
Angles.Z = 0;
return Angles;
}
CInline void AngleVectors(Vector3* forward, Vector3* right, Vector3* up)
{
static _prec angle;
static _prec sr, sp, sy, cr, cp, cy;
angle = Z * (M_PI*2 / 360);
sr = sin(angle);
cr = cos(angle);
angle = X * (M_PI*2 / 360);
sp = sin(angle);
cp = cos(angle);
angle = Y * (M_PI*2 / 360);
sy = sin(angle);
cy = cos(angle);
if (right)
{
right->X = (-1*sr*sp*cy+-1*cr*-sy);
right->Y = (-1*sr*sp*sy+-1*cr*cy);
right->Z = -1*sr*cp;
}
if (forward)
{
forward->X = cp*cy;
forward->Y = cp*sy;
forward->Z = -sp;
}
if (up)
{
up->X = (cr*sp*cy+-sr*-sy);
up->Y = (cr*sp*sy+-sr*cy);
up->Z = cr*cp;
}
}
CInline void Normalize180()
{
Normalize360();
if (Y > 180.0)
Y -= 360.0;
if (X > 180.0)
X -= 360.0;
}
CInline void Normalize360()
{
X = ((_prec)(360.0 / 65536) * ((int)(X * (65536 / 360.0)) & 65535));
Y = ((_prec)(360.0 / 65536) * ((int)(Y * (65536 / 360.0)) & 65535));
}
CInline Vector3 UnitVector()
{
return *this / this->Length();
}
CInline bool IsNull()
{
if (*this == 0.0)
return true;
return false;
}
CInline _prec Length()
{
return sqrt(X*X+Y*Y+Z*Z);
}
};