Merge pull request #8277 from tagcup/math_checks
Added various functions basic math classes. Also enabled math checks …
This commit is contained in:
commit
5ae1e172da
13 changed files with 217 additions and 50 deletions
|
@ -63,7 +63,8 @@ Vector2 Vector2::normalized() const {
|
|||
}
|
||||
|
||||
bool Vector2::is_normalized() const {
|
||||
return Math::isequal_approx(length(), (real_t)1.0);
|
||||
// use length_squared() instead of length() to avoid sqrt(), makes it more stringent.
|
||||
return Math::is_equal_approx(length_squared(), 1.0);
|
||||
}
|
||||
|
||||
real_t Vector2::distance_to(const Vector2 &p_vector2) const {
|
||||
|
@ -281,7 +282,7 @@ Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, c
|
|||
|
||||
// slide returns the component of the vector along the given plane, specified by its normal vector.
|
||||
Vector2 Vector2::slide(const Vector2 &p_n) const {
|
||||
#ifdef DEBUG_ENABLED
|
||||
#ifdef MATH_CHECKS
|
||||
ERR_FAIL_COND_V(p_n.is_normalized() == false, Vector2());
|
||||
#endif
|
||||
return *this - p_n * this->dot(p_n);
|
||||
|
@ -292,7 +293,7 @@ Vector2 Vector2::bounce(const Vector2 &p_n) const {
|
|||
}
|
||||
|
||||
Vector2 Vector2::reflect(const Vector2 &p_n) const {
|
||||
#ifdef DEBUG_ENABLED
|
||||
#ifdef MATH_CHECKS
|
||||
ERR_FAIL_COND_V(p_n.is_normalized() == false, Vector2());
|
||||
#endif
|
||||
return 2.0 * p_n * this->dot(p_n) - *this;
|
||||
|
@ -439,7 +440,9 @@ Transform2D Transform2D::inverse() const {
|
|||
void Transform2D::affine_invert() {
|
||||
|
||||
real_t det = basis_determinant();
|
||||
#ifdef MATH_CHECKS
|
||||
ERR_FAIL_COND(det == 0);
|
||||
#endif
|
||||
real_t idet = 1.0 / det;
|
||||
|
||||
SWAP(elements[0][0], elements[1][1]);
|
||||
|
|
|
@ -35,6 +35,10 @@
|
|||
#define CMP_NORMALIZE_TOLERANCE 0.000001
|
||||
#define CMP_POINT_IN_PLANE_EPSILON 0.00001
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
#define MATH_CHECKS
|
||||
#endif
|
||||
|
||||
#define USEC_TO_SEC(m_usec) ((m_usec) / 1000000.0)
|
||||
/**
|
||||
* "Real" is a type that will be translated to either floats or fixed depending
|
||||
|
|
|
@ -168,7 +168,7 @@ public:
|
|||
static float random(float from, float to);
|
||||
static real_t random(int from, int to) { return (real_t)random((real_t)from, (real_t)to); }
|
||||
|
||||
static _ALWAYS_INLINE_ bool isequal_approx(real_t a, real_t b) {
|
||||
static _ALWAYS_INLINE_ bool is_equal_approx(real_t a, real_t b) {
|
||||
// TODO: Comparing floats for approximate-equality is non-trivial.
|
||||
// Using epsilon should cover the typical cases in Godot (where a == b is used to compare two reals), such as matrix and vector comparison operators.
|
||||
// A proper implementation in terms of ULPs should eventually replace the contents of this function.
|
||||
|
|
|
@ -62,8 +62,9 @@ void Basis::invert() {
|
|||
real_t det = elements[0][0] * co[0] +
|
||||
elements[0][1] * co[1] +
|
||||
elements[0][2] * co[2];
|
||||
|
||||
#ifdef MATH_CHECKS
|
||||
ERR_FAIL_COND(det == 0);
|
||||
#endif
|
||||
real_t s = 1.0 / det;
|
||||
|
||||
set(co[0] * s, cofac(0, 2, 2, 1) * s, cofac(0, 1, 1, 2) * s,
|
||||
|
@ -72,8 +73,9 @@ void Basis::invert() {
|
|||
}
|
||||
|
||||
void Basis::orthonormalize() {
|
||||
#ifdef MATH_CHECKS
|
||||
ERR_FAIL_COND(determinant() == 0);
|
||||
|
||||
#endif
|
||||
// Gram-Schmidt Process
|
||||
|
||||
Vector3 x = get_axis(0);
|
||||
|
@ -102,20 +104,20 @@ bool Basis::is_orthogonal() const {
|
|||
Basis id;
|
||||
Basis m = (*this) * transposed();
|
||||
|
||||
return isequal_approx(id, m);
|
||||
return is_equal_approx(id, m);
|
||||
}
|
||||
|
||||
bool Basis::is_rotation() const {
|
||||
return Math::isequal_approx(determinant(), 1) && is_orthogonal();
|
||||
return Math::is_equal_approx(determinant(), 1) && is_orthogonal();
|
||||
}
|
||||
|
||||
bool Basis::is_symmetric() const {
|
||||
|
||||
if (Math::abs(elements[0][1] - elements[1][0]) > CMP_EPSILON)
|
||||
if (!Math::is_equal_approx(elements[0][1], elements[1][0]))
|
||||
return false;
|
||||
if (Math::abs(elements[0][2] - elements[2][0]) > CMP_EPSILON)
|
||||
if (!Math::is_equal_approx(elements[0][2], elements[2][0]))
|
||||
return false;
|
||||
if (Math::abs(elements[1][2] - elements[2][1]) > CMP_EPSILON)
|
||||
if (!Math::is_equal_approx(elements[1][2], elements[2][1]))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
@ -123,11 +125,11 @@ bool Basis::is_symmetric() const {
|
|||
|
||||
Basis Basis::diagonalize() {
|
||||
|
||||
//NOTE: only implemented for symmetric matrices
|
||||
//with the Jacobi iterative method method
|
||||
|
||||
//NOTE: only implemented for symmetric matrices
|
||||
//with the Jacobi iterative method method
|
||||
#ifdef MATH_CHECKS
|
||||
ERR_FAIL_COND_V(!is_symmetric(), Basis());
|
||||
|
||||
#endif
|
||||
const int ite_max = 1024;
|
||||
|
||||
real_t off_matrix_norm_2 = elements[0][1] * elements[0][1] + elements[0][2] * elements[0][2] + elements[1][2] * elements[1][2];
|
||||
|
@ -160,7 +162,7 @@ Basis Basis::diagonalize() {
|
|||
|
||||
// Compute the rotation angle
|
||||
real_t angle;
|
||||
if (Math::abs(elements[j][j] - elements[i][i]) < CMP_EPSILON) {
|
||||
if (Math::is_equal_approx(elements[j][j], elements[i][i])) {
|
||||
angle = Math_PI / 4;
|
||||
} else {
|
||||
angle = 0.5 * Math::atan(2 * elements[i][j] / (elements[j][j] - elements[i][i]));
|
||||
|
@ -226,11 +228,25 @@ Basis Basis::scaled(const Vector3 &p_scale) const {
|
|||
}
|
||||
|
||||
Vector3 Basis::get_scale() const {
|
||||
// We are assuming M = R.S, and performing a polar decomposition to extract R and S.
|
||||
// FIXME: We eventually need a proper polar decomposition.
|
||||
// As a cheap workaround until then, to ensure that R is a proper rotation matrix with determinant +1
|
||||
// (such that it can be represented by a Quat or Euler angles), we absorb the sign flip into the scaling matrix.
|
||||
// As such, it works in conjunction with get_rotation().
|
||||
// FIXME: We are assuming M = R.S (R is rotation and S is scaling), and use polar decomposition to extract R and S.
|
||||
// A polar decomposition is M = O.P, where O is an orthogonal matrix (meaning rotation and reflection) and
|
||||
// P is a positive semi-definite matrix (meaning it contains absolute values of scaling along its diagonal).
|
||||
//
|
||||
// Despite being different from what we want to achieve, we can nevertheless make use of polar decomposition
|
||||
// here as follows. We can split O into a rotation and a reflection as O = R.Q, and obtain M = R.S where
|
||||
// we defined S = Q.P. Now, R is a proper rotation matrix and S is a (signed) scaling matrix,
|
||||
// which can involve negative scalings. However, there is a catch: unlike the polar decomposition of M = O.P,
|
||||
// the decomposition of O into a rotation and reflection matrix as O = R.Q is not unique.
|
||||
// Therefore, we are going to do this decomposition by sticking to a particular convention.
|
||||
// This may lead to confusion for some users though.
|
||||
//
|
||||
// The convention we use here is to absorb the sign flip into the scaling matrix.
|
||||
// The same convention is also used in other similar functions such as set_scale,
|
||||
// get_rotation_axis_angle, get_rotation, set_rotation_axis_angle, set_rotation_euler, ...
|
||||
//
|
||||
// A proper way to get rid of this issue would be to store the scaling values (or at least their signs)
|
||||
// as a part of Basis. However, if we go that path, we need to disable direct (write) access to the
|
||||
// matrix elements.
|
||||
real_t det_sign = determinant() > 0 ? 1 : -1;
|
||||
return det_sign * Vector3(
|
||||
Vector3(elements[0][0], elements[1][0], elements[2][0]).length(),
|
||||
|
@ -238,6 +254,17 @@ Vector3 Basis::get_scale() const {
|
|||
Vector3(elements[0][2], elements[1][2], elements[2][2]).length());
|
||||
}
|
||||
|
||||
// Sets scaling while preserving rotation.
|
||||
// This requires some care when working with matrices with negative determinant,
|
||||
// since we're using a particular convention for "polar" decomposition in get_scale and get_rotation.
|
||||
// For details, see the explanation in get_scale.
|
||||
void Basis::set_scale(const Vector3 &p_scale) {
|
||||
Vector3 e = get_euler();
|
||||
Basis(); // reset to identity
|
||||
scale(p_scale);
|
||||
rotate(e);
|
||||
}
|
||||
|
||||
// Multiplies the matrix from left by the rotation matrix: M -> R.M
|
||||
// Note that this does *not* rotate the matrix itself.
|
||||
//
|
||||
|
@ -260,6 +287,7 @@ void Basis::rotate(const Vector3 &p_euler) {
|
|||
*this = rotated(p_euler);
|
||||
}
|
||||
|
||||
// TODO: rename this to get_rotation_euler
|
||||
Vector3 Basis::get_rotation() const {
|
||||
// Assumes that the matrix can be decomposed into a proper rotation and scaling matrix as M = R.S,
|
||||
// and returns the Euler angles corresponding to the rotation part, complementing get_scale().
|
||||
|
@ -274,6 +302,42 @@ Vector3 Basis::get_rotation() const {
|
|||
return m.get_euler();
|
||||
}
|
||||
|
||||
void Basis::get_rotation_axis_angle(Vector3 &p_axis, real_t &p_angle) const {
|
||||
// Assumes that the matrix can be decomposed into a proper rotation and scaling matrix as M = R.S,
|
||||
// and returns the Euler angles corresponding to the rotation part, complementing get_scale().
|
||||
// See the comment in get_scale() for further information.
|
||||
Basis m = orthonormalized();
|
||||
real_t det = m.determinant();
|
||||
if (det < 0) {
|
||||
// Ensure that the determinant is 1, such that result is a proper rotation matrix which can be represented by Euler angles.
|
||||
m.scale(Vector3(-1, -1, -1));
|
||||
}
|
||||
|
||||
m.get_axis_angle(p_axis, p_angle);
|
||||
}
|
||||
|
||||
// Sets rotation while preserving scaling.
|
||||
// This requires some care when working with matrices with negative determinant,
|
||||
// since we're using a particular convention for "polar" decomposition in get_scale and get_rotation.
|
||||
// For details, see the explanation in get_scale.
|
||||
void Basis::set_rotation_euler(const Vector3 &p_euler) {
|
||||
Vector3 s = get_scale();
|
||||
Basis(); // reset to identity
|
||||
scale(s);
|
||||
rotate(p_euler);
|
||||
}
|
||||
|
||||
// Sets rotation while preserving scaling.
|
||||
// This requires some care when working with matrices with negative determinant,
|
||||
// since we're using a particular convention for "polar" decomposition in get_scale and get_rotation.
|
||||
// For details, see the explanation in get_scale.
|
||||
void Basis::set_rotation_axis_angle(const Vector3 &p_axis, real_t p_angle) {
|
||||
Vector3 s = get_scale();
|
||||
Basis(); // reset to identity
|
||||
scale(s);
|
||||
rotate(p_axis, p_angle);
|
||||
}
|
||||
|
||||
// get_euler returns a vector containing the Euler angles in the format
|
||||
// (a1,a2,a3), where a3 is the angle of the first rotation, and a1 is the last
|
||||
// (following the convention they are commonly defined in the literature).
|
||||
|
@ -294,9 +358,9 @@ Vector3 Basis::get_euler() const {
|
|||
// -cx*cz*sy+sx*sz cz*sx+cx*sy*sz cx*cy
|
||||
|
||||
Vector3 euler;
|
||||
|
||||
#ifdef MATH_CHECKS
|
||||
ERR_FAIL_COND_V(is_rotation() == false, euler);
|
||||
|
||||
#endif
|
||||
euler.y = Math::asin(elements[0][2]);
|
||||
if (euler.y < Math_PI * 0.5) {
|
||||
if (euler.y > -Math_PI * 0.5) {
|
||||
|
@ -340,11 +404,11 @@ void Basis::set_euler(const Vector3 &p_euler) {
|
|||
*this = xmat * (ymat * zmat);
|
||||
}
|
||||
|
||||
bool Basis::isequal_approx(const Basis &a, const Basis &b) const {
|
||||
bool Basis::is_equal_approx(const Basis &a, const Basis &b) const {
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
if (Math::isequal_approx(a.elements[i][j], b.elements[i][j]) == false)
|
||||
if (Math::is_equal_approx(a.elements[i][j], b.elements[i][j]) == false)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -387,8 +451,9 @@ Basis::operator String() const {
|
|||
}
|
||||
|
||||
Basis::operator Quat() const {
|
||||
#ifdef MATH_CHECKS
|
||||
ERR_FAIL_COND_V(is_rotation() == false, Quat());
|
||||
|
||||
#endif
|
||||
real_t trace = elements[0][0] + elements[1][1] + elements[2][2];
|
||||
real_t temp[4];
|
||||
|
||||
|
@ -482,9 +547,10 @@ void Basis::set_orthogonal_index(int p_index) {
|
|||
*this = _ortho_bases[p_index];
|
||||
}
|
||||
|
||||
void Basis::get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const {
|
||||
void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const {
|
||||
#ifdef MATH_CHECKS
|
||||
ERR_FAIL_COND(is_rotation() == false);
|
||||
|
||||
#endif
|
||||
real_t angle, x, y, z; // variables for result
|
||||
real_t epsilon = 0.01; // margin to allow for rounding errors
|
||||
real_t epsilon2 = 0.1; // margin to distinguish between 0 and 180 degrees
|
||||
|
@ -573,11 +639,11 @@ Basis::Basis(const Quat &p_quat) {
|
|||
xz - wy, yz + wx, 1.0 - (xx + yy));
|
||||
}
|
||||
|
||||
Basis::Basis(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_and_angle
|
||||
|
||||
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(p_axis.is_normalized() == false);
|
||||
|
||||
#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);
|
||||
|
@ -595,3 +661,7 @@ Basis::Basis(const Vector3 &p_axis, real_t p_phi) {
|
|||
elements[2][1] = p_axis.y * p_axis.z * (1.0 - cosine) + p_axis.x * sine;
|
||||
elements[2][2] = axis_sq.z + cosine * (1.0 - axis_sq.z);
|
||||
}
|
||||
|
||||
Basis::Basis(const Vector3 &p_axis, real_t p_phi) {
|
||||
set_axis_angle(p_axis, p_phi);
|
||||
}
|
||||
|
|
|
@ -77,15 +77,25 @@ public:
|
|||
|
||||
void rotate(const Vector3 &p_euler);
|
||||
Basis rotated(const Vector3 &p_euler) const;
|
||||
Vector3 get_rotation() const;
|
||||
|
||||
void scale(const Vector3 &p_scale);
|
||||
Basis scaled(const Vector3 &p_scale) const;
|
||||
Vector3 get_scale() const;
|
||||
Vector3 get_rotation() const;
|
||||
void get_rotation_axis_angle(Vector3 &p_axis, real_t &p_angle) const;
|
||||
|
||||
void set_rotation_euler(const Vector3 &p_euler);
|
||||
void set_rotation_axis_angle(const Vector3 &p_axis, real_t p_angle);
|
||||
|
||||
Vector3 get_euler() const;
|
||||
void set_euler(const Vector3 &p_euler);
|
||||
|
||||
void get_axis_angle(Vector3 &r_axis, real_t &r_angle) const;
|
||||
void set_axis_angle(const Vector3 &p_axis, real_t p_phi);
|
||||
|
||||
void scale(const Vector3 &p_scale);
|
||||
Basis scaled(const Vector3 &p_scale) const;
|
||||
|
||||
Vector3 get_scale() const;
|
||||
void set_scale(const Vector3 &p_scale);
|
||||
|
||||
// transposed dot products
|
||||
_FORCE_INLINE_ real_t tdotx(const Vector3 &v) const {
|
||||
return elements[0][0] * v[0] + elements[1][0] * v[1] + elements[2][0] * v[2];
|
||||
|
@ -97,7 +107,7 @@ public:
|
|||
return elements[0][2] * v[0] + elements[1][2] * v[1] + elements[2][2] * v[2];
|
||||
}
|
||||
|
||||
bool isequal_approx(const Basis &a, const Basis &b) const;
|
||||
bool is_equal_approx(const Basis &a, const Basis &b) const;
|
||||
|
||||
bool operator==(const Basis &p_matrix) const;
|
||||
bool operator!=(const Basis &p_matrix) const;
|
||||
|
@ -121,8 +131,6 @@ public:
|
|||
|
||||
operator String() const;
|
||||
|
||||
void get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const;
|
||||
|
||||
/* create / set */
|
||||
|
||||
_FORCE_INLINE_ void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) {
|
||||
|
|
|
@ -92,6 +92,10 @@ Quat Quat::normalized() const {
|
|||
return *this / length();
|
||||
}
|
||||
|
||||
bool Quat::is_normalized() const {
|
||||
return Math::is_equal_approx(length(), 1.0);
|
||||
}
|
||||
|
||||
Quat Quat::inverse() const {
|
||||
return Quat(-x, -y, -z, w);
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ public:
|
|||
real_t length() const;
|
||||
void normalize();
|
||||
Quat normalized() const;
|
||||
bool is_normalized() const;
|
||||
Quat inverse() const;
|
||||
_FORCE_INLINE_ real_t dot(const Quat &q) const;
|
||||
void set_euler(const Vector3 &p_euler);
|
||||
|
@ -56,7 +57,7 @@ public:
|
|||
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;
|
||||
|
||||
_FORCE_INLINE_ void get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const {
|
||||
_FORCE_INLINE_ void get_axis_angle(Vector3 &r_axis, real_t &r_angle) const {
|
||||
r_angle = 2 * Math::acos(w);
|
||||
r_axis.x = x / Math::sqrt(1 - w * w);
|
||||
r_axis.y = y / Math::sqrt(1 - w * w);
|
||||
|
|
|
@ -389,7 +389,8 @@ Vector3 Vector3::normalized() const {
|
|||
}
|
||||
|
||||
bool Vector3::is_normalized() const {
|
||||
return Math::isequal_approx(length(), (real_t)1.0);
|
||||
// use length_squared() instead of length() to avoid sqrt(), makes it more stringent.
|
||||
return Math::is_equal_approx(length_squared(), 1.0);
|
||||
}
|
||||
|
||||
Vector3 Vector3::inverse() const {
|
||||
|
@ -404,7 +405,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_n) const {
|
||||
#ifdef DEBUG_ENABLED
|
||||
#ifdef MATH_CHECKS
|
||||
ERR_FAIL_COND_V(p_n.is_normalized() == false, Vector3());
|
||||
#endif
|
||||
return *this - p_n * this->dot(p_n);
|
||||
|
@ -415,7 +416,7 @@ Vector3 Vector3::bounce(const Vector3 &p_n) const {
|
|||
}
|
||||
|
||||
Vector3 Vector3::reflect(const Vector3 &p_n) const {
|
||||
#ifdef DEBUG_ENABLED
|
||||
#ifdef MATH_CHECKS
|
||||
ERR_FAIL_COND_V(p_n.is_normalized() == false, Vector3());
|
||||
#endif
|
||||
return 2.0 * p_n * this->dot(p_n) - *this;
|
||||
|
|
|
@ -328,6 +328,7 @@ struct _VariantCall {
|
|||
VCALL_LOCALMEM0R(Vector2, normalized);
|
||||
VCALL_LOCALMEM0R(Vector2, length);
|
||||
VCALL_LOCALMEM0R(Vector2, length_squared);
|
||||
VCALL_LOCALMEM0R(Vector2, is_normalized);
|
||||
VCALL_LOCALMEM1R(Vector2, distance_to);
|
||||
VCALL_LOCALMEM1R(Vector2, distance_squared_to);
|
||||
VCALL_LOCALMEM1R(Vector2, angle_to);
|
||||
|
@ -362,6 +363,7 @@ struct _VariantCall {
|
|||
VCALL_LOCALMEM0R(Vector3, max_axis);
|
||||
VCALL_LOCALMEM0R(Vector3, length);
|
||||
VCALL_LOCALMEM0R(Vector3, length_squared);
|
||||
VCALL_LOCALMEM0R(Vector3, is_normalized);
|
||||
VCALL_LOCALMEM0R(Vector3, normalized);
|
||||
VCALL_LOCALMEM0R(Vector3, inverse);
|
||||
VCALL_LOCALMEM1R(Vector3, snapped);
|
||||
|
@ -418,6 +420,7 @@ struct _VariantCall {
|
|||
VCALL_LOCALMEM0R(Quat, length);
|
||||
VCALL_LOCALMEM0R(Quat, length_squared);
|
||||
VCALL_LOCALMEM0R(Quat, normalized);
|
||||
VCALL_LOCALMEM0R(Quat, is_normalized);
|
||||
VCALL_LOCALMEM0R(Quat, inverse);
|
||||
VCALL_LOCALMEM1R(Quat, dot);
|
||||
VCALL_LOCALMEM1R(Quat, xform);
|
||||
|
@ -704,6 +707,9 @@ struct _VariantCall {
|
|||
VCALL_PTR1R(Basis, scaled);
|
||||
VCALL_PTR0R(Basis, get_scale);
|
||||
VCALL_PTR0R(Basis, get_euler);
|
||||
VCALL_PTR1(Basis, set_scale);
|
||||
VCALL_PTR1(Basis, set_rotation_euler);
|
||||
VCALL_PTR2(Basis, set_rotation_axis_angle);
|
||||
VCALL_PTR1R(Basis, tdotx);
|
||||
VCALL_PTR1R(Basis, tdoty);
|
||||
VCALL_PTR1R(Basis, tdotz);
|
||||
|
@ -875,6 +881,11 @@ struct _VariantCall {
|
|||
r_ret = Basis(p_args[0]->operator Vector3(), p_args[1]->operator real_t());
|
||||
}
|
||||
|
||||
static void Basis_init3(Variant &r_ret, const Variant **p_args) {
|
||||
|
||||
r_ret = Basis(p_args[0]->operator Vector3());
|
||||
}
|
||||
|
||||
static void Transform_init1(Variant &r_ret, const Variant **p_args) {
|
||||
|
||||
Transform t;
|
||||
|
@ -1429,6 +1440,7 @@ void register_variant_methods() {
|
|||
ADDFUNC0(VECTOR2, REAL, Vector2, length, varray());
|
||||
ADDFUNC0(VECTOR2, REAL, Vector2, angle, varray());
|
||||
ADDFUNC0(VECTOR2, REAL, Vector2, length_squared, varray());
|
||||
ADDFUNC0(VECTOR2, BOOL, Vector2, is_normalized, varray());
|
||||
ADDFUNC1(VECTOR2, REAL, Vector2, distance_to, VECTOR2, "to", varray());
|
||||
ADDFUNC1(VECTOR2, REAL, Vector2, distance_squared_to, VECTOR2, "to", varray());
|
||||
ADDFUNC1(VECTOR2, REAL, Vector2, angle_to, VECTOR2, "to", varray());
|
||||
|
@ -1462,6 +1474,7 @@ void register_variant_methods() {
|
|||
ADDFUNC0(VECTOR3, INT, Vector3, max_axis, varray());
|
||||
ADDFUNC0(VECTOR3, REAL, Vector3, length, varray());
|
||||
ADDFUNC0(VECTOR3, REAL, Vector3, length_squared, varray());
|
||||
ADDFUNC0(VECTOR3, BOOL, Vector3, is_normalized, varray());
|
||||
ADDFUNC0(VECTOR3, VECTOR3, Vector3, normalized, varray());
|
||||
ADDFUNC0(VECTOR3, VECTOR3, Vector3, inverse, varray());
|
||||
ADDFUNC1(VECTOR3, VECTOR3, Vector3, snapped, REAL, "by", varray());
|
||||
|
@ -1497,6 +1510,7 @@ void register_variant_methods() {
|
|||
ADDFUNC0(QUAT, REAL, Quat, length, varray());
|
||||
ADDFUNC0(QUAT, REAL, Quat, length_squared, varray());
|
||||
ADDFUNC0(QUAT, QUAT, Quat, normalized, varray());
|
||||
ADDFUNC0(QUAT, BOOL, Quat, is_normalized, varray());
|
||||
ADDFUNC0(QUAT, QUAT, Quat, inverse, varray());
|
||||
ADDFUNC1(QUAT, REAL, Quat, dot, QUAT, "b", varray());
|
||||
ADDFUNC1(QUAT, VECTOR3, Quat, xform, VECTOR3, "v", varray());
|
||||
|
@ -1692,6 +1706,9 @@ void register_variant_methods() {
|
|||
ADDFUNC0(BASIS, REAL, Basis, determinant, varray());
|
||||
ADDFUNC2(BASIS, BASIS, Basis, rotated, VECTOR3, "axis", REAL, "phi", varray());
|
||||
ADDFUNC1(BASIS, BASIS, Basis, scaled, VECTOR3, "scale", varray());
|
||||
ADDFUNC1(BASIS, NIL, Basis, set_scale, VECTOR3, "scale", varray());
|
||||
ADDFUNC1(BASIS, NIL, Basis, set_rotation_euler, VECTOR3, "euler", varray());
|
||||
ADDFUNC2(BASIS, NIL, Basis, set_rotation_axis_angle, VECTOR3, "axis", REAL, "angle", varray());
|
||||
ADDFUNC0(BASIS, VECTOR3, Basis, get_scale, varray());
|
||||
ADDFUNC0(BASIS, VECTOR3, Basis, get_euler, varray());
|
||||
ADDFUNC1(BASIS, REAL, Basis, tdotx, VECTOR3, "with", varray());
|
||||
|
@ -1749,6 +1766,7 @@ void register_variant_methods() {
|
|||
|
||||
_VariantCall::add_constructor(_VariantCall::Basis_init1, Variant::BASIS, "x_axis", Variant::VECTOR3, "y_axis", Variant::VECTOR3, "z_axis", Variant::VECTOR3);
|
||||
_VariantCall::add_constructor(_VariantCall::Basis_init2, Variant::BASIS, "axis", Variant::VECTOR3, "phi", Variant::REAL);
|
||||
_VariantCall::add_constructor(_VariantCall::Basis_init3, Variant::BASIS, "euler", Variant::VECTOR3);
|
||||
|
||||
_VariantCall::add_constructor(_VariantCall::Transform_init1, Variant::TRANSFORM, "x_axis", Variant::VECTOR3, "y_axis", Variant::VECTOR3, "z_axis", Variant::VECTOR3, "origin", Variant::VECTOR3);
|
||||
_VariantCall::add_constructor(_VariantCall::Transform_init2, Variant::TRANSFORM, "basis", Variant::BASIS, "origin", Variant::VECTOR3);
|
||||
|
|
|
@ -6865,6 +6865,15 @@
|
|||
Create a rotation matrix which rotates around the given axis by the specified angle. The axis must be a normalized vector.
|
||||
</description>
|
||||
</method>
|
||||
<method name="Basis">
|
||||
<return type="Basis">
|
||||
</return>
|
||||
<argument index="0" name="euler" type="Vector3">
|
||||
</argument>
|
||||
<description>
|
||||
Create a rotation matrix (in the XYZ convention: first Z, then Y, and X last) from the specified Euler angles, given in the vector format as (third,second,first).
|
||||
</description>
|
||||
</method>
|
||||
<method name="Basis">
|
||||
<return type="Basis">
|
||||
</return>
|
||||
|
@ -6889,8 +6898,7 @@
|
|||
<return type="Vector3">
|
||||
</return>
|
||||
<description>
|
||||
Return Euler angles (in the XYZ convention: first Z, then Y, and X last) from the matrix. Returned vector contains the rotation angles in the format (third,second,first).
|
||||
This function only works if the matrix represents a proper rotation.
|
||||
Assuming that the matrix is a proper rotation matrix (orthonormal matrix with determinant +1), return Euler angles (in the XYZ convention: first Z, then Y, and X last). Returned vector contains the rotation angles in the format (third,second,first).
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_orthogonal_index">
|
||||
|
@ -6932,6 +6940,26 @@
|
|||
Introduce an additional rotation around the given axis by phi (radians). Only relevant when the matrix is being used as a part of [Transform]. The axis must be a normalized vector.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_rotation_euler">
|
||||
<return type="Basis">
|
||||
</return>
|
||||
<argument index="0" name="euler" type="Vector3">
|
||||
</argument>
|
||||
<description>
|
||||
Changes only the rotation part of the [Basis] to a rotation corresponding to given Euler angles, while preserving the scaling part (as determined by get_scale).
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_rotation_axis_angle">
|
||||
<return type="Basis">
|
||||
</return>
|
||||
<argument index="0" name="axis" type="Vector3">
|
||||
</argument>
|
||||
<argument index="1" name="phi" type="float">
|
||||
</argument>
|
||||
<description>
|
||||
Changes only the rotation part of the [Basis] to a rotation around given axis by phi, while preserving the scaling part (as determined by get_scale).
|
||||
</description>
|
||||
</method>
|
||||
<method name="scaled">
|
||||
<return type="Basis">
|
||||
</return>
|
||||
|
@ -6941,6 +6969,15 @@
|
|||
Introduce an additional scaling specified by the given 3D scaling factor. Only relevant when the matrix is being used as a part of [Transform].
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_scale">
|
||||
<return type="Basis">
|
||||
</return>
|
||||
<argument index="0" name="scale" type="Vector3">
|
||||
</argument>
|
||||
<description>
|
||||
Changes only the scaling part of the Basis to the specified scaling, while preserving the rotation part (as determined by get_rotation).
|
||||
</description>
|
||||
</method>
|
||||
<method name="tdotx">
|
||||
<return type="float">
|
||||
</return>
|
||||
|
@ -35148,6 +35185,13 @@
|
|||
Returns a copy of the quaternion, normalized to unit length.
|
||||
</description>
|
||||
</method>
|
||||
<method name="is_normalized">
|
||||
<return type="bool">
|
||||
</return>
|
||||
<description>
|
||||
Returns whether the quaternion is normalized or not.
|
||||
</description>
|
||||
</method>
|
||||
<method name="slerp">
|
||||
<return type="Quat">
|
||||
</return>
|
||||
|
@ -48048,6 +48092,13 @@ do_property].
|
|||
Returns a normalized vector to unit length.
|
||||
</description>
|
||||
</method>
|
||||
<method name="is_normalized">
|
||||
<return type="bool">
|
||||
</return>
|
||||
<description>
|
||||
Returns whether the vector is normalized or not.
|
||||
</description>
|
||||
</method>
|
||||
<method name="reflect">
|
||||
<return type="Vector2">
|
||||
</return>
|
||||
|
@ -48272,6 +48323,13 @@ do_property].
|
|||
Return a copy of the normalized vector to unit length. This is the same as v / v.length().
|
||||
</description>
|
||||
</method>
|
||||
<method name="is_normalized">
|
||||
<return type="bool">
|
||||
</return>
|
||||
<description>
|
||||
Returns whether the vector is normalized or not.
|
||||
</description>
|
||||
</method>
|
||||
<method name="outer">
|
||||
<return type="Basis">
|
||||
</return>
|
||||
|
|
|
@ -602,7 +602,7 @@ MainLoop *test() {
|
|||
print_line(q3);
|
||||
|
||||
print_line("before v: " + v + " a: " + rtos(a));
|
||||
q.get_axis_and_angle(v, a);
|
||||
q.get_axis_angle(v, a);
|
||||
print_line("after v: " + v + " a: " + rtos(a));
|
||||
}
|
||||
|
||||
|
|
|
@ -1761,8 +1761,8 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons
|
|||
Vector3 v02, v01;
|
||||
real_t a02, a01;
|
||||
|
||||
r02.get_axis_and_angle(v02, a02);
|
||||
r01.get_axis_and_angle(v01, a01);
|
||||
r02.get_axis_angle(v02, a02);
|
||||
r01.get_axis_angle(v01, a01);
|
||||
|
||||
if (Math::abs(a02) > p_max_optimizable_angle)
|
||||
return false;
|
||||
|
|
|
@ -495,7 +495,7 @@ void BodySW::integrate_forces(real_t p_step) {
|
|||
Vector3 axis;
|
||||
real_t angle;
|
||||
|
||||
rot.get_axis_and_angle(axis, angle);
|
||||
rot.get_axis_angle(axis, angle);
|
||||
axis.normalize();
|
||||
angular_velocity = axis.normalized() * (angle / p_step);
|
||||
|
||||
|
@ -638,7 +638,7 @@ void BodySW::simulate_motion(const Transform& p_xform,real_t p_step) {
|
|||
Vector3 axis;
|
||||
real_t angle;
|
||||
|
||||
rot.get_axis_and_angle(axis,angle);
|
||||
rot.get_axis_angle(axis,angle);
|
||||
axis.normalize();
|
||||
angular_velocity=axis.normalized() * (angle/p_step);
|
||||
linear_velocity = (p_xform.origin - get_transform().origin)/p_step;
|
||||
|
|
Loading…
Reference in a new issue