Match and link CVector3d, add CVector3i.s

This commit is contained in:
Phillip Stephens 2022-10-04 12:57:04 -07:00
parent 7d5775a78a
commit cdbbfba34e
6 changed files with 108 additions and 2 deletions

View File

@ -0,0 +1,10 @@
.include "macros.inc"
.section .text, "ax"
.global __ct__9CVector3iFiii
__ct__9CVector3iFiii:
/* 80314C48 00311BA8 90 83 00 00 */ stw r4, 0(r3)
/* 80314C4C 00311BAC 90 A3 00 04 */ stw r5, 4(r3)
/* 80314C50 00311BB0 90 C3 00 08 */ stw r6, 8(r3)
/* 80314C54 00311BB4 4E 80 00 20 */ blr

View File

@ -33,6 +33,7 @@ COMPLETE_OBJECTS = [
"Kyoto/Graphics/CGX",
"Kyoto/Particles/CWarp",
"Kyoto/Math/CPlane",
"Kyoto/Math/CVector3d",
"Kyoto/Math/CVector3i",
"Kyoto/CRandom16",
"Kyoto/CCrc32",

View File

@ -50,7 +50,7 @@ public:
// BaryToWorld__5CMathFRC9CVector3fRC9CVector3fRC9CVector3fRC9CVector3f global
// GetCatmullRomSplinePoint__5CMathFRC9CVector3fRC9CVector3fRC9CVector3fRC9CVector3ff global
// FastSqrtF__5CMathFf weak
// SqrtD__5CMathFd global
static double SqrtD(double x);
// AbsD__5CMathFd weak
// IsEpsilon__5CMathFfff global
// FastMin__5CMathFff weak

View File

@ -0,0 +1,33 @@
#ifndef __CVECTOR3D_HPP__
#define __CVECTOR3D_HPP__
#include "Kyoto/Math/CVector3f.hpp"
class CVector3d {
public:
CVector3d(double x, double y, double z);
CVector3d(const CVector3f& other);
double Magnitude() const;
double MagSquared() const;
CVector3d AsNormalized() const;
CVector3f AsCVector3f() const;
double GetX() const { return mX; }
double GetY() const { return mY; }
double GetZ() const { return mZ; }
static double Dot(const CVector3d& a, const CVector3d& b);
static CVector3d Cross(const CVector3d& a, const CVector3d& b);
private:
double mX;
double mY;
double mZ;
};
CVector3d operator+(const CVector3d& other);
#endif // __CVECTOR3D_HPP__

View File

@ -522,7 +522,7 @@ KYOTO_1 :=\
$(BUILD_DIR)/asm/Kyoto/Math/CUnitVector3f.o\
$(BUILD_DIR)/asm/Kyoto/Math/CVector2f.o\
$(BUILD_DIR)/asm/Kyoto/Math/CVector2i.o\
$(BUILD_DIR)/asm/Kyoto/Math/CVector3d.o\
$(BUILD_DIR)/src/Kyoto/Math/CVector3d.o\
$(BUILD_DIR)/asm/Kyoto/Math/CVector3f.o\
$(BUILD_DIR)/src/Kyoto/Math/CVector3i.o\
$(BUILD_DIR)/asm/Kyoto/Math/RMathUtils.o\

View File

@ -0,0 +1,62 @@
#include "Kyoto/Math/CVector3d.hpp"
#include "Kyoto/Math/CMath.hpp"
CVector3d::CVector3d(double x, double y, double z) : mX(x), mY(y), mZ(z) {}
CVector3d::CVector3d(const CVector3f& other)
: mX(other.GetX()), mY(other.GetY()), mZ(other.GetZ()) {}
double CVector3d::Magnitude() const {
double ret = mX * mX;
ret += mY * mY;
ret += mZ * mZ;
return CMath::SqrtD(ret);
}
double CVector3d::MagSquared() const {
double ret = mX * mX;
ret += mY * mY;
ret += mZ * mZ;
return ret;
}
CVector3d CVector3d::AsNormalized() const {
const double mag = 1.f / Magnitude();
return CVector3d(mX * mag, mY * mag, mZ * mag);
}
CVector3f CVector3d::AsCVector3f() const {
float z = mZ;
float y = mY;
float x = mX;
return CVector3f(x, y, z);
}
double CVector3d::Dot(const CVector3d& a, const CVector3d& b) {
double ret = a.GetX() * b.GetX();
ret += a.GetY() * b.GetY();
ret += a.GetZ() * b.GetZ();
return ret;
}
CVector3d CVector3d::Cross(const CVector3d& lhs, const CVector3d& rhs) {
double x1 = lhs.GetX();
double y1 = lhs.GetY();
double z1 = lhs.GetZ();
double x2 = rhs.GetX();
double y2 = rhs.GetY();
double z2 = rhs.GetZ();
return CVector3d((y1 * z2) - (y2 * z1), (z1 * x2) - (z2 * x1), (x1 * y2) - (x2 * y1));
}
CVector3d operator+(const CVector3d& lhs, const CVector3d& rhs) {
return CVector3d(lhs.GetX() + rhs.GetX(), lhs.GetY() + rhs.GetY(), lhs.GetZ() + rhs.GetZ());
}
CVector3d operator-(const CVector3d& lhs, const CVector3d& rhs) {
return CVector3d(lhs.GetX() - rhs.GetX(), lhs.GetY() - rhs.GetY(), lhs.GetZ() - rhs.GetZ());
}
CVector3d operator*(double lhs, const CVector3d& rhs) {
return CVector3d(lhs * rhs.GetX(), lhs * rhs.GetY(), lhs * rhs.GetZ());
}