1 /* 2 * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_VEC3_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_VEC3_H 18 19 #include "base/geometry/animatable_float.h" 20 #include "base/utils/macros.h" 21 #include "base/utils/utils.h" 22 23 namespace OHOS::Ace { 24 25 class ACE_EXPORT Vec3 { 26 public: 27 Vec3() = default; 28 ~Vec3() = default; 29 Vec3(float x, float y, float z, const AnimationOption& option = AnimationOption()) { 30 x_ = AnimatableFloat(x, option); 31 y_ = AnimatableFloat(y, option); 32 z_ = AnimatableFloat(z, option); 33 animationOption_ = option; 34 } Vec3(AnimatableFloat x,AnimatableFloat y,AnimatableFloat z)35 Vec3(AnimatableFloat x, AnimatableFloat y, AnimatableFloat z) { 36 x_ = x; 37 y_ = y; 38 z_ = z; 39 animationOption_ = x_.GetAnimationOption(); 40 } 41 42 using RenderNodeAnimationCallback = std::function<void()>; 43 SetContextAndCallbacks(const WeakPtr<PipelineBase> & context,RenderNodeAnimationCallback && callback)44 void SetContextAndCallbacks( 45 const WeakPtr<PipelineBase>& context, 46 RenderNodeAnimationCallback&& callback) 47 { 48 x_.SetContextAndCallback(context, std::forward<RenderNodeAnimationCallback>(callback)); 49 y_.SetContextAndCallback(context, std::forward<RenderNodeAnimationCallback>(callback)); 50 z_.SetContextAndCallback(context, std::forward<RenderNodeAnimationCallback>(callback)); 51 } 52 GetX()53 float GetX() const 54 { 55 return x_.GetValue(); 56 } 57 GetY()58 float GetY() const 59 { 60 return y_.GetValue(); 61 } 62 GetZ()63 float GetZ() const 64 { 65 return z_.GetValue(); 66 } 67 GetAnimationOption()68 AnimationOption GetAnimationOption() const 69 { 70 return animationOption_; 71 } 72 SetX(float x)73 void SetX(float x) 74 { 75 x_ = AnimatableFloat(x); 76 } 77 SetY(float y)78 void SetY(float y) 79 { 80 y_ = AnimatableFloat(y); 81 } 82 SetZ(float z)83 void SetZ(float z) 84 { 85 z_ = AnimatableFloat(z); 86 } 87 88 bool operator==(const Vec3& vec) const 89 { 90 return NearEqual(x_.GetValue(), vec.x_.GetValue()) 91 && NearEqual(y_.GetValue(), vec.y_.GetValue()) 92 && NearEqual(z_.GetValue(), vec.z_.GetValue()); 93 } 94 95 bool operator!=(const Vec3& vec) const 96 { 97 return !operator==(vec); 98 } 99 100 Vec3& operator=(const Vec3& newValue) 101 { 102 animationOption_ = newValue.GetAnimationOption(); 103 x_ = AnimatableFloat(newValue.GetX(), animationOption_); 104 y_ = AnimatableFloat(newValue.GetY(), animationOption_); 105 z_ = AnimatableFloat(newValue.GetZ(), animationOption_); 106 return *this; 107 } 108 109 private: 110 AnimatableFloat x_; 111 AnimatableFloat y_; 112 AnimatableFloat z_; 113 // Same animation option is applied to x, y, z currently. 114 AnimationOption animationOption_; 115 }; 116 117 } // namespace OHOS::Ace 118 119 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_VEC3_H 120