Skip to content

Commit

Permalink
Add jngl::Mat3::scale(float, float)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhasse committed Jan 16, 2021
1 parent b035a9d commit e9f68d3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/jngl/Mat3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ Mat3& Mat3::translate(const jngl::Vec2& v) {
}

Mat3& Mat3::scale(const float factor) {
return *this *= boost::qvm::diag_mat(boost::qvm::vec<float, 3>{ { factor, factor, 1 } });
return scale(factor, factor);
}

Mat3& Mat3::scale(const float xfactor, const float yfactor) {
return *this *= boost::qvm::diag_mat(boost::qvm::vec<float, 3>{ { xfactor, yfactor, 1 } });
}

Mat3& Mat3::rotate(const float radian) {
Expand Down
13 changes: 12 additions & 1 deletion src/jngl/Mat3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,24 @@ class Mat3 {
/// Multiplies the matrix with a translation matrix generated from v
///
/// \return *this
Mat3& translate(const Vec2&);
Mat3& translate(const Vec2& v);

/// Multiplies the matrix by a scaling matrix
///
/// Equivalent to calling `Mat3::scale(factor, factor)`.
/// \return *this
Mat3& scale(float factor);

/// Multiplies the matrix by a scaling matrix
///
/// \return *this
///
/// If you want to draw a sprite with double the width, but the correct height:
/// \code
/// yourSprite.draw(jngl::modelview().scale(2, 1));
/// \endcode
Mat3& scale(float xfactor, float yfactor);

/// Multiplies the matrix with a rotation matrix
///
/// \return *this
Expand Down

0 comments on commit e9f68d3

Please sign in to comment.