You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-18 14:21:41 +00:00
Bring that Whole New World to the Old Continent too
Applies the clang-format style to the 2.1 branch as done for master in
5dbf1809c6.
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
#include "quat.h"
|
||||
#include "print_string.h"
|
||||
|
||||
void Quat::set_euler(const Vector3& p_euler) {
|
||||
void Quat::set_euler(const Vector3 &p_euler) {
|
||||
real_t half_yaw = p_euler.x * 0.5;
|
||||
real_t half_pitch = p_euler.y * 0.5;
|
||||
real_t half_roll = p_euler.z * 0.5;
|
||||
@@ -39,30 +39,27 @@ void Quat::set_euler(const Vector3& p_euler) {
|
||||
real_t sin_pitch = Math::sin(half_pitch);
|
||||
real_t cos_roll = Math::cos(half_roll);
|
||||
real_t sin_roll = Math::sin(half_roll);
|
||||
set(cos_roll * sin_pitch * cos_yaw+sin_roll * cos_pitch * sin_yaw,
|
||||
cos_roll * cos_pitch * sin_yaw - sin_roll * sin_pitch * cos_yaw,
|
||||
sin_roll * cos_pitch * cos_yaw - cos_roll * sin_pitch * sin_yaw,
|
||||
cos_roll * cos_pitch * cos_yaw+sin_roll * sin_pitch * sin_yaw);
|
||||
set(cos_roll * sin_pitch * cos_yaw + sin_roll * cos_pitch * sin_yaw,
|
||||
cos_roll * cos_pitch * sin_yaw - sin_roll * sin_pitch * cos_yaw,
|
||||
sin_roll * cos_pitch * cos_yaw - cos_roll * sin_pitch * sin_yaw,
|
||||
cos_roll * cos_pitch * cos_yaw + sin_roll * sin_pitch * sin_yaw);
|
||||
}
|
||||
|
||||
void Quat::operator*=(const Quat& q) {
|
||||
void Quat::operator*=(const Quat &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 * 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);
|
||||
}
|
||||
|
||||
Quat Quat::operator*(const Quat& q) const {
|
||||
Quat Quat::operator*(const Quat &q) const {
|
||||
|
||||
Quat r=*this;
|
||||
r*=q;
|
||||
Quat r = *this;
|
||||
r *= q;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
real_t Quat::length() const {
|
||||
|
||||
return Math::sqrt(length_squared());
|
||||
@@ -72,17 +69,15 @@ void Quat::normalize() {
|
||||
*this /= length();
|
||||
}
|
||||
|
||||
|
||||
Quat Quat::normalized() const {
|
||||
return *this / length();
|
||||
}
|
||||
|
||||
Quat Quat::inverse() const {
|
||||
return Quat( -x, -y, -z, w );
|
||||
return Quat(-x, -y, -z, w);
|
||||
}
|
||||
|
||||
|
||||
Quat Quat::slerp(const Quat& q, const real_t& t) const {
|
||||
Quat Quat::slerp(const Quat &q, const real_t &t) const {
|
||||
|
||||
#if 0
|
||||
|
||||
@@ -126,32 +121,29 @@ Quat Quat::slerp(const Quat& q, const real_t& t) const {
|
||||
}
|
||||
#else
|
||||
|
||||
real_t to1[4];
|
||||
real_t omega, cosom, sinom, scale0, scale1;
|
||||
|
||||
real_t to1[4];
|
||||
real_t omega, cosom, sinom, scale0, scale1;
|
||||
|
||||
// calc cosine
|
||||
cosom = x * q.x + y * q.y + z * q.z
|
||||
+ w * q.w;
|
||||
|
||||
cosom = x * q.x + y * q.y + z * q.z + w * q.w;
|
||||
|
||||
// adjust signs (if necessary)
|
||||
if ( cosom <0.0 ) {
|
||||
cosom = -cosom; to1[0] = - q.x;
|
||||
to1[1] = - q.y;
|
||||
to1[2] = - q.z;
|
||||
to1[3] = - q.w;
|
||||
} else {
|
||||
if (cosom < 0.0) {
|
||||
cosom = -cosom;
|
||||
to1[0] = -q.x;
|
||||
to1[1] = -q.y;
|
||||
to1[2] = -q.z;
|
||||
to1[3] = -q.w;
|
||||
} else {
|
||||
to1[0] = q.x;
|
||||
to1[1] = q.y;
|
||||
to1[2] = q.z;
|
||||
to1[3] = q.w;
|
||||
}
|
||||
|
||||
|
||||
// calculate coefficients
|
||||
|
||||
if ( (1.0 - cosom) > CMP_EPSILON ) {
|
||||
if ((1.0 - cosom) > CMP_EPSILON) {
|
||||
// standard case (slerp)
|
||||
omega = Math::acos(cosom);
|
||||
sinom = Math::sin(omega);
|
||||
@@ -165,15 +157,14 @@ Quat Quat::slerp(const Quat& q, const real_t& t) const {
|
||||
}
|
||||
// calculate final values
|
||||
return Quat(
|
||||
scale0 * x + scale1 * to1[0],
|
||||
scale0 * y + scale1 * to1[1],
|
||||
scale0 * z + scale1 * to1[2],
|
||||
scale0 * w + scale1 * to1[3]
|
||||
);
|
||||
scale0 * x + scale1 * to1[0],
|
||||
scale0 * y + scale1 * to1[1],
|
||||
scale0 * z + scale1 * to1[2],
|
||||
scale0 * w + scale1 * to1[3]);
|
||||
#endif
|
||||
}
|
||||
|
||||
Quat Quat::slerpni(const Quat& q, const real_t& t) const {
|
||||
Quat Quat::slerpni(const Quat &q, const real_t &t) const {
|
||||
|
||||
const Quat &from = *this;
|
||||
|
||||
@@ -181,15 +172,15 @@ Quat Quat::slerpni(const Quat& q, const real_t& t) const {
|
||||
|
||||
if (Math::absf(dot) > 0.9999f) return from;
|
||||
|
||||
float theta = Math::acos(dot),
|
||||
sinT = 1.0f / Math::sin(theta),
|
||||
newFactor = Math::sin(t * theta) * sinT,
|
||||
invFactor = Math::sin((1.0f - t) * theta) * sinT;
|
||||
float theta = Math::acos(dot),
|
||||
sinT = 1.0f / Math::sin(theta),
|
||||
newFactor = Math::sin(t * theta) * sinT,
|
||||
invFactor = Math::sin((1.0f - t) * 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 * q.x,
|
||||
invFactor * from.y + newFactor * q.y,
|
||||
invFactor * from.z + newFactor * q.z,
|
||||
invFactor * from.w + newFactor * q.w);
|
||||
|
||||
#if 0
|
||||
real_t to1[4];
|
||||
@@ -239,29 +230,27 @@ Quat Quat::slerpni(const Quat& q, const real_t& t) const {
|
||||
#endif
|
||||
}
|
||||
|
||||
Quat Quat::cubic_slerp(const Quat& q, const Quat& prep, const Quat& postq,const real_t& t) const {
|
||||
Quat Quat::cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const real_t &t) const {
|
||||
|
||||
//the only way to do slerp :|
|
||||
float t2 = (1.0-t)*t*2;
|
||||
Quat sp = this->slerp(q,t);
|
||||
Quat sq = prep.slerpni(postq,t);
|
||||
return sp.slerpni(sq,t2);
|
||||
|
||||
float t2 = (1.0 - t) * t * 2;
|
||||
Quat sp = this->slerp(q, t);
|
||||
Quat sq = prep.slerpni(postq, t);
|
||||
return sp.slerpni(sq, t2);
|
||||
}
|
||||
|
||||
|
||||
Quat::operator String() const {
|
||||
|
||||
return String::num(x)+", "+String::num(y)+", "+ String::num(z)+", "+ String::num(w);
|
||||
return String::num(x) + ", " + String::num(y) + ", " + String::num(z) + ", " + String::num(w);
|
||||
}
|
||||
|
||||
Quat::Quat(const Vector3& axis, const real_t& angle) {
|
||||
Quat::Quat(const Vector3 &axis, const real_t &angle) {
|
||||
real_t d = axis.length();
|
||||
if (d==0)
|
||||
set(0,0,0,0);
|
||||
if (d == 0)
|
||||
set(0, 0, 0, 0);
|
||||
else {
|
||||
real_t s = Math::sin(-angle * 0.5) / d;
|
||||
set(axis.x * s, axis.y * s, axis.z * s,
|
||||
Math::cos(-angle * 0.5));
|
||||
Math::cos(-angle * 0.5));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user