Spring cleaning!

This commit is contained in:
ABelliqueux 2021-04-03 15:23:30 +02:00
parent 72a6fe8226
commit 02f8f7e346
15 changed files with 70 additions and 9728 deletions

View File

@ -1,34 +0,0 @@
TARGET = primdrawGT
TYPE = ps-exe
SRCS = primdrawGT.c \
../common/crt0/crt0.s \
TIM/home.tim \
CPPFLAGS += -I../psyq/include
LDFLAGS += -L../psyq/lib
LDFLAGS += -Wl,--start-group
LDFLAGS += -lapi
LDFLAGS += -lc
LDFLAGS += -lc2
LDFLAGS += -lcard
LDFLAGS += -lcomb
LDFLAGS += -lds
LDFLAGS += -letc
LDFLAGS += -lgpu
LDFLAGS += -lgs
LDFLAGS += -lgte
LDFLAGS += -lgun
LDFLAGS += -lhmd
LDFLAGS += -lmath
LDFLAGS += -lmcrd
LDFLAGS += -lmcx
LDFLAGS += -lpad
LDFLAGS += -lpress
LDFLAGS += -lsio
LDFLAGS += -lsnd
LDFLAGS += -lspu
LDFLAGS += -ltap
LDFLAGS += -Wl,--end-group
include ../common.mk \

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

1592
coridor.c

File diff suppressed because it is too large Load Diff

291
cube.c
View File

@ -1,291 +0,0 @@
typedef struct {
TMESH * tmesh;
TIM_IMAGE * tim;
int * index;
u_long * tim_data;
} MESH;
SVECTOR modelCube_mesh[] = {
{20.0,19.999998807907104,-20.0},
{20.0,-20.0,-20.0},
{-20.00000238418579,-19.999996423721313,-20.0},
{-19.999992847442627,20.000007152557373,-20.0},
{20.000009536743164,19.99998927116394,20.0},
{19.99998688697815,-20.000011920928955,20.0},
{-20.000007152557373,-19.999992847442627,20.0},
{-19.999998807907104,20.0,20.0}
};
SVECTOR modelCube_normal[] = {
0.0,-0.0,-1.0,0,
0.0,0.0,1.0,0,
1.0,0.0,-2.384185791015625e-07,0,
-8.940696716308594e-08,-1.0,-2.9802325229866256e-07,0,
-1.0,2.384185791015625e-07,-1.4901158351676713e-07,0,
2.6822084464583895e-07,1.0,2.3841852225814364e-07,0,
0.0,0.0,-1.0,0,
0.0,-0.0,1.0,0,
1.0,-5.662441253662109e-07,3.2782537573439186e-07,0,
-4.768372150465439e-07,-1.0,8.940690321423972e-08,0,
-1.0,2.0861631355728605e-07,-1.1920931797249068e-07,0,
2.0861631355728605e-07,1.0,1.7881397695873602e-07,0
};
SVECTOR modelCube_uv[] = {
83.96831512451172,83.97151947021484, 0, 0,
125.9500732421875,41.989776611328125, 0, 0,
83.96831512451172,41.989776611328125, 0, 0,
125.9500732421875,83.9715347290039, 0, 0,
83.96831512451172,125.95329284667969, 0, 0,
125.9500732421875,125.95330047607422, 0, 0,
0.004807233810424805,83.97154235839844, 0, 0,
41.98655319213867,125.95330047607422, 0, 0,
41.98656463623047,83.97154998779297, 0, 0,
41.9865608215332,125.95328521728516, 0, 0,
83.96831512451172,83.97154998779297, 0, 0,
41.98656463623047,83.9715347290039, 0, 0,
41.98655319213867,0.008026123046875, 0, 0,
0.004795968532562256,41.989768981933594, 0, 0,
41.98655319213867,41.989776611328125, 0, 0,
41.986549377441406,83.9715347290039, 0, 0,
0.0047997236251831055,41.989776611328125, 0, 0,
0.004795968532562256,83.97154235839844, 0, 0,
83.96831512451172,83.97151947021484, 0, 0,
125.9500732421875,83.9715347290039, 0, 0,
125.9500732421875,41.989776611328125, 0, 0,
125.9500732421875,83.9715347290039, 0, 0,
83.96832275390625,83.97154998779297, 0, 0,
83.96831512451172,125.95329284667969, 0, 0,
0.004807233810424805,83.97154235839844, 0, 0,
0.004795968532562256,125.95330047607422, 0, 0,
41.98655319213867,125.95330047607422, 0, 0,
41.9865608215332,125.95328521728516, 0, 0,
83.96830749511719,125.95330047607422, 0, 0,
83.96831512451172,83.97154998779297, 0, 0,
41.98655319213867,0.008026123046875, 0, 0,
0.004800975322723389,0.008026123046875, 0, 0,
0.004795968532562256,41.989768981933594, 0, 0,
41.986549377441406,83.9715347290039, 0, 0,
41.98655319213867,41.98979187011719, 0, 0,
0.0047997236251831055,41.989776611328125, 0, 0
};
CVECTOR modelCube_color[] = {
255,255,255, 0,
255,255,255, 0,
255,0,251, 0,
255,255,255, 0,
255,5,7, 0,
255,255,255, 0,
255,255,255, 0,
255,255,255, 0,
4,18,255, 0,
255,5,7, 0,
255,255,255, 0,
255,255,255, 0,
254,255,23, 0,
122,255,107, 0,
255,255,255, 0,
255,255,255, 0,
255,255,255, 0,
254,255,94, 0,
255,255,255, 0,
35,255,11, 0,
255,255,255, 0,
255,255,255, 0,
255,255,255, 0,
255,5,7, 0,
255,255,255, 0,
255,5,7, 0,
255,255,255, 0,
255,5,7, 0,
255,255,255, 0,
255,255,255, 0,
254,255,23, 0,
255,255,255, 0,
122,255,107, 0,
255,255,255, 0,
54,65,255, 0,
255,255,255, 0
};
int modelCube_index[] = {
0,2,3,
7,5,4,
4,1,0,
5,2,1,
2,7,3,
0,7,4,
0,1,2,
7,6,5,
4,5,1,
5,6,2,
2,6,7,
0,3,7
};
TMESH modelCube = {
modelCube_mesh,
modelCube_normal,
modelCube_uv,
modelCube_color,
12
};
extern unsigned long _binary_TIM_cube_tim_start[];
extern unsigned long _binary_TIM_cube_tim_end[];
extern unsigned long _binary_TIM_cube_tim_length;
TIM_IMAGE tim_cube;
MESH meshCube = {
&modelCube,
&tim_cube,
modelCube_index,
_binary_TIM_cube_tim_start
};
SVECTOR modelCube1_mesh[] = {
{20.0,20.0,-80.0},
{20.0,-20.0,-80.0},
{-20.00000238418579,-19.999995231628418,-80.0},
{-19.999992847442627,20.000009536743164,-80.0},
{20.000009536743164,19.999990463256836,-40.0},
{19.99998688697815,-20.000011920928955,-40.0},
{-20.000007152557373,-19.999990463256836,-40.0},
{-19.999998807907104,20.0,-40.0}
};
SVECTOR modelCube1_normal[] = {
0.0,-0.0,-1.0,0,
0.0,0.0,1.0,0,
1.0,0.0,-2.384185791015625e-07,0,
-1.1920928955078125e-07,-1.0,-2.9802325229866256e-07,0,
-1.0,2.3841855067985307e-07,-1.4901156930591242e-07,0,
2.3841852225814364e-07,1.0,2.3841852225814364e-07,0,
0.0,0.0,-1.0,0,
0.0,-0.0,1.0,0,
1.0,-5.662441253662109e-07,3.2782537573439186e-07,0,
-5.364418598219345e-07,-1.0,1.1920922560193503e-07,0,
-1.0,2.0861631355728605e-07,-1.1920931797249068e-07,0,
2.3841863594498136e-07,1.0,2.3841863594498136e-07,0
};
SVECTOR modelCube1_uv[] = {
83.31231266260147,83.31549197435379, 0, 0,
124.96608829498291,41.661731481552124, 0, 0,
83.31231266260147,41.661731481552124, 0, 0,
124.96608829498291,83.31550711393356, 0, 0,
83.31231266260147,124.969282746315, 0, 0,
124.96608829498291,124.96929031610489, 0, 0,
0.004769677296280861,83.31551468372345, 0, 0,
41.65853324532509,124.96929031610489, 0, 0,
41.65854460000992,83.31552225351334, 0, 0,
41.658540815114975,124.96927517652512, 0, 0,
83.31231266260147,83.31552225351334, 0, 0,
41.65854460000992,83.31550711393356, 0, 0,
41.65853324532509,0.007963418960571289, 0, 0,
0.004758500028401613,41.66172391176224, 0, 0,
41.65853324532509,41.661731481552124, 0, 0,
41.658529460430145,83.31550711393356, 0, 0,
0.0047622257843613625,41.661731481552124, 0, 0,
0.004758500028401613,83.31551468372345, 0, 0,
83.31231266260147,83.31549197435379, 0, 0,
124.96608829498291,83.31550711393356, 0, 0,
124.96608829498291,41.661731481552124, 0, 0,
124.96608829498291,83.31550711393356, 0, 0,
83.31232023239136,83.31552225351334, 0, 0,
83.31231266260147,124.969282746315, 0, 0,
0.004769677296280861,83.31551468372345, 0, 0,
0.004758500028401613,124.96929031610489, 0, 0,
41.65853324532509,124.96929031610489, 0, 0,
41.658540815114975,124.96927517652512, 0, 0,
83.31230509281158,124.96929031610489, 0, 0,
83.31231266260147,83.31552225351334, 0, 0,
41.65853324532509,0.007963418960571289, 0, 0,
0.004763467703014612,0.007963418960571289, 0, 0,
0.004758500028401613,41.66172391176224, 0, 0,
41.658529460430145,83.31550711393356, 0, 0,
41.65853324532509,41.6617466211319, 0, 0,
0.0047622257843613625,41.661731481552124, 0, 0
};
CVECTOR modelCube1_color[] = {
255,255,255, 0,
255,255,255, 0,
255,0,251, 0,
255,255,255, 0,
255,5,7, 0,
255,255,255, 0,
255,255,255, 0,
255,255,255, 0,
4,18,255, 0,
255,5,7, 0,
255,255,255, 0,
255,255,255, 0,
254,255,23, 0,
122,255,107, 0,
255,255,255, 0,
255,255,255, 0,
255,255,255, 0,
254,255,94, 0,
255,255,255, 0,
35,255,11, 0,
255,255,255, 0,
255,255,255, 0,
255,255,255, 0,
255,5,7, 0,
255,255,255, 0,
255,5,7, 0,
255,255,255, 0,
255,5,7, 0,
255,255,255, 0,
255,255,255, 0,
254,255,23, 0,
255,255,255, 0,
122,255,107, 0,
255,255,255, 0,
54,65,255, 0,
255,255,255, 0
};
int modelCube1_index[] = {
0,2,3,
7,5,4,
4,1,0,
5,2,1,
2,7,3,
0,7,4,
0,1,2,
7,6,5,
4,5,1,
5,6,2,
2,6,7,
0,3,7
};
TMESH modelCube1 = {
modelCube1_mesh,
modelCube1_normal,
modelCube1_uv,
modelCube1_color,
12
};
extern unsigned long _binary_TIM_bousai_tim_start[];
extern unsigned long _binary_TIM_bousai_tim_end[];
extern unsigned long _binary_TIM_bousai_tim_length;
TIM_IMAGE tim_bousai;
MESH meshCube1 = {
&modelCube1,
&tim_bousai,
modelCube1_index,
_binary_TIM_bousai_tim_start
};
MESH * meshes[2] = {
&meshCube,
&meshCube1
};

Binary file not shown.

69
img2tim.txt Normal file
View File

@ -0,0 +1,69 @@
img2tim by Lameguy64 of Meido-Tek Productions
This tool converts almost any image file supported by FreeImage into a PlayStation standard TIM
texture image file. Made to replace the bmp2tim tool that came with the PsyQ SDK with additional
features not present in the original program.
The program itself is still a work in progress but its complete enough as a usable tool.
Alpha-blending options and better color-index conversion have yet to be implemented.
Option Details:
-b - Set semi-transparent bit on fully black pixels (ignored when -usealpha is specified).
If the semi-transparent bit on fully black pixels (R0 G0 B0) is set, the pixel will
be drawn opaque instead of transparent as fully black is treated by the PlayStation
as the transparent color by default.
-t - Set semi-transparent bit on non fully black pixels.
This basically enables the output image to be drawn as semi-transparent since
semi-transparency is only applied to pixels with the semi-transparency bit set.
If the bit is not set, the pixel is always drawn opaque unless its a fully
black pixel.
-org < x y > - Specifies the VRAM offset of the image.
Keep in mind that the width of the converted tim image may vary from the original
image's resolution depending on its color depth. 16-bit has no difference, 8-bit is
1/2 of the original and 4-bit is about 1/4 of the original. No offset checking is
done so its recommended to check the resulting tim file with timtool.
-plt < x y > - Specifies the VRAM offset of the CLUT.
CLUTs are usually 256x1 for 8-bit tims or 16x1 for 4-bit tims. No offset checking is
done so its recommended to check the resulting tim file with timtool.
-o < outFile > - Sets the name of the output file.
-usealpha - Use the alpha channel (if available) as a transparency mask.
Most useful when working with png image files that have an alpha channel and tools
that utilize it, the alpha channel is used as a transparency mask when converting an
image with an alpha channel.
-alpt < value > - Specifies the threshold value when using the alpha channel as a transparency mask.
If the alpha value of the pixel is less than the threshold (default: 127), the pixel
will be converted as transparent (pixel color replaced to fully black) and opaque if
above the threshold (pixel color intact).
-tindex < col > - Specify color index to be treated as transparent.
This option only applies to images that are 4-bit/8-bit palletized. Any pixel that has
the same color-index specified will be made transparent.
-tcol < r g b > - Specify RGB color value to be transparent.
Applies to both non-color index and color index images. Any pixel with a matching color
specified will be made transparent (replaced to fully black).
-bpp < bpp > - Specify the color depth for the output TIM file.
Currently, a simple color-search algorithm is used when converting images from non-indexed
color depths (24-bit/16-bit) to 8-bit or 4-bit and will fail if more than 256 colors are
found.
Supported output color depths: 4, 8, 16, 24

View File

@ -896,20 +896,9 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
f.write("\n")
f.write("};\n\n")
# UNUSED
# Write UVs vectors if a texture exists
# get name of texture image https://docs.blender.org/api/2.79b/bpy.types.Image.html#bpy.types.Image
# bpy.context.active_object.data.uv_textures.active.data[0].image.name
# bpy.context.active_object.data.uv_textures.active.data[0].image.filepath
# bpy.context.active_object.data.uv_textures.active.data[0].image.filepath_from_user()
#
# get image size x, y
# bpy.data.meshes[0].uv_textures[0].data[0].image.size[0] # x
# bpy.data.meshes[0].uv_textures[0].data[0].image.size[1] # y
# Write UV textures coordinates
if len(m.uv_textures) != None:
for t in range(len(m.uv_textures)):

3697
pcos.c

File diff suppressed because it is too large Load Diff

View File

@ -1,409 +0,0 @@
/* primdrawG.c, by Schnappy, 12-2020
- Draw a gouraud shaded, UV textured mesh exported by the blender <= 2.79b plugin io_export_psx_tmesh.py
* added depth cueing use with fog farcolor
* switched to double buffer
* switched to vsync callback for pad input
based on primdraw.c by Lameguy64 (http://www.psxdev.net/forum/viewtopic.php?f=64&t=537)
2014 Meido-Tek Productions.
Demonstrates:
- Using a primitive OT to draw triangles without libgs.
- Using the GTE to rotate, translate, and project 3D primitives.
Controls:
Start - Toggle interactive/non-interactive mode.
Select - Reset object's position and angles.
L1/L2 - Move object closer/farther.
L2/R2 - Rotate object (XY).
Up/Down/Left/Right - Rotate object (XZ/YZ).
Triangle/Cross/Square/Circle - Move object up/down/left/right.
*/
/* PSX screen coordinate system
*
* Z+
* /
* /
* +------X+
* /|
* / |
* / Y+
* eye */
#include <sys/types.h>
#include <libgte.h>
#include <libgpu.h>
#include <libetc.h>
#include <stdio.h>
// Precalculated sin/cos values
#include "psin.c"
#include "pcos.c"
// Sample model
#include "coridor.c"
#define VMODE 0 // 0: NTSC, 1: PAL
#define SCREENXRES 320
#define SCREENYRES 240
#define CENTERX SCREENXRES/2
#define CENTERY SCREENYRES/2
#define OTLEN 2048 // Maximum number of OT entries
#define PRIMBUFFLEN 1024 * sizeof(POLY_GT3) // Maximum number of POLY_GT3 primitives
// Display and draw environments, double buffered
DISPENV disp[2];
DRAWENV draw[2];
u_long ot[2][OTLEN] = {0}; // Ordering table (contains addresses to primitives)
char primbuff[2][PRIMBUFFLEN] = {0}; // Primitive list // That's our prim buffer
char * nextpri = primbuff[0]; // Primitive counter
char db = 0; // Current buffer counter
short vs;
int PadStatus;
typedef struct{
int x, xv; // x: current value += vx : new value
int y, yv;
int z, zv;
int pan, panv; // horizontal rotation
int tilt, tiltv; // vertical rotation
int rol; // lateral rotation
VECTOR pos; // camera current pos vector
SVECTOR rot; // camera current rot vector
MATRIX mat;
} CAMERA;
CAMERA camera = {0};
// Prototypes
void init(void);
void display(void);
void applyCamera(CAMERA * cam);
void applyOrbCam(MESH * mesh);
void LoadTexture(u_long * tim, TIM_IMAGE * tparam);
void callback(void);
int main() {
int i;
long t, p, OTz, Flag; // t == vertex count, p == depth cueing interpolation value, OTz == value to create Z-ordered OT, Flag == see LibOver47.pdf, p.143
POLY_GT3 * poly; // pointer to a POLY_GT3
MATRIX PolyMatrix = {0}; // global transformation matrix
CVECTOR outCol, outCol1, outCol2 = {0,0,0,0}; // Holds vertices colors with depth cueing applied
init();
VSyncCallback(callback); // pad is read on vsync callback
SetFarColor(20, 20, 40); // vertices colors are mixed with farcolor depending on p value
SetFogNearFar(1200, 3000,SCREENXRES); // fog distance thresholds
for (int k = 0; k < sizeof(meshes)/sizeof(TMESH *); k++){
LoadTexture(meshes[k]->tim_data, meshes[k]->tim);
}
// Set Camera starting pos and rot
camera.xv = -ONE * -89;
camera.yv = -ONE * 59;
camera.zv = -ONE * 133;
camera.tiltv = 232 ;
camera.panv = -336;
applyCamera(&camera);
// Main loop
while (1) {
// Local Transform
meshes[2]->rot->vy -= 28; // rotate small cube
meshes[1]->rot->vy += 28; // rotate blue monolith thingy
//World Translations
meshes[1]->pos->vz = meshes[1]->pos->vz + (pcos[VSync(-1)%1024]/768 ); // move blue monolith thingy
meshes[1]->pos->vx = meshes[1]->pos->vx + (psin[VSync(-1)%1024]/768 );
// Camera setup
camera.pos.vx = -(camera.x/ONE);
camera.pos.vy = -(camera.y/ONE);
camera.pos.vz = -(camera.z/ONE);
camera.rot.vx = camera.tilt;
camera.rot.vy = -camera.pan;
applyCamera(&camera);
// Clear the current OT
ClearOTagR(ot[db], OTLEN);
for (int k = 0; k < sizeof(meshes)/sizeof(meshes[0]); k++){
// Render the sample vector model
t=0;
// modelCube is a TMESH, len member == # vertices, but here it's # of triangle... So, for each tri * 3 vertices ...
for (i = 0; i < (meshes[k]->tmesh->len * 3); i += 3) {
poly = (POLY_GT3 *)nextpri;
RotMatrix(meshes[k]->rot, meshes[k]->mat); // Apply mesh rotation to matrix
TransMatrix(meshes[k]->mat, meshes[k]->pos); // Apply mesh translation to matrix
CompMatrixLV(&camera.mat, meshes[k]->mat, &PolyMatrix); // Make a composite matrix from cam matrix + meshes matrices
SetRotMatrix(&PolyMatrix); // Set rotation matrix
SetTransMatrix(&PolyMatrix); // Set Transmatrix matrix
// Draw meshes
SetPolyGT3(poly);
DpqColor3(&meshes[k]->tmesh->c[i],&meshes[k]->tmesh->c[i+1],&meshes[k]->tmesh->c[i+2], *meshes[k]->p,
&outCol,&outCol1,&outCol2
);
setRGB0(poly, outCol.r, outCol.g , outCol.b);
setRGB1(poly, outCol1.r, outCol1.g, outCol1.b);
setRGB2(poly, outCol2.r, outCol2.g, outCol2.b);
// WIP : Trying to use the draw area as a texture to create pseudo refraction effect
if (*meshes[k]->isPrism){
((POLY_GT3 *)poly)->tpage = getTPage(meshes[k]->tim->mode&0x3, 0,
0,
320
);
setUV3(poly, 32, 32,
32, 220,
220,220);
} else {
((POLY_GT3 *)poly)->tpage = getTPage(meshes[k]->tim->mode&0x3, 0,
meshes[k]->tim->prect->x,
meshes[k]->tim->prect->y
);
}
setUV3(poly, meshes[k]->tmesh->u[i].vx , meshes[k]->tmesh->u[i].vy + meshes[k]->tim->prect->y,
meshes[k]->tmesh->u[i+1].vx, meshes[k]->tmesh->u[i+1].vy + meshes[k]->tim->prect->y,
meshes[k]->tmesh->u[i+2].vx, meshes[k]->tmesh->u[i+2].vy + meshes[k]->tim->prect->y);
//~ }
// Rotate, translate, and project the vectors and output the results into a primitive
OTz = RotTransPers(&meshes[k]->tmesh->v[meshes[k]->index[t]] , (long*)&poly->x0, meshes[k]->p, &Flag);
OTz += RotTransPers(&meshes[k]->tmesh->v[meshes[k]->index[t+1]], (long*)&poly->x1, meshes[k]->p, &Flag);
OTz += RotTransPers(&meshes[k]->tmesh->v[meshes[k]->index[t+2]], (long*)&poly->x2, meshes[k]->p, &Flag);
// Using RotTransPers3 is a bit faster (-31ms/frame), but you loose precision for Z-ordering
//~ OTz = RotTransPers3(
//~ &meshes[k]->tmesh->v[meshes[k]->index[t]],
//~ &meshes[k]->tmesh->v[meshes[k]->index[t+1]],
//~ &meshes[k]->tmesh->v[meshes[k]->index[t+2]],
//~ (long*)&poly->x0, (long*)&poly->x1, (long*)&poly->x2,
//~ meshes[k]->p,
//~ &Flag
//~ );
// Sort the primitive into the OT
OTz /= 3;
if ((OTz > 0) && (OTz < OTLEN) && (*meshes[k]->p < 3588)){
AddPrim(&ot[db][OTz-2], poly);
}
nextpri += sizeof(POLY_GT3);
t+=3;
}
}
//~ FntPrint("BASED ON PRIMDRAW BY LAMEGUY64, 2014 \n");
FntPrint("#Tris :%d \n", sizeof(ot[db])/sizeof(POLY_GT3));
FntPrint("Vsync :%d \n", VSync(0));
FntPrint("#Meshes %d\n", sizeof(meshes)/sizeof(TMESH *));
FntPrint("Cam pos : %d, %d, %d\n", camera.pos.vx, camera.pos.vy, camera.pos.vz);
FntPrint("Cam or : %d, %d", camera.tilt, camera.pan);
FntPrint("\np:%d", *meshes[0]->p);
FntPrint("\n%d %d", meshes[1]->pos->vx, meshes[1]->pos->vz);
FntPrint("\n%d %d", *meshes[0]->isPrism, *meshes[1]->isPrism);
FntFlush(-1);
display();
}
return 0;
}
void init(){
// Reset the GPU before doing anything and the controller
PadInit(0);
ResetGraph(0);
// Initialize and setup the GTE
InitGeom();
SetGeomOffset(CENTERX, CENTERY); // x, y offset
SetGeomScreen(CENTERX); // Distance between eye and screen
// Set the display and draw environments
SetDefDispEnv(&disp[0], 0, 0 , SCREENXRES, SCREENYRES);
SetDefDispEnv(&disp[1], 0, SCREENYRES, SCREENXRES, SCREENYRES);
SetDefDrawEnv(&draw[0], 0, SCREENYRES, SCREENXRES, SCREENYRES);
SetDefDrawEnv(&draw[1], 0, 0, SCREENXRES, SCREENYRES);
if (VMODE)
{
SetVideoMode(MODE_PAL);
disp[0].screen.y += 8;
disp[1].screen.y += 8;
}
setRGB0(&draw[0], 0, 0, 0);
setRGB0(&draw[1], 0, 0, 0);
draw[0].isbg = 1;
draw[1].isbg = 1;
PutDispEnv(&disp[db]);
PutDrawEnv(&draw[db]);
// Init font system
FntLoad(960, 0);
FntOpen(16, 16, 196, 96, 0, 512);
}
void display(void){
DrawSync(0);
vs = VSync(-1);
PutDispEnv(&disp[db]);
PutDrawEnv(&draw[db]);
SetDispMask(1);
DrawOTag(ot[db] + OTLEN - 1);
db = !db;
nextpri = primbuff[db];
}
void applyCamera(CAMERA * cam){
VECTOR vec; // Vector that holds the output values of the following instructions
RotMatrix(&cam->rot, &cam->mat); // Convert rotation angle in psx units (360° == 4096) to rotation matrix)
ApplyMatrixLV(&cam->mat, &cam->pos, &vec); // Multiply matrix by vector pos and output to vec
TransMatrix(&cam->mat, &vec); // Apply transform vector
SetRotMatrix(&cam->mat); // Set Rotation matrix
SetTransMatrix(&cam->mat); // Set Transform matrix
}
void LoadTexture(u_long * tim, TIM_IMAGE * tparam){ // This part is from Lameguy64's tutorial series : lameguy64.net/svn/pstutorials/chapter1/3-textures.html login/pw: annoyingmous
OpenTIM(tim); // Open the tim binary data, feed it the address of the data in memory
ReadTIM(tparam); // This read the header of the TIM data and sets the corresponding members of the TIM_IMAGE structure
LoadImage(tparam->prect, tparam->paddr); // Transfer the data from memory to VRAM at position prect.x, prect.y
DrawSync(0); // Wait for the drawing to end
if (tparam->mode & 0x8){ // check 4th bit // If 4th bit == 1, TIM has a CLUT
LoadImage(tparam->crect, tparam->caddr); // Load it to VRAM at position crect.x, crect.y
DrawSync(0); // Wait for drawing to end
}
}
void callback(void){
PadStatus = PadRead(0);
// Camera panning
if (PadStatus & PADLup) camera.tiltv += 8;
if (PadStatus & PADLdown) camera.tiltv -= 8;
if (PadStatus & PADLleft) camera.panv -= 12;
if (PadStatus & PADLright) camera.panv += 12;
// Camera movement
if (PadStatus & PADRup) {
camera.zv += (ccos(camera.pan) * ccos(camera.tilt)) / 1024; // pan = horizontal motion, tilt = vertical. cos(pan) returns value in rang -ONE,ONE on the horiz. axis. -4096-0 = left, 0-4096 = right
camera.xv += (csin(camera.pan) * ccos(camera.tilt)) / 1024;
camera.yv += (csin(camera.tilt) * ccos(camera.tilt)) / 1024;
}
if (PadStatus & PADRdown) {
camera.zv -= (ccos(camera.pan) * ccos(camera.tilt)) / 1024; // pan = horizontal motion, tilt = vertical. cos(pan) returns value in rang -ONE,ONE on the horiz. axis. -4096-0 = left, 0-4096 = right
camera.xv -= (csin(camera.pan) * ccos(camera.tilt)) / 1024;
camera.yv -= (csin(camera.tilt) * ccos(camera.tilt)) / 1024;
}
if (PadStatus & PADRleft) {
camera.zv += (csin(camera.pan)*2);
camera.xv -= (ccos(camera.pan)*2);
}
if (PadStatus & PADRright) {
camera.zv -= (csin(camera.pan)*2);
camera.xv += (ccos(camera.pan)*2);
}
if (PadStatus & PADR1) camera.yv -= ONE*1;
if (PadStatus & PADR2) camera.yv += ONE*1;
// Reset
if (PadStatus & PADselect) {
camera.x = camera.y = camera.z = 0;
camera.pan = camera.tilt = camera.rol = 0;
camera.panv = camera.tiltv = 0;
camera.xv = 0;
camera.yv = 0;
camera.zv = -150;
}
camera.x += camera.xv;
camera.y += camera.yv;
camera.z += camera.zv;
camera.pan += camera.panv;
camera.tilt += camera.tiltv;
camera.xv = 0;
camera.yv = 0;
camera.zv = 0;
camera.panv = 0;
camera.tiltv = 0;
}

3693
psin.c

File diff suppressed because it is too large Load Diff

BIN
scene.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB