1 /* 2 * Copyright (c) 2021 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 #ifndef RENDER_SERVICE_CLIENT_CORE_COMMON_RS_OBJ_GEOMETRY_H 16 #define RENDER_SERVICE_CLIENT_CORE_COMMON_RS_OBJ_GEOMETRY_H 17 18 #include <cmath> 19 20 #include "common/rs_common_def.h" 21 #include "common/rs_vector4.h" 22 namespace OHOS { 23 namespace Rosen { 24 class Transform { 25 public: 26 Transform() = default; 27 Transform(const Transform& other) = default; 28 ~Transform() = default; 29 float pivotX_ { 0.5f }; 30 float pivotY_ { 0.5f }; 31 float pivotZ_ { 0.0f }; 32 float scaleX_ { 1.0f }; 33 float scaleY_ { 1.0f }; 34 float rotation_ { 0.0f }; 35 float rotationX_ { 0.0f }; 36 float rotationY_ { 0.0f }; 37 float translateX_ { 0.0f }; 38 float translateY_ { 0.0f }; 39 float translateZ_ { 0.0f }; 40 float cameraDistance_ { 0.0f }; 41 Quaternion quaternion_ { 0.0f, 0.0f, 0.0f, 1.0f }; 42 }; 43 44 class RSObjGeometry { 45 public: RSObjGeometry()46 RSObjGeometry() : x_(-INFINITY), y_(-INFINITY), z_(0.0f), width_(-INFINITY), height_(-INFINITY) {} 47 48 virtual ~RSObjGeometry() = default; 49 SetX(float x)50 void SetX(float x) 51 { 52 x_ = x; 53 } SetY(float y)54 void SetY(float y) 55 { 56 y_ = y; 57 } SetZ(float z)58 void SetZ(float z) 59 { 60 z_ = z; 61 } SetWidth(float w)62 void SetWidth(float w) 63 { 64 width_ = w; 65 } SetHeight(float h)66 void SetHeight(float h) 67 { 68 height_ = h; 69 } SetPosition(float x,float y)70 void SetPosition(float x, float y) 71 { 72 SetX(x); 73 SetY(y); 74 } SetSize(float w,float h)75 void SetSize(float w, float h) 76 { 77 SetWidth(w); 78 SetHeight(h); 79 } SetRect(float x,float y,float w,float h)80 void SetRect(float x, float y, float w, float h) 81 { 82 SetPosition(x, y); 83 SetSize(w, h); 84 } SetPivotX(float x)85 void SetPivotX(float x) 86 { 87 if (!trans_) { 88 trans_ = std::make_optional<Transform>(); 89 } 90 trans_->pivotX_ = x; 91 } SetPivotY(float y)92 void SetPivotY(float y) 93 { 94 if (!trans_) { 95 trans_ = std::make_optional<Transform>(); 96 } 97 trans_->pivotY_ = y; 98 } SetPivotZ(float z)99 void SetPivotZ(float z) 100 { 101 if (!trans_) { 102 trans_ = std::make_optional<Transform>(); 103 } 104 trans_->pivotZ_ = z; 105 } SetPivot(float x,float y)106 void SetPivot(float x, float y) 107 { 108 SetPivotX(x); 109 SetPivotY(y); 110 } SetScaleX(float x)111 void SetScaleX(float x) 112 { 113 if (!trans_) { 114 trans_ = std::make_optional<Transform>(); 115 } 116 trans_->scaleX_ = x; 117 } SetScaleY(float y)118 void SetScaleY(float y) 119 { 120 if (!trans_) { 121 trans_ = std::make_optional<Transform>(); 122 } 123 trans_->scaleY_ = y; 124 } SetScale(float x,float y)125 void SetScale(float x, float y) 126 { 127 SetScaleX(x); 128 SetScaleY(y); 129 } SetRotation(float rotation)130 void SetRotation(float rotation) 131 { 132 if (!trans_) { 133 trans_ = std::make_optional<Transform>(); 134 } 135 trans_->rotation_ = rotation; 136 } SetRotationX(float rotationX)137 void SetRotationX(float rotationX) 138 { 139 if (!trans_) { 140 trans_ = std::make_optional<Transform>(); 141 } 142 trans_->rotationX_ = rotationX; 143 } SetRotationY(float rotationY)144 void SetRotationY(float rotationY) 145 { 146 if (!trans_) { 147 trans_ = std::make_optional<Transform>(); 148 } 149 trans_->rotationY_ = rotationY; 150 } SetTranslateX(float translateX)151 void SetTranslateX(float translateX) 152 { 153 if (!trans_) { 154 trans_ = std::make_optional<Transform>(); 155 } 156 trans_->translateX_ = translateX; 157 } SetTranslateY(float translateY)158 void SetTranslateY(float translateY) 159 { 160 if (!trans_) { 161 trans_ = std::make_optional<Transform>(); 162 } 163 trans_->translateY_ = translateY; 164 } SetTranslateZ(float translateZ)165 void SetTranslateZ(float translateZ) 166 { 167 if (!trans_) { 168 trans_ = std::make_optional<Transform>(); 169 } 170 if (!ROSEN_EQ(trans_->translateZ_, translateZ)) { 171 trans_->translateZ_ = translateZ; 172 } 173 } SetCameraDistance(float cameraDistance)174 void SetCameraDistance(float cameraDistance) 175 { 176 if (!trans_) { 177 trans_ = std::make_optional<Transform>(); 178 } 179 trans_->cameraDistance_ = cameraDistance; 180 } SetQuaternion(const Quaternion & quaternion)181 void SetQuaternion(const Quaternion& quaternion) 182 { 183 if (!trans_) { 184 trans_ = std::make_optional<Transform>(); 185 } 186 trans_->quaternion_ = quaternion; 187 } 188 GetX()189 float GetX() const 190 { 191 return x_; 192 } GetWidth()193 float GetWidth() const 194 { 195 return width_; 196 } GetY()197 float GetY() const 198 { 199 return y_; 200 } GetHeight()201 float GetHeight() const 202 { 203 return height_; 204 } GetZ()205 float GetZ() const 206 { 207 return z_; 208 } GetPivotX()209 float GetPivotX() const 210 { 211 return trans_ ? trans_->pivotX_ : 0.5f; 212 } GetPivotY()213 float GetPivotY() const 214 { 215 return trans_ ? trans_->pivotY_ : 0.5f; 216 } GetPivotZ()217 float GetPivotZ() const 218 { 219 return trans_ ? trans_->pivotZ_ : 0.f; 220 } GetScaleX()221 float GetScaleX() const 222 { 223 return trans_ ? trans_->scaleX_ : 1.f; 224 } GetScaleY()225 float GetScaleY() const 226 { 227 return trans_ ? trans_->scaleY_ : 1.f; 228 } GetRotation()229 float GetRotation() const 230 { 231 return trans_ ? trans_->rotation_ : 0.f; 232 } GetRotationX()233 float GetRotationX() const 234 { 235 return trans_ ? trans_->rotationX_ : 0.f; 236 } GetRotationY()237 float GetRotationY() const 238 { 239 return trans_ ? trans_->rotationY_ : 0.f; 240 } GetTranslateX()241 float GetTranslateX() const 242 { 243 return trans_ ? trans_->translateX_ : 0.f; 244 } GetTranslateY()245 float GetTranslateY() const 246 { 247 return trans_ ? trans_->translateY_ : 0.f; 248 } GetTranslateZ()249 float GetTranslateZ() const 250 { 251 return trans_ ? trans_->translateZ_ : 0.f; 252 } GetCameraDistance()253 float GetCameraDistance() const 254 { 255 return trans_ ? trans_->cameraDistance_ : 0.f; 256 } GetQuaternion()257 Quaternion GetQuaternion() const 258 { 259 return trans_ ? trans_->quaternion_ : Quaternion(); 260 } IsEmpty()261 bool IsEmpty() const 262 { 263 return width_ <= 0 && height_ <= 0; 264 } 265 RSObjGeometry& operator=(const RSObjGeometry& geo) 266 { 267 if (&geo != this) { 268 SetRect(geo.x_, geo.y_, geo.width_, geo.height_); 269 SetZ(geo.z_); 270 trans_ = geo.trans_; 271 } 272 return *this; 273 } Reset()274 virtual void Reset() 275 { 276 x_ = -INFINITY; 277 y_ = -INFINITY; 278 z_ = 0.0f; 279 width_ = -INFINITY; 280 height_ = -INFINITY; 281 trans_.reset(); 282 } 283 284 protected: 285 float x_; 286 float y_; 287 float z_; 288 float width_; 289 float height_; 290 std::optional<Transform> trans_; 291 }; 292 } // namespace Rosen 293 } // namespace OHOS 294 #endif // RENDER_SERVICE_CLIENT_CORE_COMMON_RS_OBJ_GEOMETRY_H 295