1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef MATRIX44_H 17 #define MATRIX44_H 18 19 #include "impl_interface/matrix44_impl.h" 20 #include "utils/drawing_macros.h" 21 #include "utils/scalar.h" 22 23 namespace OHOS { 24 namespace Rosen { 25 namespace Drawing { 26 class DRAWING_API Matrix44 { 27 public: 28 // Matrix44 is a 4x4 float type matrix. 29 constexpr static int MATRIX44_SIZE = 16; 30 31 Matrix44(); ~Matrix44()32 virtual ~Matrix44() {} 33 34 /** 35 * @brief Sets Matrix44 to translate by (dx, dy, dz). 36 * @param dx horizontal translation. 37 * @param dy vertical translation. 38 * @param dz z-axis translation. 39 */ 40 void Translate(scalar dx, scalar dy, scalar dz); 41 42 /** 43 * @brief Sets Matrix44 to scale by sx, sy and sz about pivot point at (0, 0, 0). 44 * @param sx horizontal scale factor. 45 * @param sy vertical scale factor. 46 * @param sz z-axis scale factor. 47 */ 48 void Scale(scalar sx, scalar sy, scalar sz); 49 50 void PreTranslate(scalar dx, scalar dy, scalar dz = 0); 51 52 void PostTranslate(scalar dx, scalar dy, scalar dz = 0); 53 54 void PreScale(scalar sx, scalar sy, scalar sz = 1); 55 56 void SetCol(int column, scalar x, scalar y, scalar z, scalar w); 57 /** 58 * @brief Gets new Matrix44 to Matrix44 multiplied by Matrix44 other. 59 * @param other on right side of multiply expression. 60 * @return A new calculated Matrix44. 61 */ 62 Matrix44 operator*(const Matrix44& other); 63 64 /** 65 * @brief Converts the Matrix44 to Matrix. 66 * @return A Matrix which converts by Matrix44. 67 */ 68 explicit operator Matrix() const; 69 70 /** 71 * @brief Sets Matrix44 to sixteen values in buffer. 72 * @param buffer a [col][row] array. eg. buffer[0] maps to m00, buffer[1] maps to m10 73 */ 74 using Buffer = std::array<scalar, MATRIX44_SIZE>; 75 void SetMatrix44ColMajor(const Buffer& buffer); 76 void SetMatrix44RowMajor(const Buffer& buffer); 77 78 /** 79 * @brief Get the adaptation layer instance, called in the adaptation layer. 80 * @return Adaptation Layer instance. 81 */ 82 template<typename T> GetImpl()83 T* GetImpl() const 84 { 85 return impl_->DowncastingTo<T>(); 86 } 87 private: 88 std::shared_ptr<Matrix44Impl> impl_; 89 }; 90 } // namespace Drawing 91 } // namespace Rosen 92 } // namespace OHOS 93 #endif