#ifndef VECTOR3_H__ #define VECTOR3_H__ #include #include template class Vector3 { public: Vector3(); Vector3(const T& x, const T& y, const T& z); ~Vector3(); T Length() const; void Normalize(); void Zero(); T Dot(const Vector3& v) const; Vector3 Cross(const Vector3& v) const; Vector3 operator+(const Vector3& v) const; Vector3 operator-(const Vector3& v) const; Vector3 operator-() const; Vector3 operator+(const T& v) const; Vector3 operator-(const T& v) const; Vector3 operator/(const T& v) const; Vector3 operator*(const T& v) const; Vector3& operator=(const Vector3& v); Vector3& operator+=(const Vector3& v); Vector3& operator-=(const Vector3& v); Vector3& operator+=(const T& v); Vector3& operator-=(const T& v); Vector3& operator/=(const T& v); Vector3& operator*=(const T& v); bool operator==(const Vector3& v) const; bool operator!=(const Vector3& v) const; void Afficher() const; public: T x, y, z; }; typedef Vector3 Vector3i; typedef Vector3 Vector3f; template inline std::ostream& operator<<(std::ostream& out, const Vector3& v) { out << "[" << v.x << ", " << v.y << ", " << v.z << "]"; return out; } template Vector3::Vector3() { } template Vector3::Vector3(const T& x, const T& y, const T& z) : x(x), y(y), z(z) { } template Vector3::~Vector3() { } template T Vector3::Length() const { return sqrt(x*x + y*y + z*z); } template void Vector3::Normalize() { T len = Length(); if (len != 0) { x /= len; y /= len; z /= len; } } template void Vector3::Zero() { x = y = z = 0; } template T Vector3::Dot(const Vector3& v) const { return (x * v.x) + (y * v.y) + (z * v.z); } template Vector3 Vector3::Cross(const Vector3& v) const { return Vector3( y * v.z - v.y * z, z * v.x - v.z * x, x * v.y - v.x * y); } template Vector3 Vector3::operator+(const Vector3& v) const { return Vector3(x + v.x, y + v.y, z + v.z); } template Vector3 Vector3::operator-(const Vector3& v) const { return Vector3(x - v.x, y - v.y, z - v.z); } template Vector3 Vector3::operator-() const { return Vector3(-x, -y, -z); } template Vector3 Vector3::operator+(const T& v) const { return Vector3(x + v, y + v, z + v); } template Vector3 Vector3::operator-(const T& v) const { return Vector3(x - v, y - v, z - v); } template Vector3 Vector3::operator/(const T& v) const { return Vector3(x / v, y / v, z / v); } template Vector3 Vector3::operator*(const T& v) const { return Vector3(x * v, y * v, z * v); } template Vector3& Vector3::operator=(const Vector3& v) { x = v.x; y = v.y; z = v.z; return *this; } template Vector3& Vector3::operator+=(const Vector3& v) { return (*this = *this + v); } template Vector3& Vector3::operator-=(const Vector3& v) { return (*this = *this - v); } template Vector3& Vector3::operator+=(const T& v) { return (*this = *this + v); } template Vector3& Vector3::operator-=(const T& v) { return (*this = *this - v); } template Vector3& Vector3::operator/=(const T& v) { return (*this = *this / v); } template Vector3& Vector3::operator*=(const T& v) { return (*this = *this * v); } template bool Vector3::operator==(const Vector3& v) const { return (x == v.x && y == v.y && z == v.z); } template bool Vector3::operator!=(const Vector3& v) const { return !(*this == v); } template void Vector3::Afficher() const { std::cout << "[" << x << ", " << y << ", " << z << "]" << std::endl; } #endif // VECTOR3_H__