math compiles again.
[fail.git] / include / math / Vector3f.h
blobe23d87000214472af7fc0f92b2e213a39189fe38
1 #ifndef AWFUL_MATH_VECTOR3F_H_
2 #define AWFUL_MATH_VECTOR3F_H_
4 #include "core/core.h"
5 #include <cmath>
7 namespace awful { namespace math
9 struct Vector3f
11 Vector3f() :
12 m_x( 0.f ),
13 m_y( 0.f ),
14 m_z( 0.f )
18 Vector3f( float x_, float y_, float z_ ) :
19 m_x( x_ ),
20 m_y( y_ ),
21 m_z( z_ )
25 float& x() { return m_x; }
26 float& y() { return m_y; }
27 float& z() { return m_z; }
28 const float& x() const { return m_x; }
29 const float& y() const { return m_y; }
30 const float& z() const { return m_z; }
32 Vector3f operator+( const Vector3f& b ) const
34 return Vector3f( m_x + b.m_x, m_y + b.m_y, m_z + b.m_z );
37 Vector3f operator-( const Vector3f& b ) const
39 return Vector3f( m_x - b.m_x, m_y - b.m_y, m_z + b.m_z );
42 const Vector3f& operator+=( const Vector3f& b )
44 m_x += b.m_x;
45 m_y += b.m_y;
46 m_z += b.m_z;
47 return *this;
50 const Vector3f& operator-=( const Vector3f& b )
52 m_x -= b.m_x;
53 m_y -= b.m_y;
54 m_z -= b.m_z;
55 return *this;
58 bool operator==( const Vector3f& b ) const
60 return m_x == b.m_x && m_y == b.m_y && m_z == b.m_z;
63 float length() const
65 return std::sqrt( m_x * m_x + m_y * m_y + m_z * m_z );
68 void normalize()
70 float Len = length();
71 m_x /= Len;
72 m_y /= Len;
73 m_z /= Len;
76 private:
77 float m_x;
78 float m_y;
79 float m_z;
83 #endif