2021-08-02 16:34:47 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* Quat.hpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2017-03-03 02:14:34 +00:00
|
|
|
#ifndef QUAT_H
|
|
|
|
#define QUAT_H
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
2017-03-06 07:49:24 +00:00
|
|
|
#include "Vector3.hpp"
|
2017-03-03 02:14:34 +00:00
|
|
|
|
2017-03-03 02:39:56 +00:00
|
|
|
// #include "Basis.h"
|
|
|
|
|
2017-03-03 02:14:34 +00:00
|
|
|
namespace godot {
|
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
class Quat {
|
2017-03-03 02:14:34 +00:00
|
|
|
public:
|
2020-12-08 23:00:34 +00:00
|
|
|
static const Quat IDENTITY;
|
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
real_t x, y, z, w;
|
2017-03-03 02:14:34 +00:00
|
|
|
|
2017-03-06 02:30:46 +00:00
|
|
|
real_t length_squared() const;
|
|
|
|
real_t length() const;
|
2017-03-03 02:39:56 +00:00
|
|
|
|
2017-03-06 02:30:46 +00:00
|
|
|
void normalize();
|
2017-03-03 02:39:56 +00:00
|
|
|
|
2017-03-06 02:30:46 +00:00
|
|
|
Quat normalized() const;
|
2017-03-03 02:39:56 +00:00
|
|
|
|
2019-05-22 09:06:01 +00:00
|
|
|
bool is_normalized() const;
|
|
|
|
|
2017-03-06 02:30:46 +00:00
|
|
|
Quat inverse() const;
|
2017-03-03 02:39:56 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
void set_euler_xyz(const Vector3 &p_euler);
|
2018-01-22 23:24:23 +00:00
|
|
|
Vector3 get_euler_xyz() const;
|
2018-11-23 22:09:41 +00:00
|
|
|
void set_euler_yxz(const Vector3 &p_euler);
|
2018-01-22 23:24:23 +00:00
|
|
|
Vector3 get_euler_yxz() const;
|
2017-03-03 02:39:56 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
inline void set_euler(const Vector3 &p_euler) { set_euler_yxz(p_euler); }
|
2018-01-22 23:24:23 +00:00
|
|
|
inline Vector3 get_euler() const { return get_euler_yxz(); }
|
2017-03-03 02:39:56 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
real_t dot(const Quat &q) const;
|
2017-03-03 02:14:34 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
Quat slerp(const Quat &q, const real_t &t) const;
|
2017-03-03 02:14:34 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
Quat slerpni(const Quat &q, const real_t &t) const;
|
2017-03-03 02:14:34 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
Quat cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const real_t &t) const;
|
2017-03-03 02:14:34 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
void get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const;
|
2017-03-03 02:14:34 +00:00
|
|
|
|
2019-05-22 09:06:01 +00:00
|
|
|
void set_axis_angle(const Vector3 &axis, const float angle);
|
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
void operator*=(const Quat &q);
|
|
|
|
Quat operator*(const Quat &q) const;
|
2017-03-03 02:14:34 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
Quat operator*(const Vector3 &v) const;
|
2017-03-03 02:14:34 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
Vector3 xform(const Vector3 &v) const;
|
2017-03-03 02:14:34 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
void operator+=(const Quat &q);
|
|
|
|
void operator-=(const Quat &q);
|
|
|
|
void operator*=(const real_t &s);
|
|
|
|
void operator/=(const real_t &s);
|
|
|
|
Quat operator+(const Quat &q2) const;
|
|
|
|
Quat operator-(const Quat &q2) const;
|
2017-03-03 02:14:34 +00:00
|
|
|
Quat operator-() const;
|
2018-11-23 22:09:41 +00:00
|
|
|
Quat operator*(const real_t &s) const;
|
|
|
|
Quat operator/(const real_t &s) const;
|
2017-03-03 02:14:34 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
bool operator==(const Quat &p_quat) const;
|
|
|
|
bool operator!=(const Quat &p_quat) const;
|
2017-03-03 02:14:34 +00:00
|
|
|
|
2017-03-06 02:30:46 +00:00
|
|
|
operator String() const;
|
2017-03-03 02:14:34 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
inline void set(real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
|
|
|
|
x = p_x;
|
|
|
|
y = p_y;
|
|
|
|
z = p_z;
|
|
|
|
w = p_w;
|
2017-03-03 02:14:34 +00:00
|
|
|
}
|
|
|
|
inline Quat(real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
|
2018-11-23 22:09:41 +00:00
|
|
|
x = p_x;
|
|
|
|
y = p_y;
|
|
|
|
z = p_z;
|
|
|
|
w = p_w;
|
2017-03-03 02:14:34 +00:00
|
|
|
}
|
2018-11-23 22:09:41 +00:00
|
|
|
Quat(const Vector3 &axis, const real_t &angle);
|
2017-03-03 02:14:34 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
Quat(const Vector3 &v0, const Vector3 &v1);
|
2017-03-03 02:14:34 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
inline Quat() {
|
|
|
|
x = y = z = 0;
|
|
|
|
w = 1;
|
|
|
|
}
|
2017-03-03 02:14:34 +00:00
|
|
|
};
|
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
} // namespace godot
|
2017-03-03 02:14:34 +00:00
|
|
|
|
|
|
|
#endif // QUAT_H
|