Skip to content

Commit

Permalink
Scaffold camera, more sysMath
Browse files Browse the repository at this point in the history
  • Loading branch information
HeartPiece44 committed Dec 24, 2024
1 parent 9a6522b commit 6d208c7
Show file tree
Hide file tree
Showing 18 changed files with 606 additions and 983 deletions.
69 changes: 41 additions & 28 deletions include/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "types.h"
#include "Vector.h"
#include "Matrix4f.h"
#include "Plane.h"

struct Graphics;
struct Node;
Expand All @@ -19,15 +20,14 @@ struct CullingPlane {
void CheckMinMaxDir();

// TODO: members
Vector3f _00; // _00
u8 _0C[0x4]; // _0C, unknown
Plane mPlane; // _00
int _10; // _10
int _14; // _10
int _18; // _10
int _1C; // _10
int _20; // _10
int _24; // _24
u8 _28[0x4]; // _28, unknown
u8 _28; // _28
};

/**
Expand All @@ -37,7 +37,7 @@ struct CullFrustum {
CullFrustum()
{
_155 = 0;
mPosition.set(0.0f, 0.0f, 0.0f);
mEyePosition.set(0.0f, 0.0f, 0.0f);
_1CC = 60.0f;
_1D0 = 1.0f;
_1D4 = 1000.0f;
Expand All @@ -58,28 +58,37 @@ struct CullFrustum {
void createInvVecs();
void calcLookFrom(Vector3f&, Vector3f&);

u8 _00[0x4]; // _00, unknown
void projectVector(Vector3f& vec, Vector3f& projVec)
{
projVec.x = vec.dot(mViewXAxis);
projVec.y = vec.dot(mViewYAxis);
projVec.z = vec.dot(mViewZAxis);
}

int _00; // _00
int _04; // _04
u8 _08[0x4]; // _08, unknown
int _08; // _08
CullingPlane mCullPlanes[6]; // _0C
u8 _114[0x154 - 0x114]; // _114, unknown
Plane* _114[6]; // _114, idk how many are in this
u8 _12C[0x154 - 0x12C]; // _12C, unknown
u8 _154; // _154
u8 _155; // _155
Vector3f _158; // _158
Vector3f mPosition; // _164
Vector3f _170; // _170
Vector3f _17C; // _17C
Vector3f _188; // _188
Vector3f _194; // _194
Vector3f _1A0; // _1A0
Vector3f _1AC; // _1AC
Vector3f _1B8; // _1B8
Vector3f mEyePosition; // _164
Vector3f mTargetPosition; // _170
Vector3f mViewXAxis; // _17C
Vector3f mViewYAxis; // _188
Vector3f mViewZAxis; // _194
Vector3f mInvXAxis; // _1A0
Vector3f mInvYAxis; // _1AC
Vector3f mInvZAxis; // _1B8
f32 _1C4; // _1C4
u8 _1C8[0x4]; // _1C8, unknown
f32 _1C8; // _1C8
f32 _1CC; // _1CC
f32 _1D0; // _1D0
f32 _1D4; // _1D4
u8 _1D8[0x8]; // _1D8, unknown
f32 _1D8; // _1D8
f32 _1DC; // _1DC
Matrix4f mLookAtMtx; // _1E0
Matrix4f mInverseLookAtMtx; // _220
};
Expand All @@ -92,20 +101,20 @@ struct CullFrustum {
struct Camera : public CullFrustum {
Camera();

void projectWorldPoint(Graphics&, Vector3f&);
f32 projectWorldPoint(Graphics&, Vector3f&);

// unused/inlined:
void camReflect(Camera&, Plane&);
void projectCamPoint(Vector3f&);

// _00-_1D8 = CullFrustum? Unsure on end point of that vs beginning of this, but after _260 and before _320
Matrix4f _260; // _260
Matrix4f _2A0; // _2A0
u8 _2E0[0x320 - 0x2E0]; // _2E0, unknown
Vector3f mRotation; // _320
Vector3f _32C; // _32C
Vector3f _338; // _338
f32 _344; // _344
// _00-_260 = CullFrustum
Matrix4f _260; // _260
Matrix4f _2A0; // _2A0
Matrix4f _2E0; // _2E0
Vector3f mRotation; // _320
Vector3f _32C; // _32C
Vector3f _338; // _338
f32 _344; // _344
};

/**
Expand All @@ -115,9 +124,13 @@ struct LightCamera : public Camera {
void initLightmap(int, int);
void calcProjection(Graphics&, bool, Node*);

// _00-_348 = Camera? Fix when size of camera is known
u8 _348[0x10]; // _348, unknown
// _00-_348 = Camera
f32 _348; // _348
f32 _34C; // _34C
f32 _350; // _350
f32 _354; // _354
Texture* mLightMap; // _358
Vector3f _35C; // _35C
};

/**
Expand Down
12 changes: 7 additions & 5 deletions include/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ struct Graphics {
Camera* mCamera; // _2E4
u32 _2E8; // _2E8
u8 _2EC[0x30C - 0x2EC]; // _2EC, unknown
int mScreenWidth; // _30C, maybe viewport width?
int mScreenHeight; // _310, maybe viewport height?
u8 _314[0x338 - 0x314]; // _2E8, unknown
int mScreenWidth; // _30C
int mScreenHeight; // _310
u8 _314[0x324 - 0x314]; // _2E8, unknown
u32 _324; // _324, unknown
u8 _328[0x338 - 0x328]; // _328, unknown
LightCamera* mLightCam; // _338
u8 _33C[0x368 - 0x33C]; // _33C, unknown
Colour _368; // _368
Expand All @@ -78,7 +80,7 @@ struct Graphics {
virtual void initRender(int, int); // _24
virtual void resetCopyFilter() = 0; // _28
virtual void setAmbient(); // _2C
virtual void setLighting(bool, PVWLightingInfo*) = 0; // _30
virtual bool setLighting(bool, PVWLightingInfo*) = 0; // _30
virtual void setLight(Light*, int) = 0; // _34
virtual void clearBuffer(int, bool) = 0; // _38
virtual void setPerspective(Mtx, f32, f32, f32, f32, f32) = 0; // _3C
Expand Down Expand Up @@ -145,7 +147,7 @@ struct DGXGraphics : public Graphics {
virtual void initRender(int, int); // _24
virtual void resetCopyFilter(); // _28
virtual void setAmbient(); // _2C
virtual void setLighting(bool, PVWLightingInfo*); // _30
virtual bool setLighting(bool, PVWLightingInfo*); // _30
virtual void setLight(Light*, int); // _34
virtual void clearBuffer(int, bool); // _38
virtual void setPerspective(Mtx, f32, f32, f32, f32, f32); // _3C
Expand Down
27 changes: 10 additions & 17 deletions include/KMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,21 @@ struct Matrix4f;
struct KTri {
KTri();

void set(Vector3f&, Vector3f&, Vector3f&);
void set(Vector3f& pointA, Vector3f& pointB, Vector3f& pointC);

Vector3f _00; // _00
Vector3f _0C; // _0C
Vector3f _18; // _18
// set clockwise
Vector3f mVertA; // _00, vertex
Vector3f mSideAB; // _0C, line from vertex A to vertex B
Vector3f mSideAC; // _18, line from vertex A to vertex C
};

/**
* @brief TODO
*/
struct KRect {
bool inside(Vector3f&);

Vector3f _00; // _00
Vector3f _0C; // _0C
Vector3f _18; // _18
// f32 _0C; // _0C
// u8 _10[0x4]; // _10, unknown
// f32 _14; // _14
// f32 _18; // _18
// u8 _1C[0x4]; // _1C, unknown
// f32 _20; // _20
// TODO: members
bool inside(Vector3f& point);

KTri mBotTri; // _00, bottom left point, left side, bottom side
};

/**
Expand All @@ -44,7 +36,8 @@ struct KSegment {
// unused/inlined:
KSegment();

// TODO: members
Vector3f mPoint; // _00
Vector3f mDirection; // _0C
};

// Global utility functions:
Expand Down
1 change: 0 additions & 1 deletion include/MapMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ struct ShadowCaster : public CoreNode {
// _00 = VTBL
// _00-_14 = CoreNode
LightCamera _14; // _14
Vector3f _370; // _370
Vector3f _37C; // _37C
Vector3f _388; // _388
};
Expand Down
4 changes: 4 additions & 0 deletions include/Matrix4f.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@ struct Matrix4f {
Mtx44 mMtx; // _00-_40
};

// this is a weird place to put these, but they get initialised in matMath.cpp, so?
extern f32 sintable[0x1000];
extern f32 costable[0x1000];

#endif
6 changes: 4 additions & 2 deletions include/Plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

/**
* @brief TODO
*
* @note Size: 0x10.
*/
struct Plane {
Plane();
Plane() { }

// unused/inlined:
bool equal(Plane&);
Expand All @@ -19,7 +21,7 @@ struct Plane {
void frictionVector(Vector3f&, f32);

Vector3f mNormal; // _00
f32 mOffset; // _10
f32 mOffset; // _0C
};

#endif
1 change: 1 addition & 0 deletions include/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ struct Texture : public GfxObject {
f32 _28; // _28
f32 _2C; // _2C
u32 _30; // _30
u8 _34[0x8]; // _34, unknown
};

/**
Expand Down
75 changes: 66 additions & 9 deletions include/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct Vector3f {
}

inline Vector3f operator*(const Vector3f& other) const { return Vector3f(x * other.x, y * other.y, z * other.z); }
inline Vector3f operator*(f32 scale) const { return Vector3f(x * scale, y * scale, z * scale); }
inline Vector3f operator*(const f32& scale) const { return Vector3f(x * scale, y * scale, z * scale); }
void rotate(struct Matrix4f&);
void rotateTo(Matrix4f&, Vector3f&);
void multMatrix(Matrix4f&);
Expand Down Expand Up @@ -60,13 +60,7 @@ struct Vector3f {
return length();
}

inline void sub2(Vector3f& a, Vector3f& b)
{
f32 newZ = a.getZ() - b.getZ();
f32 newY = a.getY() - b.getY();
f32 newX = a.getX() - b.getX();
set(newX, newY, newZ);
}
inline void sub2(Vector3f& a, Vector3f& b) { set(a.getX() - b.getX(), a.getY() - b.getY(), a.getZ() - b.getZ()); }

inline void set(const f32& pX, const f32& pY, const f32& pZ)
{
Expand Down Expand Up @@ -110,7 +104,7 @@ struct Vector3f {

inline f32 squaredLength() const { return x * x + y * y + z * z; }
inline f32 squaredLength2D() const { return x * x + z * z; }
inline f32 length() const { return std::sqrtf(squaredLength()); }
inline f32 length() const { return std::sqrtf(x * x + y * y + z * z); }
inline f32 length2D() const { return std::sqrtf(squaredLength2D()); }

// seems good according to InteractBomb::actPiki
Expand Down Expand Up @@ -146,6 +140,63 @@ struct Vector3f {

void reset() { set(Vector3f(0.0f, 0.0f, 0.0f)); }

void lerpTo(Vector3f& other, f32 t, Vector3f& outVec)
{
outVec.x = (other.x - x) * t + x;
outVec.y = (other.y - y) * t + y;
outVec.z = (other.z - z) * t + z;
}

void bounce(Vector3f& surface, f32 elasticity)
{
f32 dp = -dot(surface) * elasticity;
if (dp > 0.0f) {
x = dp * surface.x + x;
y = dp * surface.y + y;
z = dp * surface.z + z;
}
}

bool isSame(Vector3f& other)
{
if (absF(x - other.x) < 0.0001f && absF(y - other.y) < 0.0001f && absF(z - other.z) < 0.0001f) {
return true;
}
return false;
}

void cross(Vector3f& vec1, Vector3f& vec2)
{
x = vec1.y * vec2.z - vec1.z * vec2.y;
y = vec1.z * vec2.x - vec1.x * vec2.z;
z = vec1.x * vec2.y - vec1.y * vec2.x;
}

void cross(Vector3f& vec2)
{
Vector3f tmp;
tmp.x = y * vec2.z - z * vec2.y;
tmp.y = z * vec2.x - x * vec2.z;
tmp.z = x * vec2.y - y * vec2.x;
x = tmp.x;
y = tmp.y;
z = tmp.z;
}

void multiply(f32 scale)
{
x *= scale;
y *= scale;
z *= scale;
}

void add(Vector3f& other)
{
x += other.x;
y += other.y;
z += other.z;
}

// unused/inlined:
void rotateTranspose(Matrix4f&);
void rotate(Quat&);
Expand All @@ -172,6 +223,12 @@ struct Vector2f {
Vector2f() { }
Vector2f(const f32& x, const f32& y);

void set(f32 _x, f32 _y)
{
x = _x;
y = _y;
}

f32 x, y; // _00, _04
};

Expand Down
6 changes: 3 additions & 3 deletions include/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ f64 __setflm(f64);

static inline f32 sqrtf(f32 x)
{
static const f64 _half = .5;
static const f64 _three = 3.0;
const f64 _half = .5;
const f64 _three = 3.0;

vf32 y;
if (x > 0.0f) {
Expand All @@ -74,7 +74,7 @@ static inline f32 sqrtf(f32 x)
return x;
}

static inline f32 absF(f32 val) { return __fabs(val); }
static inline f32 absF(f32 val) { return (f32)__fabsf(val); }

static inline f32 absVal(f32 val) { return (val < 0.0f) ? -val : val; }

Expand Down
Loading

0 comments on commit 6d208c7

Please sign in to comment.