corrected GTE init and vectors

This commit is contained in:
ABelliqueux 2020-12-27 19:30:21 +01:00
parent 9b80d1ebd9
commit ac50461d6b
4 changed files with 83 additions and 20 deletions

View File

@ -1,4 +1,4 @@
#~ ## Hello world
## Hello world
TARGET = hello_world
TYPE = ps-exe
@ -26,7 +26,7 @@ SRCS = hello_world.c \
#~ SRCS = hello_2pads.c \
#~ ../common/crt0/crt0.s \
#~ ## Hello poly
## Hello poly
#~ TARGET = hello_poly
#~ TYPE = ps-exe
@ -76,7 +76,7 @@ SRCS = hello_world.c \
#~ VAG/hello.vag
#~ VAG/poly.vag
#~ ## Poly fun !
## Poly fun !
#~ TARGET = fun_with_poly
#~ TYPE = ps-exe

View File

@ -73,8 +73,8 @@ void init(void)
// Initialize and setup the GTE
InitGeom();
SetGeomOffset(0,0);
SetGeomScreen(1);
SetGeomOffset(CENTERX,CENTERY);
SetGeomScreen(CENTERX);
SetDefDispEnv(&disp[0], 0, 0, SCREENXRES, SCREENYRES);
SetDefDispEnv(&disp[1], 0, SCREENYRES, SCREENXRES, SCREENYRES);
@ -128,7 +128,8 @@ int main(void)
POLY_F4 *poly = {0}; // pointer to a POLY_F4
SVECTOR RotVector = {0, 0, 0}; // Initialize rotation vector {x, y, z}
VECTOR MovVector = {CENTERX, CENTERY, 0}; // Initialize translation vector {x, y, z}
VECTOR MovVector = {0, 0, CENTERX, 0}; // Initialize translation vector {x, y, z}
VECTOR ScaleVector ={ONE, ONE, ONE}; // ONE is define as 4096 in libgte.h
SVECTOR VertPos[4] = { // Set initial vertices position relative to 0,0 - see here : https://psx.arthus.net/docs/poly_f4.jpg
{-32, -32, 1 }, // Vert 1
@ -140,6 +141,7 @@ int main(void)
long polydepth;
long polyflag;
long OTz;
init();
@ -152,7 +154,8 @@ int main(void)
// Set transform matrices for this polygon
RotMatrix(&RotVector, &PolyMatrix); // Apply rotation matrix
TransMatrix(&PolyMatrix, &MovVector); // Apply translation matrix
TransMatrix(&PolyMatrix, &MovVector);
ScaleMatrix(&PolyMatrix, &ScaleVector); // Apply translation matrix
SetRotMatrix(&PolyMatrix); // Set default rotation matrix
SetTransMatrix(&PolyMatrix); // Set default transformation matrix
@ -160,7 +163,17 @@ int main(void)
setPolyF4(poly); // Initialize poly as a POLY_F4
setRGB0(poly, 255, 0, 255); // Set poly color
RotTransPers4(
// RotTransPers
//~ OTz = RotTransPers(&VertPos[0], (long*)&poly->x0, &polydepth, &polyflag);
//~ RotTransPers(&VertPos[1], (long*)&poly->x1, &polydepth, &polyflag);
//~ RotTransPers(&VertPos[2], (long*)&poly->x2, &polydepth, &polyflag);
//~ RotTransPers(&VertPos[3], (long*)&poly->x3, &polydepth, &polyflag);
// RotTransPers4 equivalent
OTz = RotTransPers4(
&VertPos[0], &VertPos[1], &VertPos[2], &VertPos[3],
(long*)&poly->x0, (long*)&poly->x1, (long*)&poly->x2, (long*)&poly->x3,
&polydepth,
@ -168,7 +181,10 @@ int main(void)
); // Perform coordinate and perspective transformation for 4 vertices
RotVector.vz+=16; // Apply rotation on Z-axis. On PSX, the Z-axis is pointing away from the screen.
RotVector.vy += 4;
RotVector.vz += 4; // Apply rotation on Z-axis. On PSX, the Z-axis is pointing away from the screen.
addPrim(ot[db], poly); // add poly to the Ordering table

View File

@ -1,6 +1,18 @@
// With help from Nicolas Noble, Jaby smoll Seamonstah
// Based on Lameguy64's tutorial series : http://lameguy64.net/svn/pstutorials/chapter1/2-graphics.html
//
// From ../psyq/addons/graphics/MESH/RMESH/TUTO0.C :
//
/* PSX screen coordinate system
*
* Z+
* /
* /
* +------X+
* /|
* / |
* / Y+
* eye */
#include <sys/types.h>
#include <stdio.h>
@ -80,8 +92,8 @@ void init(void)
// Initialize and setup the GTE
InitGeom();
SetGeomOffset(0,0);
SetGeomScreen(1);
SetGeomOffset(CENTERX,CENTERY);
SetGeomScreen(CENTERX);
SetDefDispEnv(&disp[0], 0, 0, SCREENXRES, SCREENYRES);
SetDefDispEnv(&disp[1], 0, SCREENYRES, SCREENXRES, SCREENYRES);
@ -135,7 +147,8 @@ int main(void)
POLY_FT4 *poly = {0}; // pointer to a POLY_G4
SVECTOR RotVector = {0, 0, 0}; // Initialize rotation vector {x, y, z}
VECTOR MovVector = {CENTERX, CENTERY, 0}; // Initialize translation vector {x, y, z}
VECTOR MovVector = {0, 0, CENTERX/2, 0}; // Initialize translation vector {x, y, z, pad}
VECTOR ScaleVector = {ONE, ONE, ONE}; // ONE is define as 4096 in libgte.h
SVECTOR VertPos[4] = { // Set initial vertices position relative to 0,0 - see here : https://psx.arthus.net/docs/poly_f4.jpg
{-32, -32, 1 }, // Vert 1
@ -148,6 +161,8 @@ int main(void)
long polydepth;
long polyflag;
int ping = 0;
init();
LoadTexture(_binary_TIM_bousai_tim_start, &bousai);
@ -162,6 +177,7 @@ int main(void)
RotMatrix(&RotVector, &PolyMatrix); // Apply rotation matrix
TransMatrix(&PolyMatrix, &MovVector); // Apply translation matrix
ScaleMatrix(&PolyMatrix, &ScaleVector); // Apply scale matrix
SetRotMatrix(&PolyMatrix); // Set default rotation matrix
SetTransMatrix(&PolyMatrix); // Set default transformation matrix
@ -181,7 +197,25 @@ int main(void)
setUV4(poly, 0, 0, 0, 144, 144, 0, 144, 144); // Set UV coordinates in order Top Left, Bottom Left, Top Right, Bottom Right
RotVector.vz+=16; // Apply rotation on Z-axis. On PSX, the Z-axis is pointing away from the screen.
// Let's have some fun on the Z axis
if(!ping){
if (MovVector.vz < CENTERX){ // While Poly position on Z axis is < 160, push it
MovVector.vz += 1; // Push on Z axis
} else {
ping = !ping; // Switch ping value
}
}
if(ping){
if (MovVector.vz > CENTERX/2){ // While Poly position on Z axis is > 80, pull it
MovVector.vz -= 1; // Pull on Z axis
} else {
ping = !ping; // Switch ping value
}
}
addPrim(ot[db], poly); // add poly to the Ordering table

View File

@ -1,6 +1,19 @@
// With help from Nicolas Noble, Jaby smoll Seamonstah
// Based on Lameguy64's tutorial series : http://lameguy64.net/svn/pstutorials/chapter1/2-graphics.html
//
// From ../psyq/addons/graphics/MESH/RMESH/TUTO0.C :
//
/* PSX screen coordinate system
*
* Z+
* /
* /
* +------X+
* /|
* / |
* / Y+
* eye */
#include <sys/types.h>
#include <stdio.h>
@ -81,7 +94,7 @@ void init(void)
InitGeom();
SetGeomOffset(CENTERX,CENTERY);
SetGeomScreen(8);
SetGeomScreen(CENTERX);
SetDefDispEnv(&disp[0], 0, 0, SCREENXRES, SCREENYRES);
SetDefDispEnv(&disp[1], 0, SCREENYRES, SCREENXRES, SCREENYRES);
@ -136,7 +149,7 @@ int main(void)
POLY_GT4 *poly = {0}; // pointer to a POLY_G4
SVECTOR RotVector = {0, 0, 0}; // Initialize rotation vector {x, y, z}
VECTOR MovVector = {0,0, 12}; // Initialize translation vector {x, y, z}
VECTOR MovVector = {0, 0, 120, 0}; // Initialize translation vector {x, y, z}
SVECTOR VertPos[4] = { // Set initial vertices position relative to 0,0 - see here : https://psx.arthus.net/docs/poly_f4.jpg
{-32, -32, 0 }, // Vert 1
@ -186,7 +199,7 @@ int main(void)
setUV4(poly, 0, 0, 0, 144, 144, 0, 144, 144); // Set UV coordinates in order Top Left, Bottom Left, Top Right, Bottom Right
RotVector.vz += 16; // Apply rotation on Z-axis. On PSX, the Z-axis is pointing away from the screen.
RotVector.vx += 8; // Apply rotation on Z-axis. On PSX, the Z-axis is pointing away from the screen.
addPrim(ot[db], poly); // add poly to the Ordering table