@ -42,19 +42,20 @@ 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 3 D graphics sense , but they serve a more immediate role for polygon ordering .
/ / You can also see them as " layers " in the modern 3 D graphics sense , but they serve a more immediate role for polygon ordering .
char primbuff [ 2 ] [ 327 68 ] ; / / Primitive buffer , just a raw buffer of bytes to use as a pool for primitives
char primbuff [ 2 ] [ 655 36] ; / / Primitive buffer , just a raw buffer of bytes to use as a pool for primitives
char * nextpri ;
char * nextpri ;
extern u_long mdl_player [ ] ;
extern u_long tim_player_f [ ] ;
extern u_long tim_player_f [ ] ;
extern u_long tim_player_b [ ] ;
extern u_long tim_player_b [ ] ;
extern u_long tim_player16bpp [ ] ;
extern u_long tim_shambler [ ] ;
extern u_long mdl_player [ ] ;
extern u_long mdl_shambler [ ] ;
extern u_long tim_shambler_f [ ] ;
extern u_long tim_shambler_b [ ] ;
/ / The player texture is divided into two pieces , so that each part is aligned to their own texture page
/ / The player texture is divided into two pieces , so that each part is aligned to their own texture page
TIM_IMAGE playerFrontTex , playerBackTex ;
TIM_IMAGE playerFrontTex , playerBackTex ;
TIM_IMAGE shamblerTex ;
ps1mdl_t model ;
TIM_IMAGE shamblerFrontTex , shamblerBack Tex ;
ps1mdl_t playerModel , sha mblerM odel;
void loadTexture ( const u_long * tim , TIM_IMAGE * tparam )
void loadTexture ( const u_long * tim , TIM_IMAGE * tparam )
{
{
@ -124,12 +125,13 @@ void init(void)
nextpri = primbuff [ 0 ] ;
nextpri = primbuff [ 0 ] ;
loadModel ( mdl_player , & playerModel ) ;
loadTexture ( tim_player_f , & playerFrontTex ) ;
loadTexture ( tim_player_f , & playerFrontTex ) ;
loadTexture ( tim_player_b , & playerBackTex ) ;
loadTexture ( tim_player_b , & playerBackTex ) ;
/ / loadTexture ( tim_player16bpp , & playerFrontTex ) ;
loadTexture ( tim_shambler , & shamblerTex ) ;
loadModel ( mdl_player , & model ) ;
loadModel ( mdl_shambler , & shamblerModel ) ;
loadTexture ( tim_shambler_f , & shamblerFrontTex ) ;
loadTexture ( tim_shambler_b , & shamblerBackTex ) ;
/ / Set texture page for the entire drawing environment . Nice in some cases perhaps , but not what we need .
/ / Set texture page for the entire drawing environment . Nice in some cases perhaps , but not what we need .
/ / draw [ 0 ] . tpage = getTPage ( playerFrontTex . mode & 0x3 , 0 , playerFrontTex . prect - > x , playerFrontTex . prect - > y ) ;
/ / draw [ 0 ] . tpage = getTPage ( playerFrontTex . mode & 0x3 , 0 , playerFrontTex . prect - > x , playerFrontTex . prect - > y ) ;
@ -289,33 +291,22 @@ static int fakeLight(const int *norm)
return lit < < 16 | lit < < 8 | lit ;
return lit < < 16 | lit < < 8 | lit ;
}
}
void drawStuff ( int c ounter )
void drawModel ( ps1mdl_t * model , TIM_IMAGE * frontTex , TIM_IMAGE * backTex , int xOffset , int frameC ounter )
{
{
ClearOTagR ( ot [ db ] , OTLEN ) ;
/ / Print the obligatory hello world and counter to show that the
/ / program isn ' t locking up to the last created text stream
FntPrint ( - 1 , " COUNTER=%d, SIN=%d \n " , counter , isin ( counter ) ) ;
FntPrint ( - 1 , " Image x %d y %d w %d h %d mode 0x%x \n " , playerFrontTex . prect - > x , playerFrontTex . prect - > y , playerFrontTex . prect - > w , playerFrontTex . prect - > h , playerFrontTex . mode ) ;
FntPrint ( - 1 , " Model: %d tris, %d verts \n " , model . header - > triangleCount , model . header - > vertexCount ) ;
int frameNum = frameCounter % model - > header - > frameCount ;
int vertOffs = frameNum * model - > header - > vertexCount ;
/ / Draw the last created text stream
FntFlush ( - 1 ) ;
int frameNum = ( counter > > 2 ) % model . header - > frameCount ;
int vertOffs = frameNum * model . header - > vertexCount ;
for ( int triIdx = 0 ; triIdx < model . header - > triangleCount ; + + triIdx )
for ( int triIdx = 0 ; triIdx < model - > header - > triangleCount ; + + triIdx )
{
{
ps1mdl_triangle_t * tri = & model . triangles [ triIdx ] ;
ps1mdl_triangle_t * tri = & model - > triangles [ triIdx ] ;
ps1mdl_vertex_t * v0 = & model . vertices [ tri - > vertexIndex [ 0 ] + vertOffs ] ;
ps1mdl_vertex_t * v1 = & model . vertices [ tri - > vertexIndex [ 1 ] + vertOffs ] ;
ps1mdl_vertex_t * v2 = & model . vertices [ tri - > vertexIndex [ 2 ] + vertOffs ] ;
ps1mdl_vertex_t * v0 = & model - > vertices [ tri - > vertexIndex [ 0 ] + vertOffs ] ;
ps1mdl_vertex_t * v1 = & model - > vertices [ tri - > vertexIndex [ 1 ] + vertOffs ] ;
ps1mdl_vertex_t * v2 = & model - > vertices [ tri - > vertexIndex [ 2 ] + vertOffs ] ;
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 [ tri - > vertexIndex [ 0 ] ] ;
ps1mdl_texcoord_t * tc1 = & model - > texCoords [ tri - > vertexIndex [ 1 ] ] ;
ps1mdl_texcoord_t * tc2 = & model - > texCoords [ tri - > vertexIndex [ 2 ] ] ;
/ / Use normal indices to generate a greyscale value . Good for just giving the polygons some gradients .
/ / Use normal indices to generate a greyscale value . Good for just giving the polygons some gradients .
unsigned int n0 = v0 - > normalIndex , n1 = v1 - > normalIndex , n2 = v2 - > normalIndex ;
unsigned int n0 = v0 - > normalIndex , n1 = v1 - > normalIndex , n2 = v2 - > normalIndex ;
@ -337,19 +328,36 @@ void drawStuff(int counter)
unsigned short depth = ( ( unsigned short ) v0 - > position [ 1 ] + ( unsigned short ) v1 - > position [ 1 ] + ( unsigned short ) v2 - > position [ 1 ] ) / 3 ;
unsigned short depth = ( ( unsigned short ) v0 - > position [ 1 ] + ( unsigned short ) v1 - > position [ 1 ] + ( unsigned short ) v2 - > position [ 1 ] ) / 3 ;
/ / Since we have the texture split into two parts , we need to correct the UVs that are * not * on the seam , instead of the other way round
/ / Since we have the texture split into two parts , we need to correct the UVs that are * not * on the seam , instead of the other way round
short u0 = ! tri - > frontFace & & ! tc0 - > onSeam ? tc0 - > u - ( model . header - > skinWidth > > 1 ) : tc0 - > u ;
short u1 = ! tri - > frontFace & & ! tc1 - > onSeam ? tc1 - > u - ( model . header - > skinWidth > > 1 ) : tc1 - > u ;
short u2 = ! tri - > frontFace & & ! tc2 - > onSeam ? tc2 - > u - ( model . header - > skinWidth > > 1 ) : tc2 - > u ;
short u0 = ! tri - > frontFace & & ! tc0 - > onSeam ? tc0 - > u - ( model - > header - > skinWidth > > 1 ) : tc0 - > u ;
short u1 = ! tri - > frontFace & & ! tc1 - > onSeam ? tc1 - > u - ( model - > header - > skinWidth > > 1 ) : tc1 - > u ;
short u2 = ! tri - > frontFace & & ! tc2 - > onSeam ? tc2 - > u - ( model - > header - > skinWidth > > 1 ) : tc2 - > u ;
addGouraudTexturedTriangle (
addGouraudTexturedTriangle (
v0 - > position [ 0 ] , 240 - v0 - > position [ 2 ] ,
v1 - > position [ 0 ] , 240 - v1 - > position [ 2 ] ,
v2 - > position [ 0 ] , 240 - v2 - > position [ 2 ] ,
xOffset + v0 - > position [ 0 ] , 240 - v0 - > position [ 2 ] ,
xOffset + v1 - > position [ 0 ] , 240 - v1 - > position [ 2 ] ,
xOffset + v2 - > position [ 0 ] , 240 - v2 - > position [ 2 ] ,
( unsigned char ) depth ,
( unsigned char ) depth ,
rgb0 , rgb1 , rgb2 ,
rgb0 , rgb1 , rgb2 ,
u0 , tc0 - > v , u1 , tc1 - > v , u2 , tc2 - > v , tri - > frontFace ? & playerFrontTex : & playerBackTex ) ;
u0 , tc0 - > v , u1 , tc1 - > v , u2 , tc2 - > v , tri - > frontFace ? frontTex : backTex ) ;
}
}
}
void drawStuff ( int counter )
{
ClearOTagR ( ot [ db ] , OTLEN ) ;
/ / Print the obligatory hello world and counter to show that the
/ / program isn ' t locking up to the last created text stream
FntPrint ( - 1 , " COUNTER=%d, SIN=%d \n " , counter , isin ( counter ) ) ;
FntPrint ( - 1 , " Image x %d y %d w %d h %d mode 0x%x \n " , playerFrontTex . prect - > x , playerFrontTex . prect - > y , playerFrontTex . prect - > w , playerFrontTex . prect - > h , playerFrontTex . mode ) ;
FntPrint ( - 1 , " Model: %d tris, %d verts \n " , playerModel . header - > triangleCount , playerModel . header - > vertexCount ) ;
/ / Draw the last created text stream
FntFlush ( - 1 ) ;
drawModel ( & playerModel , & playerFrontTex , & playerBackTex , - 40 , counter > > 2 ) ;
drawModel ( & shamblerModel , & shamblerFrontTex , & shamblerBackTex , 80 , counter > > 2 ) ;
return ;
return ;
int r , g , b ;
int r , g , b ;
@ -363,7 +371,7 @@ void drawStuff(int counter)
addColoredTriangle ( 260 , 140 , 220 , 220 , 300 , 220 , 0xFF0000 , 0x00FF00 , 0x0000FF , 0 ) ;
addColoredTriangle ( 260 , 140 , 220 , 220 , 300 , 220 , 0xFF0000 , 0x00FF00 , 0x0000FF , 0 ) ;
addTexturedTriangle ( 260 , 40 , 220 , 120 , 300 , 120 , 0 , 94 , 74 , 124 , 58 , 1 , & playerFrontTex ) ;
addTexturedTriangle ( 260 , 40 , 220 , 120 , 300 , 120 , 0 , 94 , 74 , 124 , 58 , 1 , & playerFrontTex ) ;
addTexturedSprite ( 20 , 140 , 80 , 80 , & playerFrontTex ) ;
addTexturedSprite ( 20 , 140 , 80 , 80 , & playerFrontTex ) ;
addTexturedSprite ( 80 , 40 , 154 , 114 , & shamblerTex ) ;
addTexturedSprite ( 80 , 40 , 154 , 114 , & shamblerFront Tex ) ;
}
}
/ / Main function , program entrypoint
/ / Main function , program entrypoint