Egg Camera a small bit closer

This commit is contained in:
elijah-thomas774
2025-03-21 19:38:30 -04:00
parent b6505d23ad
commit 00ececa0b5
4 changed files with 109 additions and 43 deletions
+14 -9
View File
@@ -2,6 +2,7 @@
#define EGG_CAMERA_H
#include "egg/math/eggMatrix.h"
#include "egg/math/eggRotation.h"
#include "egg/math/eggVector.h"
#include "nw4r/g3d/g3d_camera.h"
@@ -10,7 +11,6 @@ namespace EGG {
class BaseCamera {
public:
BaseCamera() {}
// Which way around?
virtual Matrix34f &getViewMatrix() = 0;
virtual const Matrix34f &getViewMatrix() const = 0;
virtual void updateMatrix();
@@ -23,11 +23,18 @@ public:
virtual Matrix34f &getViewMatrixOld() = 0;
void setG3DCamera(nw4r::g3d::Camera &);
// Vector3f getRightVector();
// Vector3f getLookVector();
// Vector3f getUpVector();
protected:
/* 0x04 */ Matrix34f mViewMtx;
/* 0x34 */ Matrix34f mOtherMtx;
};
class LookAtCamera : public BaseCamera {
public:
LookAtCamera() : mPosition(0.0f, 10.0f, 0.0f), mRight(0.0f, 0.0f, 0.0f), mUp(0.0f, 1.0f, 0.0f) {}
LookAtCamera() : mPos(0.0f, 10.0f, 0.0f), mAt(0.0f, 0.0f, 0.0f), mUp(0.0f, 1.0f, 0.0f) {}
// Which way around?
virtual Matrix34f &getViewMatrix() override {
return mViewMtx;
@@ -40,17 +47,15 @@ public:
virtual void loadMatrix() override;
virtual void loadOldMatrix() override;
virtual EGG::Vector3f getPosition() override {
return mPosition;
return mPos;
}
virtual void doDraw() override;
virtual Matrix34f &getViewMatrixOld() override;
protected:
/* 0x04 */ Matrix34f mViewMtx;
/* 0x34 */ Matrix34f mOtherMtx;
/* 0x64 */ Vector3f mPosition;
/* 0x70 */ Vector3f mRight;
/* 0x64 */ Vector3f mPos;
/* 0x70 */ Vector3f mAt;
/* 0x7C */ Vector3f mUp;
};
@@ -63,8 +68,8 @@ public:
private:
void update_parms();
/* 0x88 */ f32 field_0x88;
/* 0x8C */ f32 field_0x8C;
/* 0x88 */ EGG::Rotation<f32> field_0x88;
/* 0x8C */ EGG::Rotation<f32> field_0x8C;
};
} // namespace EGG
+50
View File
@@ -0,0 +1,50 @@
#ifndef EGG_ROTATION_H
#define EGG_ROTATION_H
#include "egg/math/eggMath.h"
namespace EGG {
template <typename T>
struct Rotation {
Rotation() {}
Rotation(T val) : mRot(val) {}
Rotation(const Rotation &other) {
mRot = other.mRot;
}
Rotation &operator=(const Rotation &other) {
mRot = val;
return *this;
}
Rotation &operator=(T val) {
mRot = val;
return *this;
}
operator T() const {
return mRot;
}
Rotation &operator-=(T val) {
mRot -= val;
return *this;
}
Rotation &operator+=(T val) {
mRot -= val;
return *this;
}
const T cos() const {
return Math<T>::cos(*this);
}
const T sin() const {
return Math<T>::sin(*this);
}
protected:
T mRot;
};
} // namespace EGG
#endif
+8 -18
View File
@@ -3,25 +3,19 @@
#include "common.h"
#include "egg/math/eggMath.h"
#include "nw4r/math.h"
namespace EGG {
struct Vector3f : public nw4r::math::VEC3 {
// __ct__Q23EGG8Vector3fFv
Vector3f() : nw4r::math::VEC3() {}
// __ct__Q23EGG8Vector3fFfff
Vector3f(f32 fx, f32 fy, f32 fz) : VEC3(fx, fy, fz) {}
// ~Vector3f() {}
// __cl__Q23EGG8Vector3fFi
f32 &operator()(int i) {
return ((f32 *)this)[i];
}
// __ml__Q23EGG8Vector3fCFf
Vector3f operator*(f32 f) const {
return Vector3f(x * f, y * f, z * f);
}
@@ -30,12 +24,10 @@ struct Vector3f : public nw4r::math::VEC3 {
return Vector3f(v.x * f, v.y * f, v.z * f);
}
// __pl__Q23EGG8Vector3fCFRCQ23EGG8Vector3f
Vector3f operator+(const Vector3f &v) const {
return Vector3f(x + v.x, y + v.y, z + v.z);
}
// __apl__Q23EGG8Vector3fFRCQ23EGG8Vector3f
Vector3f &operator+=(const Vector3f &v) {
x += v.x;
y += v.y;
@@ -43,7 +35,6 @@ struct Vector3f : public nw4r::math::VEC3 {
return *this;
}
// __mi__Q23EGG8Vector3fCFv
Vector3f operator-() const {
f32 z = this->z;
f32 y = this->y;
@@ -51,12 +42,10 @@ struct Vector3f : public nw4r::math::VEC3 {
return Vector3f(-x, -y, -z);
}
// __mi__Q23EGG8Vector3fCFRCQ23EGG8Vector3f
Vector3f operator-(const Vector3f &v) {
return Vector3f(x - v.x, y - v.y, z - v.z);
}
// __ami__Q23EGG8Vector3fFRCQ23EGG8Vector3f
Vector3f &operator-=(const Vector3f &v) {
x -= v.x;
y -= v.y;
@@ -64,24 +53,20 @@ struct Vector3f : public nw4r::math::VEC3 {
return *this;
}
// __amu__Q23EGG8Vector3fFf
Vector3f &operator*=(f32 f) {
multScalar(f);
return *this;
}
// __dv__Q23EGG8Vector3fCFf
Vector3f operator/(f32 f) const {
return Vector3f(x / f, y / f, z / f);
}
// __adv__Q23EGG8Vector3fCFf // assumed
Vector3f &operator/=(f32 f) {
divScalar(f);
return *this;
}
// __ne__Q23EGG8Vector3fCFRCQ23EGG8Vector3f
bool operator!=(const Vector3f &v) {
return x != v.x || y != v.y || z != v.z;
}
@@ -101,12 +86,10 @@ struct Vector3f : public nw4r::math::VEC3 {
return EGG::Math<f32>::abs(EGG::Math<f32>::atan2(b, a));
}
// dot__Q23EGG8Vector3fCFRCQ23EGG8Vector3f
f32 dot(const Vector3f &v) const {
return x * v.x + y * v.y + z * v.z;
}
// cross__Q23EGG8Vector3fCFRCQ23EGG8Vector3f
Vector3f cross(const Vector3f &b) const {
f32 _x = (y * b.z) - (z * b.y);
f32 _y = (z * b.x) - (x * b.z);
@@ -126,6 +109,13 @@ struct Vector3f : public nw4r::math::VEC3 {
}
f32 normalise();
Vector3f normalize() {
Vector3f other(x, y, z);
other.normalise();
return other;
}
f32 setLength(const Vector3f &src, f32 len);
f32 setLength(f32 len);
+37 -16
View File
@@ -12,7 +12,7 @@ void BaseCamera::updateMatrix() {
doUpdateMatrix();
}
void EGG::BaseCamera::draw(EGG::BaseCamera *cam) {
void BaseCamera::draw(EGG::BaseCamera *cam) {
cam->loadMatrix();
doDraw();
}
@@ -27,21 +27,37 @@ Matrix34f &LookAtCamera::getViewMatrixOld() {
void LookAtCamera::doUpdateMatrix() {
// NONMATCHING
mOtherMtx.copyFrom(mViewMtx);
EGG::Vector3f posRight = mPosition;
posRight -= mRight;
posRight.normalise();
EGG::Vector3f forward = posRight.cross(mUp);
forward.normalise();
mOtherMtx = mViewMtx;
EGG::Vector3f up = posRight.cross(forward);
Vector3f right(mPos);
right -= mAt;
right.normalise();
Vector3f forward(mUp.cross(right).normalize());
Vector3f up(right.cross(forward));
up.normalise();
mViewMtx.setTranslation(Vector3f((forward.dot(mPosition)), (up.dot(mPosition)), (posRight.dot(mPosition))));
mViewMtx.setBase(0, forward);
mViewMtx.setBase(1, up);
mViewMtx.setBase(2, posRight);
f32 tx = -forward.dot(mPos);
f32 ty = -up.dot(mPos);
f32 tz = -right.dot(mPos);
mViewMtx(0, 0) = forward(0);
mViewMtx(0, 1) = forward(1);
mViewMtx(0, 2) = forward(2);
mViewMtx(0, 3) = tx;
mViewMtx(1, 0) = up(0);
mViewMtx(1, 1) = up(1);
mViewMtx(1, 2) = up(2);
mViewMtx(1, 3) = ty;
mViewMtx(2, 0) = right(0);
mViewMtx(2, 1) = right(1);
mViewMtx(2, 2) = right(2);
mViewMtx(2, 3) = tz;
}
void LookAtCamera::doDraw() {}
@@ -64,10 +80,15 @@ OrthoCamera::OrthoCamera() {
void OrthoCamera::update_parms() {
// NONMATCHING
f32 z = field_0x8C;
f32 sin = Math<f32>::sin(field_0x88);
f32 cos = Math<f32>::cos(field_0x88);
mPosition.set(mRight.x, mRight.y, z);
mUp.set(sin, cos, 0.0f);
f32 sin = field_0x88.sin();
f32 cos = field_0x88.cos();
mPos(2) = z;
mPos(1) = mAt(1);
mPos(0) = mAt(0);
mUp(2) = 0.f;
mUp(1) = cos;
mUp(0) = sin;
}
void OrthoCamera::doUpdateMatrix() {