diff --git a/include/Nazara/Math/Vector2.hpp b/include/Nazara/Math/Vector2.hpp index 72c72da4c..75e86f709 100644 --- a/include/Nazara/Math/Vector2.hpp +++ b/include/Nazara/Math/Vector2.hpp @@ -63,8 +63,8 @@ namespace Nz String ToString() const; - operator T* (); - operator const T* () const; + T& operator[](std::size_t i); + T operator[](std::size_t i) const; const Vector2& operator+() const; Vector2 operator-() const; diff --git a/include/Nazara/Math/Vector2.inl b/include/Nazara/Math/Vector2.inl index 7d2754955..22eb72566 100644 --- a/include/Nazara/Math/Vector2.inl +++ b/include/Nazara/Math/Vector2.inl @@ -450,29 +450,25 @@ namespace Nz } /*! - * \brief Converts vector to pointer to its own data - * \return A pointer to the own data - * - * \remark Access to index greather than 1 is undefined behavior + * \brief Access a vector component by index + * \return X, Y depending on index (0, 1) */ - template - Vector2::operator T* () + T& Vector2::operator[](std::size_t i) { - return &x; + NazaraAssert(i < 2, "index out of range"); + return *(&x + i); } /*! - * \brief Converts vector to const pointer to its own data - * \return A constant pointer to the own data - * - * \remark Access to index greather than 1 is undefined behavior + * \brief Access a vector component by index + * \return X, Y depending on index (0, 1) */ - template - Vector2::operator const T* () const + T Vector2::operator[](std::size_t i) const { - return &x; + NazaraAssert(i < 2, "index out of range"); + return *(&x + i); } /*! diff --git a/include/Nazara/Math/Vector3.hpp b/include/Nazara/Math/Vector3.hpp index 1603f7d34..4fd965484 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -74,8 +74,8 @@ namespace Nz String ToString() const; - operator T* (); - operator const T* () const; + T& operator[](std::size_t i); + T operator[](std::size_t i) const; const Vector3& operator+() const; Vector3 operator-() const; diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index a9602a248..f9585d91e 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -583,27 +583,25 @@ namespace Nz } /*! - * \brief Converts vector to pointer to its own data - * \return A pointer to the own data - * - * \remark Access to index greather than 2 is undefined behavior + * \brief Access a vector component by index + * \return X, Y, Z depending on index (0, 1, 2) */ template - Vector3::operator T* () + T& Vector3::operator[](std::size_t i) { - return &x; + NazaraAssert(i < 3, "index out of range"); + return *(&x + i); } /*! - * \brief Converts vector to const pointer to its own data - * \return A constant pointer to the own data - * - * \remark Access to index greather than 2 is undefined behavior + * \brief Access a vector component by index + * \return X, Y, Z depending on index (0, 1, 2) */ template - Vector3::operator const T* () const + T Vector3::operator[](std::size_t i) const { - return &x; + NazaraAssert(i < 3, "index out of range"); + return *(&x + i); } /*! diff --git a/include/Nazara/Math/Vector4.hpp b/include/Nazara/Math/Vector4.hpp index 24893ee65..5c5c9721f 100644 --- a/include/Nazara/Math/Vector4.hpp +++ b/include/Nazara/Math/Vector4.hpp @@ -61,8 +61,8 @@ namespace Nz String ToString() const; - operator T* (); - operator const T* () const; + T& operator[](std::size_t i); + T operator[](std::size_t i) const; const Vector4& operator+() const; Vector4 operator-() const; diff --git a/include/Nazara/Math/Vector4.inl b/include/Nazara/Math/Vector4.inl index 93003da9b..dfc39aafe 100644 --- a/include/Nazara/Math/Vector4.inl +++ b/include/Nazara/Math/Vector4.inl @@ -494,29 +494,25 @@ namespace Nz } /*! - * \brief Converts vector to pointer to its own data - * \return A pointer to the own data - * - * \remark Access to index greather than 3 is undefined behavior + * \brief Access a vector component by index + * \return X, Y, Z depending on index (0, 1, 2) */ - template - Vector4::operator T* () + T& Vector4::operator[](std::size_t i) { - return &x; + NazaraAssert(i < 4, "index out of range"); + return *(&x + i); } /*! - * \brief Converts vector to const pointer to its own data - * \return A constant pointer to the own data - * - * \remark Access to index greather than 3 is undefined behavior + * \brief Access a vector component by index + * \return X, Y, Z depending on index (0, 1, 2) */ - template - Vector4::operator const T* () const + T Vector4::operator[](std::size_t i) const { - return &x; + NazaraAssert(i < 4, "index out of range"); + return *(&x + i); } /*! diff --git a/src/Nazara/Utility/Formats/MD2Loader.cpp b/src/Nazara/Utility/Formats/MD2Loader.cpp index 0f369cfe5..890572d35 100644 --- a/src/Nazara/Utility/Formats/MD2Loader.cpp +++ b/src/Nazara/Utility/Formats/MD2Loader.cpp @@ -166,8 +166,8 @@ namespace Nz std::vector vertices(header.num_vertices); Vector3f scale, translate; - stream.Read(scale, sizeof(Vector3f)); - stream.Read(translate, sizeof(Vector3f)); + stream.Read(&scale, sizeof(Vector3f)); + stream.Read(&translate, sizeof(Vector3f)); stream.Read(nullptr, 16*sizeof(char)); //< Frame name, unused stream.Read(vertices.data(), header.num_vertices*sizeof(MD2_Vertex));