2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _CQUATERNION
|
|
|
|
#define _CQUATERNION
|
2022-08-13 02:48:34 +00:00
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
2022-09-19 04:19:46 +00:00
|
|
|
#include "Kyoto/Math/CMatrix3f.hpp"
|
|
|
|
#include "Kyoto/Math/CTransform4f.hpp"
|
|
|
|
|
2022-10-03 04:49:11 +00:00
|
|
|
class CRelAngle;
|
|
|
|
class CUnitVector3f;
|
2022-10-17 23:53:49 +00:00
|
|
|
class CNUQuaternion;
|
2022-10-03 04:49:11 +00:00
|
|
|
|
2022-08-13 02:48:34 +00:00
|
|
|
class CQuaternion {
|
2022-08-14 18:38:41 +00:00
|
|
|
public:
|
2024-10-24 21:58:22 +00:00
|
|
|
CQuaternion(CInputStream& in);
|
2022-11-04 12:33:59 +00:00
|
|
|
CQuaternion(float w, float x, float y, float z) : w(w), imaginary(x, y, z) {}
|
2024-09-28 19:43:23 +00:00
|
|
|
CQuaternion(float w, const CVector3f& imaginary) : w(w), imaginary(imaginary) {}
|
2022-09-21 05:18:07 +00:00
|
|
|
|
2022-09-18 05:55:13 +00:00
|
|
|
// CQuaternion(const CQuaternion& other)
|
|
|
|
// : w(other.w)
|
|
|
|
// , x(other.x)
|
|
|
|
// , y(other.y)
|
|
|
|
// , z(other.z) {}
|
2022-09-21 05:18:07 +00:00
|
|
|
// CQuaternion& operator=(const CQuaternion& other) {
|
|
|
|
// w = other.w;
|
|
|
|
// x = other.x;
|
|
|
|
// y = other.y;
|
|
|
|
// z = other.z;
|
|
|
|
// }
|
2022-09-18 05:55:13 +00:00
|
|
|
|
2022-09-19 04:19:46 +00:00
|
|
|
CQuaternion operator*(const CQuaternion&) const;
|
2022-09-21 05:18:07 +00:00
|
|
|
// __amu__11CQuaternionFRC11CQuaternion
|
|
|
|
// ScalarVector__11CQuaternionFfRC9CVector3f
|
2022-09-19 04:19:46 +00:00
|
|
|
// Slerp__11CQuaternionFRC11CQuaternionRC11CQuaternionf
|
|
|
|
// ShortestRotationArc__11CQuaternionFRC9CVector3fRC9CVector3f
|
|
|
|
// LookAt__11CQuaternionFRC13CUnitVector3fRC13CUnitVector3fRC9CRelAngle
|
2022-11-11 12:55:40 +00:00
|
|
|
static CQuaternion LookAt(const CUnitVector3f&, const CUnitVector3f&, const CRelAngle&);
|
2022-09-19 04:19:46 +00:00
|
|
|
// normalize_angle__Ff
|
|
|
|
// IsValidQuaternion__11CQuaternionCFf
|
2022-11-26 13:51:04 +00:00
|
|
|
static CQuaternion SlerpLocal(const CQuaternion& from, const CQuaternion& to, float t);
|
2022-09-19 04:19:46 +00:00
|
|
|
// AngleFrom__11CQuaternionCFRC11CQuaternion
|
|
|
|
// BuildEquivalent__11CQuaternionCFv
|
|
|
|
// BuildNormalized__11CQuaternionCFv
|
2022-10-03 04:49:11 +00:00
|
|
|
static CQuaternion AxisAngle(const CUnitVector3f&, const CRelAngle&);
|
|
|
|
CVector3f Transform(const CVector3f&) const;
|
2022-11-14 13:37:44 +00:00
|
|
|
static CQuaternion XRotation(const CRelAngle&);
|
|
|
|
static CQuaternion YRotation(const CRelAngle&);
|
2022-10-24 23:29:11 +00:00
|
|
|
static CQuaternion ZRotation(const CRelAngle&);
|
2022-11-14 13:37:44 +00:00
|
|
|
CMatrix3f BuildTransform() const;
|
2022-09-19 04:19:46 +00:00
|
|
|
CTransform4f BuildTransform4f() const;
|
|
|
|
CTransform4f BuildTransform4f(const CVector3f&) const;
|
2022-10-03 04:49:11 +00:00
|
|
|
CQuaternion BuildInverted() const {
|
2022-10-09 05:37:23 +00:00
|
|
|
// double w = this->w;
|
|
|
|
// double x = -this->x;
|
|
|
|
// double y = -this->y;
|
|
|
|
// double z = -this->z;
|
2022-11-04 12:33:59 +00:00
|
|
|
return CQuaternion(w, -imaginary.GetX(), -imaginary.GetY(), -imaginary.GetZ());
|
2022-10-03 04:49:11 +00:00
|
|
|
}
|
2022-09-19 04:19:46 +00:00
|
|
|
|
|
|
|
static CQuaternion FromMatrixRows(const CVector3f&, const CVector3f&, const CVector3f&);
|
|
|
|
static CQuaternion FromMatrix(const CMatrix3f&);
|
|
|
|
static CQuaternion FromMatrix(const CTransform4f&);
|
2022-10-17 23:53:49 +00:00
|
|
|
static CQuaternion FromNUQuaternion(const CNUQuaternion&);
|
2022-09-19 04:19:46 +00:00
|
|
|
|
2022-09-18 05:55:13 +00:00
|
|
|
static const CQuaternion& NoRotation() { return sNoRotation; }
|
2022-08-14 18:38:41 +00:00
|
|
|
|
2022-10-16 22:49:37 +00:00
|
|
|
static float Dot(const CQuaternion& a, const CQuaternion& b) {
|
|
|
|
return (a.GetW() * b.GetW()) + (a.GetX() * b.GetX()) + (a.GetY() * b.GetY()) + (a.GetZ() * b.GetZ());
|
|
|
|
}
|
|
|
|
|
|
|
|
float GetW() const { return w; }
|
2022-11-04 12:33:59 +00:00
|
|
|
float GetX() const { return imaginary.GetX(); }
|
|
|
|
float GetY() const { return imaginary.GetY(); }
|
|
|
|
float GetZ() const { return imaginary.GetZ(); }
|
|
|
|
const CVector3f& GetImaginary() const { return imaginary; }
|
2022-10-16 22:49:37 +00:00
|
|
|
|
2022-08-13 02:48:34 +00:00
|
|
|
private:
|
2022-10-09 05:37:23 +00:00
|
|
|
float w;
|
2022-11-04 12:33:59 +00:00
|
|
|
CVector3f imaginary;
|
2022-09-18 05:55:13 +00:00
|
|
|
|
|
|
|
static const CQuaternion sNoRotation;
|
2022-08-13 02:48:34 +00:00
|
|
|
};
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _CQUATERNION
|