Fixes #5: 't' is now used in drawPoly()

This commit is contained in:
ABelliqueux 2021-06-29 16:30:44 +02:00
parent d2f5a86ef0
commit 92d05f24a7
7 changed files with 232 additions and 114 deletions

View File

@ -16,66 +16,67 @@ struct NODE;
struct QUAD;
typedef struct BODY {
VECTOR gForce;
VECTOR position;
SVECTOR velocity;
int mass;
int invMass;
VECTOR min;
VECTOR max;
int restitution;
} BODY;
VECTOR gForce;
VECTOR position;
SVECTOR velocity;
int mass;
int invMass;
VECTOR min;
VECTOR max;
int restitution;
} BODY;
typedef struct VANIM {
int nframes; // number of frames e.g 20
int nvert; // number of vertices e.g 21
int cursor; // anim cursor
int lerpCursor; // anim cursor
int dir; // playback direction (1 or -1)
int interpolate; // use lerp to interpolate keyframes
SVECTOR data[]; // vertex pos as SVECTORs e.g 20 * 21 SVECTORS
} VANIM;
int nframes; // number of frames e.g 20
int nvert; // number of vertices e.g 21
int cursor; // anim cursor
int lerpCursor; // anim cursor
int dir; // playback direction (1 or -1)
int interpolate; // use lerp to interpolate keyframes
SVECTOR data[]; // vertex pos as SVECTORs e.g 20 * 21 SVECTORS
} VANIM;
typedef struct PRIM {
VECTOR order;
int code; // Same as POL3/POL4 codes : Code (F3 = 1, FT3 = 2, G3 = 3,
VECTOR order;
int code; // Same as POL3/POL4 codes : Code (F3 = 1, FT3 = 2, G3 = 3,
// GT3 = 4) Code (F4 = 5, FT4 = 6, G4 = 7, GT4 = 8)
} PRIM;
} PRIM;
typedef struct MESH {
TMESH * tmesh;
PRIM * index;
TIM_IMAGE * tim;
unsigned long * tim_data;
MATRIX mat;
VECTOR pos;
SVECTOR rot;
short isRigidBody;
short isStaticBody;
short isRound;
short isPrism;
short isAnim;
short isActor;
short isLevel;
short isBG;
short isSprite;
long p;
long OTz;
BODY * body;
VANIM * anim;
struct NODE * node;
VECTOR pos2D;
} MESH;
typedef struct MESH {
int totalVerts;
TMESH * tmesh;
PRIM * index;
TIM_IMAGE * tim;
unsigned long * tim_data;
MATRIX mat;
VECTOR pos;
SVECTOR rot;
short isRigidBody;
short isStaticBody;
short isRound;
short isPrism;
short isAnim;
short isActor;
short isLevel;
short isBG;
short isSprite;
long p;
long OTz;
BODY * body;
VANIM * anim;
struct NODE * node;
VECTOR pos2D;
} MESH;
typedef struct QUAD {
VECTOR v0, v1;
VECTOR v2, v3;
} QUAD;
VECTOR v0, v1;
VECTOR v2, v3;
} QUAD;
typedef struct CAMPOS {
VECTOR pos;
SVECTOR rot;
} CAMPOS;
VECTOR pos;
SVECTOR rot;
} CAMPOS;
// Blender cam ~= PSX cam with these settings :
@ -85,49 +86,49 @@ typedef struct CAMPOS {
// Lower values mean wider angle
typedef struct CAMANGLE {
CAMPOS * campos;
TIM_IMAGE * BGtim;
unsigned long * tim_data;
QUAD bw, fw;
int index;
MESH * objects[];
} CAMANGLE;
CAMPOS * campos;
TIM_IMAGE * BGtim;
unsigned long * tim_data;
QUAD bw, fw;
int index;
MESH * objects[];
} CAMANGLE;
typedef struct CAMPATH {
short len, cursor, pos;
VECTOR points[];
} CAMPATH;
short len, cursor, pos;
VECTOR points[];
} CAMPATH;
typedef struct SIBLINGS {
int index;
struct NODE * list[];
} SIBLINGS ;
int index;
struct NODE * list[];
} SIBLINGS ;
typedef struct CHILDREN {
int index;
MESH * list[];
} CHILDREN ;
int index;
MESH * list[];
} CHILDREN ;
typedef struct NODE {
MESH * plane;
SIBLINGS * siblings;
CHILDREN * objects;
CHILDREN * rigidbodies;
} NODE;
MESH * plane;
SIBLINGS * siblings;
CHILDREN * objects;
CHILDREN * rigidbodies;
} NODE;
typedef struct LEVEL {
CVECTOR * BGc;
VECTOR * BKc;
MATRIX * cmat;
MATRIX * lgtmat;
MESH ** meshes;
int * meshes_length;
MESH * actorPtr;
MESH * levelPtr;
MESH * propPtr;
CAMANGLE * camPtr;
CAMPATH * camPath;
CAMANGLE ** camAngles;
NODE * curNode;
MESH * meshPlan; // This one is temporary
} LEVEL;
CVECTOR * BGc;
VECTOR * BKc;
MATRIX * cmat;
MATRIX * lgtmat;
MESH ** meshes;
int * meshes_length;
MESH * actorPtr;
MESH * levelPtr;
MESH * propPtr;
CAMANGLE * camPtr;
CAMPATH * camPath;
CAMANGLE ** camAngles;
NODE * curNode;
MESH * meshPlan; // This one is temporary
} LEVEL;

View File

@ -8,13 +8,13 @@ void transformMesh(CAMERA * camera, MESH * meshes);
void enlightMesh(LEVEL * curLvl, MESH * actorPtr, SVECTOR * lgtang);
void drawPoly(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw);
// Tri drawing
long drawTri(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw, int t, int i);
void set3VertexLerPos(MESH * mesh, long t);
void set3Prism(POLY_GT3 * poly, MESH * mesh, DRAWENV * draw, int i);
void set3Tex(POLY_GT3 * poly, MESH * mesh, DRAWENV * draw, long t, int i);
long interpolateTri(POLY_GT3 * poly, MESH * mesh, long t, long * Flag);
void drawTri(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw);
//Quad drawing
void drawQuad(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw);
long drawQuad(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw, int t, int i);
void set4VertexLerPos(MESH * mesh, long t);
void set4Prism(POLY_GT4 * poly4, MESH * mesh, DRAWENV * draw, int i);
void set4Tex(POLY_GT4 * poly4, MESH * mesh, DRAWENV * draw, long t, int i);

View File

@ -1,8 +1,8 @@
#include "level0.h"
CVECTOR level0_BGc = { 149, 218, 216, 0 };
CVECTOR level0_BGc = { 92, 218, 216, 0 };
VECTOR level0_BKc = { 0, 255, 255, 0 };
VECTOR level0_BKc = { 88, 4, 0, 0 };
CAMPOS level0_camPos_Camera = {
{ -770,459,623 },
@ -16,7 +16,7 @@ CAMPATH level0_camPath = {
};
MATRIX level0_lgtmat = {
-1919, 3254, 1581,
-2486, 3254, -22,
0,0,0,
0,0,0,
@ -106,13 +106,14 @@ TMESH level0_modelCube = {
};
MESH level0_meshCube = {
24,
&level0_modelCube,
level0_modelCube_index,
0,
0,
{0},
{0,-236,23, 0},
{0,-1024,0},
{0,-1024,0, 0},
1, // isRigidBody
0, // isStaticBody
0, // isRound
@ -903,14 +904,95 @@ TMESH level0_modelPlane = {
100
};
SVECTOR level0_modelPlan_mesh[] = {
{ -45,36,-3 },
{ 48,36,-3 },
{ -45,2,2 },
{ 48,2,2 }
};
SVECTOR level0_modelPlan_normal[] = {
0,638,4046, 0,
0,638,4046, 0,
0,638,4046, 0,
0,638,4046, 0
};
SVECTOR level0_modelPlan_uv[] = {
64,155, 0, 0,
129,155, 0, 0,
129,130, 0, 0,
64,130, 0, 0
};
CVECTOR level0_modelPlan_color[] = {
80, 80, 80, 0,
128, 128, 128, 0,
128, 128, 128, 0
};
PRIM level0_modelPlan_index[] = {
0,1,3,2,8
};
BODY level0_modelPlan_body = {
{0, 0, 0, 0},
-40,-40,194, 0,
0,0,0, 0,
1,
ONE/1,
-45,2,-3, 0,
48,36,2, 0,
0,
};
TMESH level0_modelPlan = {
level0_modelPlan_mesh,
level0_modelPlan_normal,
level0_modelPlan_uv,
level0_modelPlan_color,
1
};
extern unsigned long _binary_TIM_home_tim_start[];
TIM_IMAGE level0_tim_home;
MESH level0_meshPlan = {
4,
&level0_modelPlan,
level0_modelPlan_index,
&level0_tim_home,
_binary_TIM_home_tim_start,
{0},
{-40,-40,194, 0},
{0,0,0},
0,
1,
0,
0,
0,
0,
0,
0,
1,
0,
0,
&level0_modelPlan_body,
0,
0,
0
};
MESH level0_meshPlane = {
400,
&level0_modelPlane,
level0_modelPlane_index,
0,
0,
{0},
{0,0,0, 0},
{0,0,0},
{0,0,0, 0},
0, // isRigidBody
0, // isStaticBody
0, // isRound
@ -998,4 +1080,5 @@ LEVEL level0 = {
&level0_camPath,
(CAMANGLE **)&level0_camAngles,
&level0_nodePlane,
&level0_meshPlan
};

View File

@ -4,9 +4,9 @@
extern LEVEL level0;
extern CVECTOR level0_BGc;;
extern CVECTOR level0_BGc;
extern VECTOR level0_BKc;;
extern VECTOR level0_BKc;
extern CAMPOS level0_camPos_Camera;
@ -72,3 +72,16 @@ extern NODE * level0_curNode;
extern NODE level0_nodePlane;
extern SVECTOR level0_modelPlan_normal[];
extern SVECTOR level0_modelPlan_uv[];
extern CVECTOR level0_modelPlan_color[];
extern PRIM level0_modelPlan_index[];
extern BODY level0_modelPlan_body;
extern TMESH level0_modelPlan;
extern MESH level0_meshPlan;

View File

@ -968,6 +968,7 @@ extern unsigned long _binary_TIM_cat_tim_length;
TIM_IMAGE level1_tim_cat;
MESH level1_meshCube = {
324,
&level1_modelCube,
level1_modelCube_index,
&level1_tim_cat,
@ -1321,7 +1322,7 @@ VANIM level1_modelCylindre_anim = {
0,
0,
1,
0,
1,
{
//Frame 0
{ 3,35,47 },
@ -1811,6 +1812,7 @@ extern unsigned long _binary_TIM_home_tim_length;
TIM_IMAGE level1_tim_home;
MESH level1_meshCylindre = {
114,
&level1_modelCylindre,
level1_modelCylindre_index,
&level1_tim_home,
@ -2278,6 +2280,7 @@ TMESH level1_modelgnd = {
};
MESH level1_meshgnd = {
144,
&level1_modelgnd,
level1_modelgnd_index,
&level1_tim_home,
@ -2595,6 +2598,7 @@ TMESH level1_modelgnd_001 = {
};
MESH level1_meshgnd_001 = {
90,
&level1_modelgnd_001,
level1_modelgnd_001_index,
&level1_tim_home,
@ -2912,6 +2916,7 @@ TMESH level1_modelgnd_003 = {
};
MESH level1_meshgnd_003 = {
90,
&level1_modelgnd_003,
level1_modelgnd_003_index,
&level1_tim_home,
@ -3229,6 +3234,7 @@ TMESH level1_modelgnd_002 = {
};
MESH level1_meshgnd_002 = {
90,
&level1_modelgnd_002,
level1_modelgnd_002_index,
&level1_tim_home,
@ -8840,6 +8846,7 @@ extern unsigned long _binary_TIM_lara_tim_length;
TIM_IMAGE level1_tim_lara;
MESH level1_meshLara = {
2082,
&level1_modelLara,
level1_modelLara_index,
&level1_tim_lara,
@ -8999,6 +9006,7 @@ TMESH level1_modelobject = {
};
MESH level1_meshobject = {
36,
&level1_modelobject,
level1_modelobject_index,
&level1_tim_home,
@ -9074,6 +9082,7 @@ TMESH level1_modelPlan = {
};
MESH level1_meshPlan = {
4,
&level1_modelPlan,
level1_modelPlan_index,
&level1_tim_home,
@ -9537,6 +9546,7 @@ TMESH level1_modelSphere = {
};
MESH level1_meshSphere = {
150,
&level1_modelSphere,
level1_modelSphere_index,
&level1_tim_home,
@ -10000,6 +10010,7 @@ TMESH level1_modelSphere_001 = {
};
MESH level1_meshSphere_001 = {
150,
&level1_modelSphere_001,
level1_modelSphere_001_index,
&level1_tim_home,
@ -10167,6 +10178,7 @@ TMESH level1_modelwall = {
};
MESH level1_meshwall = {
36,
&level1_modelwall,
level1_modelwall_index,
&level1_tim_home,
@ -10402,6 +10414,7 @@ TMESH level1_modelwall_001 = {
};
MESH level1_meshwall_001 = {
60,
&level1_modelwall_001,
level1_modelwall_001_index,
&level1_tim_home,
@ -10637,6 +10650,7 @@ TMESH level1_modelwall_002 = {
};
MESH level1_meshwall_002 = {
60,
&level1_modelwall_002,
level1_modelwall_002_index,
&level1_tim_home,
@ -10804,6 +10818,7 @@ TMESH level1_modelwall_003 = {
};
MESH level1_meshwall_003 = {
36,
&level1_modelwall_003,
level1_modelwall_003_index,
&level1_tim_home,

View File

@ -28,13 +28,17 @@ void drawPoly(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpr
long nclip, t = 0;
// FIXME : t is not incremented, thus always 0. It works if the mesh only has tris or quads, but won't work with mixed meshes.
// mesh is POLY_GT3 ( triangle )
if (mesh->index[0].code == 4) {
drawTri(mesh, Flag, atime, camMode, nextpri, ot, db, draw);
for (int i = 0; i < (mesh->totalVerts);) {
if (mesh->index[t].code == 4) {
t = drawTri(mesh, Flag, atime, camMode, nextpri, ot, db, draw, t, i);
i += 3;
}
// If mesh is quad
if (mesh->index[t].code == 8) {
t = drawQuad(mesh, Flag, atime, camMode, nextpri, ot, db, draw, t, i);
i += 4;
}
}
// If mesh is quad
if (mesh->index[0].code == 8) {
drawQuad(mesh, Flag, atime, camMode, nextpri, ot, db, draw);
}
};
void set3VertexLerPos(MESH * mesh, long t){
// Find and set 3 interpolated vertex value
@ -279,11 +283,11 @@ void set4Subdiv(void){
//~ }
};
void drawQuad(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw) {
long nclip, t = 0;
long drawQuad(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw, int t, int i) {
long nclip = 0;
// If mesh is quad
POLY_GT4 * poly4;
for (int i = 0; i < (mesh->tmesh->len * 4); i += 4) {
POLY_GT4 * poly4;
//~ for (int i = 0; i < (mesh->tmesh->len * 4); i += 4) {
// if mesh is not part of BG, draw them, else, discard
if ( !(mesh->isBG) || *camMode != 2 ) {
poly4 = (POLY_GT4 *)*nextpri;
@ -343,16 +347,17 @@ void drawQuad(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpr
}
*nextpri += sizeof( POLY_GT4 );
}
t += 1;
t++;
return t;
}
}
//~ }
};
void drawTri(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw) {
long nclip, t = 0;
long drawTri(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw, int t, int i) {
long nclip = 0;
// mesh is POLY_GT3 ( triangle )
POLY_GT3 * poly;
// len member == # vertices, but here it's # of triangle... So, for each tri * 3 vertices ...
for ( int i = 0; i < (mesh->tmesh->len * 3); i += 3 ) {
//~ for ( int i = 0; i < (mesh->tmesh->len * 3); i += 3 ) {
// If mesh is not part of precalculated background, draw them, else, discard
if ( !( mesh->isBG ) || *camMode != 2) {
poly = (POLY_GT3 *)*nextpri;
@ -412,9 +417,10 @@ void drawTri(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpri
}
*nextpri += sizeof(POLY_GT3);
}
t+=1;
t++;
return t;
}
}
//~ }
};
void drawBG(CAMANGLE * camPtr, char ** nextpri, u_long * otdisc, char * db) {
// Draw BG image in two SPRT since max width == 256 px

View File

@ -93,7 +93,7 @@ void LvlPtrSet(LEVEL * curLevel, LEVEL * level){
curLevel->camAngles = level->camAngles;
curLevel->curNode = level->curNode; // Blank
// Move these to drawPoly()
curLevel->meshPlan = level->meshPlan;
//~ curLevel->meshPlan = level->meshPlan;
//~ FntPrint("%x %x", curLevel->meshes, level->meshes);
};
int LoadLevelCD(const char*const LevelName, u_long * LoadAddress){