More CCubeMaterial

This commit is contained in:
2022-09-05 00:00:04 -04:00
parent 1179a651b3
commit 78022784ef
15 changed files with 318 additions and 27 deletions

View File

@@ -25,6 +25,16 @@ inline f32 ToReal32(register const u8& in) {
}
return r;
}
inline s16 FtoS(register f32 in) {
s16 a;
register s16* ptr = &a;
asm {
psq_st in, 0(ptr), 1, OS_FASTCAST_S16
}
return *ptr;
}
#else
inline u8 ToUint8(f32 in) {
return static_cast<u8>(in);
@@ -32,6 +42,9 @@ inline u8 ToUint8(f32 in) {
inline f32 ToReal32(u8 in) {
return static_cast<f32>(in);
}
inline s16 FtoS(f32 in) {
return static_cast<s16>(in);
}
#endif
} // namespace CCast

View File

@@ -5,6 +5,8 @@
#include "Kyoto/Basics/CCast.hpp"
#include <dolphin/gx/GXStruct.h>
#ifdef __MWERKS__
#pragma cpp_extensions on
#endif
@@ -39,6 +41,7 @@ public:
u8 GetBlueu8() const { return mB; }
u8 GetAlphau8() const { return mA; }
u16 ToRGB5A3() const;
GXColor ToGX(u32);
static const CColor& Black();
static const CColor& White();
@@ -72,4 +75,8 @@ private:
static const CColor sOrangeColor;
};
#ifdef __MWERKS__
#pragma cpp_extensions off
#endif
#endif // __CCOLOR_HPP__

View File

@@ -11,7 +11,7 @@ extern CVector3f sPlayerPosition;
class CCubeMaterial {
public:
private:
void SetupBlendMode(u32 blendFactors, const CModelFlags& flags, bool alphaTest);
static void SetupBlendMode(u32 blendFactors, const CModelFlags& flags, bool alphaTest);
static CVector3f sViewingFrom;
};

View File

@@ -5,7 +5,8 @@
#include <stddef.h>
#include "dolphin/gx.h"
#include <dolphin/gx.h>
#include <dolphin/mtx.h>
class CGX {
public:
@@ -124,6 +125,10 @@ public:
static void ResetGXStates();
static void ResetGXStatesFull(); // name?
static inline void LoadTexMtxImm(const f32 mtx[][4], unsigned long id, GXTexMtxType type) {
GXLoadTexMtxImm(const_cast<MtxPtr>(mtx), id, type);
}
static GXColor GetChanAmbColor(EChannelId channel);
static void GetFog(GXFogType* fogType, f32* fogStartZ, f32* fogEndZ, f32* fogNearZ, f32* fogFarZ, GXColor* fogColor);

View File

@@ -52,9 +52,13 @@ public:
static void StreamEnd();
static const CTransform4f& GetViewMatrix() { return mViewMatrix; }
static const CTransform4f& GetModelMatrix() { return mModelMatrix; }
static float GetSecondsMod900();
private:
static CTransform4f mViewMatrix;
static CTransform4f mModelMatrix;
};
#endif

View File

@@ -63,7 +63,7 @@ public:
static CModelFlags ColorModulate(const CColor& color);
private:
u8 x0_blendMode;
s8 x0_blendMode;
u8 x1_matSetIdx;
u16 x2_flags;
CColor x4_color;

View File

@@ -0,0 +1,16 @@
#ifndef _CMATH_HPP
#define _CMATH_HPP
#include "types.h"
class CMath {
public:
static f32 FastCosR(f32 v);
static f32 FastSinR(f32 v);
static inline f32 FastFmod(f32 x, f32 y) {
s32 v = static_cast<s32>(x * (1.f / y));
return x - v * y;
}
};
#endif

View File

@@ -5,6 +5,8 @@
#include "Kyoto/Math/CVector3f.hpp"
typedef const f32 (*ConstMtxPtr)[4];
class CInputStream;
class CMatrix3f;
@@ -13,6 +15,8 @@ public:
CTransform4f() {
// TODO
}
CTransform4f(const CVector3f& m0, const CVector3f& m1, const CVector3f& m2, const CVector3f& pos)
: m0(m0), posX(pos.GetX()), m1(m1), posY(pos.GetY()), m2(m2), posZ(pos.GetZ()) {}
CTransform4f(f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32);
CTransform4f(const CInputStream& in);
CTransform4f(const CMatrix3f& rotation, const CVector3f& translation);
@@ -23,36 +27,37 @@ public:
CVector3f GetRight() const { return CVector3f(m0.GetX(), m1.GetX(), m2.GetX()); }
CVector3f GetForward() const { return CVector3f(m0.GetY(), m1.GetY(), m2.GetY()); }
CVector3f GetUp() const { return CVector3f(m0.GetZ(), m1.GetZ(), m2.GetZ()); }
ConstMtxPtr GetCStyleMatrix() const { return reinterpret_cast<ConstMtxPtr>(this); }
CMatrix3f BuildMatrix3f() const;
// Get00__12CTransform4fCFv
// Get01__12CTransform4fCFv
// Get02__12CTransform4fCFv
// Get03__12CTransform4fCFv
// Get10__12CTransform4fCFv
// Get11__12CTransform4fCFv
// Get12__12CTransform4fCFv
// Get13__12CTransform4fCFv
// Get20__12CTransform4fCFv
// Get21__12CTransform4fCFv
// Get22__12CTransform4fCFv
// Get23__12CTransform4fCFv
f32 Get00() const { return m0.GetX(); }
f32 Get01() const { return m0.GetY(); }
f32 Get02() const { return m0.GetZ(); }
f32 Get03() const { return posX; }
f32 Get10() const { return m1.GetX(); }
f32 Get11() const { return m1.GetY(); }
f32 Get12() const { return m1.GetZ(); }
f32 Get13() const { return posY; }
f32 Get20() const { return m2.GetX(); }
f32 Get21() const { return m2.GetY(); }
f32 Get22() const { return m2.GetZ(); }
f32 Get23() const { return posZ; }
// GetColumn__12CTransform4fCF5EDimX
// GetColumn__12CTransform4fCF5EDimY
// GetColumn__12CTransform4fCF5EDimZ
// GetColumn__12CTransform4fCFi
// GetCStyleMatrix__12CTransform4fCFv
// GetInverse__12CTransform4fCFv
// GetQuickInverse__12CTransform4fCFv
CTransform4f GetQuickInverse() const;
// GetRotation__12CTransform4fCFv
// GetRow__12CTransform4fCF5EDimX
// GetRow__12CTransform4fCF5EDimY
// GetRow__12CTransform4fCF5EDimZ
inline const CVector3f& GetRow(EDimX dim) const { return m0; }
inline const CVector3f& GetRow(EDimY dim) const { return m1; }
inline const CVector3f& GetRow(EDimZ dim) const { return m2; }
// GetRow__12CTransform4fCFi
// GetUp__12CTransform4fCFv
// LookAt__12CTransform4fFRC9CVector3fRC9CVector3fRC9CVector3f
// MakeRotationsBasedOnY__12CTransform4fFRC13CUnitVector3f
// MultiplyIgnoreTranslation__12CTransform4fCFRC12CTransform4f
CTransform4f MultiplyIgnoreTranslation(const CTransform4f& other) const;
// Orthonormalize__12CTransform4fFv
// Rotate__12CTransform4fCFRC9CVector3f
// RotateLocalX__12CTransform4fFRC9CRelAngle
@@ -85,8 +90,8 @@ public:
void AddTranslationZ(f32 z) { posZ += z; }
CTransform4f& operator*=(const CTransform4f& other);
CTransform4f& operator*(const CTransform4f& vec);
CTransform4f& operator*(const CVector3f& vec);
CTransform4f operator*(const CTransform4f& vec) const;
CTransform4f operator*(const CVector3f& vec) const;
static CTransform4f FromColumns(const CVector3f&, const CVector3f&, const CVector3f&, const CVector3f&);
static const CTransform4f& Identity() { return sIdentity; }

View File

@@ -8,6 +8,10 @@
class CInputStream;
class COutputStream;
enum EDimX { kDX };
enum EDimY { kDY };
enum EDimZ { kDZ };
class CVector3f {
public:
CVector3f() : mX(0.f), mY(0.f), mZ(0.f) {}
@@ -37,8 +41,15 @@ public:
// IsEqu__9CVector3fCFRC9CVector3ff
// Lerp__9CVector3fFRC9CVector3fRC9CVector3ff
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; }
f32& operator[](s32 i) { return *(&mX + i); }
f32 operator[](s32 i) const { return *(&mX + i); }
// f32 operator[](s32 i) const { return *(&mX + i); }
bool IsNonZero() const { return mX != 0.f || mY != 0.f || mZ != 0.f; }
void DropZ() { mZ = 0.f; }

View File

@@ -54,7 +54,7 @@ inline u32 cinput_stream_helper(const TType< u32 >& type, CInputStream& in) {
return in.ReadLong();
}
template <>
inline unsigned long cinput_stream_helper(const TType< unsigned long >& type, CInputStream& in) {
inline unsigned int cinput_stream_helper(const TType< unsigned int >& type, CInputStream& in) {
return in.ReadLong();
}
template <>

9
include/dolphin/mtx.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef DOLPHIN_MTX_H
#define DOLPHIN_MTX_H
#include <dolphin/types.h>
typedef f32 Mtx[3][4];
typedef f32 (*MtxPtr)[4];
#endif

View File

@@ -6,8 +6,10 @@ extern "C" {
#endif
#define OS_FASTCAST_U8 2
#define OS_FASTCAST_S16 5
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -12,6 +12,8 @@ extern "C" {
// Pointer to unknown, to be determined at a later date.
typedef void* unkptr;
#define SBig(x) x
#ifdef __cplusplus
}
#endif