Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Vector3
- {
- public:
- float x, y, z;
- Vector3()
- {
- x = y = z = 0.0f;
- }
- Vector3( float X, float Y, float Z )
- {
- x = X; y = Y; z = Z;
- }
- Vector3( float XYZ )
- {
- x = XYZ; y = XYZ; z = XYZ;
- }
- Vector3( float* v )
- {
- x = v[ 0 ]; y = v[ 1 ]; z = v[ 2 ];
- }
- Vector3( const float* v )
- {
- x = v[ 0 ]; y = v[ 1 ]; z = v[ 2 ];
- }
- inline Vector3& operator=( const Vector3& v )
- {
- x = v.x; y = v.y; z = v.z; return *this;
- }
- inline Vector3& operator=( const float* v )
- {
- x = v[ 0 ]; y = v[ 1 ]; z = v[ 2 ]; return *this;
- }
- inline float& operator[]( int i )
- {
- return ( ( float* )this )[ i ];
- }
- inline float operator[]( int i ) const
- {
- return ( ( float* )this )[ i ];
- }
- inline Vector3& operator+=( const Vector3& v )
- {
- x += v.x; y += v.y; z += v.z; return *this;
- }
- inline Vector3& operator-=( const Vector3& v )
- {
- x -= v.x; y -= v.y; z -= v.z; return *this;
- }
- inline Vector3& operator*=( const Vector3& v )
- {
- x *= v.x; y *= v.y; z *= v.z; return *this;
- }
- inline Vector3& operator/=( const Vector3& v )
- {
- x /= v.x; y /= v.y; z /= v.z; return *this;
- }
- inline Vector3& operator+=( float v )
- {
- x += v; y += v; z += v; return *this;
- }
- inline Vector3& operator-=( float v )
- {
- x -= v; y -= v; z -= v; return *this;
- }
- inline Vector3& operator*=( float v )
- {
- x *= v; y *= v; z *= v; return *this;
- }
- inline Vector3& operator/=( float v )
- {
- x /= v; y /= v; z /= v; return *this;
- }
- inline Vector3 operator-( ) const
- {
- return Vector3( -x, -y, -z );
- }
- inline Vector3 operator+( const Vector3& v ) const
- {
- return Vector3( x + v.x, y + v.y, z + v.z );
- }
- inline Vector3 operator-( const Vector3& v ) const
- {
- return Vector3( x - v.x, y - v.y, z - v.z );
- }
- inline Vector3 operator*( const Vector3& v ) const
- {
- return Vector3( x * v.x, y * v.y, z * v.z );
- }
- inline Vector3 operator/( const Vector3& v ) const
- {
- return Vector3( x / v.x, y / v.y, z / v.z );
- }
- inline Vector3 operator+( float v ) const
- {
- return Vector3( x + v, y + v, z + v );
- }
- inline Vector3 operator-( float v ) const
- {
- return Vector3( x - v, y - v, z - v );
- }
- inline Vector3 operator*( float v ) const
- {
- return Vector3( x * v, y * v, z * v );
- }
- inline Vector3 operator/( float v ) const
- {
- return Vector3( x / v, y / v, z / v );
- }
- inline float Length() const
- {
- return sqrtf( x * x + y * y + z * z );
- }
- inline float LengthSqr() const
- {
- return ( x * x + y * y + z * z );
- }
- inline float LengthXY() const
- {
- return sqrtf( x * x + y * y );
- }
- inline float LengthXZ() const
- {
- return sqrtf( x * x + z * z );
- }
- inline float DistTo( const Vector3& v ) const
- {
- return ( *this - v ).Length();
- }
- inline float Dot( const Vector3& v ) const
- {
- return ( x * v.x + y * v.y + z * v.z );
- }
- inline Vector3 Cross( const Vector3& v ) const
- {
- return Vector3( y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x );
- }
- inline bool IsZero() const
- {
- return ( x > -0.01f && x < 0.01f
- && y > -0.01f && y < 0.01f
- && z > -0.01f && z < 0.01f );
- }
- inline void Reset()
- {
- x = 0.f; y = 0.f; z = 0.f;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement