Rename Quat to Quaternion.

This commit is contained in:
Relintai 2023-05-31 15:39:37 +02:00
parent cbb15f8b7d
commit 8f369a0980
11 changed files with 122 additions and 122 deletions

View File

@ -39,7 +39,7 @@
namespace godot { namespace godot {
class Quat; class Quaternion;
class Basis { class Basis {
private: private:
@ -332,7 +332,7 @@ public:
return *this; return *this;
} }
Basis(const Quat &p_quaternion); // euler Basis(const Quaternion &p_quaternion); // euler
Basis(const Vector3 &p_euler); // euler Basis(const Vector3 &p_euler); // euler
Basis(const Vector3 &p_axis, real_t p_phi); Basis(const Vector3 &p_axis, real_t p_phi);
@ -450,7 +450,7 @@ public:
Basis diagonalize(); Basis diagonalize();
operator Quat() const; operator Quaternion() const;
}; };
} // namespace godot } // namespace godot

View File

@ -41,7 +41,7 @@
#include "NodePath.hpp" #include "NodePath.hpp"
#include "Plane.hpp" #include "Plane.hpp"
#include "PoolArrays.hpp" #include "PoolArrays.hpp"
#include "Quat.hpp" #include "Quaternion.hpp"
#include "RID.hpp" #include "RID.hpp"
#include "Rect2.hpp" #include "Rect2.hpp"
#include "String.hpp" #include "String.hpp"

View File

@ -423,18 +423,18 @@ struct _PropertyDefaultGetFunc {
template <class T, class P> template <class T, class P>
void register_property(const char *name, P(T::*var), P default_value, void register_property(const char *name, P(T::*var), P default_value,
pandemonium_method_rpc_mode rpc_mode = PANDEMONIUM_METHOD_RPC_MODE_DISABLED, pandemonium_method_rpc_mode rpc_mode = PANDEMONIUM_METHOD_RPC_MODE_DISABLED,
pandemonium_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, pandemonium_property_usage_flags usage = PANDEMONIUM_PROPERTY_USAGE_DEFAULT,
pandemonium_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "") { pandemonium_property_hint hint = PANDEMONIUM_PROPERTY_HINT_NONE, String hint_string = "") {
static_assert(T::___CLASS_IS_SCRIPT, "This function must only be used on custom classes"); static_assert(T::___CLASS_IS_SCRIPT, "This function must only be used on custom classes");
Variant def_val = default_value; Variant def_val = default_value;
usage = (pandemonium_property_usage_flags)((int)usage | GODOT_PROPERTY_USAGE_SCRIPT_VARIABLE); usage = (pandemonium_property_usage_flags)((int)usage | PANDEMONIUM_PROPERTY_USAGE_SCRIPT_VARIABLE);
if (def_val.get_type() == Variant::OBJECT) { if (def_val.get_type() == Variant::OBJECT) {
Object *o = detail::get_wrapper<Object>(def_val.operator pandemonium_object *()); Object *o = detail::get_wrapper<Object>(def_val.operator pandemonium_object *());
if (o && o->is_class("Resource")) { if (o && o->is_class("Resource")) {
hint = (pandemonium_property_hint)((int)hint | GODOT_PROPERTY_HINT_RESOURCE_TYPE); hint = (pandemonium_property_hint)((int)hint | PANDEMONIUM_PROPERTY_HINT_RESOURCE_TYPE);
hint_string = o->get_class(); hint_string = o->get_class();
} }
} }
@ -479,8 +479,8 @@ void register_property(const char *name, P(T::*var), P default_value,
template <class T, class P> template <class T, class P>
void register_property(const char *name, void (T::*setter)(P), P (T::*getter)(), P default_value, void register_property(const char *name, void (T::*setter)(P), P (T::*getter)(), P default_value,
pandemonium_method_rpc_mode rpc_mode = PANDEMONIUM_METHOD_RPC_MODE_DISABLED, pandemonium_method_rpc_mode rpc_mode = PANDEMONIUM_METHOD_RPC_MODE_DISABLED,
pandemonium_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, pandemonium_property_usage_flags usage = PANDEMONIUM_PROPERTY_USAGE_DEFAULT,
pandemonium_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "") { pandemonium_property_hint hint = PANDEMONIUM_PROPERTY_HINT_NONE, String hint_string = "") {
static_assert(T::___CLASS_IS_SCRIPT, "This function must only be used on custom classes"); static_assert(T::___CLASS_IS_SCRIPT, "This function must only be used on custom classes");
Variant def_val = default_value; Variant def_val = default_value;
@ -522,8 +522,8 @@ void register_property(const char *name, void (T::*setter)(P), P (T::*getter)(),
template <class T, class P> template <class T, class P>
void register_property(const char *name, void (T::*setter)(P), P (T::*getter)() const, P default_value, void register_property(const char *name, void (T::*setter)(P), P (T::*getter)() const, P default_value,
pandemonium_method_rpc_mode rpc_mode = PANDEMONIUM_METHOD_RPC_MODE_DISABLED, pandemonium_method_rpc_mode rpc_mode = PANDEMONIUM_METHOD_RPC_MODE_DISABLED,
pandemonium_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, pandemonium_property_usage_flags usage = PANDEMONIUM_PROPERTY_USAGE_DEFAULT,
pandemonium_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "") { pandemonium_property_hint hint = PANDEMONIUM_PROPERTY_HINT_NONE, String hint_string = "") {
register_property(name, setter, (P(T::*)())getter, default_value, rpc_mode, usage, hint, hint_string); register_property(name, setter, (P(T::*)())getter, default_value, rpc_mode, usage, hint, hint_string);
} }

View File

@ -1,5 +1,5 @@
/*************************************************************************/ /*************************************************************************/
/* Quat.hpp */ /* Quaternion.hpp */
/*************************************************************************/ /*************************************************************************/
/* This file is part of: */ /* This file is part of: */
/* GODOT ENGINE */ /* GODOT ENGINE */
@ -39,9 +39,9 @@
namespace godot { namespace godot {
class Quat { class Quaternion {
public: public:
static const Quat IDENTITY; static const Quaternion IDENTITY;
real_t x, y, z, w; real_t x, y, z, w;
@ -50,11 +50,11 @@ public:
void normalize(); void normalize();
Quat normalized() const; Quaternion normalized() const;
bool is_normalized() const; bool is_normalized() const;
Quat inverse() const; Quaternion inverse() const;
void set_euler_xyz(const Vector3 &p_euler); void set_euler_xyz(const Vector3 &p_euler);
Vector3 get_euler_xyz() const; Vector3 get_euler_xyz() const;
@ -64,37 +64,37 @@ public:
inline void set_euler(const Vector3 &p_euler) { set_euler_yxz(p_euler); } inline void set_euler(const Vector3 &p_euler) { set_euler_yxz(p_euler); }
inline Vector3 get_euler() const { return get_euler_yxz(); } inline Vector3 get_euler() const { return get_euler_yxz(); }
real_t dot(const Quat &q) const; real_t dot(const Quaternion &q) const;
Quat slerp(const Quat &q, const real_t &t) const; Quaternion slerp(const Quaternion &q, const real_t &t) const;
Quat slerpni(const Quat &q, const real_t &t) const; Quaternion slerpni(const Quaternion &q, const real_t &t) const;
Quat cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const real_t &t) const; Quaternion cubic_slerp(const Quaternion &q, const Quaternion &prep, const Quaternion &postq, const real_t &t) const;
void get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const; void get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const;
void set_axis_angle(const Vector3 &axis, const float angle); void set_axis_angle(const Vector3 &axis, const float angle);
void operator*=(const Quat &q); void operator*=(const Quaternion &q);
Quat operator*(const Quat &q) const; Quaternion operator*(const Quaternion &q) const;
Quat operator*(const Vector3 &v) const; Quaternion operator*(const Vector3 &v) const;
Vector3 xform(const Vector3 &v) const; Vector3 xform(const Vector3 &v) const;
void operator+=(const Quat &q); void operator+=(const Quaternion &q);
void operator-=(const Quat &q); void operator-=(const Quaternion &q);
void operator*=(const real_t &s); void operator*=(const real_t &s);
void operator/=(const real_t &s); void operator/=(const real_t &s);
Quat operator+(const Quat &q2) const; Quaternion operator+(const Quaternion &q2) const;
Quat operator-(const Quat &q2) const; Quaternion operator-(const Quaternion &q2) const;
Quat operator-() const; Quaternion operator-() const;
Quat operator*(const real_t &s) const; Quaternion operator*(const real_t &s) const;
Quat operator/(const real_t &s) const; Quaternion operator/(const real_t &s) const;
bool operator==(const Quat &p_quaternion) const; bool operator==(const Quaternion &p_quaternion) const;
bool operator!=(const Quat &p_quaternion) const; bool operator!=(const Quaternion &p_quaternion) const;
operator String() const; operator String() const;
@ -104,17 +104,17 @@ public:
z = p_z; z = p_z;
w = p_w; w = p_w;
} }
inline Quat(real_t p_x, real_t p_y, real_t p_z, real_t p_w) { inline Quaternion(real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
x = p_x; x = p_x;
y = p_y; y = p_y;
z = p_z; z = p_z;
w = p_w; w = p_w;
} }
Quat(const Vector3 &axis, const real_t &angle); Quaternion(const Vector3 &axis, const real_t &angle);
Quat(const Vector3 &v0, const Vector3 &v1); Quaternion(const Vector3 &v0, const Vector3 &v1);
inline Quat() { inline Quaternion() {
x = y = z = 0; x = y = z = 0;
w = 1; w = 1;
} }

View File

@ -84,8 +84,8 @@ public:
static String md5(const uint8_t *p_md5); static String md5(const uint8_t *p_md5);
static String hex_encode_buffer(const uint8_t *p_buffer, int p_len); static String hex_encode_buffer(const uint8_t *p_buffer, int p_len);
wchar_t &operator[](const int idx); char32_t &operator[](const int idx);
wchar_t operator[](const int idx) const; char32_t operator[](const int idx) const;
void operator=(const String &s); void operator=(const String &s);
void operator=(String &&s); void operator=(String &&s);
@ -93,7 +93,7 @@ public:
bool operator!=(const String &s) const; bool operator!=(const String &s) const;
String operator+(const String &s) const; String operator+(const String &s) const;
void operator+=(const String &s); void operator+=(const String &s);
void operator+=(const wchar_t c); void operator+=(const char32_t c);
bool operator<(const String &s) const; bool operator<(const String &s) const;
bool operator<=(const String &s) const; bool operator<=(const String &s) const;
bool operator>(const String &s) const; bool operator>(const String &s) const;
@ -102,7 +102,7 @@ public:
operator NodePath() const; operator NodePath() const;
int length() const; int length() const;
const wchar_t *unicode_str() const; const char32_t *unicode_str() const;
char *alloc_c_string() const; char *alloc_c_string() const;
CharString utf8() const; CharString utf8() const;
CharString ascii(bool p_extended = false) const; CharString ascii(bool p_extended = false) const;

View File

@ -41,7 +41,7 @@
#include "NodePath.hpp" #include "NodePath.hpp"
#include "Plane.hpp" #include "Plane.hpp"
#include "PoolArrays.hpp" #include "PoolArrays.hpp"
#include "Quat.hpp" #include "Quaternion.hpp"
#include "RID.hpp" #include "RID.hpp"
#include "Rect2.hpp" #include "Rect2.hpp"
#include "String.hpp" #include "String.hpp"
@ -203,7 +203,7 @@ public:
Variant(const godot::AABB &p_aabb); Variant(const godot::AABB &p_aabb);
Variant(const Quat &p_quaternion); Variant(const Quaternion &p_quaternion);
Variant(const Basis &p_transform); Variant(const Basis &p_transform);
@ -261,7 +261,7 @@ public:
operator Vector3() const; operator Vector3() const;
operator Plane() const; operator Plane() const;
operator godot::AABB() const; operator godot::AABB() const;
operator Quat() const; operator Quaternion() const;
operator Basis() const; operator Basis() const;
operator Transform() const; operator Transform() const;
operator Transform2D() const; operator Transform2D() const;

View File

@ -30,7 +30,7 @@
#include "Basis.hpp" #include "Basis.hpp"
#include "Defs.hpp" #include "Defs.hpp"
#include "Quat.hpp" #include "Quaternion.hpp"
#include "Vector3.hpp" #include "Vector3.hpp"
#include <algorithm> #include <algorithm>
@ -172,7 +172,7 @@ Vector3 Basis::get_scale() const {
// We are assuming M = R.S, and performing a polar decomposition to extract R and S. // We are assuming M = R.S, and performing a polar decomposition to extract R and S.
// FIXME: We eventually need a proper polar decomposition. // 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 // 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. // (such that it can be represented by a Quaternion or Euler angles), we absorb the sign flip into the scaling matrix.
// As such, it works in conjuction with get_rotation(). // As such, it works in conjuction with get_rotation().
real_t det_sign = determinant() > 0 ? 1 : -1; real_t det_sign = determinant() > 0 ? 1 : -1;
return det_sign * Vector3( return det_sign * Vector3(
@ -185,8 +185,8 @@ Vector3 Basis::get_scale() const {
Basis Basis::slerp(Basis b, float t) const { Basis Basis::slerp(Basis b, float t) const {
ERR_FAIL_COND_V(!is_rotation(), Basis()); ERR_FAIL_COND_V(!is_rotation(), Basis());
ERR_FAIL_COND_V(!b.is_rotation(), Basis()); ERR_FAIL_COND_V(!b.is_rotation(), Basis());
Quat from(*this); Quaternion from(*this);
Quat to(b); Quaternion to(b);
return Basis(from.slerp(to, t)); return Basis(from.slerp(to, t));
} }
@ -636,11 +636,11 @@ Basis::Basis(const Vector3 &p_euler) {
} // namespace godot } // namespace godot
#include "Quat.hpp" #include "Quaternion.hpp"
namespace godot { namespace godot {
Basis::Basis(const Quat &p_quaternion) { Basis::Basis(const Quaternion &p_quaternion) {
real_t d = p_quaternion.length_squared(); real_t d = p_quaternion.length_squared();
real_t s = 2.0 / d; real_t s = 2.0 / d;
real_t xs = p_quaternion.x * s, ys = p_quaternion.y * s, zs = p_quaternion.z * s; real_t xs = p_quaternion.x * s, ys = p_quaternion.y * s, zs = p_quaternion.z * s;
@ -673,9 +673,9 @@ Basis::Basis(const Vector3 &p_axis, real_t p_phi) {
elements[2][2] = axis_sq.z + cosine * (1.0 - axis_sq.z); elements[2][2] = axis_sq.z + cosine * (1.0 - axis_sq.z);
} }
Basis::operator Quat() const { Basis::operator Quaternion() const {
//commenting this check because precision issues cause it to fail when it shouldn't //commenting this check because precision issues cause it to fail when it shouldn't
//ERR_FAIL_COND_V(is_rotation() == false, Quat()); //ERR_FAIL_COND_V(is_rotation() == false, Quaternion());
real_t trace = elements[0][0] + elements[1][1] + elements[2][2]; real_t trace = elements[0][0] + elements[1][1] + elements[2][2];
real_t temp[4]; real_t temp[4];
@ -704,7 +704,7 @@ Basis::operator Quat() const {
temp[k] = (elements[k][i] + elements[i][k]) * s; temp[k] = (elements[k][i] + elements[i][k]) * s;
} }
return Quat(temp[0], temp[1], temp[2], temp[3]); return Quaternion(temp[0], temp[1], temp[2], temp[3]);
} }
} // namespace godot } // namespace godot

View File

@ -1,5 +1,5 @@
/*************************************************************************/ /*************************************************************************/
/* Quat.cpp */ /* Quaternion.cpp */
/*************************************************************************/ /*************************************************************************/
/* This file is part of: */ /* This file is part of: */
/* GODOT ENGINE */ /* GODOT ENGINE */
@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#include "Quat.hpp" #include "Quaternion.hpp"
#include "Basis.hpp" #include "Basis.hpp"
#include "Defs.hpp" #include "Defs.hpp"
#include "Vector3.hpp" #include "Vector3.hpp"
@ -37,13 +37,13 @@
namespace godot { namespace godot {
const Quat Quat::IDENTITY = Quat(); const Quaternion Quaternion::IDENTITY = Quaternion();
// set_euler_xyz expects a vector containing the Euler angles in the format // set_euler_xyz expects a vector containing the Euler angles in the format
// (ax,ay,az), where ax is the angle of rotation around x axis, // (ax,ay,az), where ax is the angle of rotation around x axis,
// and similar for other axes. // and similar for other axes.
// This implementation uses XYZ convention (Z is the first rotation). // This implementation uses XYZ convention (Z is the first rotation).
void Quat::set_euler_xyz(const Vector3 &p_euler) { void Quaternion::set_euler_xyz(const Vector3 &p_euler) {
real_t half_a1 = p_euler.x * 0.5; real_t half_a1 = p_euler.x * 0.5;
real_t half_a2 = p_euler.y * 0.5; real_t half_a2 = p_euler.y * 0.5;
real_t half_a3 = p_euler.z * 0.5; real_t half_a3 = p_euler.z * 0.5;
@ -69,7 +69,7 @@ void Quat::set_euler_xyz(const Vector3 &p_euler) {
// (ax,ay,az), where ax is the angle of rotation around x axis, // (ax,ay,az), where ax is the angle of rotation around x axis,
// and similar for other axes. // and similar for other axes.
// This implementation uses XYZ convention (Z is the first rotation). // This implementation uses XYZ convention (Z is the first rotation).
Vector3 Quat::get_euler_xyz() const { Vector3 Quaternion::get_euler_xyz() const {
Basis m(*this); Basis m(*this);
return m.get_euler_xyz(); return m.get_euler_xyz();
} }
@ -78,7 +78,7 @@ Vector3 Quat::get_euler_xyz() const {
// (ax,ay,az), where ax is the angle of rotation around x axis, // (ax,ay,az), where ax is the angle of rotation around x axis,
// and similar for other axes. // and similar for other axes.
// This implementation uses YXZ convention (Z is the first rotation). // This implementation uses YXZ convention (Z is the first rotation).
void Quat::set_euler_yxz(const Vector3 &p_euler) { void Quaternion::set_euler_yxz(const Vector3 &p_euler) {
real_t half_a1 = p_euler.y * 0.5; real_t half_a1 = p_euler.y * 0.5;
real_t half_a2 = p_euler.x * 0.5; real_t half_a2 = p_euler.x * 0.5;
real_t half_a3 = p_euler.z * 0.5; real_t half_a3 = p_euler.z * 0.5;
@ -104,33 +104,33 @@ void Quat::set_euler_yxz(const Vector3 &p_euler) {
// (ax,ay,az), where ax is the angle of rotation around x axis, // (ax,ay,az), where ax is the angle of rotation around x axis,
// and similar for other axes. // and similar for other axes.
// This implementation uses YXZ convention (Z is the first rotation). // This implementation uses YXZ convention (Z is the first rotation).
Vector3 Quat::get_euler_yxz() const { Vector3 Quaternion::get_euler_yxz() const {
Basis m(*this); Basis m(*this);
return m.get_euler_yxz(); return m.get_euler_yxz();
} }
real_t Quat::length() const { real_t Quaternion::length() const {
return ::sqrt(length_squared()); return ::sqrt(length_squared());
} }
void Quat::normalize() { void Quaternion::normalize() {
*this /= length(); *this /= length();
} }
Quat Quat::normalized() const { Quaternion Quaternion::normalized() const {
return *this / length(); return *this / length();
} }
bool Quat::is_normalized() const { bool Quaternion::is_normalized() const {
return std::abs(length_squared() - 1.0) < 0.00001; return std::abs(length_squared() - 1.0) < 0.00001;
} }
Quat Quat::inverse() const { Quaternion Quaternion::inverse() const {
return Quat(-x, -y, -z, w); return Quaternion(-x, -y, -z, w);
} }
Quat Quat::slerp(const Quat &q, const real_t &t) const { Quaternion Quaternion::slerp(const Quaternion &q, const real_t &t) const {
Quat to1; Quaternion to1;
real_t omega, cosom, sinom, scale0, scale1; real_t omega, cosom, sinom, scale0, scale1;
// calc cosine // calc cosine
@ -165,15 +165,15 @@ Quat Quat::slerp(const Quat &q, const real_t &t) const {
scale1 = t; scale1 = t;
} }
// calculate final values // calculate final values
return Quat( return Quaternion(
scale0 * x + scale1 * to1.x, scale0 * x + scale1 * to1.x,
scale0 * y + scale1 * to1.y, scale0 * y + scale1 * to1.y,
scale0 * z + scale1 * to1.z, scale0 * z + scale1 * to1.z,
scale0 * w + scale1 * to1.w); scale0 * w + scale1 * to1.w);
} }
Quat Quat::slerpni(const Quat &q, const real_t &t) const { Quaternion Quaternion::slerpni(const Quaternion &q, const real_t &t) const {
const Quat &from = *this; const Quaternion &from = *this;
real_t dot = from.dot(q); real_t dot = from.dot(q);
@ -185,28 +185,28 @@ Quat Quat::slerpni(const Quat &q, const real_t &t) const {
newFactor = ::sin(t * theta) * sinT, newFactor = ::sin(t * theta) * sinT,
invFactor = ::sin((1.0 - t) * theta) * sinT; invFactor = ::sin((1.0 - t) * theta) * sinT;
return Quat(invFactor * from.x + newFactor * q.x, return Quaternion(invFactor * from.x + newFactor * q.x,
invFactor * from.y + newFactor * q.y, invFactor * from.y + newFactor * q.y,
invFactor * from.z + newFactor * q.z, invFactor * from.z + newFactor * q.z,
invFactor * from.w + newFactor * q.w); invFactor * from.w + newFactor * q.w);
} }
Quat Quat::cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const real_t &t) const { Quaternion Quaternion::cubic_slerp(const Quaternion &q, const Quaternion &prep, const Quaternion &postq, const real_t &t) const {
//the only way to do slerp :| //the only way to do slerp :|
real_t t2 = (1.0 - t) * t * 2; real_t t2 = (1.0 - t) * t * 2;
Quat sp = this->slerp(q, t); Quaternion sp = this->slerp(q, t);
Quat sq = prep.slerpni(postq, t); Quaternion sq = prep.slerpni(postq, t);
return sp.slerpni(sq, t2); return sp.slerpni(sq, t2);
} }
void Quat::get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const { void Quaternion::get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const {
r_angle = 2 * ::acos(w); r_angle = 2 * ::acos(w);
r_axis.x = x / ::sqrt(1 - w * w); r_axis.x = x / ::sqrt(1 - w * w);
r_axis.y = y / ::sqrt(1 - w * w); r_axis.y = y / ::sqrt(1 - w * w);
r_axis.z = z / ::sqrt(1 - w * w); r_axis.z = z / ::sqrt(1 - w * w);
} }
void Quat::set_axis_angle(const Vector3 &axis, const float angle) { void Quaternion::set_axis_angle(const Vector3 &axis, const float angle) {
ERR_FAIL_COND(!axis.is_normalized()); ERR_FAIL_COND(!axis.is_normalized());
real_t d = axis.length(); real_t d = axis.length();
@ -221,24 +221,24 @@ void Quat::set_axis_angle(const Vector3 &axis, const float angle) {
} }
} }
Quat Quat::operator*(const Vector3 &v) const { Quaternion Quaternion::operator*(const Vector3 &v) const {
return Quat(w * v.x + y * v.z - z * v.y, return Quaternion(w * v.x + y * v.z - z * v.y,
w * v.y + z * v.x - x * v.z, w * v.y + z * v.x - x * v.z,
w * v.z + x * v.y - y * v.x, w * v.z + x * v.y - y * v.x,
-x * v.x - y * v.y - z * v.z); -x * v.x - y * v.y - z * v.z);
} }
Vector3 Quat::xform(const Vector3 &v) const { Vector3 Quaternion::xform(const Vector3 &v) const {
Quat q = *this * v; Quaternion q = *this * v;
q *= this->inverse(); q *= this->inverse();
return Vector3(q.x, q.y, q.z); return Vector3(q.x, q.y, q.z);
} }
Quat::operator String() const { Quaternion::operator String() const {
return String(); // @Todo return String(); // @Todo
} }
Quat::Quat(const Vector3 &axis, const real_t &angle) { Quaternion::Quaternion(const Vector3 &axis, const real_t &angle) {
real_t d = axis.length(); real_t d = axis.length();
if (d == 0) if (d == 0)
set(0, 0, 0, 0); set(0, 0, 0, 0);
@ -251,7 +251,7 @@ Quat::Quat(const Vector3 &axis, const real_t &angle) {
} }
} }
Quat::Quat(const Vector3 &v0, const Vector3 &v1) // shortest arc Quaternion::Quaternion(const Vector3 &v0, const Vector3 &v1) // shortest arc
{ {
Vector3 c = v0.cross(v1); Vector3 c = v0.cross(v1);
real_t d = v0.dot(v1); real_t d = v0.dot(v1);
@ -272,80 +272,80 @@ Quat::Quat(const Vector3 &v0, const Vector3 &v1) // shortest arc
} }
} }
real_t Quat::dot(const Quat &q) const { real_t Quaternion::dot(const Quaternion &q) const {
return x * q.x + y * q.y + z * q.z + w * q.w; return x * q.x + y * q.y + z * q.z + w * q.w;
} }
real_t Quat::length_squared() const { real_t Quaternion::length_squared() const {
return dot(*this); return dot(*this);
} }
void Quat::operator+=(const Quat &q) { void Quaternion::operator+=(const Quaternion &q) {
x += q.x; x += q.x;
y += q.y; y += q.y;
z += q.z; z += q.z;
w += q.w; w += q.w;
} }
void Quat::operator-=(const Quat &q) { void Quaternion::operator-=(const Quaternion &q) {
x -= q.x; x -= q.x;
y -= q.y; y -= q.y;
z -= q.z; z -= q.z;
w -= q.w; w -= q.w;
} }
void Quat::operator*=(const Quat &q) { void Quaternion::operator*=(const Quaternion &q) {
set(w * q.x + x * q.w + y * q.z - z * q.y, 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.y + y * q.w + z * q.x - x * q.z,
w * q.z + z * q.w + x * q.y - y * q.x, w * q.z + z * q.w + x * q.y - y * q.x,
w * q.w - x * q.x - y * q.y - z * q.z); w * q.w - x * q.x - y * q.y - z * q.z);
} }
void Quat::operator*=(const real_t &s) { void Quaternion::operator*=(const real_t &s) {
x *= s; x *= s;
y *= s; y *= s;
z *= s; z *= s;
w *= s; w *= s;
} }
void Quat::operator/=(const real_t &s) { void Quaternion::operator/=(const real_t &s) {
*this *= 1.0 / s; *this *= 1.0 / s;
} }
Quat Quat::operator+(const Quat &q2) const { Quaternion Quaternion::operator+(const Quaternion &q2) const {
const Quat &q1 = *this; const Quaternion &q1 = *this;
return Quat(q1.x + q2.x, q1.y + q2.y, q1.z + q2.z, q1.w + q2.w); return Quaternion(q1.x + q2.x, q1.y + q2.y, q1.z + q2.z, q1.w + q2.w);
} }
Quat Quat::operator-(const Quat &q2) const { Quaternion Quaternion::operator-(const Quaternion &q2) const {
const Quat &q1 = *this; const Quaternion &q1 = *this;
return Quat(q1.x - q2.x, q1.y - q2.y, q1.z - q2.z, q1.w - q2.w); return Quaternion(q1.x - q2.x, q1.y - q2.y, q1.z - q2.z, q1.w - q2.w);
} }
Quat Quat::operator*(const Quat &q2) const { Quaternion Quaternion::operator*(const Quaternion &q2) const {
Quat q1 = *this; Quaternion q1 = *this;
q1 *= q2; q1 *= q2;
return q1; return q1;
} }
Quat Quat::operator-() const { Quaternion Quaternion::operator-() const {
const Quat &q2 = *this; const Quaternion &q2 = *this;
return Quat(-q2.x, -q2.y, -q2.z, -q2.w); return Quaternion(-q2.x, -q2.y, -q2.z, -q2.w);
} }
Quat Quat::operator*(const real_t &s) const { Quaternion Quaternion::operator*(const real_t &s) const {
return Quat(x * s, y * s, z * s, w * s); return Quaternion(x * s, y * s, z * s, w * s);
} }
Quat Quat::operator/(const real_t &s) const { Quaternion Quaternion::operator/(const real_t &s) const {
return *this * (1.0 / s); return *this * (1.0 / s);
} }
bool Quat::operator==(const Quat &p_quaternion) const { bool Quaternion::operator==(const Quaternion &p_quaternion) const {
return x == p_quaternion.x && y == p_quaternion.y && z == p_quaternion.z && w == p_quaternion.w; return x == p_quaternion.x && y == p_quaternion.y && z == p_quaternion.z && w == p_quaternion.w;
} }
bool Quat::operator!=(const Quat &p_quaternion) const { bool Quaternion::operator!=(const Quaternion &p_quaternion) const {
return x != p_quaternion.x || y != p_quaternion.y || z != p_quaternion.z || w != p_quaternion.w; return x != p_quaternion.x || y != p_quaternion.y || z != p_quaternion.z || w != p_quaternion.w;
} }

View File

@ -111,11 +111,11 @@ String::~String() {
godot::api->pandemonium_string_destroy(&_pandemonium_string); godot::api->pandemonium_string_destroy(&_pandemonium_string);
} }
wchar_t &String::operator[](const int idx) { char32_t &String::operator[](const int idx) {
return *const_cast<wchar_t *>(godot::api->pandemonium_string_operator_index(&_pandemonium_string, idx)); return *const_cast<char32_t *>(godot::api->pandemonium_string_operator_index(&_pandemonium_string, idx));
} }
wchar_t String::operator[](const int idx) const { char32_t String::operator[](const int idx) const {
return *godot::api->pandemonium_string_operator_index((pandemonium_string *)&_pandemonium_string, idx); return *godot::api->pandemonium_string_operator_index((pandemonium_string *)&_pandemonium_string, idx);
} }
@ -149,7 +149,7 @@ void String::operator+=(const String &s) {
*this = String(godot::api->pandemonium_string_operator_plus(&_pandemonium_string, &s._pandemonium_string)); *this = String(godot::api->pandemonium_string_operator_plus(&_pandemonium_string, &s._pandemonium_string));
} }
void String::operator+=(const wchar_t c) { void String::operator+=(const char32_t c) {
String _to_be_added = String(c); String _to_be_added = String(c);
*this = String(godot::api->pandemonium_string_operator_plus(&_pandemonium_string, &_to_be_added._pandemonium_string)); *this = String(godot::api->pandemonium_string_operator_plus(&_pandemonium_string, &_to_be_added._pandemonium_string));
} }
@ -175,8 +175,8 @@ String::operator NodePath() const {
return NodePath(*this); return NodePath(*this);
} }
const wchar_t *String::unicode_str() const { const char32_t *String::unicode_str() const {
return godot::api->pandemonium_string_wide_str(&_pandemonium_string); return godot::api->pandemonium_string_get_data(&_pandemonium_string);
} }
char *String::alloc_c_string() const { char *String::alloc_c_string() const {
@ -431,8 +431,8 @@ float String::similarity(String text) const {
// TODO Suport allow_empty // TODO Suport allow_empty
PoolStringArray String::split(String divisor, bool /*allow_empty*/) const { PoolStringArray String::split(String divisor, bool /*allow_empty*/) const {
pandemonium_array arr = godot::api->pandemonium_string_split(&_pandemonium_string, &divisor._pandemonium_string); pandemonium_pool_string_array arr = godot::api->pandemonium_string_split(&_pandemonium_string, &divisor._pandemonium_string);
return Array(arr); return PoolStringArray(arr);
} }
// TODO Suport allow_empty // TODO Suport allow_empty
@ -500,7 +500,7 @@ String String::dedent() const {
PoolStringArray String::rsplit(const String &divisor, const bool allow_empty, const int maxsplit) const { PoolStringArray String::rsplit(const String &divisor, const bool allow_empty, const int maxsplit) const {
pandemonium_pool_string_array arr = pandemonium_pool_string_array arr =
godot::api->pandemonium_string_rsplit(&_pandemonium_string, &divisor._pandemonium_string, allow_empty, maxsplit); godot::api->pandemonium_string_rsplit_maxsplit(&_pandemonium_string, &divisor._pandemonium_string, allow_empty, maxsplit);
return PoolStringArray(arr); return PoolStringArray(arr);
} }

View File

@ -35,7 +35,7 @@
#include "AABB.hpp" #include "AABB.hpp"
#include "Plane.hpp" #include "Plane.hpp"
#include "Quat.hpp" #include "Quaternion.hpp"
namespace godot { namespace godot {
@ -220,11 +220,11 @@ Transform Transform::interpolate_with(const Transform &p_transform, real_t p_c)
/* not sure if very "efficient" but good enough? */ /* not sure if very "efficient" but good enough? */
Vector3 src_scale = basis.get_scale(); Vector3 src_scale = basis.get_scale();
Quat src_rot = basis; Quaternion src_rot = basis;
Vector3 src_loc = origin; Vector3 src_loc = origin;
Vector3 dst_scale = p_transform.basis.get_scale(); Vector3 dst_scale = p_transform.basis.get_scale();
Quat dst_rot = p_transform.basis; Quaternion dst_rot = p_transform.basis;
Vector3 dst_loc = p_transform.origin; Vector3 dst_loc = p_transform.origin;
Transform dst; Transform dst;

View File

@ -120,7 +120,7 @@ Variant::Variant(const godot::AABB &p_aabb) {
godot::api->pandemonium_variant_new_aabb(&_pandemonium_variant, (pandemonium_aabb *)&p_aabb); godot::api->pandemonium_variant_new_aabb(&_pandemonium_variant, (pandemonium_aabb *)&p_aabb);
} }
Variant::Variant(const Quat &p_quaternion) { Variant::Variant(const Quaternion &p_quaternion) {
godot::api->pandemonium_variant_new_quaternion(&_pandemonium_variant, (pandemonium_quaternion *)&p_quaternion); godot::api->pandemonium_variant_new_quaternion(&_pandemonium_variant, (pandemonium_quaternion *)&p_quaternion);
} }
@ -265,9 +265,9 @@ Variant::operator godot::AABB() const {
pandemonium_aabb s = godot::api->pandemonium_variant_as_aabb(&_pandemonium_variant); pandemonium_aabb s = godot::api->pandemonium_variant_as_aabb(&_pandemonium_variant);
return *(godot::AABB *)&s; return *(godot::AABB *)&s;
} }
Variant::operator Quat() const { Variant::operator Quaternion() const {
pandemonium_quaternion s = godot::api->pandemonium_variant_as_quaternion(&_pandemonium_variant); pandemonium_quaternion s = godot::api->pandemonium_variant_as_quaternion(&_pandemonium_variant);
return *(Quat *)&s; return *(Quaternion *)&s;
} }
Variant::operator Basis() const { Variant::operator Basis() const {
pandemonium_basis s = godot::api->pandemonium_variant_as_basis(&_pandemonium_variant); pandemonium_basis s = godot::api->pandemonium_variant_as_basis(&_pandemonium_variant);