Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
godot
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
community
godot
Commits
a002b93d
Unverified
Commit
a002b93d
authored
Jan 24, 2020
by
Hugo Locurcio
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add explanations for errors related to Vector/Quat normalization
parent
97cc2e53
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
28 additions
and
28 deletions
+28
-28
basis.cpp
core/math/basis.cpp
+1
-1
quat.cpp
core/math/quat.cpp
+9
-9
quat.h
core/math/quat.h
+1
-1
vector2.cpp
core/math/vector2.cpp
+2
-2
vector2.h
core/math/vector2.h
+1
-1
vector3.h
core/math/vector3.h
+2
-2
editor_scene_importer_gltf.cpp
editor/import/editor_scene_importer_gltf.cpp
+6
-6
editor_scene_importer_assimp.cpp
modules/assimp/editor_scene_importer_assimp.cpp
+6
-6
No files found.
core/math/basis.cpp
View file @
a002b93d
...
...
@@ -800,7 +800,7 @@ void Basis::set_quat(const Quat &p_quat) {
void
Basis
::
set_axis_angle
(
const
Vector3
&
p_axis
,
real_t
p_phi
)
{
// Rotation matrix from axis and angle, see https://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_angle
#ifdef MATH_CHECKS
ERR_FAIL_COND_MSG
(
!
p_axis
.
is_normalized
(),
"
Axis
must be normalized."
);
ERR_FAIL_COND_MSG
(
!
p_axis
.
is_normalized
(),
"
The axis Vector3
must be normalized."
);
#endif
Vector3
axis_sq
(
p_axis
.
x
*
p_axis
.
x
,
p_axis
.
y
*
p_axis
.
y
,
p_axis
.
z
*
p_axis
.
z
);
real_t
cosine
=
Math
::
cos
(
p_phi
);
...
...
core/math/quat.cpp
View file @
a002b93d
...
...
@@ -100,7 +100,7 @@ void Quat::set_euler_yxz(const Vector3 &p_euler) {
// This implementation uses YXZ convention (Z is the first rotation).
Vector3
Quat
::
get_euler_yxz
()
const
{
#ifdef MATH_CHECKS
ERR_FAIL_COND_V
(
!
is_normalized
(),
Vector3
(
0
,
0
,
0
)
);
ERR_FAIL_COND_V
_MSG
(
!
is_normalized
(),
Vector3
(
0
,
0
,
0
),
"The quaternion must be normalized."
);
#endif
Basis
m
(
*
this
);
return
m
.
get_euler_yxz
();
...
...
@@ -145,15 +145,15 @@ bool Quat::is_normalized() const {
Quat
Quat
::
inverse
()
const
{
#ifdef MATH_CHECKS
ERR_FAIL_COND_V
(
!
is_normalized
(),
Quat
()
);
ERR_FAIL_COND_V
_MSG
(
!
is_normalized
(),
Quat
(),
"The quaternion must be normalized."
);
#endif
return
Quat
(
-
x
,
-
y
,
-
z
,
w
);
}
Quat
Quat
::
slerp
(
const
Quat
&
q
,
const
real_t
&
t
)
const
{
#ifdef MATH_CHECKS
ERR_FAIL_COND_V
(
!
is_normalized
(),
Quat
()
);
ERR_FAIL_COND_V
(
!
q
.
is_normalized
(),
Quat
()
);
ERR_FAIL_COND_V
_MSG
(
!
is_normalized
(),
Quat
(),
"The start quaternion must be normalized."
);
ERR_FAIL_COND_V
_MSG
(
!
q
.
is_normalized
(),
Quat
(),
"The end quaternion must be normalized."
);
#endif
Quat
to1
;
real_t
omega
,
cosom
,
sinom
,
scale0
,
scale1
;
...
...
@@ -199,8 +199,8 @@ Quat Quat::slerp(const Quat &q, const real_t &t) const {
Quat
Quat
::
slerpni
(
const
Quat
&
q
,
const
real_t
&
t
)
const
{
#ifdef MATH_CHECKS
ERR_FAIL_COND_V
(
!
is_normalized
(),
Quat
()
);
ERR_FAIL_COND_V
(
!
q
.
is_normalized
(),
Quat
()
);
ERR_FAIL_COND_V
_MSG
(
!
is_normalized
(),
Quat
(),
"The start quaternion must be normalized."
);
ERR_FAIL_COND_V
_MSG
(
!
q
.
is_normalized
(),
Quat
(),
"The end quaternion must be normalized."
);
#endif
const
Quat
&
from
=
*
this
;
...
...
@@ -221,8 +221,8 @@ Quat Quat::slerpni(const Quat &q, const real_t &t) const {
Quat
Quat
::
cubic_slerp
(
const
Quat
&
q
,
const
Quat
&
prep
,
const
Quat
&
postq
,
const
real_t
&
t
)
const
{
#ifdef MATH_CHECKS
ERR_FAIL_COND_V
(
!
is_normalized
(),
Quat
()
);
ERR_FAIL_COND_V
(
!
q
.
is_normalized
(),
Quat
()
);
ERR_FAIL_COND_V
_MSG
(
!
is_normalized
(),
Quat
(),
"The start quaternion must be normalized."
);
ERR_FAIL_COND_V
_MSG
(
!
q
.
is_normalized
(),
Quat
(),
"The end quaternion must be normalized."
);
#endif
//the only way to do slerp :|
real_t
t2
=
(
1.0
-
t
)
*
t
*
2
;
...
...
@@ -238,7 +238,7 @@ Quat::operator String() const {
void
Quat
::
set_axis_angle
(
const
Vector3
&
axis
,
const
real_t
&
angle
)
{
#ifdef MATH_CHECKS
ERR_FAIL_COND
(
!
axis
.
is_normalized
()
);
ERR_FAIL_COND
_MSG
(
!
axis
.
is_normalized
(),
"The axis Vector3 must be normalized."
);
#endif
real_t
d
=
axis
.
length
();
if
(
d
==
0
)
...
...
core/math/quat.h
View file @
a002b93d
...
...
@@ -84,7 +84,7 @@ public:
_FORCE_INLINE_
Vector3
xform
(
const
Vector3
&
v
)
const
{
#ifdef MATH_CHECKS
ERR_FAIL_COND_V
(
!
is_normalized
(),
v
);
ERR_FAIL_COND_V
_MSG
(
!
is_normalized
(),
v
,
"The quaternion must be normalized."
);
#endif
Vector3
u
(
x
,
y
,
z
);
Vector3
uv
=
u
.
cross
(
v
);
...
...
core/math/vector2.cpp
View file @
a002b93d
...
...
@@ -187,7 +187,7 @@ Vector2 Vector2::move_toward(const Vector2 &p_to, const real_t p_delta) const {
// slide returns the component of the vector along the given plane, specified by its normal vector.
Vector2
Vector2
::
slide
(
const
Vector2
&
p_normal
)
const
{
#ifdef MATH_CHECKS
ERR_FAIL_COND_V
(
!
p_normal
.
is_normalized
(),
Vector2
()
);
ERR_FAIL_COND_V
_MSG
(
!
p_normal
.
is_normalized
(),
Vector2
(),
"The normal Vector2 must be normalized."
);
#endif
return
*
this
-
p_normal
*
this
->
dot
(
p_normal
);
}
...
...
@@ -198,7 +198,7 @@ Vector2 Vector2::bounce(const Vector2 &p_normal) const {
Vector2
Vector2
::
reflect
(
const
Vector2
&
p_normal
)
const
{
#ifdef MATH_CHECKS
ERR_FAIL_COND_V
(
!
p_normal
.
is_normalized
(),
Vector2
()
);
ERR_FAIL_COND_V
_MSG
(
!
p_normal
.
is_normalized
(),
Vector2
(),
"The normal Vector2 must be normalized."
);
#endif
return
2.0
*
p_normal
*
this
->
dot
(
p_normal
)
-
*
this
;
}
...
...
core/math/vector2.h
View file @
a002b93d
...
...
@@ -242,7 +242,7 @@ Vector2 Vector2::linear_interpolate(const Vector2 &p_b, real_t p_t) const {
Vector2
Vector2
::
slerp
(
const
Vector2
&
p_b
,
real_t
p_t
)
const
{
#ifdef MATH_CHECKS
ERR_FAIL_COND_V
(
!
is_normalized
(),
Vector2
()
);
ERR_FAIL_COND_V
_MSG
(
!
is_normalized
(),
Vector2
(),
"The start Vector2 must be normalized."
);
#endif
real_t
theta
=
angle_to
(
p_b
);
return
rotated
(
theta
*
p_t
);
...
...
core/math/vector3.h
View file @
a002b93d
...
...
@@ -454,7 +454,7 @@ void Vector3::zero() {
// slide returns the component of the vector along the given plane, specified by its normal vector.
Vector3
Vector3
::
slide
(
const
Vector3
&
p_normal
)
const
{
#ifdef MATH_CHECKS
ERR_FAIL_COND_V
(
!
p_normal
.
is_normalized
(),
Vector3
()
);
ERR_FAIL_COND_V
_MSG
(
!
p_normal
.
is_normalized
(),
Vector3
(),
"The normal Vector3 must be normalized."
);
#endif
return
*
this
-
p_normal
*
this
->
dot
(
p_normal
);
}
...
...
@@ -465,7 +465,7 @@ Vector3 Vector3::bounce(const Vector3 &p_normal) const {
Vector3
Vector3
::
reflect
(
const
Vector3
&
p_normal
)
const
{
#ifdef MATH_CHECKS
ERR_FAIL_COND_V
(
!
p_normal
.
is_normalized
(),
Vector3
()
);
ERR_FAIL_COND_V
_MSG
(
!
p_normal
.
is_normalized
(),
Vector3
(),
"The normal Vector3 must be normalized."
);
#endif
return
2
.
0
*
p_normal
*
this
->
dot
(
p_normal
)
-
*
this
;
}
...
...
editor/import/editor_scene_importer_gltf.cpp
View file @
a002b93d
...
...
@@ -2634,22 +2634,22 @@ template <>
struct
EditorSceneImporterGLTFInterpolate
<
Quat
>
{
Quat
lerp
(
const
Quat
&
a
,
const
Quat
&
b
,
const
float
c
)
const
{
ERR_FAIL_COND_V
(
!
a
.
is_normalized
(),
Quat
()
);
ERR_FAIL_COND_V
(
!
b
.
is_normalized
(),
Quat
()
);
ERR_FAIL_COND_V
_MSG
(
!
a
.
is_normalized
(),
Quat
(),
"The quaternion
\"
a
\"
must be normalized."
);
ERR_FAIL_COND_V
_MSG
(
!
b
.
is_normalized
(),
Quat
(),
"The quaternion
\"
b
\"
must be normalized."
);
return
a
.
slerp
(
b
,
c
).
normalized
();
}
Quat
catmull_rom
(
const
Quat
&
p0
,
const
Quat
&
p1
,
const
Quat
&
p2
,
const
Quat
&
p3
,
const
float
c
)
{
ERR_FAIL_COND_V
(
!
p1
.
is_normalized
(),
Quat
()
);
ERR_FAIL_COND_V
(
!
p2
.
is_normalized
(),
Quat
()
);
ERR_FAIL_COND_V
_MSG
(
!
p1
.
is_normalized
(),
Quat
(),
"The quaternion
\"
p1
\"
must be normalized."
);
ERR_FAIL_COND_V
_MSG
(
!
p2
.
is_normalized
(),
Quat
(),
"The quaternion
\"
p2
\"
must be normalized."
);
return
p1
.
slerp
(
p2
,
c
).
normalized
();
}
Quat
bezier
(
const
Quat
start
,
const
Quat
control_1
,
const
Quat
control_2
,
const
Quat
end
,
const
float
t
)
{
ERR_FAIL_COND_V
(
!
start
.
is_normalized
(),
Quat
()
);
ERR_FAIL_COND_V
(
!
end
.
is_normalized
(),
Quat
()
);
ERR_FAIL_COND_V
_MSG
(
!
start
.
is_normalized
(),
Quat
(),
"The start quaternion must be normalized."
);
ERR_FAIL_COND_V
_MSG
(
!
end
.
is_normalized
(),
Quat
(),
"The end quaternion must be normalized."
);
return
start
.
slerp
(
end
,
t
).
normalized
();
}
...
...
modules/assimp/editor_scene_importer_assimp.cpp
View file @
a002b93d
...
...
@@ -188,22 +188,22 @@ template <>
struct
EditorSceneImporterAssetImportInterpolate
<
Quat
>
{
Quat
lerp
(
const
Quat
&
a
,
const
Quat
&
b
,
float
c
)
const
{
ERR_FAIL_COND_V
(
!
a
.
is_normalized
(),
Quat
()
);
ERR_FAIL_COND_V
(
!
b
.
is_normalized
(),
Quat
()
);
ERR_FAIL_COND_V
_MSG
(
!
a
.
is_normalized
(),
Quat
(),
"The quaternion
\"
a
\"
must be normalized."
);
ERR_FAIL_COND_V
_MSG
(
!
b
.
is_normalized
(),
Quat
(),
"The quaternion
\"
b
\"
must be normalized."
);
return
a
.
slerp
(
b
,
c
).
normalized
();
}
Quat
catmull_rom
(
const
Quat
&
p0
,
const
Quat
&
p1
,
const
Quat
&
p2
,
const
Quat
&
p3
,
float
c
)
{
ERR_FAIL_COND_V
(
!
p1
.
is_normalized
(),
Quat
()
);
ERR_FAIL_COND_V
(
!
p2
.
is_normalized
(),
Quat
()
);
ERR_FAIL_COND_V
_MSG
(
!
p1
.
is_normalized
(),
Quat
(),
"The quaternion
\"
p1
\"
must be normalized."
);
ERR_FAIL_COND_V
_MSG
(
!
p2
.
is_normalized
(),
Quat
(),
"The quaternion
\"
p2
\"
must be normalized."
);
return
p1
.
slerp
(
p2
,
c
).
normalized
();
}
Quat
bezier
(
Quat
start
,
Quat
control_1
,
Quat
control_2
,
Quat
end
,
float
t
)
{
ERR_FAIL_COND_V
(
!
start
.
is_normalized
(),
Quat
()
);
ERR_FAIL_COND_V
(
!
end
.
is_normalized
(),
Quat
()
);
ERR_FAIL_COND_V
_MSG
(
!
start
.
is_normalized
(),
Quat
(),
"The start quaternion must be normalized."
);
ERR_FAIL_COND_V
_MSG
(
!
end
.
is_normalized
(),
Quat
(),
"The end quaternion must be normalized."
);
return
start
.
slerp
(
end
,
t
).
normalized
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment