|
|
@ -43,6 +43,7 @@ int db; |
|
|
|
|
|
|
|
|
u_long ot[2][OTLEN]; // Ordering tables, two arrays for double buffering. These are basically the buckets for bucket sorting of polygons. |
|
|
u_long ot[2][OTLEN]; // Ordering tables, two arrays for double buffering. These are basically the buckets for bucket sorting of polygons. |
|
|
// You can also see them as "layers" in the modern 3D graphics sense, but they serve a more immediate role for polygon ordering. |
|
|
// You can also see them as "layers" in the modern 3D graphics sense, but they serve a more immediate role for polygon ordering. |
|
|
|
|
|
// Layer 0 is free for overlays, as polygons at depth 0 will be clipped. |
|
|
char primbuff[2][65536]; // Primitive buffer, just a raw buffer of bytes to use as a pool for primitives |
|
|
char primbuff[2][65536]; // Primitive buffer, just a raw buffer of bytes to use as a pool for primitives |
|
|
char *nextpri; |
|
|
char *nextpri; |
|
|
|
|
|
|
|
|
@ -96,6 +97,7 @@ const MATRIX identity = { |
|
|
0, 0, 0, |
|
|
0, 0, 0, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Transform to change the coordinate system from PS1 Default (Y down, Z forward) to Quake (Z up, Y forward) |
|
|
const MATRIX quake_swizzle = { |
|
|
const MATRIX quake_swizzle = { |
|
|
ONE, 0, 0, |
|
|
ONE, 0, 0, |
|
|
0, 0, -ONE, |
|
|
0, 0, -ONE, |
|
|
@ -445,10 +447,14 @@ void drawModel(MATRIX *view_matrix, ps1mdl_t *model, ps1skin_t *skin, int frameC |
|
|
for (unsigned short triIdx = 0; triIdx < triangleCount; ++triIdx) |
|
|
for (unsigned short triIdx = 0; triIdx < triangleCount; ++triIdx) |
|
|
{ |
|
|
{ |
|
|
ps1mdl_triangle_t *tri = &model->triangles[triIdx]; |
|
|
ps1mdl_triangle_t *tri = &model->triangles[triIdx]; |
|
|
|
|
|
|
|
|
|
|
|
unsigned short i0 = tri->vertexIndex[0]; |
|
|
|
|
|
unsigned short i1 = tri->vertexIndex[1]; |
|
|
|
|
|
unsigned short i2 = tri->vertexIndex[2]; |
|
|
|
|
|
|
|
|
SVECTOR *v0 = &vertexBuffer[tri->vertexIndex[0]]; |
|
|
|
|
|
SVECTOR *v1 = &vertexBuffer[tri->vertexIndex[1]]; |
|
|
|
|
|
SVECTOR *v2 = &vertexBuffer[tri->vertexIndex[2]]; |
|
|
|
|
|
|
|
|
SVECTOR *v0 = &vertexBuffer[i0]; |
|
|
|
|
|
SVECTOR *v1 = &vertexBuffer[i1]; |
|
|
|
|
|
SVECTOR *v2 = &vertexBuffer[i2]; |
|
|
|
|
|
|
|
|
gte_ldv3(v0, v1, v2); |
|
|
gte_ldv3(v0, v1, v2); |
|
|
gte_rtpt(); // Rotation, Translation and Perspective triplet (all three vertices at once) |
|
|
gte_rtpt(); // Rotation, Translation and Perspective triplet (all three vertices at once) |
|
|
@ -463,12 +469,12 @@ void drawModel(MATRIX *view_matrix, ps1mdl_t *model, ps1skin_t *skin, int frameC |
|
|
gte_avsz3(); |
|
|
gte_avsz3(); |
|
|
gte_stotz(&p); |
|
|
gte_stotz(&p); |
|
|
unsigned short depth = p;//p >> 2; |
|
|
unsigned short depth = p;//p >> 2; |
|
|
if (depth < 0 || depth >= OTLEN) |
|
|
|
|
|
|
|
|
if (depth <= 0 || depth >= OTLEN) |
|
|
continue; |
|
|
continue; |
|
|
|
|
|
|
|
|
ps1mdl_texcoord_t *tc0 = &model->texCoords[tri->vertexIndex[0]]; |
|
|
|
|
|
ps1mdl_texcoord_t *tc1 = &model->texCoords[tri->vertexIndex[1]]; |
|
|
|
|
|
ps1mdl_texcoord_t *tc2 = &model->texCoords[tri->vertexIndex[2]]; |
|
|
|
|
|
|
|
|
ps1mdl_texcoord_t *tc0 = &model->texCoords[i0]; |
|
|
|
|
|
ps1mdl_texcoord_t *tc1 = &model->texCoords[i1]; |
|
|
|
|
|
ps1mdl_texcoord_t *tc2 = &model->texCoords[i2]; |
|
|
|
|
|
|
|
|
if (tri->frontFace) |
|
|
if (tri->frontFace) |
|
|
{ |
|
|
{ |
|
|
@ -533,8 +539,8 @@ void drawStuff(int counter) |
|
|
ScaleMatrixL(&proj_matrix, &aspect_scale); // Apply aspect ratio correction for the current resolution |
|
|
ScaleMatrixL(&proj_matrix, &aspect_scale); // Apply aspect ratio correction for the current resolution |
|
|
|
|
|
|
|
|
MATRIX view_matrix; |
|
|
MATRIX view_matrix; |
|
|
SVECTOR trot = { -cam_rot.vx, -cam_rot.vy, -cam_rot.vz, 0 }; // inverse camera rotation (in Quake coordinates) |
|
|
|
|
|
VECTOR tpos = { -cam_pos.vx, -cam_pos.vy, -cam_pos.vz }; // inverse camera position (in Quake coordinates) |
|
|
|
|
|
|
|
|
SVECTOR trot = { -cam_rot.vx, -cam_rot.vy, -cam_rot.vz, 0 }; // Inverse camera rotation (in Quake coordinates) |
|
|
|
|
|
VECTOR tpos = { -cam_pos.vx, -cam_pos.vy, -cam_pos.vz }; // Inverse camera position (in Quake coordinates) |
|
|
RotMatrix(&trot, &view_matrix); // Set camera rotation part of the view matrix |
|
|
RotMatrix(&trot, &view_matrix); // Set camera rotation part of the view matrix |
|
|
ApplyMatrixLV(&view_matrix, &tpos, &tpos); // Apply camera rotation to camera position |
|
|
ApplyMatrixLV(&view_matrix, &tpos, &tpos); // Apply camera rotation to camera position |
|
|
TransMatrix(&view_matrix, &tpos); // Apply transformed position to the translation part of the view matrix |
|
|
TransMatrix(&view_matrix, &tpos); // Apply transformed position to the translation part of the view matrix |
|
|
@ -552,6 +558,7 @@ void handleInput() |
|
|
{ |
|
|
{ |
|
|
const int moveSpeed = 32; |
|
|
const int moveSpeed = 32; |
|
|
const short rotSpeed = 32; |
|
|
const short rotSpeed = 32; |
|
|
|
|
|
const char deadZone = 0x30; |
|
|
|
|
|
|
|
|
// Check if we have a connected controller on port 1 |
|
|
// Check if we have a connected controller on port 1 |
|
|
if (padBuffer[0][0] != 0) |
|
|
if (padBuffer[0][0] != 0) |
|
|
@ -630,13 +637,13 @@ void handleInput() |
|
|
if (padType == 0x5 || padType == 0x7) |
|
|
if (padType == 0x5 || padType == 0x7) |
|
|
{ |
|
|
{ |
|
|
short rightJoyX = (short)(padBuffer[0][4]) - 0x80; |
|
|
short rightJoyX = (short)(padBuffer[0][4]) - 0x80; |
|
|
if (rightJoyX > -0x20 && rightJoyX < 0x20) rightJoyX = 0; |
|
|
|
|
|
|
|
|
if (rightJoyX > -deadZone && rightJoyX < deadZone) rightJoyX = 0; |
|
|
short rightJoyY = (short)(padBuffer[0][5]) - 0x80; |
|
|
short rightJoyY = (short)(padBuffer[0][5]) - 0x80; |
|
|
if (rightJoyY > -0x20 && rightJoyY < 0x20) rightJoyY = 0; |
|
|
|
|
|
|
|
|
if (rightJoyY > -deadZone && rightJoyY < deadZone) rightJoyY = 0; |
|
|
short leftJoyX = (short)(padBuffer[0][6]) - 0x80; |
|
|
short leftJoyX = (short)(padBuffer[0][6]) - 0x80; |
|
|
if (leftJoyX > -0x20 && leftJoyX < 0x20) leftJoyX = 0; |
|
|
|
|
|
|
|
|
if (leftJoyX > -deadZone && leftJoyX < deadZone) leftJoyX = 0; |
|
|
short leftJoyY = (short)(padBuffer[0][7]) - 0x80; |
|
|
short leftJoyY = (short)(padBuffer[0][7]) - 0x80; |
|
|
if (leftJoyY > -0x20 && leftJoyY < 0x20) leftJoyY = 0; |
|
|
|
|
|
|
|
|
if (leftJoyY > -deadZone && leftJoyY < deadZone) leftJoyY = 0; |
|
|
|
|
|
|
|
|
// Move forward/backward |
|
|
// Move forward/backward |
|
|
cam_pos.vx -= (cam_mtx.m[0][1] * leftJoyY * moveSpeed) >> 19; |
|
|
cam_pos.vx -= (cam_mtx.m[0][1] * leftJoyY * moveSpeed) >> 19; |
|
|
|