Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Transform.inl
Go to the documentation of this file.
1/*
2Copyright (c) 2018 DIVIDE-Studio
3Copyright (c) 2009 Ionut Cava
4
5This file is part of DIVIDE Framework.
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software
9and associated documentation files (the "Software"), to deal in the Software
10without restriction,
11including without limitation the rights to use, copy, modify, merge, publish,
12distribute, sublicense,
13and/or sell copies of the Software, and to permit persons to whom the
14Software is furnished to do so,
15subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in
18all copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED,
22INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23PARTICULAR PURPOSE AND NONINFRINGEMENT.
24IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25DAMAGES OR OTHER LIABILITY,
26WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27IN CONNECTION WITH THE SOFTWARE
28OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30*/
31
32#ifndef DVD_TRANSFORM_INL_
33#define DVD_TRANSFORM_INL_
34
35namespace Divide {
36
38inline void Transform::setPosition(const vec3<F32>& position) noexcept {
39 setPosition(position.x, position.y, position.z);
40}
41
43inline void Transform::setPosition(const F32 x, const F32 y, const F32 z) noexcept {
44 _translation.set(x, y, z);
45}
46
48inline void Transform::setPositionX(const F32 positionX) noexcept {
49 setPosition(positionX, _translation.y, _translation.z);
50}
52inline void Transform::setPositionY(const F32 positionY) noexcept {
53 setPosition(_translation.x, positionY, _translation.z);
54}
55
57inline void Transform::setPositionZ(const F32 positionZ) noexcept {
58 setPosition(_translation.x, _translation.y, positionZ);
59}
60
62inline void Transform::setScale(const vec3<F32>& amount) noexcept {
63 _scale.set(amount);
64}
65
68inline void Transform::setRotation(const vec3<F32>& axis, const Angle::DEGREES<F32> degrees) noexcept {
69 _orientation.fromAxisAngle(axis, degrees);
70 _orientation.normalize();
71}
72
75inline void Transform::setRotation(const Angle::DEGREES<F32> pitch, const Angle::DEGREES<F32> yaw, const Angle::DEGREES<F32> roll) noexcept {
76 _orientation.fromEuler(pitch, yaw, roll);
77}
78
80inline void Transform::setRotation(const Quaternion<F32>& quat) noexcept {
81 _orientation.set(quat);
82 _orientation.normalize();
83}
84
86inline void Transform::translate(const vec3<F32>& axisFactors) noexcept {
87 _translation += axisFactors;
88}
89
91inline void Transform::scale(const vec3<F32>& axisFactors) noexcept {
92 _scale *= axisFactors;
93}
94
98inline void Transform::rotate(const vec3<F32>& axis, const Angle::DEGREES<F32> degrees) noexcept {
99 rotate(Quaternion<F32>(axis, degrees));
100}
101
105inline void Transform::rotate(const Angle::DEGREES<F32> pitch, const Angle::DEGREES<F32> yaw, const Angle::DEGREES<F32> roll) noexcept {
106 rotate(Quaternion<F32>(pitch, yaw, roll));
107}
108
110inline void Transform::rotate(const Quaternion<F32>& quat) noexcept {
111 setRotation(quat * _orientation);
112}
113
115inline void Transform::rotateSlerp(const Quaternion<F32>& quat, const D64 deltaTime) {
116 _orientation.slerp(quat, to_F32(deltaTime));
118}
119
121inline void Transform::setScaleX(const F32 amount) noexcept {
122 setScale(vec3<F32>(amount, _scale.y, _scale.z));
123}
125inline void Transform::setScaleY(const F32 amount) noexcept {
126 setScale(vec3<F32>(_scale.x, amount, _scale.z));
127}
129inline void Transform::setScaleZ(const F32 amount) noexcept {
130 setScale(vec3<F32>(_scale.x, _scale.y, amount));
131}
132
134inline void Transform::scaleX(const F32 amount) noexcept {
135 scale(vec3<F32>(amount, _scale.y, _scale.z));
136}
138inline void Transform::scaleY(const F32 amount) noexcept {
139 scale(vec3<F32>(_scale.x, amount, _scale.z));
140}
142inline void Transform::scaleZ(const F32 amount) noexcept {
143 scale(vec3<F32>(_scale.x, _scale.y, amount));
144}
147inline void Transform::rotateX(const Angle::DEGREES<F32> angle) noexcept {
148 rotate(vec3<F32>(1, 0, 0), angle);
149}
152inline void Transform::rotateY(const Angle::DEGREES<F32> angle) noexcept {
153 rotate(vec3<F32>(0, 1, 0), angle);
154}
157inline void Transform::rotateZ(const Angle::DEGREES<F32> angle) noexcept {
158 rotate(vec3<F32>(0, 0, 1), angle);
159}
162inline void Transform::setRotationX(const Angle::DEGREES<F32> angle) noexcept {
163 setRotation(vec3<F32>(1, 0, 0), angle);
164}
167inline void Transform::setRotationY(const Angle::DEGREES<F32> angle) noexcept {
168 setRotation(vec3<F32>(0, 1, 0), angle);
169}
172inline void Transform::setRotationZ(const Angle::DEGREES<F32> angle) noexcept {
173 setRotation(vec3<F32>(0, 0, 1), angle);
174}
175
177inline void Transform::getScale(vec3<F32>& scaleOut) const noexcept {
178 scaleOut.set(_scale);
179}
180
182inline void Transform::getPosition(vec3<F32>& posOut) const noexcept {
183 posOut.set(_translation);
184}
185
187inline void Transform::getOrientation(Quaternion<F32>& quatOut) const noexcept {
188 quatOut.set(_orientation);
189}
190
191inline bool Transform::isUniformScale(const F32 tolerance) const noexcept {
192 return _scale.isUniform(tolerance);
193}
194
195inline void Transform::clone(const Transform* const transform) noexcept {
196 setValues(*transform);
197}
198
200inline void Transform::setValues(const TransformValues& values) noexcept {
201 _translation = values._translation;
202 _scale = values._scale;
203 _orientation = values._orientation;
204}
205
208 return static_cast<const TransformValues&>(*this) == static_cast<const TransformValues&>(other);
209}
210
212 return static_cast<const TransformValues&>(*this) != static_cast<const TransformValues&>(other);
213}
214}
215
216#endif //DVD_TRANSFORM_INL_
#define FORCE_INLINE
void normalize() noexcept
normalizing a quaternion works similar to a vector. This method will not
Definition: Quaternion.inl:164
void slerp(const Quaternion &q, F32 t) noexcept
Definition: Quaternion.inl:281
void rotate(const vec3< F32 > &axis, Angle::DEGREES< F32 > degrees) noexcept override
Definition: Transform.inl:98
void setScaleZ(F32 amount) noexcept override
Set the scaling factor on the Z axis.
Definition: Transform.inl:129
void setPositionY(F32 positionY) noexcept override
Set the object's position on the Y axis.
Definition: Transform.inl:52
void clone(const Transform *transform) noexcept
Set all of the internal values to match those of the specified transform.
Definition: Transform.inl:195
void scaleZ(F32 amount) noexcept override
Increase the scaling factor on the Z axis by the specified factor.
Definition: Transform.inl:142
void setScaleX(F32 amount) noexcept override
Set the scaling factor on the X axis.
Definition: Transform.inl:121
void setScale(const vec3< F32 > &amount) noexcept override
Set the local X,Y and Z amount factors.
Definition: Transform.inl:62
void rotateX(Angle::DEGREES< F32 > angle) noexcept override
Definition: Transform.inl:147
void setRotationX(Angle::DEGREES< F32 > angle) noexcept override
Definition: Transform.inl:162
void getOrientation(Quaternion< F32 > &quatOut) const noexcept override
Return the orientation quaternion.
Definition: Transform.inl:187
bool operator!=(const Transform &other) const
Definition: Transform.inl:211
void getScale(vec3< F32 > &scaleOut) const noexcept override
Return the scale factor.
Definition: Transform.inl:177
bool operator==(const Transform &other) const
Compares 2 transforms.
Definition: Transform.inl:207
void setRotationY(Angle::DEGREES< F32 > angle) noexcept override
Definition: Transform.inl:167
void rotateY(Angle::DEGREES< F32 > angle) noexcept override
Definition: Transform.inl:152
void getPosition(vec3< F32 > &posOut) const noexcept override
Return the position.
Definition: Transform.inl:182
void translate(const vec3< F32 > &axisFactors) noexcept override
Add the specified translation factors to the current local position.
Definition: Transform.inl:86
void setPositionX(F32 positionX) noexcept override
Set the object's position on the X axis.
Definition: Transform.inl:48
void setRotation(const vec3< F32 > &axis, Angle::DEGREES< F32 > degrees) noexcept override
Definition: Transform.inl:68
void setPositionZ(F32 positionZ) noexcept override
Set the object's position on the Z axis.
Definition: Transform.inl:57
void setScaleY(F32 amount) noexcept override
Set the scaling factor on the Y axis.
Definition: Transform.inl:125
void rotateSlerp(const Quaternion< F32 > &quat, D64 deltaTime) override
Perform a SLERP rotation towards the specified quaternion.
Definition: Transform.inl:115
bool isUniformScale(const F32 tolerance=EPSILON_F32) const noexcept
Definition: Transform.inl:191
void setRotationZ(Angle::DEGREES< F32 > angle) noexcept override
Definition: Transform.inl:172
void scale(const vec3< F32 > &axisFactors) noexcept override
Add the specified scale factors to the current local position.
Definition: Transform.inl:91
void scaleY(F32 amount) noexcept override
Increase the scaling factor on the Y axis by the specified factor.
Definition: Transform.inl:138
void setValues(const TransformValues &values) noexcept
Set position, scale and rotation based on the specified transform values.
Definition: Transform.inl:200
void rotateZ(Angle::DEGREES< F32 > angle) noexcept override
Definition: Transform.inl:157
void setPosition(const vec3< F32 > &position) noexcept override
Set the local X,Y and Z position.
Definition: Transform.inl:38
void scaleX(F32 amount) noexcept override
Increase the scaling factor on the X axis by the specified factor.
Definition: Transform.inl:134
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
constexpr F32 to_F32(const T value)
double D64
Quaternion< F32 > _orientation