3D FPS Example
Posted: July 10th, 2014, 2:41 pm
Yet another 3D related example but with simple texturing and a first-person camera this time.

Programming, Homebrew, Reverse Engineering, Hacks, Mods and Net Yaroze
http://www.psxdev.net/forum/
Code: Select all
# -----------------------------------------
# PlayStation 1 Psy-Q Makefile
# -----------------------------------------
all:
del fptest.map
del fptest.sym
del fptest.exe
del fptest.cpe
cls
ccpsx -Xm -Xo$80010000 fptest.c -ofptest.cpe,fptest.sym,fptest.map
cpe2x /ce fptest.cpe
kirito1910 wrote:wow amazing example
someone know how he obtained a .c file from a 3d mesh file?
It actually just contains an array of 3D vertex coordinates for each quad... Thanks for the compliments though!gwald wrote:I'd say it's just a bin2code conversion.
Code: Select all
t=0; NumPrims=0;
for (i=0; i<quad_count; i++) {
myPrimTempT = (POLY_FT4*)myPrimPtr;
nclip = RotAverageNclip4(
&quad_mesh[t], &quad_mesh[t+1], &quad_mesh[t+2], &quad_mesh[t+3],
(long*)&myPrimTempT->x0, (long*)&myPrimTempT->x1,
(long*)&myPrimTempT->x3, (long*)&myPrimTempT->x2,
&p, &OTz, &Flag);
if ((nclip > 0) && (OTz > 0)) {
SetPolyFT4(myPrimTempT);
quad_color[i].cd = myPrimTempT->code;
OTc = OTz>>(14-OT_LENGTH);
// High LOD level (subdivided)
if (OTc < 15) {
if (OTc > 5) div.ndiv = 1; else div.ndiv = 2;
DivideFT4(
&quad_mesh[t], &quad_mesh[t+1], &quad_mesh[t+3], &quad_mesh[t+2],
(u_long*)&tp[0], (u_long*)&tp[1], (u_long*)&tp[2], (u_long*)&tp[3],
&quad_color[i],
myPrimTempT, &myOT[ActivePage][OTc],
&div);
// Increment primitive list pointer
myPrimPtr += POLY_FT4_size*((1<<(div.ndiv))<<(div.ndiv));
NumPrims += ((1<<(div.ndiv))<<(div.ndiv));
// Low LOD level (no subdivision)
} else if (OTc < 48) {
myPrimTempT->u0 = tp[0].u; myPrimTempT->v0 = tp[0].v;
myPrimTempT->u1 = tp[1].u; myPrimTempT->v1 = tp[1].v;
myPrimTempT->u2 = tp[2].u; myPrimTempT->v2 = tp[2].v;
myPrimTempT->u3 = tp[3].u; myPrimTempT->v3 = tp[3].v;
myPrimTempT->clut = tp[0].page;
myPrimTempT->tpage = tp[1].page;
DpqColor(&quad_color[i], p, &ColTemp);
setRGB0(myPrimTempT, ColTemp.r, ColTemp.g, ColTemp.b);
addPrim(&myOT[ActivePage][OTc], myPrimTempT);
myPrimPtr += POLY_FT4_size;
NumPrims += 1;
}
}
t+=4;
}
*/
The rest looks familiar.. I'm sure the yaroze SDK can do it.. I remember doing custom TMD stuff.RotAverageNclip4
Perform a coordinate transformation and perspective transformation for four points; find an interpolation
value, average of Z values, and outer product.
Library
libgte.lib
Header File
libgte.h
Introduced
2.x
Syntax
long RotAverageNclip4(
SVECTOR *v0, SVECTOR *v1, SVECTOR *v2, SVECTOR *v3,
long *sxy0, *sxy1, *sxy2, *sxy3,
long *p,
long *otz,
long *flag)
Documentation Date
12/14/98
Pointer to vectors (input)
Pointer to coordinates (output)
Pointer to interpolation value
(output)
Pointer to OTZ value (output)
Pointer to flag (output)
Explanation
A coordinate transformation of four points v0, v1, v2, and v3 is performed using a rotation matrix. Next a
perspective transformation is performed and four screen coordinates sxy0, sxy1, sxy2 and sxy3 are
returned. An interpolation value for depth cueing on v2 to p is also returned. Finally, we also receive 1/4 of
the Z value of the screen coordinates for v2 to otz.
v0, v1, v2, v3 -> vx, vy, vz
sxy0, sxy1, sxy2, sxy3
p
otz
flag
: (1, 15, 0)
: (1, 15, 0), (1, 15, 0)
: (0, 20, 12)
: (0, 32, 0)
: (0, 32, 0)
When the return value is negative, SX, SY, etc., are incorrect. When SX and SY are required, use
RotAverage4().
Return value
Outer product of (sx0, sy0), (sx1, sy1), (sx2, sy2).
See also
RotAverage4(), RotAverageNclip3()
Uhm, the MAKEFILE is shown in my first post. It uses CCPSX, but you can get away with using GCC if you know how.Aquilus wrote:Hi! Can you please upload the "Makefile" i'm using another SDK and without it i can't compile! Thank you very much
Code: Select all
ccpsx -Xm -Xo$80010000 fptest.c -ofptest.cpe,fptest.sym,fptest.map
There are many methods of getting collision "data". What you can do is use simple trigonometry to check the sides of the camera (player), and check the distance between yourself and the walls, floors, ceilings, and if it is too close - tell it to stop moving. If you can get all of the "boxes" in the scene, you could use AABB collisions to check and see if you are within the bounds of one of those "boxes". AABB is meant for 2D, but if you add the other axis (I'll call it AABBCC), you could get the same variant in 3D.NITROYUASH wrote: ↑January 13th, 2018, 9:16 pm good stuff, but what about collision between camera and model(s)?
So, i have a test level (TIM, RSD and TMD) and i want to test it with this example code.It actually just contains an array of 3D vertex coordinates for each quad... Thanks for the compliments though!
TMD is a dirty word around hereNITROYUASH wrote: ↑November 6th, 2018, 4:14 am So, i think a TMD format is perfect for basic 3D objects (characters, decorations, etc), but not for level geometry, right?