[FEAT] Add shearing matrix transform
This commit is contained in:
@@ -382,6 +382,20 @@ Matrix Matrix::rotation_z(double a_radians)
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
Matrix Matrix::shearing(double a_xy, double a_xz, double a_yx, double a_yz, double a_zx, double a_zy)
|
||||
{
|
||||
Matrix the_shearing = {
|
||||
{ 1, a_xy, a_xz, 0},
|
||||
{a_yx, 1, a_yz, 0},
|
||||
{a_zx, a_zy, 1, 0},
|
||||
{ 0, 0, 0, 1}
|
||||
};
|
||||
|
||||
return the_shearing;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
bool Matrix::validate_dimensions(const std::initializer_list<std::initializer_list<double>> &a_values) const
|
||||
{
|
||||
for (const auto &the_row : a_values)
|
||||
|
||||
@@ -76,6 +76,7 @@ namespace Raytracer
|
||||
static Matrix rotation_x(double a_radians);
|
||||
static Matrix rotation_y(double a_radians);
|
||||
static Matrix rotation_z(double a_radians);
|
||||
static Matrix shearing(double a_xy, double a_xz, double a_yx, double a_yz, double a_zx, double a_zy);
|
||||
|
||||
private:
|
||||
bool validate_dimensions(const std::initializer_list<std::initializer_list<double>> &a_values) const;
|
||||
|
||||
@@ -151,3 +151,53 @@ TEST_CASE("[04][Trans] Rotating a point around the z axis", "[Matrix]")
|
||||
REQUIRE(half_quarter * p == Tuple::Point(-sqrt(2) / 2, sqrt(2) / 2, 0));
|
||||
REQUIRE(full_quarter * p == Tuple::Point(-1, 0, 0));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[04][Trans] A shearing transformation moves x in proportion to y", "[Matrix]")
|
||||
{
|
||||
Matrix transform = Matrix::shearing(1, 0, 0, 0, 0, 0);
|
||||
Tuple p = Tuple::Point(2, 3, 4);
|
||||
|
||||
REQUIRE(transform * p == Tuple::Point(5, 3, 4));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[04][Trans] A shearing transformation moves y in proportion to x", "[Matrix]")
|
||||
{
|
||||
Matrix transform = Matrix::shearing(0, 0, 1, 0, 0, 0);
|
||||
Tuple p = Tuple::Point(2, 3, 4);
|
||||
|
||||
REQUIRE(transform * p == Tuple::Point(2, 5, 4));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[04][Trans] A shearing transformation moves y in proportion to z", "[Matrix]")
|
||||
{
|
||||
Matrix transform = Matrix::shearing(0, 0, 0, 1, 0, 0);
|
||||
Tuple p = Tuple::Point(2, 3, 4);
|
||||
|
||||
REQUIRE(transform * p == Tuple::Point(2, 7, 4));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[04][Trans] A shearing transformation moves z in proportion to x", "[Matrix]")
|
||||
{
|
||||
Matrix transform = Matrix::shearing(0, 0, 0, 0, 1, 0);
|
||||
Tuple p = Tuple::Point(2, 3, 4);
|
||||
|
||||
REQUIRE(transform * p == Tuple::Point(2, 3, 6));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
TEST_CASE("[04][Trans] A shearing transformation moves z in proportion to y", "[Matrix]")
|
||||
{
|
||||
Matrix transform = Matrix::shearing(0, 0, 0, 0, 0, 1);
|
||||
Tuple p = Tuple::Point(2, 3, 4);
|
||||
|
||||
REQUIRE(transform * p == Tuple::Point(2, 3, 7));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user