Instanced model rendering supported

This commit is contained in:
theclub654 2024-01-01 00:17:35 -05:00
parent c61b858377
commit 45a623d31d
25 changed files with 3690 additions and 187 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@ Sly1/x64/
x64/
Sly1/jb_intro.brx
Sly1/uw_bonus_drivewheels_final.brx
Sly1/uw_exterior_boat.brx
Sly1/uw_bonus_library.brx
Sly1/uw_bonus_security.brx
Sly1/uw_boss_blimp.brx

View File

@ -34,7 +34,7 @@ void RemoveAloHierarchy(ALO *palo)
s_pdliFirst = &plo;
plo.m_ppv = (void**)plo.m_pdl;
// Loading object header from RIPG object
// Loading object header from object
LO *LocalObject = (LO*)palo;
while (true)
@ -131,6 +131,7 @@ void LoadAloFromBrx(ALO* palo, CBinaryInputStream* pbis)
{
palo->xf.mat = pbis->ReadMatrix();
palo->xf.pos = pbis->ReadVector();
pbis->U8Read();
pbis->U8Read();
pbis->U8Read();
@ -140,7 +141,7 @@ void LoadAloFromBrx(ALO* palo, CBinaryInputStream* pbis)
palo->sRadiusRenderSelf = pbis->F32Read();
palo->sRadiusRenderAll = pbis->F32Read();
LoadOptionFromBrx(palo, pbis);
LoadGlobsetFromBrx(&palo->globset, pbis, palo);
LoadGlobsetFromBrx(&palo->globset ,pbis, palo);
LoadAloAloxFromBrx(pbis);
palo->cposec = pbis->U8Read();
@ -258,7 +259,7 @@ void RenderAloAsBone(ALO* palo, CM* pcm, RO* pro)
void DrawAlo(ALO* palo)
{
DrawGlob(&palo->globset);
DrawGlob(&palo->globset, palo->xf.mat, palo->xf.pos);
}
void DeleteModel(ALO *palo)

View File

@ -67,33 +67,35 @@ float CBinaryInputStream::F32Read()
}
glm::vec3 CBinaryInputStream::ReadVector()
{
return glm::vec3(F32Read(), F32Read(), F32Read());
}
glm::vec2 CBinaryInputStream::ReadVector2()
{
return glm::vec2(F32Read(), F32Read());
{
glm::vec3 temp{};
file.read(reinterpret_cast<char*> (&temp), sizeof(glm::vec3));
return temp;
}
glm::vec4 CBinaryInputStream::ReadVector4()
{
return glm::vec4 (F32Read(), F32Read(), F32Read(), F32Read());
glm::vec4 temp{};
file.read(reinterpret_cast<char*> (&temp), sizeof(glm::vec4));
return temp;
}
glm::mat3 CBinaryInputStream::ReadMatrix()
{
return glm::mat3 (ReadVector(), ReadVector(), ReadVector());
}
glm::mat4x4 CBinaryInputStream::ReadMatrix4x4()
{
return glm::mat4x2(ReadVector(), ReadVector(), ReadVector(), ReadVector());
glm::mat3 temp{};
file.read(reinterpret_cast<char*> (&temp), sizeof(glm::mat3));
return temp;
}
glm::mat4 CBinaryInputStream::ReadMatrix4()
{
return glm::mat4(ReadVector4(), ReadVector4(), ReadVector4(), ReadVector4());
glm::mat4 temp{};
file.read(reinterpret_cast<char*> (&temp[0]), sizeof(glm::vec3));
file.read(reinterpret_cast<char*> (&temp[1]), sizeof(glm::vec3));
file.read(reinterpret_cast<char*> (&temp[2]), sizeof(glm::vec3));
file.read(reinterpret_cast<char*> (&temp[3]), sizeof(glm::vec3));
temp[3][3] = 1.0;
return temp;
}
void CBinaryInputStream::ReadGeom(GEOM *pgeom)
@ -142,9 +144,9 @@ void CBinaryInputStream::ReadGeom(GEOM *pgeom)
void CBinaryInputStream::ReadBspc()
{
U16Read();
uint16_t unk0 = U16Read();
uint16_t cbsp = U16Read();
for (int i = 0; i < unk0; i++)
for (int i = 0; i < cbsp; i++)
{
U16Read();
U16Read();

View File

@ -34,16 +34,13 @@ class CBinaryInputStream
float F32Read();
// Reads vector from file
glm::vec3 ReadVector();
// Reads vector 2 from file
glm::vec2 ReadVector2();
// Reads vector 4 from file
glm::vec4 ReadVector4();
// Reads matrix from file
glm::mat3 ReadMatrix();
// Reads matrix4x4 from file
glm::mat4x4 ReadMatrix4x4();
// Reads matrix 4 from file
glm::mat4 ReadMatrix4();
// Reads Collision data from file
void ReadGeom(GEOM *pgeom);
void ReadBspc();
void ReadVbsp(); // GOTTA COME BACK TO THIS

View File

@ -13,8 +13,8 @@ LO* PloNew(CID cid, SW* psw, ALO* paloParent, OID oid, int isplice)
VTLO *pvtlo = (VTLO*)g_mpcidpvt[cid];
// Returning a address for the newly made object
LO *localObject = (LO*)pvtlo->pfnNewLo();
LO* localObject = (LO*)pvtlo->pfnNewLo();
// Storing vtable with object
localObject->pvtlo = pvtlo;
// Storing the object ID with object

View File

@ -8,5 +8,5 @@ uniform mat4 model;
void main()
{
gl_Position = proj * view * model * vec4(pos.y, pos.x, pos.z, 1.0);
gl_Position = proj * view * model * vec4(pos, 1.0);
}

View File

@ -27,6 +27,11 @@ void RenderMenuGui(SW* psw)
}
if (ImGui::MenuItem("Wireframe", "", &fRenderWireFrame))
{
}
ImGui::EndMenu();
}

View File

@ -11,5 +11,6 @@ void DeleteWorld(SW* psw);
static ImGuiFileDialog instance_a;
extern inline bool fRenderModels = true;
extern inline bool fRenderCollision = false;
extern inline bool fRenderWireFrame = false;
void RenderMenuGui(SW* psw);

View File

@ -7,7 +7,6 @@ void* NewFly()
void InitFly(FLY* pfly)
{
//std::cout << "FLY Size: " << sizeof(FLY) << "\n";
InitSo(pfly);
AppendDlEntry(&pfly->psw->dlFly, pfly);
}

View File

@ -3,13 +3,13 @@
FREECAMERA::FREECAMERA(glm::vec3 position)
{
cameraPos = position;
worldUp = glm::vec3(0.0f, 1.0f, 0.0f);
yaw = -90.0;
pitch = 0.0f;
worldUp = glm::vec3(0.0f, 0.0f, 1.0f);
yaw = -90;
pitch = 0;
speed = 10000.0;
fov = 45.0f;
cameraDirection = glm::vec3(1.0f, 0.0f, 0.0f);
cameraDirection = glm::vec3{0.0};
cameraRight = glm::vec3(0.0f, 0.0f, 0.0f);
UpdateCameraVectors();
}
@ -77,10 +77,11 @@ void FREECAMERA::UpdateViewProjMatrix(int height, int width, GLSHADER shader)
glm::mat4 view{ 1.0 };
// Creates a large frustum
proj = glm::perspective(glm::radians(fov), (float)height / (float)width, 100.0f, 1000000.0f);
proj = glm::perspective(fov, (float)height / (float)width, 100.0f, 1000000.0f);
// Transform coordinates from world space to camera space
view = glm::lookAt(cameraPos, cameraPos + cameraDirection, cameraUp);
SendViewProjShader(proj, view, shader);
}
@ -100,9 +101,10 @@ void FREECAMERA::SendViewProjShader(glm::mat4 proj, glm::mat4 view, GLSHADER sha
void FREECAMERA::UpdateCameraVectors()
{
glm::vec3 direction;
direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
direction.y = sin(glm::radians(pitch));
direction.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
direction.x = cos(glm::radians(-yaw)) * cos(glm::radians(-pitch));
direction.z = sin(glm::radians(pitch));
direction.y = sin(glm::radians(-yaw)) * cos(glm::radians(-pitch));
cameraDirection = glm::normalize(direction);
cameraRight = glm::normalize(glm::cross(cameraDirection, worldUp));

View File

@ -20,27 +20,27 @@ enum class CAMERADIRECTION
class FREECAMERA
{
public:
public:
glm::vec3 cameraPos;
glm::vec3 cameraDirection;
glm::vec3 cameraUp;
glm::vec3 cameraRight;
glm::vec3 worldUp;
glm::vec3 cameraPos;
glm::vec3 cameraDirection;
glm::vec3 cameraUp;
glm::vec3 cameraRight;
glm::vec3 worldUp;
float yaw;
float pitch;
float speed;
float fov;
float yaw;
float pitch;
float speed;
float fov;
FREECAMERA(glm::vec3 position);
FREECAMERA(glm::vec3 position);
void UpdateCameraDirection(double dx, double dy);
void UpdateCameraPos(CAMERADIRECTION direction, double dt);
void UpdateCameraFov(double dy);
void UpdateViewProjMatrix(int height, int width, GLSHADER shader);
void SendViewProjShader(glm::mat4 proj, glm::mat4 view, GLSHADER shader);
void UpdateCameraVectors();
void UpdateCameraDirection(double dx, double dy);
void UpdateCameraPos(CAMERADIRECTION direction, double dt);
void UpdateCameraFov(double dy);
void UpdateViewProjMatrix(int height, int width, GLSHADER shader);
void SendViewProjShader(glm::mat4 proj, glm::mat4 view, GLSHADER shader);
void UpdateCameraVectors();
};
// Global free camera class

View File

@ -32,7 +32,6 @@ void GL::InitGL()
glViewport(0, 0, width, height);
glEnable(GL_DEPTH_TEST);
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
IMGUI_CHECKVERSION();
ImGui::CreateContext();

View File

@ -4,7 +4,7 @@ std::vector <SHD> g_ashd;
extern std::vector<ALO*> allSWAloObjs;
extern std::vector<void*> allSwLights;
void LoadGlobsetFromBrx(GLOBSET* pglobset, CBinaryInputStream* pbis, ALO* palo)
void LoadGlobsetFromBrx(GLOBSET* pglobset ,CBinaryInputStream* pbis, ALO* palo)
{
pglobset->cpsaa = 0;
@ -38,14 +38,11 @@ void LoadGlobsetFromBrx(GLOBSET* pglobset, CBinaryInputStream* pbis, ALO* palo)
if ((unk_5 & 1) != 0)
{
pbis->S16Read();
pglobset->aglob[i].pdmat =
{
pbis->F32Read(), pbis->F32Read(), pbis->F32Read(), 0.0f,
pbis->F32Read(), pbis->F32Read(), pbis->F32Read(), 0.0f,
pbis->F32Read(), pbis->F32Read(), pbis->F32Read(), 0.0f,
pbis->F32Read(), pbis->F32Read(), pbis->F32Read(), 1.0f,
};
int instanceIndex = pbis->S16Read();
glm::mat4 pdmat = pbis->ReadMatrix4();
if(instanceIndex != 0)
pglobset->aglob[instanceIndex].pdmat.push_back(pdmat);
}
if ((unk_5 & 2) != 0)
@ -77,27 +74,33 @@ void LoadGlobsetFromBrx(GLOBSET* pglobset, CBinaryInputStream* pbis, ALO* palo)
if ((unk_5 & 0x100) != 0)
{
pbis->S16Read();
int8_t unk_8 = pbis->S8Read();
WRBG wrbg{};
WRBG* pwrbg = &wrbg;
if (unk_8 != -1)
pwrbg->oid = (OID)pbis->S16Read();
pwrbg->weki.wek = (WEK)pbis->S8Read();
if (pwrbg->weki.wek != -1)
{
pbis->F32Read();
pbis->F32Read();
pbis->F32Read();
pbis->F32Read();
pbis->ReadMatrix4x4();
pwrbg->weki.sInner = pbis->F32Read();
pwrbg->weki.uInner = pbis->F32Read();
pwrbg->weki.sOuter = pbis->F32Read();
pwrbg->weki.uOuter = pbis->F32Read();
pwrbg->weki.dmat = pbis->ReadMatrix4();
}
pbis->U8Read();
pbis->U8Read();
pbis->U8Read();
pwrbg->cmat = pbis->U8Read();
pwrbg->fDpos = pbis->U8Read();
pwrbg->fDuv = pbis->U8Read();
pglobset->aglob[i].pwrbg = pwrbg;
pwrbg->pwrbgNextGlobset = pglobset->pwrbgFirst;
pglobset->pwrbgFirst = pwrbg;
}
pglobset->aglob[i].posCenter = pbis->ReadVector();
pglobset->aglob[i].sRadius = pbis->F32Read();
pbis->S16Read();
pbis->U8Read();
pglobset->aglob[i].rtck = (RTCK)pbis->U8Read();
pbis->U8Read();
pglobset->aglob[i].oid = (OID)pbis->U8Read();
@ -132,21 +135,21 @@ void LoadGlobsetFromBrx(GLOBSET* pglobset, CBinaryInputStream* pbis, ALO* palo)
pglobset->aglob[i].asubglob[a].indexes.resize(indexCount);
pbis->Align(4);
//std::cout << "Vertices: " << std::hex << pbis->file.tellg() << "\n";
for (int b = 0; b < vertexCount; b++)
pglobset->aglob[i].asubglob[a].vertexes[b] = pbis->ReadVector();
//std::cout << "Normals: " << std::hex << pbis->file.tellg() << "\n";
for (int c = 0; c < normalCount; c++)
pglobset->aglob[i].asubglob[a].normals[c] = pbis->ReadVector();
//std::cout << "Vertex Colors: " << std::hex << pbis->file.tellg() << "\n";
for (int d = 0; d < vertexColorCount; d++)
{
pglobset->aglob[i].asubglob[a].vertexColors[d].bRed = pbis->U8Read();
pglobset->aglob[i].asubglob[a].vertexColors[d].bRed = pbis->U8Read();
pglobset->aglob[i].asubglob[a].vertexColors[d].bGreen = pbis->U8Read();
pglobset->aglob[i].asubglob[a].vertexColors[d].bBlue = pbis->U8Read();
pglobset->aglob[i].asubglob[a].vertexColors[d].bBlue = pbis->U8Read();
pglobset->aglob[i].asubglob[a].vertexColors[d].bAlpha = pbis->U8Read();
}
@ -160,13 +163,13 @@ void LoadGlobsetFromBrx(GLOBSET* pglobset, CBinaryInputStream* pbis, ALO* palo)
//std::cout << "Indexes: " << std::hex << pbis->file.tellg() << "\n\n";
for (int f = 0; f < indexCount; f++)
{
pglobset->aglob[i].asubglob[a].indexes[f].ipos = pbis->U8Read();
pglobset->aglob[i].asubglob[a].indexes[f].ipos = pbis->U8Read();
pglobset->aglob[i].asubglob[a].indexes[f].inormal = pbis->U8Read();
pglobset->aglob[i].asubglob[a].indexes[f].iuv = pbis->U8Read();
pglobset->aglob[i].asubglob[a].indexes[f].bMisc = pbis->U8Read();
pglobset->aglob[i].asubglob[a].indexes[f].iuv = pbis->U8Read();
pglobset->aglob[i].asubglob[a].indexes[f].bMisc = pbis->U8Read();
}
// Loading texture property info from vector
// Loading texture property
pglobset->aglob[i].asubglob[a].pshd = &g_ashd[pbis->U16Read()];
pglobset->aglob[i].asubglob[a].unSelfIllum = pbis->U8Read();
@ -204,6 +207,7 @@ void LoadGlobsetFromBrx(GLOBSET* pglobset, CBinaryInputStream* pbis, ALO* palo)
}
BuildSubGlob(pglobset, pglobset->aglob[i].asubglob[a].pshd, pglobset->aglob[i].asubglob[a].vertices, pglobset->aglob[i].asubglob[a].vertexes, pglobset->aglob[i].asubglob[a].normals, pglobset->aglob[i].asubglob[a].vertexColors, pglobset->aglob[i].asubglob[a].texcoords, pglobset->aglob[i].asubglob[a].indexes, pglobset->aglob[i].asubglob[a].indices);
MakeGLBuffers(&pglobset->aglob[i].asubglob[a]);
}
uint16_t numSubMesh1 = pbis->U16Read();
@ -251,22 +255,19 @@ void LoadGlobsetFromBrx(GLOBSET* pglobset, CBinaryInputStream* pbis, ALO* palo)
}
}
if (pglobset->cglob != 0)
{
MakeGLBuffers(pglobset);
allSWAloObjs.push_back(palo);
}
allSWAloObjs.push_back(palo);
}
void BuildSubGlob(GLOBSET* pglobset, SHD* pshd ,std::vector<VERTICE>& vertices,std::vector<glm::vec3>& vertexes, std::vector<glm::vec3>& normals, std::vector<RGBA>& vertexColors, std::vector<glm::vec2>& texcoords, std::vector<VTXFLG>& indexes, std::vector<uint16_t> &indices)
void BuildSubGlob(GLOBSET* pglobset, SHD* pshd, std::vector<VERTICE>& vertices, std::vector <glm::vec3>& vertexes, std::vector <glm::vec3>& normals, std::vector <RGBA>& vertexColors, std::vector <glm::vec2>& texcoords, std::vector <VTXFLG>& indexes, std::vector<uint16_t>& indices)
{
for (int i = 0; i < indexes.size(); i++)
{
VERTICE vertice;
vertice.pos = vertexes[indexes[i].ipos];
vertice.pos = vertexes[indexes[i].ipos];
vertice.normal = normals[indexes[i].inormal];
vertice.color = (RGBA)0;
if (indexes[i].iuv == 0xFF)
vertice.uv = glm::vec2{0.0};
else
@ -275,6 +276,9 @@ void BuildSubGlob(GLOBSET* pglobset, SHD* pshd ,std::vector<VERTICE>& vertices,s
vertices.push_back(vertice);
}
for (int i = 0; i < vertexColors.size(); i++)
vertices[i].color = vertexColors[i];
uint32_t idx = 0;
for (int i = 2; i < indexes.size(); i++)
{
@ -301,58 +305,70 @@ void BuildSubGlob(GLOBSET* pglobset, SHD* pshd ,std::vector<VERTICE>& vertices,s
vertexColors.shrink_to_fit();
texcoords.clear();
texcoords.shrink_to_fit();
indexes.clear();
indexes.shrink_to_fit();
}
void MakeGLBuffers(GLOBSET *pglobset)
void MakeGLBuffers(SUBGLOB *subglob)
{
for (int i = 0; i < pglobset->aglob.size(); i++)
{
for (int a = 0; a < pglobset->aglob[i].asubglob.size(); a++)
{
glGenVertexArrays(1, &pglobset->aglob[i].asubglob[a].VAO);
glBindVertexArray(pglobset->aglob[i].asubglob[a].VAO);
glGenVertexArrays(1, &subglob->VAO);
glBindVertexArray(subglob->VAO);
glGenBuffers(1, &pglobset->aglob[i].asubglob[a].VBO);
glBindBuffer(GL_ARRAY_BUFFER, pglobset->aglob[i].asubglob[a].VBO);
glBufferData(GL_ARRAY_BUFFER, pglobset->aglob[i].asubglob[a].vertices.size() * sizeof(VERTICE), pglobset->aglob[i].asubglob[a].vertices.data(), GL_STATIC_DRAW);
glGenBuffers(1, &subglob->VBO);
glBindBuffer(GL_ARRAY_BUFFER, subglob->VBO);
glBufferData(GL_ARRAY_BUFFER, subglob->vertices.size() * sizeof(VERTICE), subglob->vertices.data(), GL_STATIC_DRAW);
glGenBuffers(1, &pglobset->aglob[i].asubglob[a].EBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pglobset->aglob[i].asubglob[a].EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, pglobset->aglob[i].asubglob[a].indices.size() * sizeof(uint16_t), pglobset->aglob[i].asubglob[a].indices.data(), GL_STATIC_DRAW);
glGenBuffers(1, &subglob->EBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, subglob->EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, subglob->indices.size() * sizeof(uint16_t), subglob->indices.data(), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VERTICE), (void*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VERTICE), (void*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(VERTICE), (void*)12);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(VERTICE), (void*)12);
glEnableVertexAttribArray(1);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(VERTICE), (void*)24);
glEnableVertexAttribArray(2);
glBindVertexArray(0);
}
}
glVertexAttribPointer(2, 1, GL_UNSIGNED_INT, GL_FALSE, sizeof(VERTICE), (void*)24);
glEnableVertexAttribArray(2);
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, sizeof(VERTICE), (void*)28);
glEnableVertexAttribArray(3);
glBindVertexArray(0);
}
void DrawGlob(GLOBSET* pglobset)
void DrawGlob(GLOBSET* pglobset, glm::mat3 mat, glm::vec3 pos)
{
glm::mat4 model = mat;
// Sly 1 uses a Z up axis
model[3][0] = pos[0];
model[3][1] = pos[1];
model[3][2] = pos[2];
model[3][3] = 1.0;
for (int i = 0; i < pglobset->cglob; i++)
{
for (int a = 0; a < pglobset->aglob[i].csubglob; a++)
{
glm::mat4 model{ 1.0 };
int modelUniformLocation = glGetUniformLocation(glShader.ID, "model");
glUniformMatrix4fv(modelUniformLocation, 1, GL_FALSE, glm::value_ptr(model));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, pglobset->aglob[i].asubglob[a].pshd->glTexture);
glBindVertexArray(pglobset->aglob[i].asubglob[a].VAO);
glDrawElements(GL_TRIANGLES, pglobset->aglob[i].asubglob[a].indices.size(), GL_UNSIGNED_SHORT, (void*)0);
glBindVertexArray(0);
glDrawElements(GL_TRIANGLES, pglobset->aglob[i].asubglob[a].indices.size(), GL_UNSIGNED_SHORT, 0);
// Draws instanced models.
for (int b = 0; b < pglobset->aglob[i].pdmat.size(); b++)
{
glm::mat4 instanceModelMatrix = pglobset->aglob[i].pdmat[b];
int instanceModelUniformLocation = glGetUniformLocation(glShader.ID, "model");
glUniformMatrix4fv(instanceModelUniformLocation, 1, GL_FALSE, glm::value_ptr(instanceModelMatrix));
glDrawElements(GL_TRIANGLES, pglobset->aglob[i].asubglob[a].indices.size(), GL_UNSIGNED_SHORT, 0);
}
}
}
}

View File

@ -3,6 +3,7 @@
out vec4 FragColor;
in vec3 aNormal;
in vec4 aColor;
in vec2 aTexcoord;
uniform sampler2D Texture;

View File

@ -11,11 +11,47 @@ enum TWPS
TWPS_ShadowMidtone = 1,
TWPS_ShadowMidtoneSaturate = 2
};
enum RTCK
{
RTCK_Nil = -1,
RTCK_None = 0,
RTCK_All = 1,
RTCK_WorldZ = 2,
RTCK_LocalX = 3,
RTCK_LocalY = 4,
RTCK_LocalZ = 5,
RTCK_Max = 6
};
enum WEK
{
WEK_Nil = -1,
WEK_XYZ = 0,
WEK_XY = 1,
WEK_XZ = 2,
WEK_YZ = 3,
WEK_X = 4,
WEK_Y = 5,
WEK_Z = 6,
WEK_Max = 7
};
struct LTFN
{
float ruShadow;
float ruMidtone;
float ruHighlight;
float ruUnused;
float duShadow;
float duMidtone;
float duHighlight;
float duUnused;
};
struct VERTICE
{
glm::vec3 pos;
glm::vec3 normal;
RGBA color;
glm::vec2 uv;
};
@ -32,6 +68,30 @@ struct VTXFLG
byte bMisc;
};
struct WEKI
{
WEK wek;
float sInner;
float uInner;
float sOuter;
float uOuter;
glm::mat4 dmat;
};
struct WRBG
{
struct ALO* palo;
struct GLOB* pglob;
OID oid;
struct WR* pwr;
int cmat;
int fDpos;
int fDuv;
WEKI weki;
struct WRBG* pwrbgNextGlobset;
struct WRBG* pwrbgNextWr;
};
struct SUBGLOB // NOT DONE
{
GLuint VAO;
@ -40,7 +100,6 @@ struct SUBGLOB // NOT DONE
glm::vec3 posCenter; // Submodel orgin
float sRadius;
std::vector <VERTICE> vertices;
std::vector <glm::vec3> vertexes;
std::vector <glm::vec3> normals;
@ -48,8 +107,11 @@ struct SUBGLOB // NOT DONE
std::vector <glm::vec2> texcoords;
std::vector <VTXFLG> indexes;
std::vector <uint16_t> indices;
uint32_t unSelfIllum;
struct SHD* pshd;
struct RSGLD *prsgld;
struct WRBSG *pwrbsg;
int cibnd;
int aibnd[4];
@ -69,19 +131,19 @@ struct GLOB // NOT DONE
int fDynamic;
int grfglob;
//GLEAM *pgleam
//RTCK rtck;
RTCK rtck;
struct SAA* psaa;
float uFog;
//FGFN fgfn;
float rSubglobRadius;
//WRBG *pwrbg;
struct WRBG *pwrbg;
// Number of submodels for model
int csubglob;
std::vector<SUBGLOB> asubglob;
int csubcel;
//SUBCEL *asubcel;
// Object world space coordinates
glm::mat4 pdmat;
std::vector <glm::mat4> pdmat;
//BLOT *pblot;
OID oid;
char* pchzName;
@ -92,7 +154,7 @@ struct GLOBI // NOT DONE
int grfzon;
//SUBGLOBI *asubglobi;
int cframeStaticLights;
//TWPS twps;
TWPS twps;
float uAlpha;
float tUnfade;
}; // NOT DONE
@ -100,27 +162,27 @@ struct GLOBI // NOT DONE
struct GLOBSET // NOT DONE
{
int cbnd;
//BND *abnd;
struct BND *abnd;
std::vector <OID> mpibndoid;
// Number of submodeles for a model
int cglob;
uint64_t cglob;
std::vector <GLOB> aglob;
std::vector <GLOBI> aglobi;
//LTFN ltfn;
LTFN ltfn;
uint32_t grfglobset;
RGBA rgbaCel;
int cpose;
std::vector <float> agPoses;
std::vector <float> agPosesOrig;
//WRBG *pwrbgFirst;
struct WRBG *pwrbgFirst;
int cpsaa;
struct SAA** apsaa;
}; // NOT DONE
};
// Loads 3D models from binary file
// Loads 3D model data from binary file
void LoadGlobsetFromBrx(GLOBSET* pglobset, CBinaryInputStream* pbis, ALO* palo); // NOT FINISHED
// Converts strips to tri lists
void BuildSubGlob(GLOBSET *pglobset, SHD* pshd, std::vector<VERTICE> &vertices , std::vector <glm::vec3> &vertexes, std::vector <glm::vec3> &normals, std::vector <RGBA> &vertexColors, std::vector <glm::vec2> &texcoords, std::vector <VTXFLG> &indexes, std::vector<uint16_t> &indices);
// Storing 3D models in VRAM
void MakeGLBuffers(GLOBSET* pglobset);
void MakeGLBuffers(SUBGLOB* subglob);
// Draws Model
void DrawGlob(GLOBSET *pglobset); // NOT FINISHED
void DrawGlob(GLOBSET* pglobset, glm::mat3 mat, glm::vec3 pos); // NOT FINISHED

View File

@ -2,9 +2,11 @@
layout (location = 0) in vec3 pos;
layout (location = 1) in vec3 normal;
layout (location = 2) in vec2 texCoord;
layout (location = 2) in vec4 color;
layout (location = 3) in vec2 texcoord;
out vec3 aNormal;
out vec4 aColor;
out vec2 aTexcoord;
uniform mat4 proj;
@ -13,7 +15,8 @@ uniform mat4 model;
void main()
{
gl_Position = proj * view * model * vec4(pos.y, pos.x, pos.z, 1.0);
gl_Position = proj * view * model * vec4(pos, 1.0);
aNormal = normal;
aTexcoord = texCoord;
aColor = color;
aTexcoord = texcoord;
}

File diff suppressed because it is too large Load Diff

View File

@ -47,6 +47,11 @@ int main(int cphzArgs, char* aphzArgs[])
g_freecamera.UpdateViewProjMatrix(g_gl.height, g_gl.width, glShader);
g_freecamera.UpdateViewProjMatrix(g_gl.height, g_gl.width, glShaderCollision);
if(fRenderWireFrame != 0)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
else
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
if(fRenderModels != 0)
DrawSwAll();

View File

@ -13,8 +13,10 @@ void InitProxy(PROXY *pproxy)
void LoadProxyFromBrx(PROXY *pproxy, CBinaryInputStream* pbis)
{
pbis->ReadMatrix();
pbis->ReadVector();
InitDl(&pproxy->dlProxyRoot, 0x470);
pproxy->xf.mat = pbis->ReadMatrix();
pproxy->xf.pos = pbis->ReadVector();
byte numProxyObjs = pbis->U8Read();

View File

@ -11,8 +11,6 @@ class PROXY : public ALO
DLE dleProxy;
};
static int LoadProxyFromBrxCount = 0;
void* NewProxy();
void InitProxy(PROXY *pproxy);
void LoadProxyFromBrx(PROXY *pproxy, CBinaryInputStream *pbis);

View File

@ -47,13 +47,14 @@ void DrawSwCollisionAll()
{
glShaderCollision.Use();
glm::mat4 model{ 1.0 };
int modelUniformLocation = glGetUniformLocation(glShaderCollision.ID, "model");
glUniformMatrix4fv(modelUniformLocation, 1, GL_FALSE, glm::value_ptr(model));
for (int i = 0; i < allcollisionModels.size(); i++)
{
int modelUniformLocation = glGetUniformLocation(glShaderCollision.ID, "model");
glUniformMatrix4fv(modelUniformLocation, 1, GL_FALSE, glm::value_ptr(glm::mat4{1.0}));
glBindVertexArray(allcollisionModels[i]->VAO);
glDrawElements(GL_LINES, allcollisionModels[i]->indices.size(), GL_UNSIGNED_SHORT, 0);
glBindVertexArray(0);
}
}

View File

@ -7,7 +7,7 @@ void* NewSo()
void InitSo(SO* pso)
{
InitDl(&pso->dlPhys, 0x440);
InitDl(&pso->dlPhys, 0x468);
InitAlo(pso);
InitGeom(&pso->geomLocal);

View File

@ -51,7 +51,7 @@ public:
glm::vec3 posWorldPrev;
GEOM geomLocal;
GEOM geomWorld;
void* plvo;
struct LVO* plvo;
float sRadiusSelf;
float sRadiusAll;
float sRadiusPrune;
@ -68,11 +68,11 @@ public:
glm::vec3 posMax;
char constrForce[32];
char constrTorque[32];
void* poxa;
struct OXA* poxa;
glm::vec3 dpos;
glm::vec3 drot;
void* pxa;
void* pxpInternal;
struct XA* pxa;
struct XP* pxpInternal;
int grfpvaXpValid;
int ipsoRoot;
int ipso;
@ -81,7 +81,7 @@ public:
GEOM geomCameraLocal;
GEOM geomCameraWorld;
char bspcCamera[12];
void* pstso;
struct STSO* pstso;
};
void* NewSo();

View File

@ -17,36 +17,36 @@ void InitSw(SW* psw)
InitDl(&psw->dlChild, 0x38);
InitDl(&psw->dlMRD, 0xA0);
InitDl(&psw->dlMRDRealClock, 0x1C + 0x54);
InitDl(&psw->dlMRDRealClock, 0x1C + 0x54); // GOTTA COME BACK TO THIS
InitDl(&psw->dlBusy, 0x90);
InitDl(&psw->dlBusySo, 0x1C + 0x434);
InitDl(&psw->dlRoot, 0x428);
InitDl(&psw->dlAsega, 0x1C + 0x34);
InitDl(&psw->dlAsegaRealClock, 0x1C + 0x34);
InitDl(&psw->dlAsegaPending, 0x1C + 0x34);
InitDl(&psw->dlBusySo, 0x790);
InitDl(&psw->dlRoot, 0x458);
InitDl(&psw->dlAsega, 0x1C + 0x34); // GOTTA COME BACK TO THIS
InitDl(&psw->dlAsegaRealClock, 0x1C + 0x34); // GOTTA COME BACK TO THIS
InitDl(&psw->dlAsegaPending, 0x1C + 0x34); // GOTTA COME BACK TO THIS
InitDl(&psw->dlSma, 0x10);
InitDl(&psw->dlAmb, 0x1C + 0x60);
InitDl(&psw->dlExc, 0x1C + 4);
InitDl(&psw->dlLight, 0x538);
InitDl(&psw->dlShadow, 0x1C + 0xb8);
InitDl(&psw->dlExplste, 0x1C + 100);
InitDl(&psw->dlProxy, 0x1C + 0x2ec);
InitDl(&psw->dlFly, 0x1C + 0x60c);
InitDl(&psw->dlDprize, 0x1C + 900);
InitDl(&psw->dlRat, 0x1C + 0x630);
InitDl(&psw->dlRathole, 0x1C + 0x90);
InitDl(&psw->dlDartFree, 0x1C + 0x59c);
InitDl(&psw->dlSpire, 0x1C + 0x50);
InitDl(&psw->dlRail, 0x1C + 0x50);
InitDl(&psw->dlLanding, 0x1C + 0x50);
InitDl(&psw->dlBusyLasen, 0x1C + 0xb20);
InitDl(&psw->dlBlipg, 0x1C + 0x640);
InitDl(&psw->dlBlipgFree, 0x1C + 0x640);
InitDl(&psw->dlFader, 0x1C + 0xc);
InitDl(&psw->dlRealClockFader, 0x1C + 0xc);
InitDl(&psw->dlCrfod, 0x1C + 0xb90);
InitDl(&psw->dlShape, 0x1C + 0x44);
InitDl(&psw->dlPathzone, 0x1C + 100);
InitDl(&psw->dlAmb, 0x1C + 0x60); // GOTTA COME BACK TO THIS
InitDl(&psw->dlExc, 0x1C + 4); // GOTTA COME BACK TO THIS
InitDl(&psw->dlLight, 0x568);
InitDl(&psw->dlShadow, 0x1C + 0xb8); // GOTTA COME BACK TO THIS
InitDl(&psw->dlExplste, 0x1C + 100);// GOTTA COME BACK TO THIS
InitDl(&psw->dlProxy, 0x470);
InitDl(&psw->dlFly, 0xB50);
InitDl(&psw->dlDprize, 0x500);
InitDl(&psw->dlRat, 0xB90);
InitDl(&psw->dlRathole, 0xC8);
InitDl(&psw->dlDartFree, 0xA70);
InitDl(&psw->dlSpire, 0x1C + 0x50); // GOTTA COME BACK TO THIS
InitDl(&psw->dlRail, 0x1C + 0x50); // GOTTA COME BACK TO THIS
InitDl(&psw->dlLanding, 0x1C + 0x50); // GOTTA COME BACK TO THIS
InitDl(&psw->dlBusyLasen, 0x1200);
InitDl(&psw->dlBlipg, 0x1C + 0x640);// GOTTA COME BACK TO THIS
InitDl(&psw->dlBlipgFree, 0x1C + 0x640);// GOTTA COME BACK TO THIS
InitDl(&psw->dlFader, 0x1C + 0xc);// GOTTA COME BACK TO THIS
InitDl(&psw->dlRealClockFader, 0x1C + 0xc);// GOTTA COME BACK TO THIS
InitDl(&psw->dlCrfod, 0x1C + 0xb90);// GOTTA COME BACK TO THIS
InitDl(&psw->dlShape, 0x80);
InitDl(&psw->dlPathzone, 0xB8);
}
void InitSwDlHash(SW* psw)
@ -57,7 +57,7 @@ void InitSwDlHash(SW* psw)
void LoadSwFromBrx(SW* psw, CBinaryInputStream* pbis)
{
std::cout << "Loading World\n";
std::cout << "Loading World...\n";
// Setting difficulty for world
OnDifficultyWorldPreLoad(&g_difficulty);
//StartupSplice();

View File

@ -1,7 +1,6 @@
#pragma once
#include "lo.h"
// GOTTA COME BACK TO THIS AND CHANGE VTABLE CB
enum WREK
{
WREK_Nil = -1,
@ -19,6 +18,7 @@ struct WRE
};
};
class WR : public LO
{
public: