2022-04-16 07:50:32 +00:00
|
|
|
#ifndef __CVECTOR3F_HPP__
|
|
|
|
#define __CVECTOR3F_HPP__
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
class CInputStream;
|
|
|
|
class COutputStream;
|
|
|
|
|
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-08-13 01:26:00 +00:00
|
|
|
CVector3f() : mX(0.f), mY(0.f), mZ(0.f) {}
|
2022-07-02 05:30:04 +00:00
|
|
|
explicit CVector3f(f32 x, f32 y, f32 z) : mX(x), mY(y), mZ(z) {}
|
2022-08-13 04:32:42 +00:00
|
|
|
CVector3f(const CVector2f& v, f32 z) : mX(v.GetX()), mY(v.GetY()), mZ(z) {}
|
|
|
|
|
2022-08-14 18:38:41 +00:00
|
|
|
CVector3f(const CVector3f& other) : mX(other.mX), mY(other.mY), mZ(other.mZ) {}
|
|
|
|
|
2022-08-13 04:32:42 +00:00
|
|
|
CVector3f(CInputStream& in);
|
|
|
|
void PutTo(COutputStream& out) const;
|
2022-07-02 05:30:04 +00:00
|
|
|
|
|
|
|
f32 GetX() const { return mX; }
|
|
|
|
f32 GetY() const { return mY; }
|
|
|
|
f32 GetZ() const { return mZ; }
|
|
|
|
|
2022-08-13 04:32:42 +00:00
|
|
|
void SetX(f32 x) { mX = x; }
|
|
|
|
void SetY(f32 y) { mY = y; }
|
|
|
|
void SetZ(f32 z) { mZ = z; }
|
|
|
|
|
|
|
|
// ByElementMultiply__9CVector3fFRC9CVector3fRC9CVector3f
|
|
|
|
// Slerp__9CVector3fFRC9CVector3fRC9CVector3fRC9CRelAngle
|
|
|
|
// Normalize__9CVector3fFv
|
|
|
|
// Magnitude__9CVector3fCFv
|
|
|
|
// AsNormalized__9CVector3fCFv
|
|
|
|
// CanBeNormalized__9CVector3fCFv
|
|
|
|
// GetAngleDiff__9CVector3fFRC9CVector3fRC9CVector3f
|
|
|
|
// IsEqu__9CVector3fCFRC9CVector3ff
|
|
|
|
// Lerp__9CVector3fFRC9CVector3fRC9CVector3ff
|
|
|
|
|
2022-09-05 04:00:04 +00:00
|
|
|
f32& operator[](EDimX dim) { return mX; }
|
|
|
|
f32& operator[](EDimY dim) { return mY; }
|
|
|
|
f32& operator[](EDimZ dim) { return mZ; }
|
|
|
|
f32 operator[](EDimX) const { return mX; }
|
|
|
|
f32 operator[](EDimY) const { return mY; }
|
|
|
|
f32 operator[](EDimZ) const { return mZ; }
|
|
|
|
|
2022-09-05 04:01:13 +00:00
|
|
|
f32& operator[](int i) { return *(&mX + i); }
|
|
|
|
// f32 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;
|
|
|
|
}
|
|
|
|
CVector3f& operator*=(f32 v) {
|
|
|
|
mX *= v;
|
|
|
|
mY *= v;
|
|
|
|
mZ *= v;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
CVector3f& operator/=(f32 v) {
|
|
|
|
mX /= v;
|
|
|
|
mY /= v;
|
|
|
|
mZ /= v;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
private:
|
2022-07-02 05:30:04 +00:00
|
|
|
f32 mX;
|
|
|
|
f32 mY;
|
|
|
|
f32 mZ;
|
2022-08-13 04:32:42 +00:00
|
|
|
|
|
|
|
static CVector3f sZeroVector;
|
|
|
|
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-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-08-15 04:51:06 +00:00
|
|
|
f32 x = lhs.GetX() - rhs.GetX();
|
|
|
|
f32 y = lhs.GetY() - rhs.GetY();
|
|
|
|
f32 z = lhs.GetZ() - rhs.GetZ();
|
|
|
|
return CVector3f(x, y, z);
|
2022-08-13 04:32:42 +00:00
|
|
|
}
|
|
|
|
inline CVector3f operator+(const CVector3f& lhs, const CVector3f& rhs) {
|
2022-08-15 04:51:06 +00:00
|
|
|
f32 x = lhs.GetX() + rhs.GetX();
|
|
|
|
f32 y = lhs.GetY() + rhs.GetY();
|
|
|
|
f32 z = lhs.GetZ() + rhs.GetZ();
|
|
|
|
return CVector3f(x, y, z);
|
|
|
|
}
|
|
|
|
inline CVector3f operator*(const CVector3f& vec, f32 f) {
|
|
|
|
f32 x = vec.GetX() * f;
|
|
|
|
f32 y = vec.GetY() * f;
|
|
|
|
f32 z = vec.GetZ() * f;
|
|
|
|
return CVector3f(x, y, z);
|
|
|
|
}
|
|
|
|
inline CVector3f operator/(const CVector3f& vec, f32 f) {
|
|
|
|
f32 x = vec.GetX() / f;
|
|
|
|
f32 y = vec.GetY() / f;
|
|
|
|
f32 z = vec.GetZ() / f;
|
|
|
|
return CVector3f(x, y, z);
|
|
|
|
}
|
|
|
|
inline CVector3f operator-(const CVector3f& vec) {
|
|
|
|
f32 x = -vec.GetX();
|
|
|
|
f32 y = -vec.GetY();
|
|
|
|
f32 z = -vec.GetZ();
|
|
|
|
return CVector3f(x, y, z);
|
2022-08-13 04:32:42 +00:00
|
|
|
}
|
|
|
|
|
2022-04-16 07:50:32 +00:00
|
|
|
#endif // __CVECTOR3F_HPP__
|