ILINE void _mathVec4Transform(f32 out[4], const f32 m[16], const f32 in[4]) {
#define M(row, col) m[col * 4 + row]
out[0] = M(0, 0) * in[0] + M(0, 1) * in[1] + M(0, 2) * in[2] + M(0, 3) * in[3];
out[1] = M(1, 0) * in[0] + M(1, 1) * in[1] + M(1, 2) * in[2] + M(1, 3) * in[3];
out[2] = M(2, 0) * in[0] + M(2, 1) * in[1] + M(2, 2) * in[2] + M(2, 3) * in[3];
out[3] = M(3, 0) * in[0] + M(3, 1) * in[1] + M(3, 2) * in[2] + M(3, 3) * in[3];
#undef M
}
ILINE f32 _mathVec3Project(Vec3* pvWin, const Vec3* pvObj, const int32 pViewport[4], const Matrix44* pProjection, const Matrix44* pView, const Matrix44* pWorld) {
Vec4 in, out;
in.x = pvObj->x;
in.y = pvObj->y;
in.z = pvObj->z;
in.w = 1.0f;
_mathVec4Transform((f32*)& out, (f32*)pWorld, (f32*)& in);
_mathVec4Transform((f32*)& in, (f32*)pView, (f32*)& out);
_mathVec4Transform((f32*)& out, (f32*)pProjection, (f32*)& in);
if (out.w == 0.0f) return 0.f;
out.x /= out.w;
out.y /= out.w;
out.z /= out.w;
pvWin->x = pViewport[0] + (1 + out.x) * pViewport[2] / 2;
pvWin->y = pViewport[1] + (1 - out.y) * pViewport[3] / 2;
float fViewportMinZ = 0, fViewportMaxZ = 1.0f;
pvWin->z = fViewportMinZ + out.z * (fViewportMaxZ - fViewportMinZ);
return out.w;
}
class ClientDevice
{
public:
DWORD* pDevice;
};
class IRenderer
{
public:
FLOAT GetHypotenuseFromCenter(Vec3 Point) {
Vec3 Screen;
FLOAT ScreenCenterX = (Width / 2.0f);
FLOAT ScreenCenterY = (Height / 2.0f);
if (ProjectToScreen(Point, Screen) == FALSE)return 9999.0f;
FLOAT PositionX = Screen.x > ScreenCenterX ? Screen.x - ScreenCenterX : ScreenCenterX - Screen.x;
FLOAT PositionY = Screen.y > ScreenCenterY ? Screen.y - ScreenCenterY : ScreenCenterY - Screen.y;
return (FLOAT)_sqrt(PositionX * PositionX + PositionY * PositionY);
}
void DrawAABB(AABB & aabb) { return vCall<void(__thiscall*)(PVOID, AABB&)>(this, 0x404 / 4)(this, aabb); }
bool ProjectToScreen(int32 * vp, FLOAT ptx, FLOAT pty, FLOAT ptz, FLOAT * sx, FLOAT * sy, FLOAT * sz) {
Vec3 vOut, vIn;
vIn.x = ptx;
vIn.y = pty;
vIn.z = ptz;
int32 v[4] = { vp[0], vp[1], vp[2], vp[3] };
Matrix44 mIdent;
mIdent.SetIdentity();
Matrix44 View = m_uBaseProjection;
Matrix44 Projection = m_uBaseMatrix;
if (_mathVec3Project(&vOut, &vIn, v, &Projection, &View, &mIdent)) {
*sx = vOut.x * 100.0f / (f32)v[2];
*sy = vOut.y * 100.0f / (f32)v[3];
*sz = vOut.z;
return true;
}
return false;
}
bool ProjectToScreen(Vec3 in, Vec3 & out) {
int32 v[4] = { 0, 0, Width, Height };
ProjectToScreen(v, in.x, in.y, in.z, &out.x, &out.y, &out.z);
if (out.z < 0.0f || out.z > 1.0f) return false;
out.x = out.x * (v[2] / 100.0f);
out.y = out.y * (v[3] / 100.0f);
return true;
}
char pad_0x0000[0x50]; //0x0000
Matrix44 m_uBaseProjection; //0x0050
char pad_0x0090[0xC0]; //0x0090
Matrix44 m_uBaseMatrix; //0x0150
char pad_0x0190[0x40]; //0x0190
Matrix44 CameraMatrix; //0x01D0
char pad_0x0210[0xE34]; //0x0210
Vec3 vPos; //0x1044
char pad_0x1050[0x5FC8]; //0x1050
__int32 Width; //0x7018
__int32 Height; //0x701C
char pad_0x7020[0xD34]; //0x7020
DWORD hWnd; //0x7D54
char pad_0x7D58[0x118]; //0x7D58
ClientDevice* GetDevice; //0x7E70
}; //Size=0x7E74