Move some quaternion functions in-header

This commit is contained in:
Jack Andersen 2019-06-14 14:38:56 -10:00
parent c81eb93b6d
commit 48073c783b
2 changed files with 30 additions and 54 deletions

View File

@ -67,31 +67,46 @@ public:
void fromVector3f(const CVector3f& vec); void fromVector3f(const CVector3f& vec);
CQuaternion& operator=(const CQuaternion& q); CQuaternion& operator=(const CQuaternion& q) {
mSimd = q.mSimd;
return *this;
}
CQuaternion operator+(const CQuaternion& q) const; CQuaternion operator+(const CQuaternion& q) const { return mSimd + q.mSimd; }
CQuaternion operator-(const CQuaternion& q) const; CQuaternion operator-(const CQuaternion& q) const { return mSimd - q.mSimd; }
CQuaternion operator*(const CQuaternion& q) const; CQuaternion operator*(const CQuaternion& q) const;
CQuaternion operator/(const CQuaternion& q) const; CQuaternion operator/(const CQuaternion& q) const;
CQuaternion operator*(float scale) const; CQuaternion operator*(float scale) const { return mSimd * simd<float>(scale); }
CQuaternion operator/(float scale) const; CQuaternion operator/(float scale) const { return mSimd / simd<float>(scale); }
CQuaternion operator-() const; CQuaternion operator-() const { return -mSimd; }
const CQuaternion& operator+=(const CQuaternion& q); const CQuaternion& operator+=(const CQuaternion& q) {
mSimd += q.mSimd;
return *this;
}
const CQuaternion& operator-=(const CQuaternion& q); const CQuaternion& operator-=(const CQuaternion& q) {
mSimd -= q.mSimd;
return *this;
}
const CQuaternion& operator*=(const CQuaternion& q); const CQuaternion& operator*=(const CQuaternion& q);
const CQuaternion& operator*=(float scale); const CQuaternion& operator*=(float scale) {
mSimd *= simd<float>(scale);
return *this;
}
const CQuaternion& operator/=(float scale); const CQuaternion& operator/=(float scale) {
mSimd /= simd<float>(scale);
return *this;
}
float magnitude() const { return std::sqrt(magSquared()); } float magnitude() const { return std::sqrt(magSquared()); }
@ -249,9 +264,12 @@ public:
CNUQuaternion operator*(const CNUQuaternion& q) const; CNUQuaternion operator*(const CNUQuaternion& q) const;
CNUQuaternion operator*(float f) const; CNUQuaternion operator*(float f) const { return mSimd * simd<float>(f); }
const CNUQuaternion& operator+=(const CNUQuaternion& q); const CNUQuaternion& operator+=(const CNUQuaternion& q) {
mSimd += q.mSimd;
return *this;
}
zeus::simd<float>::reference operator[](size_t idx) { zeus::simd<float>::reference operator[](size_t idx) {
assert(idx < 4); assert(idx < 4);

View File

@ -76,15 +76,6 @@ void CQuaternion::fromVector3f(const CVector3f& vec) {
mSimd.copy_from(f); mSimd.copy_from(f);
} }
CQuaternion& CQuaternion::operator=(const CQuaternion& q) {
mSimd = q.mSimd;
return *this;
}
CQuaternion CQuaternion::operator+(const CQuaternion& q) const { return mSimd + q.mSimd; }
CQuaternion CQuaternion::operator-(const CQuaternion& q) const { return mSimd - q.mSimd; }
CQuaternion CQuaternion::operator*(const CQuaternion& q) const { CQuaternion CQuaternion::operator*(const CQuaternion& q) const {
return CQuaternion(w() * q.w() - CVector3f(x(), y(), z()).dot({q.x(), q.y(), q.z()}), return CQuaternion(w() * q.w() - CVector3f(x(), y(), z()).dot({q.x(), q.y(), q.z()}),
y() * q.z() - z() * q.y() + w() * q.x() + x() * q.w(), y() * q.z() - z() * q.y() + w() * q.x() + x() * q.w(),
@ -105,29 +96,6 @@ CQuaternion CQuaternion::operator/(const CQuaternion& q) const {
return *this * p; return *this * p;
} }
CQuaternion CQuaternion::operator*(float scale) const { return mSimd * simd<float>(scale); }
CNUQuaternion CNUQuaternion::operator*(float scale) const { return mSimd * simd<float>(scale); }
CQuaternion CQuaternion::operator/(float scale) const { return mSimd / simd<float>(scale); }
CQuaternion CQuaternion::operator-() const { return -mSimd; }
const CQuaternion& CQuaternion::operator+=(const CQuaternion& q) {
mSimd += q.mSimd;
return *this;
}
const CNUQuaternion& CNUQuaternion::operator+=(const CNUQuaternion& q) {
mSimd += q.mSimd;
return *this;
}
const CQuaternion& CQuaternion::operator-=(const CQuaternion& q) {
mSimd -= q.mSimd;
return *this;
}
const CQuaternion& CQuaternion::operator*=(const CQuaternion& q) { const CQuaternion& CQuaternion::operator*=(const CQuaternion& q) {
CQuaternion orig = *this; CQuaternion orig = *this;
@ -139,16 +107,6 @@ const CQuaternion& CQuaternion::operator*=(const CQuaternion& q) {
return *this; return *this;
} }
const CQuaternion& CQuaternion::operator*=(float scale) {
mSimd *= simd<float>(scale);
return *this;
}
const CQuaternion& CQuaternion::operator/=(float scale) {
mSimd /= simd<float>(scale);
return *this;
}
CQuaternion CQuaternion::log() const { CQuaternion CQuaternion::log() const {
float a = std::acos(w()); float a = std::acos(w());
float sina = std::sin(a); float sina = std::sin(a);