From 253da17bc775bc49789b4f0793970968d72ed440 Mon Sep 17 00:00:00 2001 From: Lawrence Date: Wed, 25 Dec 2019 14:45:47 -0800 Subject: [PATCH] Add homogeneous scale transformation Add function to generate homogeneous 3 dimensional scale transformation matrices. --- rtengine/homogeneouscoordinates.cc | 17 +++++++++++++++++ rtengine/homogeneouscoordinates.h | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/rtengine/homogeneouscoordinates.cc b/rtengine/homogeneouscoordinates.cc index f134abc53..85b189b9f 100644 --- a/rtengine/homogeneouscoordinates.cc +++ b/rtengine/homogeneouscoordinates.cc @@ -147,6 +147,23 @@ Matrix rotationMatrix(double radians, Axis axis) return matrix; } +template +Matrix scaleMatrix(T x, T y, T z) +{ + Matrix matrix; + + for (int i = 0; i < 4; i++) { + matrix[i].fill(0); + } + + matrix[0][0] = x; + matrix[1][1] = y; + matrix[2][2] = z; + matrix[3][3] = 1; + + return matrix; +} + template Matrix translationMatrix(T x, T y, T z) { diff --git a/rtengine/homogeneouscoordinates.h b/rtengine/homogeneouscoordinates.h index c24b73f05..7c5924d1e 100644 --- a/rtengine/homogeneouscoordinates.h +++ b/rtengine/homogeneouscoordinates.h @@ -53,6 +53,15 @@ Matrix projectionMatrix(T location, Axis normal); template Matrix rotationMatrix(T radians, Axis axis); +/** + * Creates a 3 dimensional transformation matrix for scaling. + * @param x Scale in x-direction + * @param y Scale in y-direction + * @param z Scale in z-direction + */ +template +Matrix scaleMatrix(T x, T y, T z); + /** * Creates a 3 dimensional transformation matrix for translation. * @param x Translation in the the x-direction.