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 OHOS_RENDER_3D_QUATERNION_H
17 #define OHOS_RENDER_3D_QUATERNION_H
18 
19 #include <string>
20 #include "data_type/constants.h"
21 
22 namespace OHOS::Render3D {
23 class Quaternion {
24 public:
Quaternion()25     Quaternion() {}
Quaternion(float x,float y,float z,float w)26     Quaternion(float x, float y, float z, float w) : x_(x), y_(y), z_(z), w_(w) {}
GetX()27     float GetX() const
28     {
29         return x_;
30     }
GetY()31     float GetY() const
32     {
33         return y_;
34     }
GetZ()35     float GetZ() const
36     {
37         return z_;
38     }
GetW()39     float GetW() const
40     {
41         return w_;
42     }
SetX(float x)43     void SetX(float x)
44     {
45         x_ = x;
46     }
SetY(float y)47     void SetY(float y)
48     {
49         y_ = y;
50     }
SetZ(float z)51     void SetZ(float z)
52     {
53         z_ = z;
54     }
SetW(float w)55     void SetW(float w)
56     {
57         w_ = w;
58     }
59     bool operator==(const Quaternion& other) const
60     {
61         return (x_ == other.x_) && (y_ == other.y_) && (z_ == other.z_) && (w_ == other.w_);
62     }
63 
64 private:
65     union {
66         struct {
67             float x_;
68             float y_;
69             float z_;
70             float w_;
71         };
72         float data_[4] { 0.0f, 0.0f, 0.0f, 0.0f } ;
73     };
74 };
75 } // namespace OHOS::Render3D
76 #endif // OHOS_RENDER_3D_QUATERNION_H
77