Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef VECTOR3F_HPP
- #define VECTOR3F_HPP
- #include <cmath>
- class Vector3f
- {
- float x, y, z;
- const float pi = 3.141592653589793;
- public:
- Vector3f()
- {
- x = 0.0;
- y = 0.0;
- z = 0.0;
- }
- Vector3f(float _x, float _y, float _z)
- : x(_x)
- , y(_y)
- , z(_z)
- {
- }
- Vector3f operator =(Vector3f& other)
- {
- x = other.getX();
- y = other.getY();
- z = other.getZ();
- return *this;
- }
- float length()
- {
- return float(sqrt(x * x + y * y + z * z));
- }
- float dot(Vector3f other)
- {
- return x * other.getX() + y * other.getY() + z * other.getZ();
- }
- Vector3f normalize()
- {
- float _length = length();
- x /= _length;
- y /= _length;
- z /= _length;
- return *this;
- }
- Vector3f operator +(float n)
- {
- return add(n);
- }
- Vector3f operator +(Vector3f other)
- {
- return add(other);
- }
- Vector3f add(Vector3f other)
- {
- return Vector3f{x + other.getX(), y + other.getY(), z + other.getZ()};
- }
- Vector3f add(float n)
- {
- return Vector3f{x + n, y + n, z + n};
- }
- Vector3f operator -(float n)
- {
- return sub(n);
- }
- Vector3f operator -(Vector3f other)
- {
- return sub(other);
- }
- Vector3f sub(Vector3f other)
- {
- return Vector3f{x - other.getX(), y - other.getY(), z - other.getZ()};
- }
- Vector3f sub(float n)
- {
- return Vector3f{x - n, y - n, z - n};
- }
- Vector3f operator *(float n)
- {
- return mul(n);
- }
- Vector3f operator *(Vector3f other)
- {
- return mul(other);
- }
- Vector3f mul(Vector3f other)
- {
- return Vector3f{x * other.getX(), y * other.getY(), z * other.getZ()};
- }
- Vector3f mul(float n)
- {
- return Vector3f{x * n, y * n, z * n};
- }
- Vector3f operator /(float n)
- {
- return div(n);
- }
- Vector3f operator /(Vector3f other)
- {
- return div(other);
- }
- Vector3f div(Vector3f other)
- {
- return Vector3f{x / other.getX(), y / other.getY(), z / other.getZ()};
- }
- Vector3f div(float n)
- {
- return Vector3f{x / n, y / n, z / n};
- }
- inline bool operator ==(Vector3f other)
- {
- return x == other.getX() && y == other.getY() && z == other.getZ();
- }
- inline bool operator !=(Vector3f other)
- {
- return x != other.getX() && y != other.getY() && z != other.getZ();
- }
- Vector3f cross(Vector3f other)
- {
- float _x = y * other.getZ() - z * other.getY();
- float _y = z * other.getX() - x * other.getZ();
- float _z = x * other.getY() - y * other.getX();
- return Vector3f{_x, _y, _z};
- }
- float getX()
- {
- return x;
- }
- float getY()
- {
- return y;
- }
- float getZ()
- {
- return z;
- }
- };
- #endif // VECTOR3F_HPP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement