Skip to content

Commit

Permalink
Improve some argument names for core types
Browse files Browse the repository at this point in the history
  • Loading branch information
kleonc committed Apr 23, 2021
1 parent aa4cb40 commit 4d7f642
Show file tree
Hide file tree
Showing 19 changed files with 177 additions and 174 deletions.
10 changes: 5 additions & 5 deletions core/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ struct Color {
Color inverted() const;
Color contrasted() const;

_FORCE_INLINE_ Color linear_interpolate(const Color &p_b, float p_t) const {
_FORCE_INLINE_ Color linear_interpolate(const Color &p_to, float p_weight) const {

Color res = *this;

res.r += (p_t * (p_b.r - r));
res.g += (p_t * (p_b.g - g));
res.b += (p_t * (p_b.b - b));
res.a += (p_t * (p_b.a - a));
res.r += (p_weight * (p_to.r - r));
res.g += (p_weight * (p_to.g - g));
res.b += (p_weight * (p_to.b - b));
res.a += (p_weight * (p_to.a - a));

return res;
}
Expand Down
12 changes: 6 additions & 6 deletions core/math/basis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,16 +1033,16 @@ void Basis::set_diagonal(const Vector3 &p_diag) {
elements[2][2] = p_diag.z;
}

Basis Basis::slerp(const Basis &target, const real_t &t) const {
Basis Basis::slerp(const Basis &p_to, const real_t &p_weight) const {

//consider scale
Quat from(*this);
Quat to(target);
Quat to(p_to);

Basis b(from.slerp(to, t));
b.elements[0] *= Math::lerp(elements[0].length(), target.elements[0].length(), t);
b.elements[1] *= Math::lerp(elements[1].length(), target.elements[1].length(), t);
b.elements[2] *= Math::lerp(elements[2].length(), target.elements[2].length(), t);
Basis b(from.slerp(to, p_weight));
b.elements[0] *= Math::lerp(elements[0].length(), p_to.elements[0].length(), p_weight);
b.elements[1] *= Math::lerp(elements[1].length(), p_to.elements[1].length(), p_weight);
b.elements[2] *= Math::lerp(elements[2].length(), p_to.elements[2].length(), p_weight);

return b;
}
2 changes: 1 addition & 1 deletion core/math/basis.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class Basis {
bool is_diagonal() const;
bool is_rotation() const;

Basis slerp(const Basis &target, const real_t &t) const;
Basis slerp(const Basis &p_to, const real_t &p_weight) const;

operator String() const;

Expand Down
72 changes: 36 additions & 36 deletions core/math/quat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,18 @@ Vector3 Quat::get_euler_yxz() const {
return m.get_euler_yxz();
}

void Quat::operator*=(const Quat &q) {
void Quat::operator*=(const Quat &p_q) {

set(w * q.x + x * q.w + y * q.z - z * q.y,
w * q.y + y * q.w + z * q.x - x * q.z,
w * q.z + z * q.w + x * q.y - y * q.x,
w * q.w - x * q.x - y * q.y - z * q.z);
set(w * p_q.x + x * p_q.w + y * p_q.z - z * p_q.y,
w * p_q.y + y * p_q.w + z * p_q.x - x * p_q.z,
w * p_q.z + z * p_q.w + x * p_q.y - y * p_q.x,
w * p_q.w - x * p_q.x - y * p_q.y - z * p_q.z);
}

Quat Quat::operator*(const Quat &q) const {
Quat Quat::operator*(const Quat &p_q) const {

Quat r = *this;
r *= q;
r *= p_q;
return r;
}

Expand Down Expand Up @@ -150,29 +150,29 @@ Quat Quat::inverse() const {
return Quat(-x, -y, -z, w);
}

Quat Quat::slerp(const Quat &q, const real_t &t) const {
Quat Quat::slerp(const Quat &p_to, const real_t &p_weight) const {
#ifdef MATH_CHECKS
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.");
ERR_FAIL_COND_V_MSG(!p_to.is_normalized(), Quat(), "The end quaternion must be normalized.");
#endif
Quat to1;
real_t omega, cosom, sinom, scale0, scale1;

// calc cosine
cosom = dot(q);
cosom = dot(p_to);

// adjust signs (if necessary)
if (cosom < 0.0) {
cosom = -cosom;
to1.x = -q.x;
to1.y = -q.y;
to1.z = -q.z;
to1.w = -q.w;
to1.x = -p_to.x;
to1.y = -p_to.y;
to1.z = -p_to.z;
to1.w = -p_to.w;
} else {
to1.x = q.x;
to1.y = q.y;
to1.z = q.z;
to1.w = q.w;
to1.x = p_to.x;
to1.y = p_to.y;
to1.z = p_to.z;
to1.w = p_to.w;
}

// calculate coefficients
Expand All @@ -181,13 +181,13 @@ Quat Quat::slerp(const Quat &q, const real_t &t) const {
// standard case (slerp)
omega = Math::acos(cosom);
sinom = Math::sin(omega);
scale0 = Math::sin((1.0 - t) * omega) / sinom;
scale1 = Math::sin(t * omega) / sinom;
scale0 = Math::sin((1.0 - p_weight) * omega) / sinom;
scale1 = Math::sin(p_weight * omega) / sinom;
} else {
// "from" and "to" quaternions are very close
// ... so we can do a linear interpolation
scale0 = 1.0 - t;
scale1 = t;
scale0 = 1.0 - p_weight;
scale1 = p_weight;
}
// calculate final values
return Quat(
Expand All @@ -197,37 +197,37 @@ Quat Quat::slerp(const Quat &q, const real_t &t) const {
scale0 * w + scale1 * to1.w);
}

Quat Quat::slerpni(const Quat &q, const real_t &t) const {
Quat Quat::slerpni(const Quat &p_to, const real_t &p_weight) const {
#ifdef MATH_CHECKS
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.");
ERR_FAIL_COND_V_MSG(!p_to.is_normalized(), Quat(), "The end quaternion must be normalized.");
#endif
const Quat &from = *this;

real_t dot = from.dot(q);
real_t dot = from.dot(p_to);

if (Math::absf(dot) > 0.9999) return from;

real_t theta = Math::acos(dot),
sinT = 1.0 / Math::sin(theta),
newFactor = Math::sin(t * theta) * sinT,
invFactor = Math::sin((1.0 - t) * theta) * sinT;
newFactor = Math::sin(p_weight * theta) * sinT,
invFactor = Math::sin((1.0 - p_weight) * theta) * sinT;

return Quat(invFactor * from.x + newFactor * q.x,
invFactor * from.y + newFactor * q.y,
invFactor * from.z + newFactor * q.z,
invFactor * from.w + newFactor * q.w);
return Quat(invFactor * from.x + newFactor * p_to.x,
invFactor * from.y + newFactor * p_to.y,
invFactor * from.z + newFactor * p_to.z,
invFactor * from.w + newFactor * p_to.w);
}

Quat Quat::cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const real_t &t) const {
Quat Quat::cubic_slerp(const Quat &p_b, const Quat &p_pre_a, const Quat &p_post_b, const real_t &p_weight) const {
#ifdef MATH_CHECKS
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.");
ERR_FAIL_COND_V_MSG(!p_b.is_normalized(), Quat(), "The end quaternion must be normalized.");
#endif
//the only way to do slerp :|
real_t t2 = (1.0 - t) * t * 2;
Quat sp = this->slerp(q, t);
Quat sq = prep.slerpni(postq, t);
real_t t2 = (1.0 - p_weight) * p_weight * 2;
Quat sp = this->slerp(p_b, p_weight);
Quat sq = p_pre_a.slerpni(p_post_b, p_weight);
return sp.slerpni(sq, t2);
}

Expand Down
60 changes: 30 additions & 30 deletions core/math/quat.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Quat {
Quat normalized() const;
bool is_normalized() const;
Quat inverse() const;
_FORCE_INLINE_ real_t dot(const Quat &q) const;
_FORCE_INLINE_ real_t dot(const Quat &p_q) const;

void set_euler_xyz(const Vector3 &p_euler);
Vector3 get_euler_xyz() const;
Expand All @@ -59,9 +59,9 @@ class Quat {
void set_euler(const Vector3 &p_euler) { set_euler_yxz(p_euler); };
Vector3 get_euler() const { return get_euler_yxz(); };

Quat slerp(const Quat &q, const real_t &t) const;
Quat slerpni(const Quat &q, const real_t &t) const;
Quat cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const real_t &t) const;
Quat slerp(const Quat &p_to, const real_t &p_weight) const;
Quat slerpni(const Quat &p_to, const real_t &p_weight) const;
Quat cubic_slerp(const Quat &p_b, const Quat &p_pre_a, const Quat &p_post_b, const real_t &p_weight) const;

void set_axis_angle(const Vector3 &axis, const real_t &angle);
_FORCE_INLINE_ void get_axis_angle(Vector3 &r_axis, real_t &r_angle) const {
Expand All @@ -72,8 +72,8 @@ class Quat {
r_axis.z = z * r;
}

void operator*=(const Quat &q);
Quat operator*(const Quat &q) const;
void operator*=(const Quat &p_q);
Quat operator*(const Quat &p_q) const;

Quat operator*(const Vector3 &v) const {
return Quat(w * v.x + y * v.z - z * v.y,
Expand All @@ -91,8 +91,8 @@ class Quat {
return v + ((uv * w) + u.cross(uv)) * ((real_t)2);
}

_FORCE_INLINE_ void operator+=(const Quat &q);
_FORCE_INLINE_ void operator-=(const Quat &q);
_FORCE_INLINE_ void operator+=(const Quat &p_q);
_FORCE_INLINE_ void operator-=(const Quat &p_q);
_FORCE_INLINE_ void operator*=(const real_t &s);
_FORCE_INLINE_ void operator/=(const real_t &s);
_FORCE_INLINE_ Quat operator+(const Quat &q2) const;
Expand Down Expand Up @@ -121,18 +121,18 @@ class Quat {
Quat(const Vector3 &axis, const real_t &angle) { set_axis_angle(axis, angle); }

Quat(const Vector3 &euler) { set_euler(euler); }
Quat(const Quat &q) :
x(q.x),
y(q.y),
z(q.z),
w(q.w) {
Quat(const Quat &p_q) :
x(p_q.x),
y(p_q.y),
z(p_q.z),
w(p_q.w) {
}

Quat operator=(const Quat &q) {
x = q.x;
y = q.y;
z = q.z;
w = q.w;
Quat operator=(const Quat &p_q) {
x = p_q.x;
y = p_q.y;
z = p_q.z;
w = p_q.w;
return *this;
}

Expand Down Expand Up @@ -166,26 +166,26 @@ class Quat {
}
};

real_t Quat::dot(const Quat &q) const {
return x * q.x + y * q.y + z * q.z + w * q.w;
real_t Quat::dot(const Quat &p_q) const {
return x * p_q.x + y * p_q.y + z * p_q.z + w * p_q.w;
}

real_t Quat::length_squared() const {
return dot(*this);
}

void Quat::operator+=(const Quat &q) {
x += q.x;
y += q.y;
z += q.z;
w += q.w;
void Quat::operator+=(const Quat &p_q) {
x += p_q.x;
y += p_q.y;
z += p_q.z;
w += p_q.w;
}

void Quat::operator-=(const Quat &q) {
x -= q.x;
y -= q.y;
z -= q.z;
w -= q.w;
void Quat::operator-=(const Quat &p_q) {
x -= p_q.x;
y -= p_q.y;
z -= p_q.z;
w -= p_q.w;
}

void Quat::operator*=(const real_t &s) {
Expand Down
8 changes: 4 additions & 4 deletions core/math/vector2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ Vector2 Vector2::posmodv(const Vector2 &p_modv) const {
return Vector2(Math::fposmod(x, p_modv.x), Math::fposmod(y, p_modv.y));
}

Vector2 Vector2::project(const Vector2 &p_b) const {
return p_b * (dot(p_b) / p_b.length_squared());
Vector2 Vector2::project(const Vector2 &p_to) const {
return p_to * (dot(p_to) / p_to.length_squared());
}

Vector2 Vector2::snapped(const Vector2 &p_by) const {
Expand All @@ -158,14 +158,14 @@ Vector2 Vector2::clamped(real_t p_len) const {
return v;
}

Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const {
Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_weight) const {

Vector2 p0 = p_pre_a;
Vector2 p1 = *this;
Vector2 p2 = p_b;
Vector2 p3 = p_post_b;

real_t t = p_t;
real_t t = p_weight;
real_t t2 = t * t;
real_t t3 = t2 * t;

Expand Down
Loading

0 comments on commit 4d7f642

Please sign in to comment.