Change folder structure

This commit is contained in:
ABelliqueux 2021-06-23 19:25:12 +02:00
parent 45bb2f9d32
commit 8657f7bfc2
29 changed files with 2704 additions and 22931 deletions

View File

@ -1,14 +1,14 @@
TARGET = main
TYPE = ps-exe
SRCS = main.c \
pad.c \
math.c \
camera.c \
physics.c \
graphics.c \
psx.c \
space.c \
SRCS = src/main.c \
src/pad.c \
src/math.c \
src/camera.c \
src/physics.c \
src/graphics.c \
src/psx.c \
src/space.c \
levels/level0.c \
levels/level1.c \
../common/crt0/crt0.s \

View File

@ -37,10 +37,13 @@ Real-time 3D / 8bpp background / 4bpp background
You need to install [mkpsxiso](https://github.com/Lameguy64/mkpsxiso) and the [pcsx-redux emulator and Nugget+PsyQ SDK](https://github.com/ABelliqueux/nolibgs_hello_worlds#setting-up-the-sdk--modern-gcc--psyq-aka-nuggetpsyq) before
you can build the engine. Put `mkpsxiso` and `pcsx-redux` in your $PATH and you should be good to go.
1. Clone this repo in `(...)/pcsx-redux/src/mips/`
1. Clone this repo in `(...)/pcsx-redux/src/mips/` as a new project :
```bash
git clone https://github.com/ABelliqueux/3dcam-headers my-project
```
2. Navigate to that folder in a terminal :
```bash
cd /pcsx-redux/src/mips/3dcam-headers
cd /pcsx-redux/src/mips/my-project
```
3. Type `./isotest.sh`. This should compile the example, build an iso with `mkpsxiso` and launch it with `pcsx-redux`.
4. Install the [blender extension](https://github.com/ABelliqueux/blender_io_export_psx_mesh) to create your own levels.

View File

@ -1,4 +1,4 @@
BOOT=cdrom:\SCES_003.90;1
BOOT=cdrom:\SCES_313.37;1
TCB=4
EVENT=10
STACK=801FFFF0
STACK=801FFFF0

View File

@ -1,22 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<iso_project image_name="OverlayExample.bin" cue_sheet="OverlayExample.cue" no_xa="0">
<track type="data">
<identifiers
system = "PLAYSTATION"
application = "PLAYSTATION"
volume = "MYDISC"
volume_set = "MYDISC"
publisher = "JABY"
data_preparer = "MKPSXISO"
copyright = "COPYLEFT"
/>
<license file="LICENSEE.DAT"/>
<directory_tree>
<file name="system.cnf" type="data" source="config/OverlayExample.cnf"/>
<file name="SCES_003.90" type="data" source="main.ps-exe"/>
<file name="LEVEL0.bin" type="data" source="Overlay.lvl0" />
<file name="LEVEL1.bin" type="data" source="Overlay.lvl1" />
<dummy sectors="1024"/>
</directory_tree>
</track>
<track type="data">
<identifiers
system = "PLAYSTATION"
application = "PLAYSTATION"
volume = "MYDISC"
volume_set = "MYDISC"
publisher = "SCHNAPPY"
data_preparer = "MKPSXISO"
copyright = "COPYLEFT"
/>
<!--<license file="LICENSEE.DAT"/>-->
<directory_tree>
<file name="system.cnf" type="data" source="config/OverlayExample.cnf"/>
<file name="SCES_313.37" type="data" source="main.ps-exe"/>
<file name="LEVEL0.bin" type="data" source="Overlay.lvl0" />
<file name="LEVEL1.bin" type="data" source="Overlay.lvl1" />
<dummy sectors="1024"/>
</directory_tree>
</track>
</iso_project>

View File

@ -16,66 +16,65 @@ 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 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;
TMESH * tmesh;
PRIM * index;
TIM_IMAGE * tim;
unsigned long * tim_data;
MATRIX mat;
VECTOR pos;
SVECTOR rot;
short isRigidBody;
short isStaticBody;
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 :
// NTSC - 320x240, PAL 320x256, pixel ratio 1:1,
@ -84,47 +83,48 @@ 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 {
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;
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;

30
include/camera.h Normal file
View File

@ -0,0 +1,30 @@
#pragma once
#include <sys/types.h>
#include <libgte.h>
// Camera modes
#define ACTOR 0
#define ROTATE 1
#define FIXED 2
#define TRACK 3
#define FLYCAM 4
#define FOLLOW 5
typedef struct{
int x, xv; // x: current value += xv : new value
int y, yv; // x,y,z, vx, vy, vz are in PSX units (ONE == 4096)
int z, zv;
int pan, panv;
int tilt, tiltv;
int rol;
VECTOR pos;
SVECTOR rot;
SVECTOR dvs;
MATRIX mat;
} CAMERA;
void getCameraXZ(int * x, int * z, int actorX, int actorZ, int angle, int distance);
void getCameraXZY(int * x, int * z, int * y, int actorX, int actorZ, int actorY, int angle, int angleX, int distance);
void getCameraZY( int * z, int * y, int actorZ, int actorY, int angleX, int distance);
void applyCamera(CAMERA * cam);
void setCameraPos(CAMERA * camera, VECTOR pos, SVECTOR rot);

52
include/defines.h Normal file
View File

@ -0,0 +1,52 @@
#define VMODE 0 // 0 == NTSC, 1 == PAL
#define VSYNC 0
#define SCREENXRES 320
#define SCREENYRES 240
#define CENTERX SCREENXRES/2
#define CENTERY SCREENYRES/2
#define FOV CENTERX
#define CLEAR_COLOR_R 0
#define CLEAR_COLOR_G 0
#define CLEAR_COLOR_B 0
// Debug Font
#define FNT_VRAM_X 960
#define FNT_VRAM_Y 256
#define FNT_SCR_X 16
#define FNT_SCR_Y 192
#define FNT_SCR_W 240
#define FNT_SCR_H 32
#define FNT_SCR_BG 0
#define FNT_SCR_MAX_CHAR 256
// Ordering table
#define OT2LEN 8
#define OTLEN 768
#define PRIMBUFFLEN 4096 * sizeof(POLY_GT4) // Maximum number of POLY_GT3 primitives
// Fog
#define FOG_NEAR 1300
#define FOG_FAR 1600
// Physics
#define GRAVITY 10
#define SCALE 4
// Pad codes defines
// Applied on PADL
#define PadSelect ( 1 )
#define PadStart ( 1 << 3 )
// Up, Right, Down, Left will be used on PADL (left side of pad )and PADR (right side of pad)
#define PadUp ( 1 << 4 )
#define PadRight ( 1 << 5 )
#define PadDown ( 1 << 6 )
#define PadLeft ( 1 << 7 )
#define PadR3 ( 1 << 2 )
#define PadL3 ( 1 << 1 )
// Triggers applied on PADR
#define PadShldL1 ( 1 << 2 )
#define PadShldL2 ( 1 )
#define PadShldR1 ( 1 << 3 )
#define PadShldR2 ( 1 << 1 )

9
include/graphics.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
#include "../include/camera.h"
#include "../include/physics.h"
#include "../include/defines.h"
// Drawing
void transformMesh(CAMERA * camera, MESH * meshes);
void drawPoly(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw);
void drawBG(CAMANGLE * camPtr, char ** nextpri, u_long * otdisc, char * db);

27
include/macros.h Normal file
View File

@ -0,0 +1,27 @@
// MACROS
// swap(x, y, buffer)
#define SWAP(a,b,c) {(c)=(a); (a)=(b); (b)=(c);}
// dotproduct of two vectors
#define dotProduct(v0, v1) \
(v0).vx * (v1).vx + \
(v0).vy * (v1).vy + \
(v0).vz * (v1).vz
// min value
#define min(a,b) \
(a)-(b)>0?(b):(a)
// max
#define max(a,b) \
(a)-(b)>0?(a):(b)
// substract vector
#define subVector(v0, v1) \
(v0).vx - (v1).vx, \
(v0).vy - (v1).vy, \
(v0).vz - (v1).vz
#define normalizeVector(v) \
((v)->vx << 12) >> 8, \
((v)->vy << 12) >> 8, \
((v)->vz << 12) >> 8

35
include/math.h Normal file
View File

@ -0,0 +1,35 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
#include <libgte.h>
#include "../include/macros.h"
// Precalculated arctan values
#include "../src/atan.c"
// fixed point math
int32_t dMul(int32_t a, int32_t b);
uint32_t lerpU(uint32_t start, uint32_t dest, unsigned pos);
int32_t lerpS(int32_t start, int32_t dest, unsigned pos);
int32_t lerpD(int32_t start, int32_t dest, int32_t pos);
long long lerpL(long long start, long long dest, long long pos);
// Sin/Cos Table
void generateTable(void);
int ncos(u_int t);
int nsin(u_int t);
// Atan table
long long patan(long x, long y);
// Sqrt
u_int psqrt(u_int n);
// Lerps
int lerp(int start, int end, int factor); // FIXME : not working as it should
SVECTOR SVlerp(SVECTOR start, SVECTOR end, int factor); // FIXME
long long easeIn(long long i);
int easeOut(int i);
//~ int easeInOut(int i, int div);
VECTOR getVectorTo(VECTOR actor, VECTOR target);

32
include/pad.h Normal file
View File

@ -0,0 +1,32 @@
#pragma once
// Structure for storing processed controller data
typedef struct
{
int xpos, ypos; // Stored position for sprite(s)
int xpos2, ypos2; // controlled by this controller.
unsigned char status; // These 8 values are obtained
unsigned char type; // directly from the controller
unsigned char button1; // buffer we installed with InitPAD.
unsigned char button2;
unsigned char analog0;
unsigned char analog1;
unsigned char analog2;
unsigned char analog3;
} Controller_Data;
// All-purpose controller data buffer
typedef struct
{
unsigned char pad[34]; // 8-bytes w/o Multi-Tap, 34-bytes w/Multi-Tap
} Controller_Buffer;
// Structure for RAW hardware-based light gun position values
typedef struct
{
unsigned short v_count; // Y-axis (vertical scan counter)
unsigned short h_count; // H-axis (horizontal pixel clock value)
} Gun_Position;
void get_digital_direction( Controller_Data *c, int buttondata );
void read_controller( Controller_Data *c, unsigned char *buf, int port );

19
include/pcdrv.h Normal file
View File

@ -0,0 +1,19 @@
#pragma once
#include <sys/types.h>
#include <stdio.h>
#define OPEN 0
#define CLOSE 1
#define SEEK 2
#define READ 3
#define WRITE 4
#define CREATE 5
#define LOAD 6
int waitForSIODone( int * flag );
void PCload( u_long * loadAddress, u_short * flagAddress, const char * filename );
int PCopen(const char * filename, int attributes );
int PCcreate(const char * filename, int attributes );
int PCclose( int fd );
int PCseek( int fd, int offset, int accessMode );
int PCread( int fd, int len, char * buffer );

15
include/physics.h Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#include <sys/types.h>
#include <libgte.h>
#include <libgpu.h>
#include "../include/defines.h"
#include "../include/macros.h"
#include "../custom_types.h"
short checkLineW( VECTOR * pointA, VECTOR * pointB, MESH * mesh );
short checkLineS( VECTOR * pointA, VECTOR * pointB, MESH * mesh );
VECTOR getIntCollision(BODY one, BODY two);
VECTOR getExtCollision(BODY one, BODY two);
void ResolveCollision( BODY * one, BODY * two );
VECTOR angularMom(BODY body);
void applyAcceleration(BODY * actor);

21
include/psx.h Normal file
View File

@ -0,0 +1,21 @@
#pragma once
#include <sys/types.h>
#include <stdio.h>
#include <libgte.h>
#include <libetc.h>
#include <libgpu.h>
#include <libapi.h>
#include <libcd.h>
#include "../include/defines.h"
#include "../custom_types.h"
// PSX setup
void init(DISPENV disp[2], DRAWENV draw[2], short db, MATRIX * cmat, CVECTOR * BG, VECTOR * BK );
void ScrRst(void);
void display(DISPENV * disp, DRAWENV * draw, u_long * otdisc, char * primbuff, char ** nextprim, char * db);
// Utils
void LvlPtrSet( LEVEL * curLevel, LEVEL * level );
int LoadLevelCD(const char*const LevelName, u_long * LoadAddress);
void SwitchLevel( LEVEL * curLevel, LEVEL * loadLevel);
void LoadTexture(u_long * tim, TIM_IMAGE * tparam);

9
include/space.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
#include <sys/types.h>
#include <libgte.h>
#include <libgpu.h>
#include "../include/defines.h"
int cliptest3(short * v1);
void worldToScreen( VECTOR * worldPos, VECTOR * screenPos );
void screenToWorld( VECTOR * screenPos, VECTOR * worldPos );

File diff suppressed because it is too large Load Diff

View File

@ -4,17 +4,9 @@
extern LEVEL level0;
extern CAMPOS level0_camPos_camPath;
extern CVECTOR level0_BGc;;
extern CAMPOS level0_camPos_camPath_001;
extern CAMPOS level0_camPos_camPath_002;
extern CAMPOS level0_camPos_camPath_003;
extern CAMPOS level0_camPos_camPath_004;
extern CAMPOS level0_camPos_camPath_005;
extern CAMPOS level0_camPos_Camera;
extern CAMPATH level0_camPath;
@ -26,8 +18,6 @@ extern SVECTOR modelCube_mesh[];
extern SVECTOR level0_modelCube_normal[];
extern SVECTOR level0_modelCube_uv[];
extern CVECTOR level0_modelCube_color[];
extern PRIM level0_modelCube_index[];
@ -36,355 +26,37 @@ extern BODY level0_modelCube_body;
extern TMESH level0_modelCube;
extern unsigned long _binary_TIM_cat_tim_start[];
extern unsigned long _binary_TIM_cat_tim_end[];
extern unsigned long _binary_TIM_cat_tim_length;
extern TIM_IMAGE level0_tim_cat;
extern MESH level0_meshCube;
extern SVECTOR modelCylindre_mesh[];
extern SVECTOR modelPlane_mesh[];
extern SVECTOR level0_modelCylindre_normal[];
extern SVECTOR level0_modelPlane_normal[];
extern SVECTOR level0_modelCylindre_uv[];
extern CVECTOR level0_modelPlane_color[];
extern CVECTOR level0_modelCylindre_color[];
extern PRIM level0_modelPlane_index[];
extern PRIM level0_modelCylindre_index[];
extern BODY level0_modelPlane_body;
extern VANIM level0_modelCylindre_anim;
extern TMESH level0_modelPlane;
extern BODY level0_modelCylindre_body;
extern MESH level0_meshPlane;
extern TMESH level0_modelCylindre;
extern unsigned long _binary_TIM_home_tim_start[];
extern unsigned long _binary_TIM_home_tim_end[];
extern unsigned long _binary_TIM_home_tim_length;
extern TIM_IMAGE level0_tim_home;
extern MESH level0_meshCylindre;
extern SVECTOR modelgnd_mesh[];
extern SVECTOR level0_modelgnd_normal[];
extern SVECTOR level0_modelgnd_uv[];
extern CVECTOR level0_modelgnd_color[];
extern PRIM level0_modelgnd_index[];
extern BODY level0_modelgnd_body;
extern TMESH level0_modelgnd;
extern MESH level0_meshgnd;
extern SVECTOR modelgnd_001_mesh[];
extern SVECTOR level0_modelgnd_001_normal[];
extern SVECTOR level0_modelgnd_001_uv[];
extern CVECTOR level0_modelgnd_001_color[];
extern PRIM level0_modelgnd_001_index[];
extern BODY level0_modelgnd_001_body;
extern TMESH level0_modelgnd_001;
extern MESH level0_meshgnd_001;
extern SVECTOR modelgnd_003_mesh[];
extern SVECTOR level0_modelgnd_003_normal[];
extern SVECTOR level0_modelgnd_003_uv[];
extern CVECTOR level0_modelgnd_003_color[];
extern PRIM level0_modelgnd_003_index[];
extern BODY level0_modelgnd_003_body;
extern TMESH level0_modelgnd_003;
extern MESH level0_meshgnd_003;
extern SVECTOR modelgnd_002_mesh[];
extern SVECTOR level0_modelgnd_002_normal[];
extern SVECTOR level0_modelgnd_002_uv[];
extern CVECTOR level0_modelgnd_002_color[];
extern PRIM level0_modelgnd_002_index[];
extern BODY level0_modelgnd_002_body;
extern TMESH level0_modelgnd_002;
extern MESH level0_meshgnd_002;
extern SVECTOR modelLara_mesh[];
extern SVECTOR level0_modelLara_normal[];
extern SVECTOR level0_modelLara_uv[];
extern CVECTOR level0_modelLara_color[];
extern PRIM level0_modelLara_index[];
extern BODY level0_modelLara_body;
extern TMESH level0_modelLara;
extern unsigned long _binary_TIM_lara_tim_start[];
extern unsigned long _binary_TIM_lara_tim_end[];
extern unsigned long _binary_TIM_lara_tim_length;
extern TIM_IMAGE level0_tim_lara;
extern MESH level0_meshLara;
extern SVECTOR modelobject_mesh[];
extern SVECTOR level0_modelobject_normal[];
extern SVECTOR level0_modelobject_uv[];
extern CVECTOR level0_modelobject_color[];
extern PRIM level0_modelobject_index[];
extern BODY level0_modelobject_body;
extern TMESH level0_modelobject;
extern MESH level0_meshobject;
extern SVECTOR modelPlan_mesh[];
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;
extern SVECTOR modelSphere_mesh[];
extern SVECTOR level0_modelSphere_normal[];
extern SVECTOR level0_modelSphere_uv[];
extern CVECTOR level0_modelSphere_color[];
extern PRIM level0_modelSphere_index[];
extern BODY level0_modelSphere_body;
extern TMESH level0_modelSphere;
extern MESH level0_meshSphere;
extern SVECTOR modelSphere_001_mesh[];
extern SVECTOR level0_modelSphere_001_normal[];
extern SVECTOR level0_modelSphere_001_uv[];
extern CVECTOR level0_modelSphere_001_color[];
extern PRIM level0_modelSphere_001_index[];
extern BODY level0_modelSphere_001_body;
extern TMESH level0_modelSphere_001;
extern MESH level0_meshSphere_001;
extern SVECTOR modelwall_mesh[];
extern SVECTOR level0_modelwall_normal[];
extern SVECTOR level0_modelwall_uv[];
extern CVECTOR level0_modelwall_color[];
extern PRIM level0_modelwall_index[];
extern BODY level0_modelwall_body;
extern TMESH level0_modelwall;
extern MESH level0_meshwall;
extern SVECTOR modelwall_001_mesh[];
extern SVECTOR level0_modelwall_001_normal[];
extern SVECTOR level0_modelwall_001_uv[];
extern CVECTOR level0_modelwall_001_color[];
extern PRIM level0_modelwall_001_index[];
extern BODY level0_modelwall_001_body;
extern TMESH level0_modelwall_001;
extern MESH level0_meshwall_001;
extern SVECTOR modelwall_002_mesh[];
extern SVECTOR level0_modelwall_002_normal[];
extern SVECTOR level0_modelwall_002_uv[];
extern CVECTOR level0_modelwall_002_color[];
extern PRIM level0_modelwall_002_index[];
extern BODY level0_modelwall_002_body;
extern TMESH level0_modelwall_002;
extern MESH level0_meshwall_002;
extern SVECTOR modelwall_003_mesh[];
extern SVECTOR level0_modelwall_003_normal[];
extern SVECTOR level0_modelwall_003_uv[];
extern CVECTOR level0_modelwall_003_color[];
extern PRIM level0_modelwall_003_index[];
extern BODY level0_modelwall_003_body;
extern TMESH level0_modelwall_003;
extern MESH level0_meshwall_003;
extern MESH * level0_meshes[15];
extern MESH * level0_meshes[2];
extern int level0_meshes_length;
extern unsigned long _binary_TIM_bg_camPath_tim_start[];
extern CAMANGLE level0_camAngle_Camera;
extern unsigned long _binary_TIM_bg_camPath_tim_end[];
extern CAMANGLE * level0_camAngles[0];
extern unsigned long _binary_TIM_bg_camPath_tim_length;
extern SIBLINGS level0_nodePlane_siblings;
extern TIM_IMAGE tim_bg_camPath;
extern CHILDREN level0_nodePlane_objects;
extern CAMANGLE level0_camAngle_camPath;
extern CHILDREN level0_nodePlane_rigidbodies;
extern unsigned long _binary_TIM_bg_camPath_001_tim_start[];
extern unsigned long _binary_TIM_bg_camPath_001_tim_end[];
extern unsigned long _binary_TIM_bg_camPath_001_tim_length;
extern TIM_IMAGE tim_bg_camPath_001;
extern CAMANGLE level0_camAngle_camPath_001;
extern unsigned long _binary_TIM_bg_camPath_002_tim_start[];
extern unsigned long _binary_TIM_bg_camPath_002_tim_end[];
extern unsigned long _binary_TIM_bg_camPath_002_tim_length;
extern TIM_IMAGE tim_bg_camPath_002;
extern CAMANGLE level0_camAngle_camPath_002;
extern unsigned long _binary_TIM_bg_camPath_003_tim_start[];
extern unsigned long _binary_TIM_bg_camPath_003_tim_end[];
extern unsigned long _binary_TIM_bg_camPath_003_tim_length;
extern TIM_IMAGE tim_bg_camPath_003;
extern CAMANGLE level0_camAngle_camPath_003;
extern unsigned long _binary_TIM_bg_camPath_004_tim_start[];
extern unsigned long _binary_TIM_bg_camPath_004_tim_end[];
extern unsigned long _binary_TIM_bg_camPath_004_tim_length;
extern TIM_IMAGE tim_bg_camPath_004;
extern CAMANGLE level0_camAngle_camPath_004;
extern unsigned long _binary_TIM_bg_camPath_005_tim_start[];
extern unsigned long _binary_TIM_bg_camPath_005_tim_end[];
extern unsigned long _binary_TIM_bg_camPath_005_tim_length;
extern TIM_IMAGE tim_bg_camPath_005;
extern CAMANGLE level0_camAngle_camPath_005;
extern CAMANGLE * level0_camAngles[6];
extern SIBLINGS level0_nodegnd_siblings;
extern CHILDREN level0_nodegnd_objects;
extern CHILDREN level0_nodegnd_rigidbodies;
extern NODE level0_nodegnd;
extern SIBLINGS level0_nodegnd_001_siblings;
extern CHILDREN level0_nodegnd_001_objects;
extern CHILDREN level0_nodegnd_001_rigidbodies;
extern NODE level0_nodegnd_001;
extern SIBLINGS level0_nodegnd_002_siblings;
extern CHILDREN level0_nodegnd_002_objects;
extern CHILDREN level0_nodegnd_002_rigidbodies;
extern NODE level0_nodegnd_002;
extern SIBLINGS level0_nodegnd_003_siblings;
extern CHILDREN level0_nodegnd_003_objects;
extern CHILDREN level0_nodegnd_003_rigidbodies;
extern NODE level0_nodegnd_003;
extern NODE level0_nodePlane;
extern MESH * level0_actorPtr;
@ -396,10 +68,5 @@ extern CAMANGLE * level0_camPtr;
extern NODE * level0_curNode;
extern NODE level0_nodegnd;
extern NODE level0_nodePlane;
extern NODE level0_nodegnd_001;
extern NODE level0_nodegnd_002;
extern NODE level0_nodegnd_003;

File diff suppressed because it is too large Load Diff

View File

@ -1,347 +0,0 @@
#pragma once
#include "../custom_types.h"
extern LEVEL level1;
extern CAMPOS level1_camPos_camPath;
extern CAMPOS level1_camPos_camPath_001;
extern CAMPOS level1_camPos_camPath_002;
extern CAMPOS level1_camPos_camPath_003;
extern CAMPOS level1_camPos_camPath_004;
extern CAMPOS level1_camPos_camPath_005;
extern CAMPATH level1_camPath;
extern MATRIX level1_lgtmat;
extern MATRIX level1_cmat;
extern SVECTOR modelCube_mesh[];
extern SVECTOR level1_modelCube_normal[];
extern SVECTOR level1_modelCube_uv[];
extern CVECTOR level1_modelCube_color[];
extern PRIM level1_modelCube_index[];
extern BODY level1_modelCube_body;
extern TMESH level1_modelCube;
extern unsigned long _binary_TIM_cat_tim_start[];
extern unsigned long _binary_TIM_cat_tim_end[];
extern unsigned long _binary_TIM_cat_tim_length;
extern TIM_IMAGE level1_tim_cat;
extern MESH level1_meshCube;
extern SVECTOR modelCylindre_mesh[];
extern SVECTOR level1_modelCylindre_normal[];
extern SVECTOR level1_modelCylindre_uv[];
extern CVECTOR level1_modelCylindre_color[];
extern PRIM level1_modelCylindre_index[];
extern VANIM level1_modelCylindre_anim;
extern BODY level1_modelCylindre_body;
extern TMESH level1_modelCylindre;
extern unsigned long _binary_TIM_home_tim_start[];
extern unsigned long _binary_TIM_home_tim_end[];
extern unsigned long _binary_TIM_home_tim_length;
extern TIM_IMAGE level1_tim_home;
extern MESH level1_meshCylindre;
extern SVECTOR modelgnd_mesh[];
extern SVECTOR level1_modelgnd_normal[];
extern SVECTOR level1_modelgnd_uv[];
extern CVECTOR level1_modelgnd_color[];
extern PRIM level1_modelgnd_index[];
extern BODY level1_modelgnd_body;
extern TMESH level1_modelgnd;
extern MESH level1_meshgnd;
extern SVECTOR modelgnd_001_mesh[];
extern SVECTOR level1_modelgnd_001_normal[];
extern SVECTOR level1_modelgnd_001_uv[];
extern CVECTOR level1_modelgnd_001_color[];
extern PRIM level1_modelgnd_001_index[];
extern BODY level1_modelgnd_001_body;
extern TMESH level1_modelgnd_001;
extern MESH level1_meshgnd_001;
extern SVECTOR modelgnd_003_mesh[];
extern SVECTOR level1_modelgnd_003_normal[];
extern SVECTOR level1_modelgnd_003_uv[];
extern CVECTOR level1_modelgnd_003_color[];
extern PRIM level1_modelgnd_003_index[];
extern BODY level1_modelgnd_003_body;
extern TMESH level1_modelgnd_003;
extern MESH level1_meshgnd_003;
extern SVECTOR modelgnd_002_mesh[];
extern SVECTOR level1_modelgnd_002_normal[];
extern SVECTOR level1_modelgnd_002_uv[];
extern CVECTOR level1_modelgnd_002_color[];
extern PRIM level1_modelgnd_002_index[];
extern BODY level1_modelgnd_002_body;
extern TMESH level1_modelgnd_002;
extern MESH level1_meshgnd_002;
extern SVECTOR modelLara_mesh[];
extern SVECTOR level1_modelLara_normal[];
extern SVECTOR level1_modelLara_uv[];
extern CVECTOR level1_modelLara_color[];
extern PRIM level1_modelLara_index[];
extern BODY level1_modelLara_body;
extern TMESH level1_modelLara;
extern unsigned long _binary_TIM_lara_tim_start[];
extern unsigned long _binary_TIM_lara_tim_end[];
extern unsigned long _binary_TIM_lara_tim_length;
extern TIM_IMAGE level1_tim_lara;
extern MESH level1_meshLara;
extern SVECTOR modelobject_mesh[];
extern SVECTOR level1_modelobject_normal[];
extern SVECTOR level1_modelobject_uv[];
extern CVECTOR level1_modelobject_color[];
extern PRIM level1_modelobject_index[];
extern BODY level1_modelobject_body;
extern TMESH level1_modelobject;
extern MESH level1_meshobject;
extern SVECTOR modelPlan_mesh[];
extern SVECTOR level1_modelPlan_normal[];
extern SVECTOR level1_modelPlan_uv[];
extern CVECTOR level1_modelPlan_color[];
extern PRIM level1_modelPlan_index[];
extern BODY level1_modelPlan_body;
extern TMESH level1_modelPlan;
extern MESH level1_meshPlan;
extern SVECTOR modelSphere_mesh[];
extern SVECTOR level1_modelSphere_normal[];
extern SVECTOR level1_modelSphere_uv[];
extern CVECTOR level1_modelSphere_color[];
extern PRIM level1_modelSphere_index[];
extern BODY level1_modelSphere_body;
extern TMESH level1_modelSphere;
extern MESH level1_meshSphere;
extern SVECTOR modelSphere_001_mesh[];
extern SVECTOR level1_modelSphere_001_normal[];
extern SVECTOR level1_modelSphere_001_uv[];
extern CVECTOR level1_modelSphere_001_color[];
extern PRIM level1_modelSphere_001_index[];
extern BODY level1_modelSphere_001_body;
extern TMESH level1_modelSphere_001;
extern MESH level1_meshSphere_001;
extern SVECTOR modelwall_mesh[];
extern SVECTOR level1_modelwall_normal[];
extern SVECTOR level1_modelwall_uv[];
extern CVECTOR level1_modelwall_color[];
extern PRIM level1_modelwall_index[];
extern BODY level1_modelwall_body;
extern TMESH level1_modelwall;
extern MESH level1_meshwall;
extern SVECTOR modelwall_001_mesh[];
extern SVECTOR level1_modelwall_001_normal[];
extern SVECTOR level1_modelwall_001_uv[];
extern CVECTOR level1_modelwall_001_color[];
extern PRIM level1_modelwall_001_index[];
extern BODY level1_modelwall_001_body;
extern TMESH level1_modelwall_001;
extern MESH level1_meshwall_001;
extern SVECTOR modelwall_002_mesh[];
extern SVECTOR level1_modelwall_002_normal[];
extern SVECTOR level1_modelwall_002_uv[];
extern CVECTOR level1_modelwall_002_color[];
extern PRIM level1_modelwall_002_index[];
extern BODY level1_modelwall_002_body;
extern TMESH level1_modelwall_002;
extern MESH level1_meshwall_002;
extern SVECTOR modelwall_003_mesh[];
extern SVECTOR level1_modelwall_003_normal[];
extern SVECTOR level1_modelwall_003_uv[];
extern CVECTOR level1_modelwall_003_color[];
extern PRIM level1_modelwall_003_index[];
extern BODY level1_modelwall_003_body;
extern TMESH level1_modelwall_003;
extern MESH level1_meshwall_003;
extern MESH * level1_meshes[15];
extern int level1_meshes_length;
extern CAMANGLE level1_camAngle_camPath_001;
extern CAMANGLE * level1_camAngles[0];
extern SIBLINGS level1_nodegnd_siblings;
extern CHILDREN level1_nodegnd_objects;
extern CHILDREN level1_nodegnd_rigidbodies;
extern NODE level1_nodegnd;
extern SIBLINGS level1_nodegnd_001_siblings;
extern CHILDREN level1_nodegnd_001_objects;
extern CHILDREN level1_nodegnd_001_rigidbodies;
extern NODE level1_nodegnd_001;
extern SIBLINGS level1_nodegnd_002_siblings;
extern CHILDREN level1_nodegnd_002_objects;
extern CHILDREN level1_nodegnd_002_rigidbodies;
extern NODE level1_nodegnd_002;
extern SIBLINGS level1_nodegnd_003_siblings;
extern CHILDREN level1_nodegnd_003_objects;
extern CHILDREN level1_nodegnd_003_rigidbodies;
extern NODE level1_nodegnd_003;
extern MESH * level1_actorPtr;
extern MESH * level1_levelPtr;
extern MESH * level1_propPtr;
extern CAMANGLE * level1_camPtr;
extern NODE * level1_curNode;
extern NODE level1_nodegnd;
extern NODE level1_nodegnd_001;
extern NODE level1_nodegnd_002;
extern NODE level1_nodegnd_003;

272
src/atan.c Normal file
View File

@ -0,0 +1,272 @@
// Arctan base table
static int AtanBaseTable[8] = {
0x0000,
-0x4000,
-0xFFFF,
0xC000,
-0x8000,
0x4000,
0x8000,
-0xC000,
};
// Arctan angle table
static short AtanAngleTable[0x802] = {
0x0000, 0x0005, 0x000A, 0x000F, 0x0014, 0x0019, 0x001F, 0x0024,
0x0029, 0x002E, 0x0033, 0x0038, 0x003D, 0x0042, 0x0047, 0x004C,
0x0051, 0x0057, 0x005C, 0x0061, 0x0066, 0x006B, 0x0070, 0x0075,
0x007A, 0x007F, 0x0084, 0x008A, 0x008F, 0x0094, 0x0099, 0x009E,
0x00A3, 0x00A8, 0x00AD, 0x00B2, 0x00B7, 0x00BC, 0x00C2, 0x00C7,
0x00CC, 0x00D1, 0x00D6, 0x00DB, 0x00E0, 0x00E5, 0x00EA, 0x00EF,
0x00F4, 0x00FA, 0x00FF, 0x0104, 0x0109, 0x010E, 0x0113, 0x0118,
0x011D, 0x0122, 0x0127, 0x012C, 0x0131, 0x0137, 0x013C, 0x0141,
0x0146, 0x014B, 0x0150, 0x0155, 0x015A, 0x015F, 0x0164, 0x0169,
0x016F, 0x0174, 0x0179, 0x017E, 0x0183, 0x0188, 0x018D, 0x0192,
0x0197, 0x019C, 0x01A1, 0x01A6, 0x01AC, 0x01B1, 0x01B6, 0x01BB,
0x01C0, 0x01C5, 0x01CA, 0x01CF, 0x01D4, 0x01D9, 0x01DE, 0x01E3,
0x01E9, 0x01EE, 0x01F3, 0x01F8, 0x01FD, 0x0202, 0x0207, 0x020C,
0x0211, 0x0216, 0x021B, 0x0220, 0x0226, 0x022B, 0x0230, 0x0235,
0x023A, 0x023F, 0x0244, 0x0249, 0x024E, 0x0253, 0x0258, 0x025D,
0x0262, 0x0268, 0x026D, 0x0272, 0x0277, 0x027C, 0x0281, 0x0286,
0x028B, 0x0290, 0x0295, 0x029A, 0x029F, 0x02A4, 0x02A9, 0x02AF,
0x02B4, 0x02B9, 0x02BE, 0x02C3, 0x02C8, 0x02CD, 0x02D2, 0x02D7,
0x02DC, 0x02E1, 0x02E6, 0x02EB, 0x02F0, 0x02F6, 0x02FB, 0x0300,
0x0305, 0x030A, 0x030F, 0x0314, 0x0319, 0x031E, 0x0323, 0x0328,
0x032D, 0x0332, 0x0337, 0x033C, 0x0341, 0x0347, 0x034C, 0x0351,
0x0356, 0x035B, 0x0360, 0x0365, 0x036A, 0x036F, 0x0374, 0x0379,
0x037E, 0x0383, 0x0388, 0x038D, 0x0392, 0x0397, 0x039C, 0x03A2,
0x03A7, 0x03AC, 0x03B1, 0x03B6, 0x03BB, 0x03C0, 0x03C5, 0x03CA,
0x03CF, 0x03D4, 0x03D9, 0x03DE, 0x03E3, 0x03E8, 0x03ED, 0x03F2,
0x03F7, 0x03FC, 0x0401, 0x0407, 0x040C, 0x0411, 0x0416, 0x041B,
0x0420, 0x0425, 0x042A, 0x042F, 0x0434, 0x0439, 0x043E, 0x0443,
0x0448, 0x044D, 0x0452, 0x0457, 0x045C, 0x0461, 0x0466, 0x046B,
0x0470, 0x0475, 0x047A, 0x047F, 0x0484, 0x0489, 0x048E, 0x0494,
0x0499, 0x049E, 0x04A3, 0x04A8, 0x04AD, 0x04B2, 0x04B7, 0x04BC,
0x04C1, 0x04C6, 0x04CB, 0x04D0, 0x04D5, 0x04DA, 0x04DF, 0x04E4,
0x04E9, 0x04EE, 0x04F3, 0x04F8, 0x04FD, 0x0502, 0x0507, 0x050C,
0x0511, 0x0516, 0x051B, 0x0520, 0x0525, 0x052A, 0x052F, 0x0534,
0x0539, 0x053E, 0x0543, 0x0548, 0x054D, 0x0552, 0x0557, 0x055C,
0x0561, 0x0566, 0x056B, 0x0570, 0x0575, 0x057A, 0x057F, 0x0584,
0x0589, 0x058E, 0x0593, 0x0598, 0x059D, 0x05A2, 0x05A7, 0x05AC,
0x05B1, 0x05B6, 0x05BB, 0x05C0, 0x05C5, 0x05CA, 0x05CF, 0x05D4,
0x05D9, 0x05DE, 0x05E3, 0x05E8, 0x05ED, 0x05F2, 0x05F7, 0x05FC,
0x0601, 0x0606, 0x060B, 0x0610, 0x0615, 0x061A, 0x061F, 0x0624,
0x0629, 0x062E, 0x0633, 0x0638, 0x063D, 0x0642, 0x0647, 0x064C,
0x0651, 0x0656, 0x065B, 0x0660, 0x0665, 0x066A, 0x066E, 0x0673,
0x0678, 0x067D, 0x0682, 0x0687, 0x068C, 0x0691, 0x0696, 0x069B,
0x06A0, 0x06A5, 0x06AA, 0x06AF, 0x06B4, 0x06B9, 0x06BE, 0x06C3,
0x06C8, 0x06CD, 0x06D2, 0x06D7, 0x06DC, 0x06E1, 0x06E5, 0x06EA,
0x06EF, 0x06F4, 0x06F9, 0x06FE, 0x0703, 0x0708, 0x070D, 0x0712,
0x0717, 0x071C, 0x0721, 0x0726, 0x072B, 0x0730, 0x0735, 0x0739,
0x073E, 0x0743, 0x0748, 0x074D, 0x0752, 0x0757, 0x075C, 0x0761,
0x0766, 0x076B, 0x0770, 0x0775, 0x077A, 0x077E, 0x0783, 0x0788,
0x078D, 0x0792, 0x0797, 0x079C, 0x07A1, 0x07A6, 0x07AB, 0x07B0,
0x07B5, 0x07B9, 0x07BE, 0x07C3, 0x07C8, 0x07CD, 0x07D2, 0x07D7,
0x07DC, 0x07E1, 0x07E6, 0x07EB, 0x07EF, 0x07F4, 0x07F9, 0x07FE,
0x0803, 0x0808, 0x080D, 0x0812, 0x0817, 0x081C, 0x0820, 0x0825,
0x082A, 0x082F, 0x0834, 0x0839, 0x083E, 0x0843, 0x0848, 0x084C,
0x0851, 0x0856, 0x085B, 0x0860, 0x0865, 0x086A, 0x086F, 0x0873,
0x0878, 0x087D, 0x0882, 0x0887, 0x088C, 0x0891, 0x0896, 0x089A,
0x089F, 0x08A4, 0x08A9, 0x08AE, 0x08B3, 0x08B8, 0x08BD, 0x08C1,
0x08C6, 0x08CB, 0x08D0, 0x08D5, 0x08DA, 0x08DF, 0x08E3, 0x08E8,
0x08ED, 0x08F2, 0x08F7, 0x08FC, 0x0901, 0x0905, 0x090A, 0x090F,
0x0914, 0x0919, 0x091E, 0x0922, 0x0927, 0x092C, 0x0931, 0x0936,
0x093B, 0x093F, 0x0944, 0x0949, 0x094E, 0x0953, 0x0958, 0x095C,
0x0961, 0x0966, 0x096B, 0x0970, 0x0975, 0x0979, 0x097E, 0x0983,
0x0988, 0x098D, 0x0992, 0x0996, 0x099B, 0x09A0, 0x09A5, 0x09AA,
0x09AE, 0x09B3, 0x09B8, 0x09BD, 0x09C2, 0x09C6, 0x09CB, 0x09D0,
0x09D5, 0x09DA, 0x09DE, 0x09E3, 0x09E8, 0x09ED, 0x09F2, 0x09F6,
0x09FB, 0x0A00, 0x0A05, 0x0A0A, 0x0A0E, 0x0A13, 0x0A18, 0x0A1D,
0x0A22, 0x0A26, 0x0A2B, 0x0A30, 0x0A35, 0x0A39, 0x0A3E, 0x0A43,
0x0A48, 0x0A4D, 0x0A51, 0x0A56, 0x0A5B, 0x0A60, 0x0A64, 0x0A69,
0x0A6E, 0x0A73, 0x0A77, 0x0A7C, 0x0A81, 0x0A86, 0x0A8B, 0x0A8F,
0x0A94, 0x0A99, 0x0A9E, 0x0AA2, 0x0AA7, 0x0AAC, 0x0AB1, 0x0AB5,
0x0ABA, 0x0ABF, 0x0AC4, 0x0AC8, 0x0ACD, 0x0AD2, 0x0AD7, 0x0ADB,
0x0AE0, 0x0AE5, 0x0AE9, 0x0AEE, 0x0AF3, 0x0AF8, 0x0AFC, 0x0B01,
0x0B06, 0x0B0B, 0x0B0F, 0x0B14, 0x0B19, 0x0B1E, 0x0B22, 0x0B27,
0x0B2C, 0x0B30, 0x0B35, 0x0B3A, 0x0B3F, 0x0B43, 0x0B48, 0x0B4D,
0x0B51, 0x0B56, 0x0B5B, 0x0B60, 0x0B64, 0x0B69, 0x0B6E, 0x0B72,
0x0B77, 0x0B7C, 0x0B80, 0x0B85, 0x0B8A, 0x0B8F, 0x0B93, 0x0B98,
0x0B9D, 0x0BA1, 0x0BA6, 0x0BAB, 0x0BAF, 0x0BB4, 0x0BB9, 0x0BBD,
0x0BC2, 0x0BC7, 0x0BCB, 0x0BD0, 0x0BD5, 0x0BD9, 0x0BDE, 0x0BE3,
0x0BE7, 0x0BEC, 0x0BF1, 0x0BF5, 0x0BFA, 0x0BFF, 0x0C03, 0x0C08,
0x0C0D, 0x0C11, 0x0C16, 0x0C1B, 0x0C1F, 0x0C24, 0x0C29, 0x0C2D,
0x0C32, 0x0C37, 0x0C3B, 0x0C40, 0x0C45, 0x0C49, 0x0C4E, 0x0C53,
0x0C57, 0x0C5C, 0x0C60, 0x0C65, 0x0C6A, 0x0C6E, 0x0C73, 0x0C78,
0x0C7C, 0x0C81, 0x0C86, 0x0C8A, 0x0C8F, 0x0C93, 0x0C98, 0x0C9D,
0x0CA1, 0x0CA6, 0x0CAB, 0x0CAF, 0x0CB4, 0x0CB8, 0x0CBD, 0x0CC2,
0x0CC6, 0x0CCB, 0x0CCF, 0x0CD4, 0x0CD9, 0x0CDD, 0x0CE2, 0x0CE6,
0x0CEB, 0x0CF0, 0x0CF4, 0x0CF9, 0x0CFD, 0x0D02, 0x0D07, 0x0D0B,
0x0D10, 0x0D14, 0x0D19, 0x0D1E, 0x0D22, 0x0D27, 0x0D2B, 0x0D30,
0x0D34, 0x0D39, 0x0D3E, 0x0D42, 0x0D47, 0x0D4B, 0x0D50, 0x0D54,
0x0D59, 0x0D5E, 0x0D62, 0x0D67, 0x0D6B, 0x0D70, 0x0D74, 0x0D79,
0x0D7D, 0x0D82, 0x0D87, 0x0D8B, 0x0D90, 0x0D94, 0x0D99, 0x0D9D,
0x0DA2, 0x0DA6, 0x0DAB, 0x0DAF, 0x0DB4, 0x0DB9, 0x0DBD, 0x0DC2,
0x0DC6, 0x0DCB, 0x0DCF, 0x0DD4, 0x0DD8, 0x0DDD, 0x0DE1, 0x0DE6,
0x0DEA, 0x0DEF, 0x0DF3, 0x0DF8, 0x0DFC, 0x0E01, 0x0E05, 0x0E0A,
0x0E0F, 0x0E13, 0x0E18, 0x0E1C, 0x0E21, 0x0E25, 0x0E2A, 0x0E2E,
0x0E33, 0x0E37, 0x0E3C, 0x0E40, 0x0E45, 0x0E49, 0x0E4E, 0x0E52,
0x0E56, 0x0E5B, 0x0E5F, 0x0E64, 0x0E68, 0x0E6D, 0x0E71, 0x0E76,
0x0E7A, 0x0E7F, 0x0E83, 0x0E88, 0x0E8C, 0x0E91, 0x0E95, 0x0E9A,
0x0E9E, 0x0EA3, 0x0EA7, 0x0EAC, 0x0EB0, 0x0EB4, 0x0EB9, 0x0EBD,
0x0EC2, 0x0EC6, 0x0ECB, 0x0ECF, 0x0ED4, 0x0ED8, 0x0EDC, 0x0EE1,
0x0EE5, 0x0EEA, 0x0EEE, 0x0EF3, 0x0EF7, 0x0EFC, 0x0F00, 0x0F04,
0x0F09, 0x0F0D, 0x0F12, 0x0F16, 0x0F1B, 0x0F1F, 0x0F23, 0x0F28,
0x0F2C, 0x0F31, 0x0F35, 0x0F3A, 0x0F3E, 0x0F42, 0x0F47, 0x0F4B,
0x0F50, 0x0F54, 0x0F58, 0x0F5D, 0x0F61, 0x0F66, 0x0F6A, 0x0F6E,
0x0F73, 0x0F77, 0x0F7C, 0x0F80, 0x0F84, 0x0F89, 0x0F8D, 0x0F91,
0x0F96, 0x0F9A, 0x0F9F, 0x0FA3, 0x0FA7, 0x0FAC, 0x0FB0, 0x0FB5,
0x0FB9, 0x0FBD, 0x0FC2, 0x0FC6, 0x0FCA, 0x0FCF, 0x0FD3, 0x0FD7,
0x0FDC, 0x0FE0, 0x0FE5, 0x0FE9, 0x0FED, 0x0FF2, 0x0FF6, 0x0FFA,
0x0FFF, 0x1003, 0x1007, 0x100C, 0x1010, 0x1014, 0x1019, 0x101D,
0x1021, 0x1026, 0x102A, 0x102E, 0x1033, 0x1037, 0x103B, 0x1040,
0x1044, 0x1048, 0x104D, 0x1051, 0x1055, 0x105A, 0x105E, 0x1062,
0x1067, 0x106B, 0x106F, 0x1073, 0x1078, 0x107C, 0x1080, 0x1085,
0x1089, 0x108D, 0x1092, 0x1096, 0x109A, 0x109E, 0x10A3, 0x10A7,
0x10AB, 0x10B0, 0x10B4, 0x10B8, 0x10BC, 0x10C1, 0x10C5, 0x10C9,
0x10CE, 0x10D2, 0x10D6, 0x10DA, 0x10DF, 0x10E3, 0x10E7, 0x10EB,
0x10F0, 0x10F4, 0x10F8, 0x10FD, 0x1101, 0x1105, 0x1109, 0x110E,
0x1112, 0x1116, 0x111A, 0x111F, 0x1123, 0x1127, 0x112B, 0x1130,
0x1134, 0x1138, 0x113C, 0x1140, 0x1145, 0x1149, 0x114D, 0x1151,
0x1156, 0x115A, 0x115E, 0x1162, 0x1166, 0x116B, 0x116F, 0x1173,
0x1177, 0x117C, 0x1180, 0x1184, 0x1188, 0x118C, 0x1191, 0x1195,
0x1199, 0x119D, 0x11A1, 0x11A6, 0x11AA, 0x11AE, 0x11B2, 0x11B6,
0x11BB, 0x11BF, 0x11C3, 0x11C7, 0x11CB, 0x11CF, 0x11D4, 0x11D8,
0x11DC, 0x11E0, 0x11E4, 0x11E9, 0x11ED, 0x11F1, 0x11F5, 0x11F9,
0x11FD, 0x1202, 0x1206, 0x120A, 0x120E, 0x1212, 0x1216, 0x121A,
0x121F, 0x1223, 0x1227, 0x122B, 0x122F, 0x1233, 0x1237, 0x123C,
0x1240, 0x1244, 0x1248, 0x124C, 0x1250, 0x1254, 0x1259, 0x125D,
0x1261, 0x1265, 0x1269, 0x126D, 0x1271, 0x1275, 0x127A, 0x127E,
0x1282, 0x1286, 0x128A, 0x128E, 0x1292, 0x1296, 0x129A, 0x129F,
0x12A3, 0x12A7, 0x12AB, 0x12AF, 0x12B3, 0x12B7, 0x12BB, 0x12BF,
0x12C3, 0x12C7, 0x12CC, 0x12D0, 0x12D4, 0x12D8, 0x12DC, 0x12E0,
0x12E4, 0x12E8, 0x12EC, 0x12F0, 0x12F4, 0x12F8, 0x12FC, 0x1301,
0x1305, 0x1309, 0x130D, 0x1311, 0x1315, 0x1319, 0x131D, 0x1321,
0x1325, 0x1329, 0x132D, 0x1331, 0x1335, 0x1339, 0x133D, 0x1341,
0x1345, 0x1349, 0x134D, 0x1351, 0x1355, 0x135A, 0x135E, 0x1362,
0x1366, 0x136A, 0x136E, 0x1372, 0x1376, 0x137A, 0x137E, 0x1382,
0x1386, 0x138A, 0x138E, 0x1392, 0x1396, 0x139A, 0x139E, 0x13A2,
0x13A6, 0x13AA, 0x13AE, 0x13B2, 0x13B6, 0x13BA, 0x13BE, 0x13C2,
0x13C6, 0x13CA, 0x13CE, 0x13D2, 0x13D6, 0x13DA, 0x13DE, 0x13E2,
0x13E6, 0x13E9, 0x13ED, 0x13F1, 0x13F5, 0x13F9, 0x13FD, 0x1401,
0x1405, 0x1409, 0x140D, 0x1411, 0x1415, 0x1419, 0x141D, 0x1421,
0x1425, 0x1429, 0x142D, 0x1431, 0x1435, 0x1439, 0x143D, 0x1440,
0x1444, 0x1448, 0x144C, 0x1450, 0x1454, 0x1458, 0x145C, 0x1460,
0x1464, 0x1468, 0x146C, 0x1470, 0x1473, 0x1477, 0x147B, 0x147F,
0x1483, 0x1487, 0x148B, 0x148F, 0x1493, 0x1497, 0x149B, 0x149E,
0x14A2, 0x14A6, 0x14AA, 0x14AE, 0x14B2, 0x14B6, 0x14BA, 0x14BE,
0x14C1, 0x14C5, 0x14C9, 0x14CD, 0x14D1, 0x14D5, 0x14D9, 0x14DD,
0x14E0, 0x14E4, 0x14E8, 0x14EC, 0x14F0, 0x14F4, 0x14F8, 0x14FB,
0x14FF, 0x1503, 0x1507, 0x150B, 0x150F, 0x1513, 0x1516, 0x151A,
0x151E, 0x1522, 0x1526, 0x152A, 0x152D, 0x1531, 0x1535, 0x1539,
0x153D, 0x1541, 0x1544, 0x1548, 0x154C, 0x1550, 0x1554, 0x1558,
0x155B, 0x155F, 0x1563, 0x1567, 0x156B, 0x156E, 0x1572, 0x1576,
0x157A, 0x157E, 0x1581, 0x1585, 0x1589, 0x158D, 0x1591, 0x1594,
0x1598, 0x159C, 0x15A0, 0x15A4, 0x15A7, 0x15AB, 0x15AF, 0x15B3,
0x15B7, 0x15BA, 0x15BE, 0x15C2, 0x15C6, 0x15C9, 0x15CD, 0x15D1,
0x15D5, 0x15D8, 0x15DC, 0x15E0, 0x15E4, 0x15E8, 0x15EB, 0x15EF,
0x15F3, 0x15F7, 0x15FA, 0x15FE, 0x1602, 0x1606, 0x1609, 0x160D,
0x1611, 0x1614, 0x1618, 0x161C, 0x1620, 0x1623, 0x1627, 0x162B,
0x162F, 0x1632, 0x1636, 0x163A, 0x163E, 0x1641, 0x1645, 0x1649,
0x164C, 0x1650, 0x1654, 0x1658, 0x165B, 0x165F, 0x1663, 0x1666,
0x166A, 0x166E, 0x1671, 0x1675, 0x1679, 0x167D, 0x1680, 0x1684,
0x1688, 0x168B, 0x168F, 0x1693, 0x1696, 0x169A, 0x169E, 0x16A1,
0x16A5, 0x16A9, 0x16AC, 0x16B0, 0x16B4, 0x16B7, 0x16BB, 0x16BF,
0x16C2, 0x16C6, 0x16CA, 0x16CD, 0x16D1, 0x16D5, 0x16D8, 0x16DC,
0x16E0, 0x16E3, 0x16E7, 0x16EB, 0x16EE, 0x16F2, 0x16F6, 0x16F9,
0x16FD, 0x1700, 0x1704, 0x1708, 0x170B, 0x170F, 0x1713, 0x1716,
0x171A, 0x171D, 0x1721, 0x1725, 0x1728, 0x172C, 0x1730, 0x1733,
0x1737, 0x173A, 0x173E, 0x1742, 0x1745, 0x1749, 0x174C, 0x1750,
0x1754, 0x1757, 0x175B, 0x175E, 0x1762, 0x1766, 0x1769, 0x176D,
0x1770, 0x1774, 0x1778, 0x177B, 0x177F, 0x1782, 0x1786, 0x1789,
0x178D, 0x1791, 0x1794, 0x1798, 0x179B, 0x179F, 0x17A2, 0x17A6,
0x17AA, 0x17AD, 0x17B1, 0x17B4, 0x17B8, 0x17BB, 0x17BF, 0x17C2,
0x17C6, 0x17C9, 0x17CD, 0x17D1, 0x17D4, 0x17D8, 0x17DB, 0x17DF,
0x17E2, 0x17E6, 0x17E9, 0x17ED, 0x17F0, 0x17F4, 0x17F7, 0x17FB,
0x17FE, 0x1802, 0x1806, 0x1809, 0x180D, 0x1810, 0x1814, 0x1817,
0x181B, 0x181E, 0x1822, 0x1825, 0x1829, 0x182C, 0x1830, 0x1833,
0x1837, 0x183A, 0x183E, 0x1841, 0x1845, 0x1848, 0x184C, 0x184F,
0x1853, 0x1856, 0x185A, 0x185D, 0x1860, 0x1864, 0x1867, 0x186B,
0x186E, 0x1872, 0x1875, 0x1879, 0x187C, 0x1880, 0x1883, 0x1887,
0x188A, 0x188E, 0x1891, 0x1894, 0x1898, 0x189B, 0x189F, 0x18A2,
0x18A6, 0x18A9, 0x18AD, 0x18B0, 0x18B3, 0x18B7, 0x18BA, 0x18BE,
0x18C1, 0x18C5, 0x18C8, 0x18CC, 0x18CF, 0x18D2, 0x18D6, 0x18D9,
0x18DD, 0x18E0, 0x18E3, 0x18E7, 0x18EA, 0x18EE, 0x18F1, 0x18F5,
0x18F8, 0x18FB, 0x18FF, 0x1902, 0x1906, 0x1909, 0x190C, 0x1910,
0x1913, 0x1917, 0x191A, 0x191D, 0x1921, 0x1924, 0x1928, 0x192B,
0x192E, 0x1932, 0x1935, 0x1938, 0x193C, 0x193F, 0x1943, 0x1946,
0x1949, 0x194D, 0x1950, 0x1953, 0x1957, 0x195A, 0x195D, 0x1961,
0x1964, 0x1968, 0x196B, 0x196E, 0x1972, 0x1975, 0x1978, 0x197C,
0x197F, 0x1982, 0x1986, 0x1989, 0x198C, 0x1990, 0x1993, 0x1996,
0x199A, 0x199D, 0x19A0, 0x19A4, 0x19A7, 0x19AA, 0x19AE, 0x19B1,
0x19B4, 0x19B8, 0x19BB, 0x19BE, 0x19C2, 0x19C5, 0x19C8, 0x19CC,
0x19CF, 0x19D2, 0x19D5, 0x19D9, 0x19DC, 0x19DF, 0x19E3, 0x19E6,
0x19E9, 0x19ED, 0x19F0, 0x19F3, 0x19F6, 0x19FA, 0x19FD, 0x1A00,
0x1A04, 0x1A07, 0x1A0A, 0x1A0D, 0x1A11, 0x1A14, 0x1A17, 0x1A1B,
0x1A1E, 0x1A21, 0x1A24, 0x1A28, 0x1A2B, 0x1A2E, 0x1A31, 0x1A35,
0x1A38, 0x1A3B, 0x1A3E, 0x1A42, 0x1A45, 0x1A48, 0x1A4B, 0x1A4F,
0x1A52, 0x1A55, 0x1A58, 0x1A5C, 0x1A5F, 0x1A62, 0x1A65, 0x1A69,
0x1A6C, 0x1A6F, 0x1A72, 0x1A76, 0x1A79, 0x1A7C, 0x1A7F, 0x1A83,
0x1A86, 0x1A89, 0x1A8C, 0x1A8F, 0x1A93, 0x1A96, 0x1A99, 0x1A9C,
0x1A9F, 0x1AA3, 0x1AA6, 0x1AA9, 0x1AAC, 0x1AB0, 0x1AB3, 0x1AB6,
0x1AB9, 0x1ABC, 0x1AC0, 0x1AC3, 0x1AC6, 0x1AC9, 0x1ACC, 0x1ACF,
0x1AD3, 0x1AD6, 0x1AD9, 0x1ADC, 0x1ADF, 0x1AE3, 0x1AE6, 0x1AE9,
0x1AEC, 0x1AEF, 0x1AF2, 0x1AF6, 0x1AF9, 0x1AFC, 0x1AFF, 0x1B02,
0x1B05, 0x1B09, 0x1B0C, 0x1B0F, 0x1B12, 0x1B15, 0x1B18, 0x1B1C,
0x1B1F, 0x1B22, 0x1B25, 0x1B28, 0x1B2B, 0x1B2E, 0x1B32, 0x1B35,
0x1B38, 0x1B3B, 0x1B3E, 0x1B41, 0x1B44, 0x1B48, 0x1B4B, 0x1B4E,
0x1B51, 0x1B54, 0x1B57, 0x1B5A, 0x1B5D, 0x1B61, 0x1B64, 0x1B67,
0x1B6A, 0x1B6D, 0x1B70, 0x1B73, 0x1B76, 0x1B79, 0x1B7D, 0x1B80,
0x1B83, 0x1B86, 0x1B89, 0x1B8C, 0x1B8F, 0x1B92, 0x1B95, 0x1B98,
0x1B9C, 0x1B9F, 0x1BA2, 0x1BA5, 0x1BA8, 0x1BAB, 0x1BAE, 0x1BB1,
0x1BB4, 0x1BB7, 0x1BBA, 0x1BBD, 0x1BC1, 0x1BC4, 0x1BC7, 0x1BCA,
0x1BCD, 0x1BD0, 0x1BD3, 0x1BD6, 0x1BD9, 0x1BDC, 0x1BDF, 0x1BE2,
0x1BE5, 0x1BE8, 0x1BEB, 0x1BEE, 0x1BF2, 0x1BF5, 0x1BF8, 0x1BFB,
0x1BFE, 0x1C01, 0x1C04, 0x1C07, 0x1C0A, 0x1C0D, 0x1C10, 0x1C13,
0x1C16, 0x1C19, 0x1C1C, 0x1C1F, 0x1C22, 0x1C25, 0x1C28, 0x1C2B,
0x1C2E, 0x1C31, 0x1C34, 0x1C37, 0x1C3A, 0x1C3D, 0x1C40, 0x1C43,
0x1C46, 0x1C49, 0x1C4C, 0x1C4F, 0x1C52, 0x1C55, 0x1C58, 0x1C5B,
0x1C5E, 0x1C61, 0x1C64, 0x1C67, 0x1C6A, 0x1C6D, 0x1C70, 0x1C73,
0x1C76, 0x1C79, 0x1C7C, 0x1C7F, 0x1C82, 0x1C85, 0x1C88, 0x1C8B,
0x1C8E, 0x1C91, 0x1C94, 0x1C97, 0x1C9A, 0x1C9D, 0x1CA0, 0x1CA3,
0x1CA6, 0x1CA9, 0x1CAC, 0x1CAF, 0x1CB2, 0x1CB5, 0x1CB8, 0x1CBB,
0x1CBE, 0x1CC1, 0x1CC3, 0x1CC6, 0x1CC9, 0x1CCC, 0x1CCF, 0x1CD2,
0x1CD5, 0x1CD8, 0x1CDB, 0x1CDE, 0x1CE1, 0x1CE4, 0x1CE7, 0x1CEA,
0x1CED, 0x1CF0, 0x1CF3, 0x1CF5, 0x1CF8, 0x1CFB, 0x1CFE, 0x1D01,
0x1D04, 0x1D07, 0x1D0A, 0x1D0D, 0x1D10, 0x1D13, 0x1D16, 0x1D18,
0x1D1B, 0x1D1E, 0x1D21, 0x1D24, 0x1D27, 0x1D2A, 0x1D2D, 0x1D30,
0x1D33, 0x1D35, 0x1D38, 0x1D3B, 0x1D3E, 0x1D41, 0x1D44, 0x1D47,
0x1D4A, 0x1D4D, 0x1D4F, 0x1D52, 0x1D55, 0x1D58, 0x1D5B, 0x1D5E,
0x1D61, 0x1D64, 0x1D66, 0x1D69, 0x1D6C, 0x1D6F, 0x1D72, 0x1D75,
0x1D78, 0x1D7B, 0x1D7D, 0x1D80, 0x1D83, 0x1D86, 0x1D89, 0x1D8C,
0x1D8E, 0x1D91, 0x1D94, 0x1D97, 0x1D9A, 0x1D9D, 0x1DA0, 0x1DA2,
0x1DA5, 0x1DA8, 0x1DAB, 0x1DAE, 0x1DB1, 0x1DB3, 0x1DB6, 0x1DB9,
0x1DBC, 0x1DBF, 0x1DC2, 0x1DC4, 0x1DC7, 0x1DCA, 0x1DCD, 0x1DD0,
0x1DD3, 0x1DD5, 0x1DD8, 0x1DDB, 0x1DDE, 0x1DE1, 0x1DE3, 0x1DE6,
0x1DE9, 0x1DEC, 0x1DEF, 0x1DF1, 0x1DF4, 0x1DF7, 0x1DFA, 0x1DFD,
0x1DFF, 0x1E02, 0x1E05, 0x1E08, 0x1E0B, 0x1E0D, 0x1E10, 0x1E13,
0x1E16, 0x1E19, 0x1E1B, 0x1E1E, 0x1E21, 0x1E24, 0x1E26, 0x1E29,
0x1E2C, 0x1E2F, 0x1E32, 0x1E34, 0x1E37, 0x1E3A, 0x1E3D, 0x1E3F,
0x1E42, 0x1E45, 0x1E48, 0x1E4A, 0x1E4D, 0x1E50, 0x1E53, 0x1E55,
0x1E58, 0x1E5B, 0x1E5E, 0x1E60, 0x1E63, 0x1E66, 0x1E69, 0x1E6B,
0x1E6E, 0x1E71, 0x1E74, 0x1E76, 0x1E79, 0x1E7C, 0x1E7F, 0x1E81,
0x1E84, 0x1E87, 0x1E8A, 0x1E8C, 0x1E8F, 0x1E92, 0x1E94, 0x1E97,
0x1E9A, 0x1E9D, 0x1E9F, 0x1EA2, 0x1EA5, 0x1EA8, 0x1EAA, 0x1EAD,
0x1EB0, 0x1EB2, 0x1EB5, 0x1EB8, 0x1EBA, 0x1EBD, 0x1EC0, 0x1EC3,
0x1EC5, 0x1EC8, 0x1ECB, 0x1ECD, 0x1ED0, 0x1ED3, 0x1ED5, 0x1ED8,
0x1EDB, 0x1EDE, 0x1EE0, 0x1EE3, 0x1EE6, 0x1EE8, 0x1EEB, 0x1EEE,
0x1EF0, 0x1EF3, 0x1EF6, 0x1EF8, 0x1EFB, 0x1EFE, 0x1F00, 0x1F03,
0x1F06, 0x1F08, 0x1F0B, 0x1F0E, 0x1F10, 0x1F13, 0x1F16, 0x1F18,
0x1F1B, 0x1F1E, 0x1F20, 0x1F23, 0x1F26, 0x1F28, 0x1F2B, 0x1F2E,
0x1F30, 0x1F33, 0x1F36, 0x1F38, 0x1F3B, 0x1F3D, 0x1F40, 0x1F43,
0x1F45, 0x1F48, 0x1F4B, 0x1F4D, 0x1F50, 0x1F53, 0x1F55, 0x1F58,
0x1F5A, 0x1F5D, 0x1F60, 0x1F62, 0x1F65, 0x1F68, 0x1F6A, 0x1F6D,
0x1F6F, 0x1F72, 0x1F75, 0x1F77, 0x1F7A, 0x1F7C, 0x1F7F, 0x1F82,
0x1F84, 0x1F87, 0x1F8A, 0x1F8C, 0x1F8F, 0x1F91, 0x1F94, 0x1F97,
0x1F99, 0x1F9C, 0x1F9E, 0x1FA1, 0x1FA4, 0x1FA6, 0x1FA9, 0x1FAB,
0x1FAE, 0x1FB0, 0x1FB3, 0x1FB6, 0x1FB8, 0x1FBB, 0x1FBD, 0x1FC0,
0x1FC3, 0x1FC5, 0x1FC8, 0x1FCA, 0x1FCD, 0x1FCF, 0x1FD2, 0x1FD5,
0x1FD7, 0x1FDA, 0x1FDC, 0x1FDF, 0x1FE1, 0x1FE4, 0x1FE6, 0x1FE9,
0x1FEC, 0x1FEE, 0x1FF1, 0x1FF3, 0x1FF6, 0x1FF8, 0x1FFB, 0x1FFD,
0x2000, 0x2000,
};

33
src/camera.c Normal file
View File

@ -0,0 +1,33 @@
#include "../include/camera.h"
#include "../include/math.h"
void getCameraXZ(int * x, int * z, int actorX, int actorZ, int angle, int distance) {
// Using Nic's Costable : https://github.com/grumpycoders/Balau/blob/master/tests/test-Handles.cc#L20-L102
// https://godbolt.org/z/q6cMcj
*x = (actorX << 12) + (distance * nsin(angle));
*z = (actorZ << 12) - (distance * ncos(angle));
};
void getCameraXZY(int * x, int * z, int * y, int actorX, int actorZ, int actorY, int angle, int angleX, int distance) {
// Using Nic's Costable : https://github.com/grumpycoders/Balau/blob/master/tests/test-Handles.cc#L20-L102
// https://godbolt.org/z/q6cMcj
*x = (actorX << 12) + (distance * nsin(angle));
*z = (actorZ << 12) - (distance * ( ( ncos(angle) * ncos(angleX) ) >> 12 ) );
*y = (actorY << 12) - (distance * nsin(angleX));
};
void getCameraZY( int * z, int * y, int actorZ, int actorY, int angleX, int distance) {
*z = (actorZ << 12) - (distance * ncos(angleX));
*y = (actorY << 12) - (distance * nsin(angleX));
};
// @Will : you might want to use sin/cos to move the camera in a circle but you could do that by moving it along its tangent and then clamping the distance
void applyCamera( CAMERA * cam ) {
VECTOR vec; // Vector that holds the output values of the following instructions
RotMatrix_gte(&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 setCameraPos( CAMERA * camera, VECTOR pos, SVECTOR rot ) {
camera->pos = pos;
camera->rot = rot;
};

412
src/graphics.c Normal file
View File

@ -0,0 +1,412 @@
#include "../include/graphics.h"
#include "../include/math.h"
void transformMesh(CAMERA * camera, MESH * mesh){
MATRIX mat;
// Apply rotation matrix
RotMatrix_gte(&mesh->rot, &mat);
// Apply translation matrix
TransMatrix(&mat, &mesh->pos);
// Compose matrix with cam
CompMatrix(&camera->mat, &mat, &mat);
// Set default rotation and translation matrices
SetRotMatrix(&mat);
SetTransMatrix(&mat);
//~ }
};
//TODO : Break this monster in tiny bits ?
void drawPoly(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw) {
long nclip, t = 0;
// mesh is POLY_GT3 ( triangle )
if (mesh->index[t].code == 4) {
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 ) {
// If mesh is not part of precalculated background, draw them, else, discard
if ( !( mesh->isBG ) || *camMode != 2) {
poly = (POLY_GT3 *)*nextpri;
// If Vertex Anim flag is set, use it
if (mesh->isAnim){
// If interpolation flag is set, use it
if(mesh->anim->interpolate){
// Ping pong
//~ //if (mesh->anim->cursor > 4096 || mesh->anim->cursor < 0){
//~ // mesh->anim->dir *= -1;
//~ //}
// Fixed point math precision
short precision = 12;
// Find next keyframe
if (mesh->anim->cursor > (1 << precision)) {
// There are still keyframes to interpolate between
if ( mesh->anim->lerpCursor < mesh->anim->nframes - 1 ) {
mesh->anim->lerpCursor ++;
mesh->anim->cursor = 0;
}
// We've reached last frame, go back to first frame
if ( mesh->anim->lerpCursor == mesh->anim->nframes - 1 ) {
mesh->anim->lerpCursor = 0;
mesh->anim->cursor = 0;
}
}
// Let's lerp between keyframes
// TODO : Finish lerped animation implementation
// Vertex 1
mesh->tmesh->v[ mesh->index[ t ].order.vx ].vx = lerpD( mesh->anim->data[mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[t].order.vx].vx << precision , mesh->anim->data[(mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[t].order.vx].vx << precision, mesh->anim->cursor << precision) >> precision;
mesh->tmesh->v[ mesh->index[ t ].order.vx ].vz = lerpD( mesh->anim->data[mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[t].order.vx].vz << precision , mesh->anim->data[(mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[t].order.vx].vz << precision, mesh->anim->cursor << precision) >> precision;
mesh->tmesh->v[ mesh->index[ t ].order.vx ].vy = lerpD( mesh->anim->data[mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[t].order.vx].vy << precision , mesh->anim->data[(mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[t].order.vx].vy << precision, mesh->anim->cursor << precision) >> precision;
// Vertex 2
mesh->tmesh->v[ mesh->index[ t ].order.vz ].vx = lerpD( mesh->anim->data[mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[t].order.vz].vx << precision , mesh->anim->data[(mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[t].order.vz].vx << precision, mesh->anim->cursor << precision) >> precision;
mesh->tmesh->v[ mesh->index[ t ].order.vz ].vz = lerpD( mesh->anim->data[mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[t].order.vz].vz << precision , mesh->anim->data[(mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[t].order.vz].vz << precision, mesh->anim->cursor << precision) >> precision;
mesh->tmesh->v[ mesh->index[ t ].order.vz ].vy = lerpD( mesh->anim->data[mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[t].order.vz].vy << precision , mesh->anim->data[(mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[t].order.vz].vy << precision, mesh->anim->cursor << precision) >> precision;
// Vertex 3
mesh->tmesh->v[ mesh->index[ t ].order.vy ].vx = lerpD( mesh->anim->data[mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[t].order.vy].vx << precision , mesh->anim->data[(mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[t].order.vy].vx << precision, mesh->anim->cursor << precision) >> precision;
mesh->tmesh->v[ mesh->index[ t ].order.vy ].vz = lerpD( mesh->anim->data[mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[t].order.vy].vz << precision , mesh->anim->data[(mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[t].order.vy].vz << precision, mesh->anim->cursor << precision) >> precision;
mesh->tmesh->v[ mesh->index[ t ].order.vy ].vy = lerpD( mesh->anim->data[mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[t].order.vy].vy << precision , mesh->anim->data[(mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[t].order.vy].vy << precision, mesh->anim->cursor << precision) >> precision;
mesh->anim->cursor += 24 * mesh->anim->dir;
// Coord transformation from world space to screen space
nclip = RotAverageNclip3(
&mesh->tmesh->v[ mesh->index[t].order.vx ],
&mesh->tmesh->v[ mesh->index[t].order.vz ],
&mesh->tmesh->v[ mesh->index[t].order.vy ],
( long* ) &poly->x0, ( long* ) &poly->x1, ( long* ) &poly->x2,
&mesh->p,
&mesh->OTz,
Flag
);
} else {
// No interpolation
// Use the pre-calculated vertices coordinates from the animation data
nclip = RotAverageNclip3(
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.vx ],
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.vz ],
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.vy ],
( long* ) &poly->x0, ( long* ) &poly->x1, ( long* ) &poly->x2,
&mesh->p,
&mesh->OTz,
Flag
);
}
} else {
// No animation
// Use model's regular vertex coordinates
nclip = RotAverageNclip3(
&mesh->tmesh->v[ mesh->index[t].order.vx ],
&mesh->tmesh->v[ mesh->index[t].order.vz ],
&mesh->tmesh->v[ mesh->index[t].order.vy ],
( long * ) &poly->x0, ( long * ) &poly->x1, ( long * ) &poly->x2,
&mesh->p,
&mesh->OTz,
Flag
);
}
// Do not draw invisible meshes
if ( nclip > 0 && mesh->OTz > 0 && (mesh->p < 4096) ) {
SetPolyGT3( poly );
// If isPrism flag is set, use it
// FIXME : Doesn't work with pre-rendered BGs
if ( mesh->isPrism ) {
// Transparency effect :
// Use current DRAWENV clip as TPAGE instead of regular textures
( (POLY_GT3 *) poly )->tpage = getTPage( mesh->tim->mode&0x3, 0,
draw->clip.x,
draw->clip.y
);
// Use projected coordinates (results from RotAverage...) as UV coords and clamp them to 0-255,0-224 Why 224 though ?
setUV3(poly, (poly->x0 < 0 ? 0 : poly->x0 > 255 ? 255 : poly->x0),
(poly->y0 < 0 ? 0 : poly->y0 > 240 ? 240 : poly->y0),
(poly->x1 < 0 ? 0 : poly->x1 > 255 ? 255 : poly->x1),
(poly->y1 < 0 ? 0 : poly->y1 > 240 ? 240 : poly->y1),
(poly->x2 < 0 ? 0 : poly->x2 > 255 ? 255 : poly->x2),
(poly->y2 < 0 ? 0 : poly->y2 > 240 ? 240 : poly->y2)
);
} else {
// No transparency effect
// Use regular TPAGE
( (POLY_GT3 *) poly )->tpage = getTPage(mesh->tim->mode&0x3, 0,
mesh->tim->prect->x,
mesh->tim->prect->y
);
setUV3(poly, mesh->tmesh->u[i].vx , mesh->tmesh->u[i].vy + mesh->tim->prect->y,
mesh->tmesh->u[i+2].vx, mesh->tmesh->u[i+2].vy + mesh->tim->prect->y,
mesh->tmesh->u[i+1].vx, mesh->tmesh->u[i+1].vy + mesh->tim->prect->y);
}
// CLUT setup
// If tim mode == 0 | 1 (4bits/8bits image), set CLUT coordinates
if ( (mesh->tim->mode & 0x3 ) < 2){
setClut(poly,
mesh->tim->crect->x,
mesh->tim->crect->y);
}
if ( mesh->isSprite ) {
SetShadeTex( poly, 1 );
}
// Defaults depth color to neutral grey
CVECTOR outCol = { 128,128,128,0 };
CVECTOR outCol1 = { 128,128,128,0 };
CVECTOR outCol2 = { 128,128,128,0 };
NormalColorDpq(&mesh->tmesh->n[ mesh->index[t].order.vx ], &mesh->tmesh->c[ mesh->index[t].order.vx ], mesh->p, &outCol);
NormalColorDpq(&mesh->tmesh->n[ mesh->index[t].order.vz ], &mesh->tmesh->c[ mesh->index[t].order.vz ], mesh->p, &outCol1);
NormalColorDpq(&mesh->tmesh->n[ mesh->index[t].order.vy ], &mesh->tmesh->c[ mesh->index[t].order.vy ], mesh->p, &outCol2);
// If transparent effect is in use, inhibit shadows
if (mesh->isPrism){
// Use un-interpolated (i.e: no light, no fog) colors
setRGB0(poly, mesh->tmesh->c[i].r, mesh->tmesh->c[i].g, mesh->tmesh->c[i].b);
setRGB1(poly, mesh->tmesh->c[i+1].r, mesh->tmesh->c[i+1].g, mesh->tmesh->c[i+1].b);
setRGB2(poly, mesh->tmesh->c[i+2].r, mesh->tmesh->c[i+2].g, mesh->tmesh->c[i+2].b);
} else {
setRGB0(poly, outCol.r, outCol.g , outCol.b);
setRGB1(poly, outCol1.r, outCol1.g, outCol1.b);
setRGB2(poly, outCol2.r, outCol2.g, outCol2.b);
}
if ( (mesh->OTz > 0) /*&& (*mesh->OTz < OTLEN)*/ && (mesh->p < 4096) ) {
AddPrim(&ot[ mesh->OTz-2 ], poly);
}
//~ mesh->pos2D.vx = *(&poly->x0);
//~ mesh->pos2D.vy = *(&poly->x0 + 1);
// mesh->pos2D.vy = poly->x0;
// FntPrint("%d %d\n", *(&poly->x0), *(&poly->x0 + 1));
*nextpri += sizeof(POLY_GT3);
}
t+=1;
}
}
}
// If mesh is quad
if (mesh->index[t].code == 8) {
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;
// Vertex Anim
if (mesh->isAnim){
// with interpolation
if ( mesh->anim->interpolate ){
// ping pong
//~ if (mesh->anim->cursor > 4096 || mesh->anim->cursor < 0){
//~ mesh->anim->dir *= -1;
//~ }
short precision = 12;
if ( mesh->anim->cursor > 1<<precision ) {
if ( mesh->anim->lerpCursor < mesh->anim->nframes - 1 ) {
mesh->anim->lerpCursor ++;
mesh->anim->cursor = 0;
}
if ( mesh->anim->lerpCursor == mesh->anim->nframes - 1 ) {
mesh->anim->lerpCursor = 0;
mesh->anim->cursor = 0;
}
}
// Vertex 1
mesh->tmesh->v[ mesh->index[ t ].order.vx ].vx = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.vx ].vx << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.vx ].vx << 12, mesh->anim->cursor << 12) >> 12;
mesh->tmesh->v[ mesh->index[ t ].order.vx ].vz = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.vx ].vz << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.vx ].vz << 12, mesh->anim->cursor << 12) >> 12;
mesh->tmesh->v[ mesh->index[ t ].order.vx ].vy = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.vx ].vy << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.vx ].vy << 12, mesh->anim->cursor << 12) >> 12;
// Vertex 2
mesh->tmesh->v[ mesh->index[ t ].order.vz ].vx = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.vz ].vx << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.vz ].vx << 12, mesh->anim->cursor << 12) >> 12;
mesh->tmesh->v[ mesh->index[ t ].order.vz ].vz = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.vz ].vz << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.vz ].vz << 12, mesh->anim->cursor << 12) >> 12;
mesh->tmesh->v[ mesh->index[ t ].order.vz ].vy = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.vz ].vy << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.vz ].vy << 12, mesh->anim->cursor << 12) >> 12;
// Vertex 3
mesh->tmesh->v[ mesh->index[ t ].order.vy ].vx = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.vy ].vx << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.vy ].vx << 12, mesh->anim->cursor << 12) >> 12;
mesh->tmesh->v[ mesh->index[ t ].order.vy ].vz = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.vy ].vz << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.vy ].vz << 12, mesh->anim->cursor << 12) >> 12;
mesh->tmesh->v[ mesh->index[ t ].order.vy ].vy = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.vy ].vy << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.vy ].vy << 12, mesh->anim->cursor << 12) >> 12;
// Vertex 4
mesh->tmesh->v[ mesh->index[ t ].order.pad ].vx = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.pad ].vx << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.pad ].vx << 12, mesh->anim->cursor << 12) >> 12;
mesh->tmesh->v[ mesh->index[ t ].order.pad ].vz = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.pad ].vz << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.pad ].vz << 12, mesh->anim->cursor << 12) >> 12;
mesh->tmesh->v[ mesh->index[ t ].order.pad ].vy = lerpD( mesh->anim->data[ mesh->anim->lerpCursor * mesh->anim->nvert + mesh->index[ t ].order.pad ].vy << 12 , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.pad ].vy << 12, mesh->anim->cursor << 12) >> 12;
mesh->anim->cursor += 2 * mesh->anim->dir;
// Coord transformations
nclip = RotAverageNclip4(
&mesh->tmesh->v[ mesh->index[t].order.pad ],
&mesh->tmesh->v[ mesh->index[t].order.vz],
&mesh->tmesh->v[ mesh->index[t].order.vx ],
&mesh->tmesh->v[ mesh->index[t].order.vy ],
( long* )&poly4->x0, ( long* )&poly4->x1, ( long* )&poly4->x2, ( long* )&poly4->x3,
&mesh->p,
&mesh->OTz,
Flag
);
} else {
// No interpolation, use all vertices coordinates in anim data
nclip = RotAverageNclip4(
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.pad ],
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.vz ],
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.vx ],
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.vy ],
( long* )&poly4->x0, ( long* )&poly4->x1, ( long* )&poly4->x2, ( long* )&poly4->x3,
&mesh->p,
&mesh->OTz,
Flag
);
}
} else {
// No animation
// Use regulare vertex coords
nclip = RotAverageNclip4(
&mesh->tmesh->v[ mesh->index[t].order.pad ],
&mesh->tmesh->v[ mesh->index[t].order.vz],
&mesh->tmesh->v[ mesh->index[t].order.vx ],
&mesh->tmesh->v[ mesh->index[t].order.vy ],
(long*)&poly4->x0, (long*)&poly4->x1, (long*)&poly4->x2, (long*)&poly4->x3,
&mesh->p,
&mesh->OTz,
Flag
);
}
if (nclip > 0 && mesh->OTz > 0 && (mesh->p < 4096)) {
SetPolyGT4(poly4);
// FIXME : Polygon subdiv - is it working ?
//~ OTc = *mesh->OTz >> 4;
//~ FntPrint("OTC:%d", OTc);
//~ if (OTc < 4) {
//~ if (OTc > 1) div4.ndiv = 1; else div4.ndiv = 2;
//~ DivideGT4(
//~ // Vertex coord
//~ &mesh->tmesh->v[ mesh->index[t].order.pad ],
//~ &mesh->tmesh->v[ mesh->index[t].order.vz ],
//~ &mesh->tmesh->v[ mesh->index[t].order.vx ],
//~ &mesh->tmesh->v[ mesh->index[t].order.vy ],
//~ // UV coord
//~ mesh->tmesh->u[i+3],
//~ mesh->tmesh->u[i+2],
//~ mesh->tmesh->u[i+0],
//~ mesh->tmesh->u[i+1],
//~ // Color
//~ mesh->tmesh->c[i],
//~ mesh->tmesh->c[i+1],
//~ mesh->tmesh->c[i+2],
//~ mesh->tmesh->c[i+3],
//~ // Gpu packet
//~ poly4,
//~ &ot[db][*mesh->OTz],
//~ &div4);
//~ // Increment primitive list pointer
//~ *nextpri += ( (sizeof(POLY_GT4) + 3) / 4 ) * (( 1 << ( div4.ndiv )) << ( div4.ndiv ));
//~ triCount = ((1<<(div4.ndiv))<<(div4.ndiv));
//~ } else if (OTc < 48) {
// Transparency effect
if (mesh->isPrism){
// Use current DRAWENV clip as TPAGE
( (POLY_GT4 *) poly4)->tpage = getTPage(mesh->tim->mode&0x3, 0,
draw->clip.x,
draw->clip.y
);
// Use projected coordinates
setUV4( poly4,
(poly4->x0 < 0? 0 : poly4->x0 > 255? 255 : poly4->x0),
(poly4->y0 < 0? 0 : poly4->y0 > 224? 224 : poly4->y0),
(poly4->x1 < 0? 0 : poly4->x1 > 255? 255 : poly4->x1),
(poly4->y1 < 0? 0 : poly4->y1 > 224? 224 : poly4->y1),
(poly4->x2 < 0? 0 : poly4->x2 > 255? 255 : poly4->x2),
(poly4->y2 < 0? 0 : poly4->y2 > 224? 224 : poly4->y2),
(poly4->x3 < 0? 0 : poly4->x3 > 255? 255 : poly4->x3),
(poly4->y3 < 0? 0 : poly4->y3 > 224? 224 : poly4->y3)
);
} else {
// Use regular TPAGE
( (POLY_GT4 *) poly4)->tpage = getTPage(
mesh->tim->mode&0x3, 0,
mesh->tim->prect->x,
mesh->tim->prect->y
);
// Use model UV coordinates
setUV4( poly4,
mesh->tmesh->u[i+3].vx, mesh->tmesh->u[i+3].vy + mesh->tim->prect->y,
mesh->tmesh->u[i+2].vx, mesh->tmesh->u[i+2].vy + mesh->tim->prect->y,
mesh->tmesh->u[i+0].vx, mesh->tmesh->u[i+0].vy + mesh->tim->prect->y,
mesh->tmesh->u[i+1].vx, mesh->tmesh->u[i+1].vy + mesh->tim->prect->y
);
}
if (mesh->isSprite){
SetShadeTex( poly4, 1 );
}
// If tim mode == 0 | 1, set CLUT coordinates
if ( (mesh->tim->mode & 0x3) < 2 ) {
setClut(poly4,
mesh->tim->crect->x,
mesh->tim->crect->y
);
}
CVECTOR outCol = {128,128,128,0};
CVECTOR outCol1 = {128,128,128,0};
CVECTOR outCol2 = {128,128,128,0};
CVECTOR outCol3 = {128,128,128,0};
NormalColorDpq(&mesh->tmesh->n[ mesh->index[t].order.pad ] , &mesh->tmesh->c[ mesh->index[t].order.pad ], mesh->p, &outCol);
NormalColorDpq(&mesh->tmesh->n[ mesh->index[t].order.vz ], &mesh->tmesh->c[ mesh->index[t].order.vz ], mesh->p, &outCol1);
NormalColorDpq(&mesh->tmesh->n[ mesh->index[t].order.vx ], &mesh->tmesh->c[ mesh->index[t].order.vx ], mesh->p, &outCol2);
NormalColorDpq(&mesh->tmesh->n[ mesh->index[t].order.vy ], &mesh->tmesh->c[ mesh->index[t].order.vy ], mesh->p, &outCol3);
if (mesh->isPrism){
setRGB0(poly4, mesh->tmesh->c[i].r, mesh->tmesh->c[i].g, mesh->tmesh->c[i].b);
setRGB1(poly4, mesh->tmesh->c[i+1].r, mesh->tmesh->c[i+1].g, mesh->tmesh->c[i+1].b);
setRGB2(poly4, mesh->tmesh->c[i+2].r, mesh->tmesh->c[i+2].g, mesh->tmesh->c[i+2].b);
setRGB3(poly4, mesh->tmesh->c[i+3].r, mesh->tmesh->c[i+3].g, mesh->tmesh->c[i+3].b);
} else {
setRGB0(poly4, outCol.r, outCol.g , outCol.b);
setRGB1(poly4, outCol1.r, outCol1.g, outCol1.b);
setRGB2(poly4, outCol2.r, outCol2.g, outCol2.b);
setRGB3(poly4, outCol3.r, outCol3.g, outCol3.b);
}
if ( (mesh->OTz > 0) /*&& (*mesh->OTz < OTLEN)*/ && (mesh->p < 4096) ) {
AddPrim( &ot[ mesh->OTz-3 ], poly4 );
}
*nextpri += sizeof( POLY_GT4 );
}
t += 1;
}
}
}
};
void drawBG(CAMANGLE * camPtr, char ** nextpri, u_long * otdisc, char * db) {
// Draw BG image in two SPRT since max width == 256 px
SPRT * sprt;
DR_TPAGE * tpage;
// Left part
sprt = ( SPRT * ) *nextpri;
setSprt( sprt );
setRGB0( sprt, 128, 128, 128 );
setXY0( sprt, 0, 0 );
setWH( sprt, 256, SCREENYRES );
setUV0( sprt, 0, 0 );
setClut( sprt,
camPtr->BGtim->crect->x,
camPtr->BGtim->crect->y
);
addPrim( otdisc[ OT2LEN - 1 ], sprt );
*nextpri += sizeof( SPRT );
// Change TPAGE
tpage = (DR_TPAGE *) *nextpri;
setDrawTPage(
tpage, 0, 1,
getTPage(
camPtr->BGtim->mode & 0x3, 0,
camPtr->BGtim->prect->x,
camPtr->BGtim->prect->y
)
);
addPrim( otdisc[OT2LEN-1], tpage);
*nextpri += sizeof(DR_TPAGE);
// Right part
sprt = ( SPRT * ) *nextpri;
setSprt( sprt );
setRGB0( sprt, 128, 128, 128 );
setXY0( sprt, SCREENXRES - ( SCREENXRES - 256 ), 0 );
setWH( sprt, SCREENXRES - 256, SCREENYRES );
setUV0( sprt, 0, 0 );
setClut( sprt,
camPtr->BGtim->crect->x,
camPtr->BGtim->crect->y
);
addPrim( otdisc[ OT2LEN-1 ], sprt );
*nextpri += sizeof( SPRT );
tpage = ( DR_TPAGE * ) *nextpri;
// Change TPAGE
setDrawTPage(
tpage, 0, 1,
getTPage(
camPtr->BGtim->mode & 0x3, 0,
// X offset width depends on TIM's mode
camPtr->BGtim->prect->x + ( 64 << ( camPtr->BGtim->mode & 0x3 ) ),
camPtr->BGtim->prect->y
)
);
addPrim( otdisc[ OT2LEN-1 ], tpage );
*nextpri += sizeof( DR_TPAGE );
};

781
src/main.c Normal file
View File

@ -0,0 +1,781 @@
// 3dcam
// With huge help from :
// @NicolasNoble : https://discord.com/channels/642647820683444236/646765703143227394/796876392670429204
// @Lameguy64
// @Impiaa
// @paul
/* PSX screen coordinate system
*
* Z+
* /
* /
* +------X+
* /|
* / |
* / Y+
* eye */
// Blender debug mode
// bpy. app. debug = True
#define _WCHAR_T
#include "../include/psx.h"
#include "../include/pad.h"
#include "../include/math.h"
#include "../include/camera.h"
#include "../include/physics.h"
#include "../include/graphics.h"
#include "../include/space.h"
#define USECD
// START OVERLAY
extern u_long load_all_overlays_here;
extern u_long __lvl0_end;
extern u_long __lvl1_end;
u_long overlaySize = 0;
#include "../levels/level0.h"
#include "../levels/level1.h"
volatile u_char level = 0;
// level 1 : 8003F05C -2147225508
// level 0 : 800AF744 -2146764988
// 80010000 -2147418112 -> -2147483648
// ovl : 800b80d4 -2146729772
u_short levelWas = 0;
u_short levelHasChanged = 0;
static char* overlayFile;
// Display and draw environments, double buffered
DISPENV disp[2];
DRAWENV draw[2];
//~ // OT for BG/FG discrimination
u_long otdisc[2][OT2LEN] = {0};
// Main OT
u_long ot[2][OTLEN] = {0}; // Ordering table (contains addresses to primitives)
char primbuff[2][PRIMBUFFLEN] = {0}; // Primitive list // That's our prim buffer
int primcnt=0; // Primitive counter
char * nextpri = primbuff[0]; // Primitive counter
char db = 0; // Current buffer counter
CVECTOR BGc = {50, 50, 75, 0}; // Far color
VECTOR BKc = {128, 128, 128, 0}; // Back color
MATRIX rotlgt;
SVECTOR lgtang = {0, 0, 0};
MATRIX light;
short vs;
CAMERA camera = {0};
// physics
u_long time = 0;
u_long timeS = 0;
//Pad
Controller_Buffer controllers[2]; // Buffers for reading controllers
Controller_Data theControllers[8]; // Processed controller data
int pressed = 0;
u_short timer = 0;
// Cam stuff
int camMode = FIXED;
VECTOR angle = {250,0,0,0};
VECTOR angleCam = {0,0,0,0};
int dist = 150;
int lerping = 0;
short curCamAngle = 0;
// Inverted Cam coordinates for Forward Vector calc
VECTOR InvCamPos = {0,0,0,0};
VECTOR fVecActor = {0,0,0,0};
u_long triCount = 0;
// Default level : Initialize everything to 0
MATRIX cmat = {0}, lgtmat = {0};
MESH actorPtr = {0}, levelPtr = {0} , propPtr = {0}, meshes[] = {0};
int meshes_length = 0;
NODE curNode = {0};
CAMPATH camPath = {0};
CAMANGLE camPtr = {0}, camAngles[] = {0};
MESH meshPlan = {0};
VECTOR modelPlan_pos = {0};
LEVEL curLvl = {
&BGc,
&cmat,
&lgtmat,
(MESH **)&meshes,
&meshes_length,
&actorPtr,
&levelPtr,
&propPtr,
&camPtr,
&camPath,
(CAMANGLE **)&camAngles,
&curNode,
&meshPlan
};
LEVEL * loadLvl;
// Pad
void callback();
int main() {
if ( level == 0 ){
overlayFile = "\\level0.bin;1";
overlaySize = __lvl0_end;
loadLvl = &level0;
} else if ( level == 1) {
overlayFile = "\\level1.bin;1";
overlaySize = __lvl1_end;
loadLvl = &level1;
}
// Load overlay
#ifdef USECD
CdInit();
LoadLevelCD(overlayFile, &load_all_overlays_here);
#endif
// TODO : Add switch case to get the correct pointers
// Get needed pointers from level file
if ( level == 0 ) {
LvlPtrSet( &curLvl, &level0);
} else if ( level == 1) {
LvlPtrSet( &curLvl, &level1);
}
levelWas = level;
// Overlay
VECTOR sp = {CENTERX,CENTERY,0};
VECTOR wp = {0,0,0};
// FIXME : Poly subdiv
//~ DIVPOLYGON4 div4 = { 0 };
//~ div4.pih = SCREENXRES;
//~ div4.piv = SCREENYRES;
//~ div4.ndiv = 2;
//~ long OTc = 0;
//~ DIVPOLYGON3 div3 = { 0 };
//~ div3.pih = SCREENXRES;
//~ div3.piv = SCREENYRES;
//~ div3.ndiv = 1;
init(disp, draw, db, curLvl.cmat, curLvl.BGc, &BKc);
InitPAD(controllers[0].pad, 34, controllers[1].pad, 34);
StartPAD();
generateTable();
VSyncCallback(callback);
// Load textures
for (int k = 0; k < *curLvl.meshes_length ; k++){
LoadTexture(curLvl.meshes[k]->tim_data, curLvl.meshes[k]->tim);
}
// Load current BG
if (curLvl.camPtr->tim_data){
LoadTexture(curLvl.camPtr->tim_data, curLvl.camPtr->BGtim);
}
// Physics
short physics = 1;
long dt;
VECTOR col_lvl, col_sphere, col_sphere_act = {0};
// Cam stuff
VECTOR posToActor = {0, 0, 0, 0}; // position of camera relative to actor
VECTOR camAngleToAct = {0, 0, 0, 0}; // rotation angles for the camera to point at actor
// Sprite system
VECTOR posToCam = {0, 0, 0, 0};
VECTOR objAngleToCam = {0, 0, 0, 0};
//~ int angle = 0; //PSX units = 4096 == 360° = 2Pi
//PSX units
short timediv = 1;
int atime = 0;
// Polycount
for (int k = 0; k < *curLvl.meshes_length; k++){
triCount += curLvl.meshes[k]->tmesh->len;
}
// Set camera starting pos
setCameraPos(&camera, curLvl.camPtr->campos->pos, curLvl.camPtr->campos->rot);
// Find curCamAngle if using pre-calculated BGs
if (camMode == 2) {
if (curLvl.camPtr->tim_data){
curCamAngle = 1;
}
}
// Main loop
//~ while (1) {
while ( VSync(1) ) {
timeS = VSync(-1) / 60;
if ( levelWas != level ){
switch ( level ){
case 0:
overlayFile = "\\level0.bin;1";
overlaySize = __lvl0_end;
loadLvl = &level0;
break;
case 1:
overlayFile = "\\level1.bin;1";
overlaySize = __lvl1_end;
loadLvl = &level1;
break;
default:
overlayFile = "\\level0.bin;1";
loadLvl = &level0;
break;
}
#ifdef USECD
LoadLevelCD( overlayFile, &load_all_overlays_here );
#endif
SwitchLevel( &curLvl, loadLvl);
//~ levelHasChanged = 0;
levelWas = level;
}
FntPrint("Ovl:%s\nLvl : %x\nLvl: %d %d \n%x", overlayFile, &level, level, levelWas, loadLvl);
//~ FntPrint("%x\n", curLvl.actorPtr->tim);
// Clear the main OT
ClearOTagR(otdisc[db], OT2LEN);
// Clear Secondary OT
ClearOTagR(ot[db], OTLEN);
// timeB = time;
time ++;
// atime is used for animations timing
timediv = 1;
if (time % timediv == 0){
atime ++;
}
// Angle between camera and actor
// using atantable (faster)
camAngleToAct.vy = (patan(-posToActor.vx, -posToActor.vz) / 16) - 3076 ;
camAngleToAct.vx = patan(dist, posToActor.vy) >> 4;
// Sprite system WIP
objAngleToCam.vy = patan( posToCam.vx,posToCam.vz );
objAngleToCam.vx = patan( posToCam.vx,posToCam.vy );
//~ objAngleToCam.vz = patan( posToCam.vz,posToCam.vy );
//~ objAngleToCam.vx = patan( psqrt(posToCam.vx * posToCam.vx + posToCam.vy * posToCam.vy), posToCam.vy );
//~ curLvl.meshPlan.rot->vx = -( (objAngleToCam.vx >> 4) - 3076 ) ;
//~ curLvl.meshPlan.rot->vx = (( (objAngleToCam.vx >> 4) - 3076 ) * ( (objAngleToCam.vz >> 4) - 3076 ) >> 12) * (nsin(posToCam.vz) >> 10 < 0 ? -1 : 1);
//~ curLvl.meshPlan.rot->vx = ( (objAngleToCam.vx >> 4) - 3076 ) * ( (objAngleToCam.vz >> 4) - 3076 ) >> 12 ;
curLvl.meshPlan->rot.vy = -( (objAngleToCam.vy >> 4) + 1024 ) ;
//~ posToCam = getVectorTo(*curLvl.meshPlan.pos, camera.pos);
//~ posToCam = getVectorTo(camera.pos, *curLvl.meshPlan.pos);
posToCam.vx = -camera.pos.vx - curLvl.meshPlan->pos.vx ;
posToCam.vz = -camera.pos.vz - curLvl.meshPlan->pos.vz ;
posToCam.vy = -camera.pos.vy - curLvl.meshPlan->pos.vy ;
//~ psqrt(posToCam.vx * posToCam.vx + posToCam.vy * posToCam.vy);
// Actor Forward vector for 3d relative orientation
fVecActor = curLvl.actorPtr->pos;
fVecActor.vx = curLvl.actorPtr->pos.vx + (nsin(curLvl.actorPtr->rot.vy/2));
fVecActor.vz = curLvl.actorPtr->pos.vz - (ncos(curLvl.actorPtr->rot.vy/2));
// Camera modes
if(camMode != 2) {
camera.rot.vy = camAngleToAct.vy;
// using csin/ccos, no need for theta
//~ camera.rot.vy = angle;
camera.rot.vx = camAngleToAct.vx;
}
if(camMode < 4 ) {
lerping = 0;
}
// Camera follows actor with lerp for rotations
if(camMode == 0) {
dist = 200;
camera.pos.vx = -(camera.x/ONE);
camera.pos.vy = -(camera.y/ONE);
camera.pos.vz = -(camera.z/ONE);
//~ InvCamPos.vx = camera.x/ONE;
//~ InvCamPos.vz = camera.z/ONE;
//~ applyVector(&InvCamPos, -1,-1,-1, *=);
angle.vy = -(curLvl.actorPtr->rot.vy / 2) + angleCam.vy;
//~ angle.vx += 10;
//~ FntPrint("cos %d", (ncos(angle.vy) * ncos(angle.vx)) >> 12);
//~ angle = curLvl.actorPtr->rot->vy;
// Camera horizontal position
getCameraZY(&camera.z, &camera.y, curLvl.actorPtr->pos.vz, curLvl.actorPtr->pos.vy, angle.vx, dist);
getCameraXZ(&camera.x, &camera.z, curLvl.actorPtr->pos.vx, curLvl.actorPtr->pos.vz, angle.vy, dist);
//~ getCameraXZY(&camera.x, &camera.z, &camera.y, curLvl.actorPtr->pos.vx, curLvl.actorPtr->pos.vz, curLvl.actorPtr->pos.vy, angle.vy, angle.vx, dist);
//~ void getCameraXZY(int * x, int * z, int * y, int actorX, int actorZ, int actorY, int angle, int angleX, int distance) {
// Camera vertical position
//~ getCameraXZ(&camera.x, &camera.y, curLvl.actorPtr->pos.vx, curLvl.actorPtr->pos.vy, angle, dist);
// FIXME! camera lerping to pos
//~ angle += lerp(camera.rot.vy, -curLvl.actorPtr->rot->vy, 128);
//~ angle = lerpD(camera.rot.vy << 12, curLvl.actorPtr->rot->vy << 12, 1024 << 12) >> 12;
}
// Camera rotates continuously around actor
if (camMode == 1) {
dist = 150;
camera.pos.vx = -(camera.x/ONE);
//~ camera.pos.vy = -(camera.y/ONE);
camera.pos.vy = 100;
camera.pos.vz = -(camera.z/ONE);
//~ fVecActor = *curLvl.actorPtr->pos;
//~ fVecActor.vx = curLvl.actorPtr->pos->vx + (nsin(curLvl.actorPtr->rot->vy));
//~ fVecActor.vz = curLvl.actorPtr->pos->vz - (ncos(curLvl.actorPtr->rot->vy));
getCameraXZ(&camera.x, &camera.z, curLvl.actorPtr->pos.vx, curLvl.actorPtr->pos.vz, angle.vy, dist);
angle.vy += 10;
}
// Fixed Camera with actor tracking
if (camMode == 3) {
// Using precalc sqrt
dist = psqrt( (posToActor.vx * posToActor.vx ) + (posToActor.vz * posToActor.vz) );
camera.pos.vx = 190;
camera.pos.vz = 100;
camera.pos.vy = 180;
}
// Fixed Camera angle
if (camMode == 2) {
// If BG images exist
if (curLvl.camPtr->tim_data){
checkLineW( &curLvl.camAngles[ curCamAngle ]->fw.v3, &curLvl.camAngles[ curCamAngle ]->fw.v2, curLvl.actorPtr);
if ( curLvl.camAngles[ curCamAngle ]->fw.v0.vx ) {
//~ FntPrint("BL x : %d, y : %d\n", camAngles[ curCamAngle ]->fw.v3.vx, camAngles[ curCamAngle ]->fw.v3.vy);
//~ FntPrint("BR x : %d, y : %d\n", camAngles[ curCamAngle ]->fw.v2.vx, camAngles[ curCamAngle ]->fw.v2.vy);
//~ FntPrint("Pos : %d\n", checkLineW( &camAngles[ curCamAngle ]->fw.v3, &camAngles[ curCamAngle ]->fw.v2, curLvl.actorPtr) );
//~ FntPrint("Pos : %d\n", checkLineW( &camAngles[ curCamAngle ]->bw.v2, &camAngles[ curCamAngle ]->bw.v3, curLvl.actorPtr) );
// If actor in camAngle->fw area of screen
if ( checkLineW( &curLvl.camAngles[ curCamAngle ]->fw.v3, &curLvl.camAngles[ curCamAngle ]->fw.v2, curLvl.actorPtr) == -1 &&
( checkLineW( &curLvl.camAngles[ curCamAngle ]->bw.v2, &curLvl.camAngles[ curCamAngle ]->bw.v3, curLvl.actorPtr) >= 0
)
) {
if (curCamAngle < 5) {
curCamAngle++;
curLvl.camPtr = curLvl.camAngles[ curCamAngle ];
LoadTexture(curLvl.camPtr->tim_data, curLvl.camPtr->BGtim);
}
}
}
if ( curLvl.camAngles[ curCamAngle ]->bw.v0.vx ) {
//~ FntPrint("BL x : %d, y : %d\n", camAngles[ curCamAngle ]->bw.v3.vx, camAngles[ curCamAngle ]->bw.v3.vy);
//~ FntPrint("BR x : %d, y : %d\n", camAngles[ curCamAngle ]->bw.v2.vx, camAngles[ curCamAngle ]->bw.v2.vy);
//~ // FntPrint("Pos : %d\n", checkLineW( &camAngles[ curCamAngle ]->bw.v2, &camAngles[ curCamAngle ]->bw.v3, curLvl.actorPtr) );
// If actor in camAngle->bw area of screen
if ( checkLineW( &curLvl.camAngles[ curCamAngle ]->fw.v3, &curLvl.camAngles[ curCamAngle ]->fw.v2, curLvl.actorPtr) >= 0 &&
checkLineW( &curLvl.camAngles[ curCamAngle ]->bw.v2, &curLvl.camAngles[ curCamAngle ]->bw.v3, curLvl.actorPtr) == -1
) {
if (curCamAngle > 0) {
curCamAngle--;
curLvl.camPtr = curLvl.camAngles[ curCamAngle ];
LoadTexture(curLvl.camPtr->tim_data, curLvl.camPtr->BGtim);
}
}
}
}
setCameraPos(&camera, curLvl.camPtr->campos->pos, curLvl.camPtr->campos->rot);
}
// Flyby mode with LERP from camStart to camEnd
if (camMode == 4) {
// If key pos exist for camera
if (curLvl.camPath->len) {
// Lerping sequence has not begun
if (!lerping){
// Set cam start position ( first key pos )
camera.pos.vx = curLvl.camPath->points[curLvl.camPath->cursor].vx;
camera.pos.vy = curLvl.camPath->points[curLvl.camPath->cursor].vy;
camera.pos.vz = curLvl.camPath->points[curLvl.camPath->cursor].vz;
// Lerping sequence is starting
lerping = 1;
// Set cam pos index to 0
curLvl.camPath->pos = 0;
}
// Pre calculated sqrt ( see psqrt() )
dist = psqrt( (posToActor.vx * posToActor.vx ) + (posToActor.vz * posToActor.vz));
// Fixed point precision 2^12 == 4096
int precision = 12;
camera.pos.vx = lerpD(curLvl.camPath->points[curLvl.camPath->cursor].vx << precision, curLvl.camPath->points[curLvl.camPath->cursor+1].vx << precision, curLvl.camPath->pos << precision) >> precision;
camera.pos.vy = lerpD(curLvl.camPath->points[curLvl.camPath->cursor].vy << precision, curLvl.camPath->points[curLvl.camPath->cursor+1].vy << precision, curLvl.camPath->pos << precision) >> precision;
camera.pos.vz = lerpD(curLvl.camPath->points[curLvl.camPath->cursor].vz << precision, curLvl.camPath->points[curLvl.camPath->cursor+1].vz << precision, curLvl.camPath->pos << precision) >> precision;
//~ FntPrint("Cam %d, %d\n", (int32_t)curLvl.camPath->points[curLvl.camPath->cursor].vx, curLvl.camPath->points[curLvl.camPath->cursor+1].vx);
//~ FntPrint("Cam %d, %d, %d\n", camera.pos.vx, camera.pos.vy, camera.pos.vz);
//~ FntPrint("Theta y: %d x: %d\n", theta.vy, theta.vx);
//~ FntPrint("Pos: %d Cur: %d\nTheta y: %d x: %d\n", curLvl.camPath->pos, curLvl.camPath->cursor, theta.vy, theta.vx);
// Linearly increment the lerp factor
curLvl.camPath->pos += 20;
// If camera has reached next key pos, reset pos index, move cursor to next key pos
if (curLvl.camPath->pos > (1 << precision) ){
curLvl.camPath->pos = 0;
curLvl.camPath->cursor ++;
}
// Last key pos is reached, reset cursor to first key pos, lerping sequence is over
if ( curLvl.camPath->cursor == curLvl.camPath->len - 1 ){
lerping = 0;
curLvl.camPath->cursor = 0;
}
} else {
// if no key pos exists, switch to next camMode
camMode ++; }
}
// Camera "on a rail" - cam is tracking actor, and moving with constraints on all axis
if (camMode == 5) {
// track actor. If theta (actor/cam rotation angle) is above or below an arbitrary angle,
// move cam so that the angle doesn't increase/decrease anymore.
short cameraSpeed = 40;
if (curLvl.camPath->len) {
// Lerping sequence has not begun
if (!lerping){
// Set cam start position ( first key pos )
camera.pos.vx = curLvl.camPath->points[curLvl.camPath->cursor].vx;
camera.pos.vy = curLvl.camPath->points[curLvl.camPath->cursor].vy;
camera.pos.vz = curLvl.camPath->points[curLvl.camPath->cursor].vz;
// Lerping sequence is starting
lerping = 1;
// Set cam pos index to 0
curLvl.camPath->pos = 0;
}
// Pre calculated sqrt ( see psqrt() )
dist = psqrt( (posToActor.vx * posToActor.vx ) + (posToActor.vz * posToActor.vz));
// Fixed point precision 2^12 == 4096
short precision = 12;
camera.pos.vx = lerpD(curLvl.camPath->points[curLvl.camPath->cursor].vx << precision, curLvl.camPath->points[curLvl.camPath->cursor + 1].vx << precision, curLvl.camPath->pos << precision) >> precision;
camera.pos.vy = lerpD(curLvl.camPath->points[curLvl.camPath->cursor].vy << precision, curLvl.camPath->points[curLvl.camPath->cursor + 1].vy << precision, curLvl.camPath->pos << precision) >> precision;
camera.pos.vz = lerpD(curLvl.camPath->points[curLvl.camPath->cursor].vz << precision, curLvl.camPath->points[curLvl.camPath->cursor + 1].vz << precision, curLvl.camPath->pos << precision) >> precision;
//~ FntPrint("%d %d %d %d\n", camAngleToAct.vy, camera.pos.vx, camera.rot.vy, dist);
// Ony move cam if position is between first curLvl.camPath->vx and last curLvl.camPath->vx
if ( camAngleToAct.vy < -50 && camera.pos.vx > curLvl.camPath->points[curLvl.camPath->len - 1].vx ) {
// Clamp curLvl.camPath position to cameraSpeed
curLvl.camPath->pos += dist < cameraSpeed ? 0 : cameraSpeed ;
}
if ( camAngleToAct.vy > 50 && camera.pos.vx > curLvl.camPath->points[curLvl.camPath->cursor].vx ) {
curLvl.camPath->pos -= dist < cameraSpeed ? 0 : cameraSpeed;
}
// If camera has reached next key pos, reset pos index, move cursor to next key pos
if (curLvl.camPath->pos > (1 << precision) ){
curLvl.camPath->pos = 0;
curLvl.camPath->cursor ++;
}
if (curLvl.camPath->pos < -100 ){
curLvl.camPath->pos = 1 << precision;
curLvl.camPath->cursor --;
}
// Last key pos is reached, reset cursor to first key pos, lerping sequence is over
if ( curLvl.camPath->cursor == curLvl.camPath->len - 1 || curLvl.camPath->cursor < 0 ){
lerping = 0;
curLvl.camPath->cursor = 0;
}
} else {
// if no key pos exists, switch to next camMode
camMode ++;
}
}
// Spatial partitioning
if (curLvl.curNode){
for ( int msh = 0; msh < curLvl.curNode->siblings->index; msh ++ ) {
// Actor
if ( !getIntCollision( *curLvl.actorPtr->body , *curLvl.curNode->siblings->list[msh]->plane->body).vx &&
!getIntCollision( *curLvl.actorPtr->body , *curLvl.curNode->siblings->list[msh]->plane->body).vz )
{
if ( curLvl.curNode != curLvl.curNode->siblings->list[msh] ) {
curLvl.curNode = curLvl.curNode->siblings->list[msh];
curLvl.levelPtr = curLvl.curNode->plane;
}
}
// DONTNEED ?
// Moveable prop
//~ if ( !getIntCollision( *propPtr->body , *curLvl.curNode->siblings->list[msh]->plane->body).vx &&
//~ !getIntCollision( *propPtr->body , *curLvl.curNode->siblings->list[msh]->plane->body).vz ) {
//~ if ( propPtr->node != curLvl.curNode->siblings->list[ msh ]){
//~ propPtr->node = curLvl.curNode->siblings->list[ msh ];
//~ }
//~ }
if ( !getIntCollision( *curLvl.propPtr->body , *curLvl.curNode->plane->body).vx &&
!getIntCollision( *curLvl.propPtr->body , *curLvl.curNode->plane->body).vz ) {
curLvl.propPtr->node = curLvl.curNode;
}
}
}
// Physics
if ( physics ) {
// if(time%1 == 0){
for ( int k = 0; k < *curLvl.meshes_length; k ++ ) {
//~ for ( int k = 0; k < curLvl.curNode->objects->index ; k ++){
if ( ( curLvl.meshes[k]->isRigidBody == 1 ) ) {
//~ if ( ( *curLvl.curNode->rigidbodies->list[k]->isRigidBody == 1 ) ) {
//~ applyAcceleration(curLvl.curNode->rigidbodies->list[k]->body);
applyAcceleration( curLvl.meshes[k]->body );
// Get col with level ( modelgnd_body )
col_lvl = getIntCollision( *curLvl.meshes[k]->body , *curLvl.levelPtr->body );
col_sphere = getIntCollision( *curLvl.propPtr->body, *curLvl.propPtr->node->plane->body );
// col_sphere = getIntCollision( *propPtr->body, *levelPtr->body );
col_sphere_act = getExtCollision( *curLvl.actorPtr->body, *curLvl.propPtr->body );
// If no col with ground, fall off
if ( col_lvl.vy ) {
if ( !col_lvl.vx && !col_lvl.vz ) {
curLvl.actorPtr->body->position.vy = curLvl.actorPtr->body->min.vy;
}
}
if (col_sphere.vy){
if ( !col_sphere.vx && !col_sphere.vz ) {
curLvl.propPtr->body->position.vy = curLvl.propPtr->body->min.vy;
}
}
if (col_sphere_act.vx && col_sphere_act.vz ) {
curLvl.propPtr->body->velocity.vx += curLvl.actorPtr->body->velocity.vx;
curLvl.propPtr->body->velocity.vz += curLvl.actorPtr->body->velocity.vz;
if ( curLvl.propPtr->body->velocity.vx ) {
VECTOR L = angularMom( *curLvl.propPtr->body );
curLvl.propPtr->rot.vz -= L.vx;
}
if ( curLvl.propPtr->body->velocity.vz ) {
VECTOR L = angularMom( *curLvl.propPtr->body );
curLvl.propPtr->rot.vx -= L.vz;
}
}
curLvl.meshes[k]->pos.vx = curLvl.meshes[k]->body->position.vx;
curLvl.meshes[k]->pos.vy = curLvl.meshes[k]->body->position.vy ;
curLvl.meshes[k]->pos.vz = curLvl.meshes[k]->body->position.vz;
}
curLvl.meshes[k]->body->velocity.vy = 0;
curLvl.meshes[k]->body->velocity.vx = 0;
curLvl.meshes[k]->body->velocity.vz = 0;
}
// }
}
if ( (camMode == 2) && (curLvl.camPtr->tim_data ) ) {
worldToScreen( &curLvl.actorPtr->pos, &curLvl.actorPtr->pos2D );
}
// Camera setup
// position of cam relative to actor
posToActor.vx = curLvl.actorPtr->pos.vx + camera.pos.vx;
posToActor.vz = curLvl.actorPtr->pos.vz + camera.pos.vz;
posToActor.vy = curLvl.actorPtr->pos.vy + camera.pos.vy;
// Polygon drawing
if (curLvl.curNode){
static long Flag;
if ( (camMode == 2) && (curLvl.camPtr->tim_data ) ) {
drawBG(curLvl.camPtr, &nextpri, otdisc[db], &db);
// Loop on camAngles
for ( int mesh = 0 ; mesh < curLvl.camAngles[ curCamAngle ]->index; mesh ++ ) {
transformMesh(&camera, curLvl.camAngles[curCamAngle]->objects[mesh]);
drawPoly(curLvl.camAngles[curCamAngle]->objects[mesh], &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
// int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw)
}
}
else {
// Draw current node's plane
drawPoly( curLvl.curNode->plane, &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
// Draw surrounding planes
for ( int sibling = 0; sibling < curLvl.curNode->siblings->index; sibling++ ) {
drawPoly(curLvl.curNode->siblings->list[ sibling ]->plane, &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
}
// Draw adjacent planes's children
for ( int sibling = 0; sibling < curLvl.curNode->siblings->index; sibling++ ) {
for ( int object = 0; object < curLvl.curNode->siblings->list[ sibling ]->objects->index; object++ ) {
long t = 0;
transformMesh(&camera, curLvl.curNode->siblings->list[ sibling ]->objects->list[ object ]);
drawPoly( curLvl.curNode->siblings->list[ sibling ]->objects->list[ object ], &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
}
}
// Draw current plane children
for ( int object = 0; object < curLvl.curNode->objects->index; object++ ) {
transformMesh(&camera, curLvl.curNode->objects->list[ object ]);
drawPoly( curLvl.curNode->objects->list[ object ], &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
}
// Draw rigidbodies
for ( int object = 0; object < curLvl.curNode->rigidbodies->index; object++ ) {
transformMesh(&camera, curLvl.curNode->rigidbodies->list[ object ]);
drawPoly( curLvl.curNode->rigidbodies->list[ object ], &Flag, atime, &camMode, &nextpri, ot[db], &db, &draw[db]);
}
}
}
// Find and apply light rotation matrix
RotMatrix(&lgtang, &rotlgt);
MulMatrix0(curLvl.lgtmat, &rotlgt, &light);
SetLightMatrix(&light);
// Set camera
applyCamera(&camera);
// Add secondary OT to main OT
AddPrims(otdisc[db], ot[db] + OTLEN - 1, ot[db]);
//~ FntPrint("curLvl.curNode : %x\nIndex: %d", curLvl.curNode, curLvl.curNode->siblings->index);
FntPrint("Time : %d dt :%d", timeS, dt);
//~ FntPrint("%d\n", curCamAngle );
//~ FntPrint("%x\n", primbuff[db]);
//~ FntPrint("Actor : %d %d\n", curLvl.actorPtr->pos->vx, curLvl.actorPtr->pos->vy);
//~ FntPrint("%d %d\n", curLvl.actorPtr->pos->vx, curLvl.actorPtr->pos->vz);
//~ FntPrint("%d %d\n", curLvl.actorPtr->pos2D.vx + CENTERX, curLvl.actorPtr->pos2D.vy + CENTERY);
//~ FntPrint(" %d %d %d\n", wp.vx, wp.vy, wp.vz);
FntFlush(-1);
display( &disp[db], &draw[db], otdisc[db], primbuff[db], &nextpri, &db);
//~ display(disp, draw, otdisc[db], primbuff[db], nextpri, db);
//~ frame = VSync(-1);
}
return 0;
}
void callback() {
// Pad 1
read_controller( &theControllers[0], &controllers[0].pad[0], 0 ); // Read controllers
// Pad 2
read_controller( &theControllers[1], &controllers[1].pad[0], 1 );
//~ u_short pad = PadRead(0);
//~ u_short pad = 0;
u_char PADL = ~theControllers[0].button1;
u_char PADR = ~theControllers[0].button2;
static u_short lastPad;
static short forceApplied = 0;
int div = 32;
static int lerpValues[4096 >> 7];
static short cursor = 0;
static short angleCamTimer = 0;
//~ static short curCamAngle = 0;
if( !lerpValues[0] ) {
for ( long long i = 0; i < div ; i++ ){
lerpValues[(div-1)-i] = lerp(-24, -264, easeIn(i));
}
}
if( timer ) {
timer--;
}
if( cursor ) {
cursor--;
}
if (angleCam.vy > 2048 || angleCam.vy < -2048) {
angleCam.vy = 0;
}
if ( PADR & PadShldR1 && !timer ) {
if (!curLvl.camPtr->tim_data){
if(camMode < 6){
camMode ++;
lerping = 0;
} else {
setCameraPos(&camera, curLvl.camPtr->campos->pos, curLvl.camPtr->campos->rot);
curLvl.camPath->cursor = 0;
camMode = 0;
lerping = 0;
}
} else {
if (curCamAngle > 4) {
curCamAngle = 0;
}
if (curCamAngle < 5) {
curCamAngle++;
curLvl.camPtr = curLvl.camAngles[ curCamAngle ];
LoadTexture(curLvl.camPtr->tim_data, curLvl.camPtr->BGtim);
}
}
lastPad = PADR;
timer = 10;
}
//~ if ( !(PADR & PadShldR1) && lastPad & PadShldR1 ) {
//pressed = 0;
//~ }
if ( PADR & PadShldL2 ) {
lgtang.vy += 32;
}
if ( PADR & PadShldL1 ) {
lgtang.vz += 32;
}
if ( PADR & PadUp && !timer ){
if (curLvl.actorPtr->isPrism){
curLvl.actorPtr->isPrism = 0;
} else {
curLvl.actorPtr->isPrism = 1;
}
timer = 10;
lastPad = PADR;
}
if ( PADR & PadDown && !timer ){
if (curLvl.actorPtr->body->gForce.vy >= 0 && curLvl.actorPtr->body->position.vy >= curLvl.actorPtr->body->min.vy ){
forceApplied -= 150;
}
cursor = div - 15;
timer = 30;
lastPad = PADR;
}
if ( !(PADR & PadDown) && lastPad & PadDown ) {
//~ lastPad = pad;
}
if ( PADR & PadLeft && !timer ) {
if (curLvl.actorPtr->anim->interpolate){
curLvl.actorPtr->anim->interpolate = 0;
} else {
curLvl.actorPtr->anim->interpolate = 1;
}
timer = 10;
lastPad = PADR;
}
if (theControllers[0].type == 0x73){
// Analog stick L up
if ( theControllers[0].analog3 >= 0 && theControllers[0].analog3 < 108 ) {
curLvl.actorPtr->body->gForce.vz = getVectorTo(fVecActor, curLvl.actorPtr->pos).vz * (128 - theControllers[0].analog3 ) >> 15 ;
curLvl.actorPtr->body->gForce.vx = -getVectorTo(fVecActor, curLvl.actorPtr->pos).vx * (128 - theControllers[0].analog3 ) >> 15 ;
lastPad = PADL;
}
// Analog stick L down
if ( theControllers[0].analog3 > 168 && theControllers[0].analog3 <= 255 ) {
curLvl.actorPtr->body->gForce.vz = -getVectorTo(fVecActor, curLvl.actorPtr->pos).vz * ( theControllers[0].analog3 - 128 ) >> 15 ;
curLvl.actorPtr->body->gForce.vx = getVectorTo(fVecActor, curLvl.actorPtr->pos).vx * ( theControllers[0].analog3 - 128 ) >> 15 ;
lastPad = PADL;
}
// Analog stick L dead zone
if ( theControllers[0].analog3 > 108 && theControllers[0].analog3 < 148 ) {
curLvl.actorPtr->body->gForce.vz = 0;
curLvl.actorPtr->body->gForce.vx = 0;
}
// Analog stick L left
if ( theControllers[0].analog2 >= 0 && theControllers[0].analog2 < 108 ) {
curLvl.actorPtr->rot.vy -= ( 40 * ( 128 - theControllers[0].analog2 ) ) >> 7 ;
}
// Analog stick L right
if ( theControllers[0].analog2 > 148 && theControllers[0].analog2 <= 255 ) {
curLvl.actorPtr->rot.vy += ( 40 * ( theControllers[0].analog2 - 128 ) ) >> 7 ;
}
}
if ( PADL & PadUp ) {
curLvl.actorPtr->body->gForce.vz = getVectorTo(fVecActor, curLvl.actorPtr->pos).vz >> 8 ;
curLvl.actorPtr->body->gForce.vx = -getVectorTo(fVecActor, curLvl.actorPtr->pos).vx >> 8 ;
lastPad = PADL;
}
if ( !(PADL & PadUp) && lastPad & PadUp) {
curLvl.actorPtr->body->gForce.vz = 0;
curLvl.actorPtr->body->gForce.vx = 0;
lastPad = PADL;
}
if ( PADL & PadDown ) {
curLvl.actorPtr->body->gForce.vz = -getVectorTo(fVecActor, curLvl.actorPtr->pos).vz >> 8 ;
curLvl.actorPtr->body->gForce.vx = getVectorTo(fVecActor, curLvl.actorPtr->pos).vx >> 8 ;
lastPad = PADL;
}
if ( !( PADL & PadDown ) && lastPad & PadDown) {
curLvl.actorPtr->body->gForce.vz = 0;
curLvl.actorPtr->body->gForce.vx = 0;
lastPad = PADL;
}
if ( PADL & PadLeft ) {
curLvl.actorPtr->rot.vy -= 32;
lastPad = PADL;
}
if ( PADL & PadRight ) {
curLvl.actorPtr->rot.vy += 32;
lastPad = PADL;
}
if ( PADL & PadSelect && !timer ) {
//~ if (!levelHasChanged){
//~ #ifndef USECD
printf("load:%p:%08x:%s", &load_all_overlays_here, &level, overlayFile);
//~ PCload( &load_all_overlays_here, &levelHasChanged, overlayFile );
//~ #endif
#ifdef USECD
level = !level;
//~ levelHasChanged = 1;
#endif
//~ }
timer = 30;
lastPad = PADL;
}
if( theControllers[0].type == 0x73 && camMode == 0){
// Cam control - horizontal
if ( theControllers[0].analog0 >= 0 && theControllers[0].analog0 < 108) {
angleCam.vy -= ( 16 * ( 128 - theControllers[0].analog0 ) ) >> 7 ;
angleCamTimer = 120;
}
if ( theControllers[0].analog0 > 148 && theControllers[0].analog0 <= 255) {
angleCam.vy += ( 16 * ( theControllers[0].analog0 - 128 ) ) >> 7 ;
angleCamTimer = 120;
}
if ( theControllers[0].analog0 >= 0 && theControllers[0].analog0 < 108) {
angleCam.vy -= ( 16 * ( 128 - theControllers[0].analog0 ) ) >> 7 ;
angleCamTimer = 120;
}
if ( theControllers[0].analog0 > 148 && theControllers[0].analog0 <= 255) {
angleCam.vy += ( 16 * ( theControllers[0].analog0 - 128 ) ) >> 7 ;
angleCamTimer = 120;
}
// Timer to lerp cam back behind actor
if ( angleCamTimer ){
angleCamTimer --;
}
if (!angleCamTimer && angleCam.vy){
angleCam.vy += lerp( angleCam.vy, 0, 64 ) == 0 ? 1 : lerp( angleCam.vy, 0, 64 );
}
}
//~ FntPrint("level :%d", level);
//~ FntPrint("angleCam :%d %d\n", angleCam.vy, lerp( angleCam.vy, 0, 64) );
//~ FntPrint( "Pad 1 : %02x\nButtons:%02x %02x, Stick:%02d %02d %02d %02d\n",
//~ theControllers[0].type, // Controller type : 0x00 == none, 0x41 == standard, 0x73 == analog/dualshock, 0x12 == mouse, 0x23 == steering wheel, 0x63 == gun, 0x53 == analog joystick
//~ theControllers[0].button1, //
//~ theControllers[0].button2,
//~ theControllers[0].analog0, // R3 hor : left: 0 7F right: 7F FF dz 78 83
//~ theControllers[0].analog1, // R3 vert : up : 0 7F down : 7F FF : dz 83 86
//~ theControllers[0].analog2, // L3 hor : left : 0 7F right: 7F FF : dz 69 81 68 - 8E
//~ theControllers[0].analog3 ); // L3 vert : up : 0 7F down : 7F FF : dz 74 8D
if ( cursor ) {
curLvl.actorPtr->body->position.vy = lerpValues[cursor];}
};

146
src/math.c Normal file
View File

@ -0,0 +1,146 @@
#include "../include/math.h"
// Stolen from grumpycoder
// this is from here : https://github.com/grumpycoders/Balau/blob/master/tests/test-Handles.cc#L20-L102
// precalc costable
static int m_cosTable[512];
static const unsigned int DC_2PI = 2048;
static const unsigned int DC_PI = 1024;
static const unsigned int DC_PI2 = 512;
// f(n) = cos(n * 2pi / 2048) <- 2048 is == DC_2PI value
// f(n) = 2 * f(1) * f(n - 1) - f(n - 2)
void generateTable(void){
m_cosTable[0] = 16777216; // 2^24 * cos(0 * 2pi / 2048) => 2^24 * 1 = 2^24 : here, 2^24 defines the precision we want after the decimal point
static const long long C = 16777137; // 2^24 * cos(1 * 2pi / 2048) = C = f(1);
m_cosTable[1] = C;
for (int i = 2; i < 512; i++){
m_cosTable[i] = ((C * m_cosTable[i - 1]) >> 23) - m_cosTable[i - 2];
m_cosTable[511] = 0;
}
};
int ncos(unsigned int t) {
t %= DC_2PI;
int r;
if (t < DC_PI2) {
r = m_cosTable[t];
} else if (t < DC_PI) {
r = -m_cosTable[DC_PI - 1 - t];
} else if (t < (DC_PI + DC_PI2)) {
r = -m_cosTable[t - DC_PI];
} else {
r = m_cosTable[DC_2PI - 1 - t];
};
return r >> 12;
};
// sin(x) = cos(x - pi / 2)
int nsin(unsigned int t) {
t %= DC_2PI;
if (t < DC_PI2){
return ncos(t + DC_2PI - DC_PI2);
};
return ncos(t - DC_PI2);
};
// https://github.com/Arsunt/TR2Main/blob/411cacb35914c616cb7960c0e677e00c71c7ee88/3dsystem/phd_math.cpp#L432
long long patan(long x, long y){
long long result;
int swapBuf;
int flags = 0;
// if either x or y are 0, return 0
if( x == 0 && y == 0){
return 0;
}
if( x < 0 ) {
flags |= 4;
x = -x;
}
if ( y < 0 ) {
flags |= 2;
y = -y;
}
if ( y > x ) {
flags |= 1;
SWAP(x, y ,swapBuf);
}
result = AtanBaseTable[flags] + AtanAngleTable[0x800 * y / x];
if ( result < 0 ){
result = -result;
return result;
}
};
u_int psqrt(u_int n){
u_int result = 0;
u_int base = 0x40000000;
u_int basedResult;
for( ; base != 0; base >>= 2 ) {
for( ; base != 0; base >>= 2 ) {
basedResult = base + result;
result >>= 1;
if( basedResult > n ) {
break;
}
n -= basedResult;
result |= base;
}
}
return result;
};
// From : https://github.com/grumpycoders/pcsx-redux/blob/7438e9995833db5bc1e14da735bbf9dc78300f0b/src/mips/shell/math.h
int32_t dMul(int32_t a, int32_t b) {
long long r = a;
r *= b;
return r >> 24;
};
// standard lerp function
// s = source, an arbitrary number up to 2^24
// d = destination, an arbitrary number up to 2^24
// p = position, a number between 0 and 256, inclusive
// p = 0 means output = s
// p = 256 means output = d
uint32_t lerpU(uint32_t start, uint32_t dest, unsigned pos) {
return (start * (256 - pos) + dest * pos) >> 8;
};
int32_t lerpS(int32_t start, int32_t dest, unsigned pos) {
return (start * (256 - pos) + dest * pos) >> 8;
};
// start, dest and pos have to be << x, then the result has to be >> x where x defines precision:
// precision = 2^24 - 2^x
// << x : 0 < pos < precision
// https://discord.com/channels/642647820683444236/646765703143227394/811318550978494505
// my angles are between 0 and 2048 (full circle), so 2^11 for the range of angles; with numbers on a 8.24 representation, a 1.0 angle (or 2pi) means it's 2^24, so to "convert" my angles from 8.24 to my internal discrete cos, I only have to shift by 13
int32_t lerpD(int32_t start, int32_t dest, int32_t pos) {
return dMul(start, 16777216 - pos) + dMul(dest, pos);
};
long long lerpL(long long start, long long dest, long long pos) {
return dMul( (start << 12), 16777216 - (pos << 12) ) + dMul((dest << 12), (pos << 12) ) >> 12;
};
int lerp(int start, int end, int factor){
// lerp interpolated cam movement
// InBetween = Value 1 + ( ( Value2 - Value1 ) * lerpValue ) ;
// lerpValue should be a int between 17 and 256.
return ( ( start ) + ( ( end - start ) * factor ) ) >> 12;
};
long long easeIn(long long i){
return ((i << 7) * (i << 7) * (i << 7) / 32 ) >> 19;
};
int easeOut(int i){
return (4096 >> 7) - ((4096 - (i << 7)) * (4096 - (i << 7))) >> 12;
};
//~ int easeInOut(int i, int div){
//~ return lerp(easeIn(i, div), easeOut(i) , i);
//~ };
SVECTOR SVlerp(SVECTOR start, SVECTOR end, int factor){
SVECTOR output = {0,0,0,0};
output.vx = lerp(start.vx, end.vx, factor);
output.vy = lerp(start.vy, end.vy, factor);
output.vz = lerp(start.vz, end.vz, factor);
return output;
};
VECTOR getVectorTo( VECTOR actor, VECTOR target ) {
// Returns a normalized vector that points from actor to target
VECTOR direction = { subVector(target, actor) };
VECTOR Ndirection = {0,0,0,0};
u_int distSq = (direction.vx * direction.vx) + (direction.vz * direction.vz);
direction.pad = psqrt(distSq);
VectorNormal(&direction, &Ndirection);
return Ndirection ;
};

61
src/pad.c Normal file
View File

@ -0,0 +1,61 @@
#include "../include/pad.h"
void get_digital_direction( Controller_Data *c, int buttondata ) // get analog stick values
{
int i;
i = ~(buttondata);
if( i & 0x80 )
c->xpos -= 1;
if( i & 0x20 )
c->xpos += 1;
if( i & 0x40 )
c->ypos += 1;
if( i & 0x10 )
c->ypos -= 1;
}
void read_controller( Controller_Data *c, unsigned char *buf, int port ) // get the raw values from controller
{
register int mouse_x, mouse_y, x;
register Gun_Position *g;
c->status = buf[0]; // Copy over raw controller data
c->type = buf[1];
c->button1 = buf[2];
c->button2 = buf[3];
c->analog0 = buf[4];
c->analog1 = buf[5];
c->analog2 = buf[6];
c->analog3 = buf[7];
if( buf[0] == 0xff ) // If controller returns BAD status then bail on it.
{
c->type = 0;
return;
}
// Look at the controller type code & process controller data as indicated
switch( c->type )
{
case 0x12: // Sony Mouse
mouse_x = buf[4];
mouse_y = buf[5];
if( mouse_x & 0x80 )
mouse_x |= 0xffffff80;
if( mouse_y & 0x80 )
mouse_y |= 0xffffff80;
c->xpos += mouse_x;
c->ypos += mouse_y;
break;
case 0x23: // Namco negCon
// Steering wheel
// Sankyo Pachinko controler
get_digital_direction( c, buf[2] );
break;
case 0x53: // Analog 2-stick
get_digital_direction( c, buf[2] );
break;
case 0x41: // Standard Sony PAD controller
get_digital_direction( c, buf[2] );
break;
default: // If don't know what it is, treat it like standard controller
get_digital_direction( c, buf[2] );
break;
}
}

57
src/pcdrv.c Normal file
View File

@ -0,0 +1,57 @@
#include "../include/pcdrv.h"
int waitForSIODone( int * flag ){
// This should wait for a signal from the SIO to tell when it's done
// Returns val < 0 if wrong
uint timeOut = 1000;
int result = 0;
for ( uint t = 0; t < timeOut; t ++){
if ( * flag == 1 ){
result = * flag;
break;
}
}
return result;
};
void PCload( u_long * loadAddress, u_short * flagAddress, const char * filename ) {
// Send filename , load address, and flag address
// flag address points to an int16 that when set to 1 enable lvl/pointers/screen refresh
// Returns 1 if all good, 0 else
//~ int flag = 0;
printf("load:%08x:%08x:%s", loadAddress, flagAddress, filename);
//~ return ; // If all is well, returns a positive int . If -1, wrong
};
//~ int PCopen(const char * filename, int attributes) {
//~ // Send filename and attributes (ro,wo,rw..)
//~ // expects an int referring to a file descriptor on the PC
//~ int fd = 0; // File Descriptor https://en.wikipedia.org/wiki/File_descriptor
//~ printf("open:%s:%i:%08x", filename, attributes, &fd);
//~ waitForSIODone(0);
//~ return fd; // If all is well, returns a positive int . If -1, wrong
//~ };
//~ int PCcreate(const char * filename, int attributes) {
//~ // Send filename and attributes (ro,wo,rw..)
//~ // expects an int referring to a file descriptor on the PC
//~ int fd = 0; // File Descriptor https://en.wikipedia.org/wiki/File_descriptor
//~ printf("create:%s:%i:%08x", filename, attributes, &fd);
//~ waitForSIODone(5); // Should return int fd, -1 else
//~ return fd; // If all is well, returns a positive int . If -1, wrong
//~ };
//~ int PCclose( int fd ) {
//~ // Send the close command and fd as int
//~ printf("close:%d", fd);
//~ return waitForSIODone(1); // Should return 1 if ok, 0 if wrong, or -1 if wrong ?
//~ };
//~ int PCseek( int fd, int offset, int accessMode){
//~ // Move file pointer in fd at offset
//~ // Access mode can be 0 abs, 1 rel to start, 2 rel to end
//~ printf("seek:%i:%08x:%i", fd, offset, accessMode);
//~ return waitForSIODone(2);
//~ };
//~ int PCread( int fd, int len, char * buffer ){
//~ // Read len bytes of fd and put them in buff
//~ int count = 0;
//~ printf("read:%i:%08x:%i", fd, len, buffer, count);
//~ waitForSIODone(3);
//~ return count;
//~ };

171
src/physics.c Normal file
View File

@ -0,0 +1,171 @@
#include "../include/physics.h"
short checkLineW( VECTOR * pointA, VECTOR * pointB, MESH * mesh ) {
long val1 = ( ( mesh->body->position.vx + mesh->body->min.vx ) - pointA->vx ) * ( pointB->vy - pointA->vy ) - ( ( mesh->body->position.vz + mesh->body->min.vy ) - pointA->vy ) * ( pointB->vx - pointA->vx ) ;
long val2 = ( ( mesh->body->position.vx + mesh->body->max.vx ) - pointA->vx ) * ( pointB->vy - pointA->vy ) - ( ( mesh->body->position.vz + mesh->body->max.vy ) - pointA->vy ) * ( pointB->vx - pointA->vx ) ;
if ( val1 > 0 && val2 > 0 ) {
// right
return 1;
}
else if ( val1 < 0 && val2 < 0 ) {
// left
return -1;
}
else if ( val1 == 0 && val2 == 0 ) {
// identical
return 0;
}
else if (
( val1 > 0 && val2 == 0 ) ||
( val1 == 0 && val2 > 0 )
) {
// right
return 1;
}
else if (
( val1 < 0 && val2 == 0 ) ||
( val1 == 0 && val2 < 0 )
) {
// left
return -1;
}
else if (
( val1 < 0 && val2 > 0 ) ||
( val1 > 0 && val2 < 0 )
) {
// intersect
return 3;
}
};
// Screen space variant
short checkLineS( VECTOR * pointA, VECTOR * pointB, MESH * mesh ) {
// FIXME : mesh->body->min.vx is not in screen space
int val1 = ( ( mesh->pos2D.vx + mesh->body->min.vx ) - pointA->vx ) * ( pointB->vy - pointA->vy ) - ( ( mesh->pos2D.vy + mesh->body->min.vy ) - pointA->vy ) * ( pointB->vx - pointA->vx ) ;
int val2 = ( ( mesh->pos2D.vx + mesh->body->max.vx ) - pointA->vx ) * ( pointB->vy - pointA->vy ) - ( ( mesh->pos2D.vy + mesh->body->max.vy ) - pointA->vy ) * ( pointB->vx - pointA->vx ) ;
if ( val1 > 0 && val2 > 0 ) {
// right
return 1;
}
else if ( val1 < 0 && val2 < 0 ) {
// left
return -1;
}
else if ( val1 == 0 && val2 == 0 ) {
// identical
return 2;
}
else if (
( val1 > 0 && val2 == 0 ) ||
( val1 == 0 && val2 > 0 )
) {
// right
return 1;
}
else if (
( val1 < 0 && val2 == 0 ) ||
( val1 == 0 && val2 < 0 )
) {
// left
return -1;
}
else if (
( val1 < 0 && val2 > 0 ) ||
( val1 > 0 && val2 < 0 )
) {
// intersect
return 3;
}
};
// Physics
VECTOR getIntCollision(BODY one, BODY two){
VECTOR d1, d2, col;
short correction = 50;
d1.vx = (one.position.vx + one.max.vx) - (two.position.vx + two.min.vx);
d1.vy = (one.position.vy + one.max.vy) - (two.position.vy + two.min.vy);
d1.vz = (one.position.vz + one.max.vz) - (two.position.vz + two.min.vz);
d2.vx = (two.position.vx + two.max.vx) - (one.position.vx - one.max.vx);
d2.vy = (two.position.vy + two.max.vy) - (one.position.vy + one.min.vy);
d2.vz = (two.position.vz + two.max.vz) - (one.position.vz - one.max.vz);
col.vx = !(d1.vx > 0 && d2.vx > 0);
col.vy = d1.vy > 0 && d2.vy > 0;
col.vz = !(d1.vz > 0 && d2.vz > 0);
return col;
};
VECTOR getExtCollision(BODY one, BODY two){
VECTOR d1, d2, col;
d1.vx = (one.position.vx + one.max.vx) - (two.position.vx + two.min.vx);
d1.vy = (one.position.vy + one.max.vy) - (two.position.vy + two.min.vy);
d1.vz = (one.position.vz + one.max.vz) - (two.position.vz + two.min.vz);
d2.vx = (two.position.vx + two.max.vx) - (one.position.vx + one.min.vx);
d2.vy = (two.position.vy + two.max.vy) - (one.position.vy + one.min.vy);
d2.vz = (two.position.vz + two.max.vz) - (one.position.vz + one.min.vz);
col.vx = d1.vx > 0 && d2.vx > 0;
col.vy = d1.vy > 0 && d2.vy > 0;
col.vz = d1.vz > 0 && d2.vz > 0;
return col;
};
void applyAcceleration(BODY * actor){
short dt = 1;
VECTOR acceleration = {actor->invMass * actor->gForce.vx , (actor->invMass * actor->gForce.vy) + (GRAVITY * ONE), actor->invMass * actor->gForce.vz};
//~ FntPrint("acc: %d %d %d\n", acceleration.vx, acceleration.vy, acceleration.vz );
actor->velocity.vx += (acceleration.vx * dt) >> 12;
actor->velocity.vy += (acceleration.vy * dt) >> 12;
actor->velocity.vz += (acceleration.vz * dt) >> 12;
//~ FntPrint("acc: %d %d %d\n", acceleration.vx / ONE, acceleration.vy / ONE, acceleration.vz / ONE );
actor->position.vx += (actor->velocity.vx * dt);
actor->position.vy += (actor->velocity.vy * dt);
actor->position.vz += (actor->velocity.vz * dt);
//~ FntPrint("vel: %d %d %d\n", actor->velocity.vx, actor->velocity.vy, actor->velocity.vz );
};
//~ // https://gamedevelopment.tutsplus.com/tutorials/how-to-create-a-custom-2d-physics-engine-the-basics-and-impulse-resolution--gamedev-6331
void ResolveCollision( BODY * one, BODY * two ){
//~ FntPrint("rv: %d, %d, %d\n", one->velocity.vx, one->velocity.vy, one->velocity.vz);
// Calculate relative velocity
VECTOR rv = { subVector( one->velocity, two->velocity) };
//~ FntPrint("rv: %d, %d, %d\n", rv.vx,rv.vy,rv.vz);
// Collision normal
VECTOR normal = { subVector( two->position, one->position ) };
// Normalize collision normal
normal.vx = normal.vx > 0 ? 1 : normal.vx < 0 ? -1 : 0 ;
normal.vy = normal.vy > 256 ? 1 : normal.vy < -256 ? -1 : 0 ;
normal.vz = normal.vz > 0 ? 1 : normal.vz < 0 ? -1 : 0 ;
//~ FntPrint("norm: %d, %d, %d\n", normal.vx,normal.vy,normal.vz);
// Calculate relative velocity in terms of the normal direction
long velAlongNormal = dotProduct( rv, normal );
//~ FntPrint("velN: %d\n", velAlongNormal);
// Do not resolve if velocities are separating
if(velAlongNormal > 0)
return;
// Calculate restitution
long e = min( one->restitution, two->restitution );
//~ FntPrint("e: %d\n", e);
//~ // Calculate impulse scalar
long j = -(1 + e) * velAlongNormal * ONE;
j /= one->invMass + two->invMass;
//~ j /= ONE;
//~ FntPrint("j: %d\n", j);
// Apply impulse
applyVector(&normal, j, j, j, *=);
//~ FntPrint("Cnormal %d %d %d\n",normal.vx,normal.vy,normal.vz);
VECTOR velOne = normal;
VECTOR velTwo = normal;
applyVector(&velOne,one->invMass,one->invMass,one->invMass, *=);
applyVector(&velTwo,two->invMass,two->invMass,two->invMass, *=);
//~ FntPrint("V1 %d %d %d\n", velOne.vx/4096,velOne.vy/4096,velOne.vz/4096);
//~ FntPrint("V2 %d %d %d\n", velTwo.vx/4096,velTwo.vy/4096,velTwo.vz/4096);
applyVector(&one->velocity, velOne.vx/4096/4096, velOne.vy/4096/4096, velOne.vz/4096/4096, +=);
applyVector(&two->velocity, velTwo.vx/4096/4096, velTwo.vy/4096/4096, velTwo.vz/4096/4096, -=);
//~ FntPrint("V1 %d %d %d\n", velOne.vx/4096/4096,velOne.vy/4096/4096,velOne.vz/4096/4096);
//~ FntPrint("V2 %d %d %d\n", velTwo.vx/4096/4096,velTwo.vy/4096/4096,velTwo.vz/4096/4096);
};
VECTOR angularMom(BODY body){
// L = r * p
// p = m * v
VECTOR w = {0,0,0,0};
int r = (body.max.vx - body.min.vx) >> 1;
w.vx = (r * body.mass * body.velocity.vx) >> 2;
w.vy = (r * body.mass * body.velocity.vy) >> 2;
w.vz = (r * body.mass * body.velocity.vz) >> 2;
//~ FntPrint("v: %d, r:%d, w:%d\n", body.velocity.vz * r, r * r, w.vz);
return w;
};

117
src/psx.c Normal file
View File

@ -0,0 +1,117 @@
#include "../include/psx.h"
void init(DISPENV disp[2], DRAWENV draw[2], short db, MATRIX * cmat, CVECTOR * BGc, VECTOR * BKc) {
ResetCallback();
// Init pad
//~ PadInit(0);
//~ InitPAD(controllers[0].pad, 34, controllers[1].pad, 34);
//~ StartPAD();
// Reset the GPU
ResetGraph( 0 );
// Initialize and setup the GTE
InitGeom();
SetGeomOffset( CENTERX, CENTERY ); // x, y offset
SetGeomScreen( FOV ); // Distance between eye and screen - Camera FOV
// 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 PAL , add 8 pix vertical offset ((256 - 240) /2)
if ( VMODE ) {
SetVideoMode(MODE_PAL);
disp[0].screen.y += 8;
disp[1].screen.y += 8;
}
// Set Draw area color
setRGB0(&draw[0], BGc->r, BGc->g, BGc->b);
setRGB0(&draw[1], BGc->r, BGc->g, BGc->b);
// Set Draw area clear flag
draw[0].isbg = 1;
draw[1].isbg = 1;
// Set the disp and draw env
PutDispEnv(&disp[db]);
PutDrawEnv(&draw[db]);
// Init font system
FntLoad(FNT_VRAM_X, FNT_VRAM_Y);
FntOpen( FNT_SCR_X,
FNT_SCR_Y,
FNT_SCR_W,
FNT_SCR_H,
FNT_SCR_BG,
FNT_SCR_MAX_CHAR
);
// Lighting setup
SetColorMatrix( cmat );
SetBackColor( BKc->vx, BKc->vy, BKc->vz );
SetFarColor( BGc->r, BGc->g, BGc->b );
SetFogNearFar( FOG_NEAR, FOG_FAR, SCREENXRES );
};
void ScrRst(void){
RECT scr;
VSync( 0 ); // Wait for current drawing to finish
SetDispMask( 0 ); // Set mask to not displayed
ResetGraph( 1 ); // Cancel current drawing
setRECT(&scr, 0, 0, SCREENXRES, SCREENYRES);
ClearImage(&scr, CLEAR_COLOR_R, CLEAR_COLOR_G, CLEAR_COLOR_B );
DrawSync( 0 );
};
void display(DISPENV * disp, DRAWENV * draw, u_long * otdisc, char * primbuff, char ** nextprim, char * db){
// https://stackoverflow.com/questions/3526503/how-to-set-pointer-reference-through-a-function
DrawSync(0);
VSync(VSYNC); // Using VSync 2 insures constant framerate. 0 makes the fr polycount dependant.
ResetGraph(1);
PutDispEnv(disp);
PutDrawEnv(draw);
SetDispMask(1);
// Main OT
DrawOTag(otdisc + OT2LEN - 1);
*db = !*db;
*nextprim = primbuff;
};
void LvlPtrSet(LEVEL * curLevel, LEVEL * level){
curLevel->BGc = level->BGc;
curLevel->cmat = level->cmat;
curLevel->lgtmat = level->lgtmat;
curLevel->meshes = level->meshes;
curLevel->meshes_length = level->meshes_length;
curLevel->actorPtr = level->actorPtr;
curLevel->levelPtr = level->levelPtr;
curLevel->propPtr = level->propPtr;
curLevel->camPtr = level->camPtr;
curLevel->camPath = level->camPath;
curLevel->camAngles = level->camAngles;
curLevel->curNode = level->curNode; // Blank
// Move these to drawPoly()
curLevel->meshPlan = level->meshPlan;
//~ FntPrint("%x %x", curLevel->meshes, level->meshes);
};
int LoadLevelCD(const char*const LevelName, u_long * LoadAddress){
int cdread = 0, cdsync = 1;
cdread = CdReadFile( (char *)(LevelName), LoadAddress, 0);
cdsync = CdReadSync(0, 0);
// return loaded size
return cdread;
};
void SwitchLevel( LEVEL * curLevel, LEVEL * loadLevel ){
//~ ScrRst();
LvlPtrSet( curLevel, loadLevel);
// Reload textures
for (int k = 0; k < *curLevel->meshes_length ; k++){
LoadTexture(curLevel->meshes[k]->tim_data, curLevel->meshes[k]->tim);
}
// BG texture
if (curLevel->camPtr->tim_data){
LoadTexture(curLevel->camPtr->tim_data, curLevel->camPtr->BGtim);
}
};
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
}
};

54
src/space.c Normal file
View File

@ -0,0 +1,54 @@
#include "../include/space.h"
// From 'psyq/addons/graphics/ZIMEN/CLIP.C'
void worldToScreen( VECTOR * worldPos, VECTOR * screenPos ) {
int distToScreen; // corresponds to FOV
MATRIX curRot; // current rotation matrix
// Get current matrix and projection */
distToScreen = ReadGeomScreen();
ReadRotMatrix(&curRot);
// Get Rotation, Translation coordinates, apply perspective correction
// Muliply world coordinates vector by current rotation matrix, store in screenPos
ApplyMatrixLV(&curRot, worldPos, screenPos);
// Get world translation vectors from rot and add to screenPos vx, vy, vz
applyVector(screenPos, curRot.t[0], curRot.t[1], curRot.t[2], +=);
// Correct perspective
screenPos -> vx = screenPos -> vx * distToScreen / ( screenPos -> vz + 1 ) ; // Add 1 to avoid division by 0
screenPos -> vy = screenPos -> vy * distToScreen / ( screenPos -> vz + 1 ) ;
screenPos -> vz = distToScreen ;
};
void screenToWorld( VECTOR * screenPos, VECTOR * worldPos ) {
int distToScreen; // corresponds to FOV
MATRIX curRot, invRot; // current rotation matrix, transpose matrix
VECTOR Trans; // working translation vector
// Get current matrix and projection
distToScreen = ReadGeomScreen();
ReadRotMatrix( &curRot );
PushMatrix(); // Store matrix on the stack (slow!)
//// worldTrans = invRot * (screenPos - Rot.t)
// Get world translation
Trans.vx = screenPos->vx - curRot.t[0]; // Substract world translation from screenpos
Trans.vy = screenPos->vy - curRot.t[1];
Trans.vz = screenPos->vz - curRot.t[2];
// We want the inverse of the current rotation matrix.
//
// Inverse matrix : M^-1 = 1 / detM * T(M)
// We know that the determinant of a rotation matrix is 1, thus:
// M^-1 = T(M)
//
// Get transpose of current rotation matrix
// > The transpose of a matrix is a new matrix whose rows are the columns of the original.
// https://www.quora.com/What-is-the-geometric-interpretation-of-the-transpose-of-a-matrix
TransposeMatrix( &curRot, &invRot );
// Multiply the transpose of current rotation matrix by the current translation vector
ApplyMatrixLV( &invRot, &Trans, worldPos );
// Get original rotation matrix back
PopMatrix();
};
int cliptest3( short *v1 ) {
if( v1[0]<0 && v1[2]<0 && v1[4]<0 ) return 0;
if( v1[1]<0 && v1[3]<0 && v1[5]<0 ) return 0;
if( v1[0] > SCREENXRES && v1[2] > SCREENXRES && v1[4] > SCREENXRES) return 0;
if( v1[1] > SCREENYRES && v1[3] > SCREENYRES && v1[5] > SCREENYRES) return 0;
return 1;
};