2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _CVECTOR3F
|
|
|
|
#define _CVECTOR3F
|
2022-04-16 07:50:32 +00:00
|
|
|
|
2022-07-02 05:30:04 +00:00
|
|
|
#include "types.h"
|
2022-04-16 07:50:32 +00:00
|
|
|
|
2022-08-13 04:32:42 +00:00
|
|
|
#include "Kyoto/Math/CVector2f.hpp"
|
|
|
|
|
2022-10-01 20:39:52 +00:00
|
|
|
#include "float.h"
|
|
|
|
|
2022-08-13 04:32:42 +00:00
|
|
|
class CInputStream;
|
|
|
|
class COutputStream;
|
2022-10-05 01:31:43 +00:00
|
|
|
class CRelAngle;
|
2022-08-13 04:32:42 +00:00
|
|
|
|
2022-09-05 04:00:04 +00:00
|
|
|
enum EDimX { kDX };
|
|
|
|
enum EDimY { kDY };
|
|
|
|
enum EDimZ { kDZ };
|
|
|
|
|
2022-04-16 07:50:32 +00:00
|
|
|
class CVector3f {
|
|
|
|
public:
|
2022-10-09 05:37:23 +00:00
|
|
|
explicit CVector3f(float x, float y, float z) : mX(x), mY(y), mZ(z) {}
|
|
|
|
CVector3f(const CVector2f& v, float z) : mX(v.GetX()), mY(v.GetY()), mZ(z) {}
|
2022-08-13 04:32:42 +00:00
|
|
|
|
|
|
|
CVector3f(CInputStream& in);
|
|
|
|
void PutTo(COutputStream& out) const;
|
2022-07-02 05:30:04 +00:00
|
|
|
|
2022-10-09 05:37:23 +00:00
|
|
|
float GetX() const { return mX; }
|
|
|
|
float GetY() const { return mY; }
|
|
|
|
float GetZ() const { return mZ; }
|
2022-07-02 05:30:04 +00:00
|
|
|
|
2022-10-09 05:37:23 +00:00
|
|
|
void SetX(float x) { mX = x; }
|
|
|
|
void SetY(float y) { mY = y; }
|
|
|
|
void SetZ(float z) { mZ = z; }
|
2022-08-13 04:32:42 +00:00
|
|
|
|
|
|
|
// ByElementMultiply__9CVector3fFRC9CVector3fRC9CVector3f
|
2022-10-05 01:31:43 +00:00
|
|
|
static CVector3f Slerp(const CVector3f& a, const CVector3f& b, const CRelAngle& angle);
|
|
|
|
CVector3f& Normalize();
|
2022-10-09 05:37:23 +00:00
|
|
|
float Magnitude() const;
|
2022-09-29 23:55:38 +00:00
|
|
|
CVector3f AsNormalized() const;
|
2022-10-05 01:31:43 +00:00
|
|
|
bool IsNotInf() const;
|
|
|
|
bool IsMagnitudeSafe() const;
|
2022-09-29 05:30:20 +00:00
|
|
|
bool CanBeNormalized() const;
|
2022-10-05 01:31:43 +00:00
|
|
|
static float GetAngleDiff(const CVector3f& a, const CVector3f& b);
|
2022-10-09 05:37:23 +00:00
|
|
|
bool IsEqu(const CVector3f& other, float epsilon = FLT_EPSILON) const;
|
2022-08-13 04:32:42 +00:00
|
|
|
// Lerp__9CVector3fFRC9CVector3fRC9CVector3ff
|
2022-10-08 04:53:28 +00:00
|
|
|
inline float MagSquared() const { return GetX() * GetX() + GetY() * GetY() + GetZ() * GetZ(); }
|
2022-10-03 02:55:05 +00:00
|
|
|
static CVector3f Cross(const CVector3f& lhs, const CVector3f& rhs) {
|
|
|
|
const float x = (lhs.GetY() * rhs.GetZ()) - (rhs.GetY() * lhs.GetZ());
|
|
|
|
const float y = (lhs.GetZ() * rhs.GetX()) - (rhs.GetZ() * lhs.GetX());
|
|
|
|
const float z = (lhs.GetX() * rhs.GetY()) - (rhs.GetX() * lhs.GetY());
|
|
|
|
return CVector3f(x, y, z);
|
|
|
|
}
|
2022-08-13 04:32:42 +00:00
|
|
|
|
2022-10-09 05:37:23 +00:00
|
|
|
float& operator[](EDimX dim) { return mX; }
|
|
|
|
float& operator[](EDimY dim) { return mY; }
|
|
|
|
float& operator[](EDimZ dim) { return mZ; }
|
|
|
|
const float& operator[](EDimX) const { return mX; }
|
|
|
|
const float& operator[](EDimY) const { return mY; }
|
|
|
|
const float& operator[](EDimZ) const { return mZ; }
|
2022-09-05 04:00:04 +00:00
|
|
|
|
2022-10-09 05:37:23 +00:00
|
|
|
float& operator[](int i) { return (&mX)[i]; }
|
|
|
|
float operator[](int i) const { return (&mX)[i]; }
|
2022-08-13 04:32:42 +00:00
|
|
|
bool IsNonZero() const { return mX != 0.f || mY != 0.f || mZ != 0.f; }
|
|
|
|
|
2022-09-19 04:19:46 +00:00
|
|
|
CVector3f DropZ() const { return CVector3f(mX, mY, 0.f); }
|
2022-08-13 04:32:42 +00:00
|
|
|
|
|
|
|
CVector3f& operator+=(const CVector3f& other) {
|
|
|
|
mX += other.mX;
|
|
|
|
mY += other.mY;
|
|
|
|
mZ += other.mZ;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
CVector3f& operator-=(const CVector3f& other) {
|
|
|
|
mX -= other.mX;
|
|
|
|
mY -= other.mY;
|
|
|
|
mZ -= other.mZ;
|
|
|
|
return *this;
|
|
|
|
}
|
2022-10-09 05:37:23 +00:00
|
|
|
CVector3f& operator*=(float v) {
|
2022-08-13 04:32:42 +00:00
|
|
|
mX *= v;
|
|
|
|
mY *= v;
|
|
|
|
mZ *= v;
|
|
|
|
return *this;
|
|
|
|
}
|
2022-10-09 05:37:23 +00:00
|
|
|
CVector3f& operator/=(float v) {
|
2022-08-13 04:32:42 +00:00
|
|
|
mX /= v;
|
|
|
|
mY /= v;
|
|
|
|
mZ /= v;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2022-10-09 05:37:23 +00:00
|
|
|
static float Dot(const CVector3f& a, const CVector3f& b) {
|
2022-09-29 23:55:38 +00:00
|
|
|
return (a.GetX() * b.GetX()) + (a.GetY() * b.GetY()) + (a.GetZ() * b.GetZ());
|
|
|
|
}
|
|
|
|
|
2022-08-13 04:32:42 +00:00
|
|
|
static const CVector3f& Zero() { return sZeroVector; }
|
|
|
|
static const CVector3f& Up() { return sUpVector; }
|
|
|
|
static const CVector3f& Down() { return sDownVector; }
|
|
|
|
static const CVector3f& Left() { return sLeftVector; }
|
|
|
|
static const CVector3f& Right() { return sRightVector; }
|
|
|
|
static const CVector3f& Forward() { return sForwardVector; }
|
|
|
|
static const CVector3f& Back() { return sBackVector; }
|
|
|
|
|
2022-10-05 16:28:37 +00:00
|
|
|
protected:
|
2022-10-09 05:37:23 +00:00
|
|
|
float mX;
|
|
|
|
float mY;
|
|
|
|
float mZ;
|
2022-08-13 04:32:42 +00:00
|
|
|
|
|
|
|
static CVector3f sZeroVector;
|
2022-10-05 01:31:43 +00:00
|
|
|
static int sUnkData[18];
|
2022-08-13 04:32:42 +00:00
|
|
|
static CVector3f sUpVector;
|
|
|
|
static CVector3f sDownVector;
|
|
|
|
static CVector3f sLeftVector;
|
|
|
|
static CVector3f sRightVector;
|
|
|
|
static CVector3f sForwardVector;
|
|
|
|
static CVector3f sBackVector;
|
2022-04-16 07:50:32 +00:00
|
|
|
};
|
2022-09-29 23:55:38 +00:00
|
|
|
CHECK_SIZEOF(CVector3f, 0xc)
|
2022-04-16 07:50:32 +00:00
|
|
|
|
2022-08-13 04:32:42 +00:00
|
|
|
// ClassifyVector__FRC9CVector3f
|
|
|
|
// TGetType<9CVector3f>__FRC9CVector3f
|
|
|
|
// close_enough__FRC9CVector3fRC9CVector3ff in CloseEnough.cpp
|
|
|
|
|
|
|
|
inline bool operator==(const CVector3f& lhs, const CVector3f& rhs) {
|
|
|
|
return lhs.GetX() == rhs.GetX() && lhs.GetY() == rhs.GetY() && lhs.GetZ() == rhs.GetZ();
|
|
|
|
}
|
|
|
|
inline bool operator!=(const CVector3f& lhs, const CVector3f& rhs) {
|
|
|
|
return lhs.GetX() != rhs.GetX() || lhs.GetY() != rhs.GetY() || lhs.GetZ() != rhs.GetZ();
|
|
|
|
}
|
|
|
|
inline CVector3f operator-(const CVector3f& lhs, const CVector3f& rhs) {
|
2022-10-09 05:37:23 +00:00
|
|
|
float x = lhs.GetX() - rhs.GetX();
|
|
|
|
float y = lhs.GetY() - rhs.GetY();
|
|
|
|
float z = lhs.GetZ() - rhs.GetZ();
|
2022-08-15 04:51:06 +00:00
|
|
|
return CVector3f(x, y, z);
|
2022-08-13 04:32:42 +00:00
|
|
|
}
|
|
|
|
inline CVector3f operator+(const CVector3f& lhs, const CVector3f& rhs) {
|
2022-10-09 05:37:23 +00:00
|
|
|
float x = lhs.GetX() + rhs.GetX();
|
|
|
|
float y = lhs.GetY() + rhs.GetY();
|
|
|
|
float z = lhs.GetZ() + rhs.GetZ();
|
2022-08-15 04:51:06 +00:00
|
|
|
return CVector3f(x, y, z);
|
|
|
|
}
|
2022-10-09 05:37:23 +00:00
|
|
|
inline CVector3f operator*(const CVector3f& vec, float f) {
|
|
|
|
float x = vec.GetX() * f;
|
|
|
|
float y = vec.GetY() * f;
|
|
|
|
float z = vec.GetZ() * f;
|
2022-08-15 04:51:06 +00:00
|
|
|
return CVector3f(x, y, z);
|
|
|
|
}
|
2022-10-05 22:50:12 +00:00
|
|
|
|
2022-10-09 05:37:23 +00:00
|
|
|
inline CVector3f operator*(float f, const CVector3f& vec) {
|
|
|
|
float x = f * vec.GetX();
|
|
|
|
float y = f * vec.GetY();
|
|
|
|
float z = f * vec.GetZ();
|
2022-10-05 22:50:12 +00:00
|
|
|
return CVector3f(x, y, z);
|
|
|
|
}
|
|
|
|
|
2022-10-09 05:37:23 +00:00
|
|
|
inline CVector3f operator/(const CVector3f& vec, float f) {
|
|
|
|
float x = vec.GetX() / f;
|
|
|
|
float y = vec.GetY() / f;
|
|
|
|
float z = vec.GetZ() / f;
|
2022-08-15 04:51:06 +00:00
|
|
|
return CVector3f(x, y, z);
|
|
|
|
}
|
|
|
|
inline CVector3f operator-(const CVector3f& vec) {
|
2022-10-07 04:23:10 +00:00
|
|
|
return CVector3f(-vec.GetX(), -vec.GetY(), -vec.GetZ());
|
2022-08-13 04:32:42 +00:00
|
|
|
}
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _CVECTOR3F
|