1 /* 2 * Copyright (C) 2024 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 MATH_UTILS_H 17 #define MATH_UTILS_H 18 19 #include <utility> 20 21 #include <glm/geometric.hpp> 22 #include <glm/gtc/matrix_transform.hpp> 23 #include <glm/gtx/matrix_transform_2d.hpp> 24 #include <glm/gtc/type_ptr.hpp> 25 #include <glm/trigonometric.hpp> 26 27 #include "render_vector.h" 28 #include "render_matrix.h" 29 #include "base/render_base.h" 30 31 namespace OHOS { 32 namespace Media { 33 namespace Effect { 34 class MathUtils { 35 public: 36 constexpr const static double PI = 3.14159265358979323846264338327f; 37 Radians(T degrees)38 template<class T> static T Radians(T degrees) 39 { 40 return glm::radians(degrees); 41 } 42 Multiply(R & result,const TL & left,const TR & right)43 template<class R, class TL, class TR> static void Multiply(R &result, const TL &left, const TR &right) 44 { 45 static_assert(std::is_same_v<R, decltype(std::declval<TL>() * std::declval<TR>())>, 46 "MathUtils::Multiply(): Wrong R Type!"); 47 result = left * right; 48 } 49 Rotate(T & result,const T & src,float radians,const Vs &...v)50 template<class T, class... Vs> static void Rotate(T &result, const T &src, float radians, const Vs &... v) 51 { 52 result = glm::rotate(src, radians, v...); 53 } 54 Perspective(float fov,float aspect,float nearV,float farV)55 static Mat4x4 Perspective(float fov, float aspect, float nearV, float farV) 56 { 57 return glm::perspective(fov, aspect, nearV, farV); 58 } 59 Inversed(const T & in)60 template<class T> static T Inversed(const T &in) 61 { 62 return glm::inverse(in); 63 } 64 NativePtr(const T & v)65 template<class T> static const void *NativePtr(const T &v) 66 { 67 return reinterpret_cast<const void *>(glm::value_ptr(v)); 68 } 69 }; 70 } // namespace Effect 71 } // namespace Media 72 } // namespace OHOS 73 #endif