#pragma once #include struct Vector; const float PI=3.14159265358979323846; const float TWOPI=PI*2.0f; const float HALFPI=PI*.5f; const float QUARTERPI=PI*.25f; const float EPSILON=1e-6f; const float INFINITY=10000000.0f; const float DEG2RAD = PI / 180.0f; const float RAD2DEG = 180.0f / PI; struct Vector{ public: inline Vector(){ x=0; y=0; z=0; } inline Vector( float _x,float _y,float _z ){ x=_x; y=_y; z=_z; } inline Vector( const Vector& v ){ x = v.x; y = v.y; z = v.z; } inline Vector operator-()const{ return Vector( -x,-y,-z ); } inline Vector operator*( float scale )const{ return Vector( x*scale,y*scale,z*scale ); } inline float operator % ( const Vector& v )const{ return x * v.x + y * v.y + z * v.z; } inline Vector operator*( const Vector &q )const{ return Vector( x*q.x,y*q.y,z*q.z ); } inline Vector operator/( float scale )const{ return Vector( x/scale,y/scale,z/scale ); } inline Vector operator/( const Vector &q )const{ return Vector( x/q.x,y/q.y,z/q.z ); } inline Vector operator+( const Vector &q )const{ return Vector( x+q.x,y+q.y,z+q.z ); } inline Vector operator-( const Vector &q )const{ return Vector( x-q.x,y-q.y,z-q.z ); } inline Vector &operator*=( float scale ){ *this = *this * scale; return *this; } inline Vector &operator*=( const Vector &q ){ *this = *this * q; return *this; } inline Vector &operator/=( float scale ){ *this = *this / scale; return *this; } inline Vector &operator/=( const Vector &q ){ *this = *this * q; return *this; } inline Vector &operator+=( const Vector &q ){ *this = *this + q; return *this; } inline Vector &operator-=( const Vector &q ){ *this = *this - q; return *this; } inline bool operator<( const Vector &q )const{ if( fabs(x-q.x)>EPSILON ) return xEPSILON ) return yEPSILON && zEPSILON || fabs(y-q.y)>EPSILON || fabs(z-q.z)>EPSILON; } inline float dot( const Vector &q )const{ return x*q.x+y*q.y+z*q.z; } inline Vector cross( const Vector &q )const{ return Vector( y*q.z-z*q.y,z*q.x-x*q.z,x*q.y-y*q.x ); } inline void cross(const Vector &v1,const Vector &v2) { x = v1.y * v2.z - v1.z * v2.y; y = v1.z * v2.x - v1.x * v2.z; z = v1.x * v2.y - v1.y * v2.x; } inline float length()const{ return sqrtf(x*x+y*y+z*z); } inline float distance( const Vector &q )const{ float dx=x-q.x,dy=y-q.y,dz=z-q.z; return sqrtf(dx*dx+dy*dy+dz*dz); } inline Vector blend( const Vector &t,float alpha )const{ return (t-*this)*alpha+*this; } inline Vector normalized()const{ float l=length();return Vector( x/l,y/l,z/l ); } inline float normalize(){ float inv,length = sqrt(x * x + y * y + z * z); if(length < EPSILON) return 0.0; inv = 1.0f / length; x *= inv; y *= inv; z *= inv; return length; } inline float yaw()const{ return -atan2f( x,z ); } inline float pitch()const{ return -atan2f( y,sqrtf( x*x+z*z ) ); } inline void zero(){ x=y=z=0; } inline void identity() { x=y=z=1; } inline operator float*() { return (float*)&x; } inline operator const float*() const { return (float*)&x; } inline float &operator[](int i) { return ((float*)&x)[i]; } inline const float operator[](int i) const { return ((float*)&x)[i]; } };