1 /* Copyright 2011 Jukka Jyl�nki
2
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 /** @file TransformOps.h
16         @author Jukka Jyl�nki
17         @brief */
18 #pragma once
19
20 #include "Math/MathFwd.h"
21 #include "Math/float3.h"
22
23 MATH_BEGIN_NAMESPACE
24
25 /// A structure that represents the translate operation for 3D objects.
26 /** This structure is used to optimize special cases of 3D transformation concatenations. The use of this
27         class occurs transparently to the user. You do not need to instantiate new TranslateOp objects in your code. */
28 class TranslateOp
29 {
30 public:
31         /// The x offset of translation.
32         float x;
33         /// The y offset of translation.
34         float y;
35         /// The z offset of translation.
36         float z;
37
38         /// Constructs an uninitialized TranslateOp.
39         TranslateOp() {}
40
41         /// Constructs a TranslateOp that translates the given amount.
42         explicit TranslateOp(const float3 &offset);
43         TranslateOp(float xfloat yfloat z);
44
45         /// Returns the translation offset (x, y, z).
46         float3 Offset() const;
47
48         /// Converts this TranslateOp object to a matrix.
49         float3x4 ToFloat3x4() const;
50         /// Converts this TranslateOp object to a matrix.
51         float4x4 ToFloat4x4() const;
52
53         /// Converts this TranslateOp object to a matrix.
54         operator float3x4() const;
55         /// Converts this TranslateOp object to a matrix.
56         operator float4x4() const;
57 };
58
59 float3x4 operator *(const TranslateOp &lhs, const float3x4 &rhs);
60 float3x4 operator *(const float3x4 &lhs, const TranslateOp &rhs);
61 float4x4 operator *(const TranslateOp &lhs, const float4x4 &rhs);
62 float4x4 operator *(const float4x4 &lhs, const TranslateOp &rhs);
63
64 /// A structure that represents the scale operation for 3D objects.
65 /** This structure is used to optimize special cases of 3D transformation concatenations. The use of this
66         class occurs transparently to the user. You do not need to instantiate new ScaleOp objects in your code. */
67 class ScaleOp
68 {
69 public:
70         /// The scale factor along the x axis.
71         float x;
72         /// The scale factor along the y axis.
73         float y;
74         /// The scale factor along the z axis.
75         float z;
76
77         /// Constructs an uninitialized ScaleOp.
78         ScaleOp() {}
79
80         /// Constructs a ScaleOp with the given scale factors.
81         explicit ScaleOp(const float3 &scale);
82         ScaleOp(float sx, float sy, float sz);
83
84         /// Returns the scale factors (x, y, z).
85         float3 Offset() const;
86
87         /// Converts this ScaleOp to a matrix.
88         operator float3x3() const;
89         /// Converts this ScaleOp to a matrix.
90         operator float3x4() const;
91         /// Converts this ScaleOp to a matrix.
92         operator float4x4() const;
93
94         /// Converts this ScaleOp to a matrix.
95         float3x3 ToFloat3x3() const;
96         /// Converts this ScaleOp to a matrix.
97         float3x4 ToFloat3x4() const;
98         /// Converts this ScaleOp to a matrix.
99         float4x4 ToFloat4x4() const;
100 };
101
102 float3x3 operator *(const ScaleOp &lhs, const float3x3 &rhs);
103 float3x3 operator *(const float3x3 &lhs, const ScaleOp &rhs);
104 float3x4 operator *(const ScaleOp &lhs, const float3x4 &rhs);
105 float3x4 operator *(const float3x4 &lhs, const ScaleOp &rhs);
106 float4x4 operator *(const ScaleOp &lhs, const float4x4 &rhs);
107 float4x4 operator *(const float4x4 &lhs, const ScaleOp &rhs);
108
109 float3x4 operator *(const ScaleOp &lhs, const TranslateOp &rhs);
110 float3x4 operator *(const TranslateOp &lhs, const ScaleOp &rhs);
111
112 MATH_END_NAMESPACE
113
114 #ifdef MATH_QT_INTEROP
115 Q_DECLARE_METATYPE(TranslateOp)
116 Q_DECLARE_METATYPE(TranslateOp*)
117 Q_DECLARE_METATYPE(ScaleOp)
118 Q_DECLARE_METATYPE(ScaleOp*)
119 #endif

Go back to previous page