Skip to content

Commit

Permalink
code tidy ups and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacey committed Sep 26, 2023
1 parent 7c2ba47 commit cfc31d5
Show file tree
Hide file tree
Showing 6 changed files with 332 additions and 593 deletions.
18 changes: 2 additions & 16 deletions src/Mat2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@
/// @file Mat2.cpp
/// @brief implementation files for Mat2s class


namespace ngl
{


Mat2::Mat2() noexcept
{
memset(&m_m, 0, sizeof(m_m));
Expand All @@ -48,7 +46,6 @@ Mat2::Mat2(Real _00, Real _01, Real _10, Real _11) noexcept
m_11 = _11;
}


Mat2::Mat2(const Real _m) noexcept
{
memset(m_m, 0, sizeof(m_m));
Expand All @@ -59,21 +56,18 @@ Mat2::Mat2(const Real _m) noexcept
#ifdef USEGLM
Mat2::Mat2(const glm::mat2 &_m)
{
memcpy(&m_m[0][0], glm::value_ptr(_m), 4*sizeof(GLfloat));
memcpy(&m_m[0][0], glm::value_ptr(_m), 4 * sizeof(GLfloat));
}

glm::mat2 Mat2::toGLM() const
{
glm::mat2 result;
memcpy(glm::value_ptr(result), &m_m[0][0], 4*sizeof(GLfloat));
memcpy(glm::value_ptr(result), &m_m[0][0], 4 * sizeof(GLfloat));
return result;
}

#endif




const Mat2 &Mat2::null() noexcept
{
memset(&m_m, 0, sizeof(m_m));
Expand All @@ -88,7 +82,6 @@ const Mat2 &Mat2::identity() noexcept
return *this;
}


Mat2 Mat2::operator*(const Mat2 &_m) const noexcept
{
Mat2 temp;
Expand All @@ -101,7 +94,6 @@ Mat2 Mat2::operator*(const Mat2 &_m) const noexcept
return temp;
}


const Mat2 &Mat2::operator*=(const Mat2 &_m) noexcept
{
Mat2 temp(*this);
Expand All @@ -114,7 +106,6 @@ const Mat2 &Mat2::operator*=(const Mat2 &_m) noexcept
return *this;
}


Mat2 Mat2::operator+(const Mat2 &_m) const noexcept
{
Mat2 ret;
Expand Down Expand Up @@ -151,7 +142,6 @@ Mat2 Mat2::operator*(Real _i) const noexcept
return ret;
}


const Mat2 &Mat2::operator*=(Real _i) noexcept
{
for(auto &v : m_openGL)
Expand All @@ -161,7 +151,6 @@ const Mat2 &Mat2::operator*=(Real _i) noexcept
return *this;
}


const Mat2 &Mat2::transpose() noexcept
{
Mat2 tmp(*this);
Expand All @@ -176,7 +165,6 @@ const Mat2 &Mat2::transpose() noexcept
return *this;
}


[[nodiscard]] Mat2 Mat2::rotate(Real _deg) noexcept
{
Mat2 m;
Expand All @@ -190,7 +178,6 @@ const Mat2 &Mat2::transpose() noexcept
return m;
}


[[nodiscard]] Mat2 Mat2::scale(Real _x, Real _y) noexcept
{
Mat2 m;
Expand All @@ -199,7 +186,6 @@ const Mat2 &Mat2::transpose() noexcept
return m;
}


Vec2 Mat2::operator*(const Vec2 &_v) const noexcept
{
Vec2 temp;
Expand Down
32 changes: 2 additions & 30 deletions src/Mat3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@
/// @file Mat3x3.cpp
/// @brief implementation files for Mat3x3 class


namespace ngl
{


Mat3::Mat3(const Mat4 &_m) noexcept
{
m_00 = _m.m_00;
Expand All @@ -53,7 +51,6 @@ Mat3::Mat3(Real _00, Real _01, Real _02, Real _10, Real _11, Real _12, Real _20,
m_00 = _00;
m_01 = _01;
m_02 = _02;

m_10 = _10;
m_11 = _11;
m_12 = _12;
Expand All @@ -62,15 +59,6 @@ Mat3::Mat3(Real _00, Real _01, Real _02, Real _10, Real _11, Real _12, Real _20,
m_22 = _22;
}

// removed as warning: definition of implicit copy assignment operator
// for 'Mat3' is deprecated because it has a user-declared copy constructor [-Wdeprecated-copy]
// Good chance compilers will optimise.
// Mat3::Mat3(const Mat3& _m) noexcept
// {
// memcpy(m_m,&_m.m_m,sizeof(m_m));
// }


Mat3::Mat3(const Real _m) noexcept
{
memset(m_m, 0, sizeof(m_m));
Expand All @@ -82,20 +70,19 @@ Mat3::Mat3(const Real _m) noexcept
#ifdef USEGLM
Mat3::Mat3(const glm::mat3 &_m)
{
memcpy(&m_m[0][0], glm::value_ptr(_m), 9*sizeof(GLfloat));
memcpy(&m_m[0][0], glm::value_ptr(_m), 9 * sizeof(GLfloat));
}

glm::mat3 Mat3::toGLM() const
{
glm::mat3 result;
memcpy(glm::value_ptr(result), &m_m[0][0], 9*sizeof(GLfloat));
memcpy(glm::value_ptr(result), &m_m[0][0], 9 * sizeof(GLfloat));

return result;
}

#endif


const Mat3 &Mat3::null() noexcept
{
memset(&m_m, 0, sizeof(m_m));
Expand All @@ -111,7 +98,6 @@ const Mat3 &Mat3::identity() noexcept
return *this;
}


Mat3 Mat3::operator*(const Mat3 &_m) const noexcept
{
Mat3 temp;
Expand All @@ -128,7 +114,6 @@ Mat3 Mat3::operator*(const Mat3 &_m) const noexcept
return temp;
}


const Mat3 &Mat3::operator*=(const Mat3 &_m) noexcept
{
Mat3 temp(*this);
Expand Down Expand Up @@ -175,7 +160,6 @@ const Mat3 &Mat3::operator*=(const Mat3 &_m) noexcept
return *this;
}


Mat3 Mat3::operator+(const Mat3 &_m) const noexcept
{
Mat3 ret;
Expand Down Expand Up @@ -218,7 +202,6 @@ Mat3 Mat3::operator*(Real _i) const noexcept
return ret;
}


const Mat3 &Mat3::operator*=(Real _i) noexcept
{
for(auto &i : m_openGL)
Expand All @@ -228,7 +211,6 @@ const Mat3 &Mat3::operator*=(Real _i) noexcept
return *this;
}


const Mat3 &Mat3::transpose() noexcept
{
Mat3 tmp(*this);
Expand All @@ -243,7 +225,6 @@ const Mat3 &Mat3::transpose() noexcept
return *this;
}


[[nodiscard]] Mat3 Mat3::rotateX(Real _deg) noexcept
{
Mat3 m;
Expand All @@ -257,7 +238,6 @@ const Mat3 &Mat3::transpose() noexcept
return m;
}


[[nodiscard]] Mat3 Mat3::rotateY(Real _deg) noexcept
{
Mat3 m;
Expand All @@ -271,7 +251,6 @@ const Mat3 &Mat3::transpose() noexcept
return m;
}


[[nodiscard]] Mat3 Mat3::rotateZ(Real _deg) noexcept
{
Mat3 m;
Expand All @@ -285,7 +264,6 @@ const Mat3 &Mat3::transpose() noexcept
return m;
}


[[nodiscard]] Mat3 Mat3::scale(Real _x, Real _y, Real _z) noexcept
{
Mat3 m;
Expand All @@ -295,7 +273,6 @@ const Mat3 &Mat3::transpose() noexcept
return m;
}


Vec3 Mat3::operator*(const Vec3 &_v) const noexcept
{
Vec3 temp;
Expand All @@ -307,7 +284,6 @@ Vec3 Mat3::operator*(const Vec3 &_v) const noexcept
return temp;
}


void Mat3::euler(Real _angle, Real _x, Real _y, Real _z) noexcept
{
// Axis and Angle Mat3x3 rotation see
Expand Down Expand Up @@ -368,7 +344,6 @@ Mat3 Mat3::inverse() noexcept
return *this;
}


Vec3 Mat3::getLeftVector() const noexcept
{
return Vec3(-m_openGL[0], -m_openGL[1], -m_openGL[2]);
Expand All @@ -384,7 +359,6 @@ Vec3 Mat3::getUpVector() const noexcept
return Vec3(m_openGL[3], m_openGL[4], m_openGL[5]);
}


Vec3 Mat3::getDownVector() const noexcept
{
return Vec3(-m_openGL[3], -m_openGL[4], -m_openGL[5]);
Expand All @@ -395,11 +369,9 @@ Vec3 Mat3::getForwardVector() const noexcept
return Vec3(-m_openGL[6], -m_openGL[7], -m_openGL[8]);
}


Vec3 Mat3::getBackVector() const noexcept
{
return Vec3(m_openGL[6], m_openGL[7], m_openGL[8]);
}


} // end namespace ngl
Loading

0 comments on commit cfc31d5

Please sign in to comment.