Refactor animation system

This commit is contained in:
ABelliqueux 2021-09-25 19:39:49 +02:00
parent 4bc75f43a5
commit 9ae3857fad
14 changed files with 16842 additions and 11553 deletions

View File

@ -21,6 +21,9 @@ TIM/bg_camPath_002.tim \
TIM/bg_camPath_003.tim \ TIM/bg_camPath_003.tim \
TIM/bg_camPath_004.tim \ TIM/bg_camPath_004.tim \
TIM/bg_camPath_005.tim \ TIM/bg_camPath_005.tim \
TIM/ground.tim \
TIM/trees.tim \
TIM/woods.tim \
VAG/hello.vag \ VAG/hello.vag \
VAG/poly.vag \ VAG/poly.vag \
VAG/0_come.vag \ VAG/0_come.vag \

BIN
TIM/ground.tim Normal file

Binary file not shown.

BIN
TIM/trees.tim Normal file

Binary file not shown.

BIN
TIM/woods.tim Normal file

Binary file not shown.

View File

@ -5,6 +5,7 @@
struct BODY; struct BODY;
struct VANIM; struct VANIM;
struct MESH_ANIMS_TRACKS;
struct PRIM; struct PRIM;
struct MESH; struct MESH;
struct CAMPOS; struct CAMPOS;
@ -37,13 +38,20 @@ typedef struct BODY {
typedef struct VANIM { typedef struct VANIM {
int nframes; // number of frames e.g 20 int nframes; // number of frames e.g 20
int nvert; // number of vertices e.g 21 int nvert; // number of vertices e.g 21
int cursor; // anim cursor int cursor; // anim cursor : -1 == not playing, n>=0 == current frame number
int lerpCursor; // anim cursor int lerpCursor; // anim cursor
int loop; // loop anim : -1 == infinite, n>0 == play n times
int dir; // playback direction (1 or -1) int dir; // playback direction (1 or -1)
int pingpong; // ping pong animation (A>B>A)
int interpolate; // use lerp to interpolate keyframes int interpolate; // use lerp to interpolate keyframes
SVECTOR data[]; // vertex pos as SVECTORs e.g 20 * 21 SVECTORS SVECTOR data[]; // vertex pos as SVECTORs e.g 20 * 21 SVECTORS
} VANIM; } VANIM;
typedef struct MESH_ANIMS_TRACKS {
u_short index;
VANIM * strips[];
} MESH_ANIMS_TRACKS;
typedef struct PRIM { typedef struct PRIM {
VECTOR order; VECTOR order;
int code; // Same as POL3/POL4 codes : Code (F3 = 1, FT3 = 2, G3 = 3, int code; // Same as POL3/POL4 codes : Code (F3 = 1, FT3 = 2, G3 = 3,
@ -73,7 +81,8 @@ typedef struct MESH {
long p; long p;
long OTz; long OTz;
BODY * body; BODY * body;
VANIM * anim; MESH_ANIMS_TRACKS * anim_tracks;
VANIM * currentAnim;
struct NODE * node; struct NODE * node;
VECTOR pos2D; VECTOR pos2D;
} MESH; } MESH;

View File

@ -25,3 +25,5 @@ long interpolateQuad(POLY_GT4 * poly4, MESH * mesh, long t);
void drawBG(CAMANGLE * camPtr, char ** nextpri, u_long * otdisc, char * db); void drawBG(CAMANGLE * camPtr, char ** nextpri, u_long * otdisc, char * db);
// Rendering // Rendering
void renderScene(LEVEL * curLvl, CAMERA * camera, int * camMode, char ** nextpri, u_long * ot, u_long * otdisc, char * db, DRAWENV * draw, short curCamAngle, int atime); void renderScene(LEVEL * curLvl, CAMERA * camera, int * camMode, char ** nextpri, u_long * ot, u_long * otdisc, char * db, DRAWENV * draw, short curCamAngle, int atime);
// Animation
void playAnim(MESH * mesh, VANIM * anim, int loop);

View File

@ -33,3 +33,5 @@ long long easeIn(long long i);
int easeOut(int i); int easeOut(int i);
//~ int easeInOut(int i, int div); //~ int easeInOut(int i, int div);
VECTOR getVectorTo(VECTOR actor, VECTOR target); VECTOR getVectorTo(VECTOR actor, VECTOR target);
int32_t round( int32_t n);

File diff suppressed because it is too large Load Diff

View File

@ -5,6 +5,12 @@
extern LEVEL level0; extern LEVEL level0;
extern CVECTOR level0_BGc; extern CVECTOR level0_BGc;
extern VECTOR level0_BKc; extern VECTOR level0_BKc;
extern MESH_ANIMS_TRACKS level0_modelCube_001_anims;
extern VANIM level0_modelCube_001_anim_KeyAction;
extern VANIM level0_modelCube_001_anim_KeyAction_004;
extern VANIM level0_modelCube_001_anim_KeyAction_003;
extern VANIM level0_modelCube_001_anim_KeyAction_001;
extern VANIM level0_modelCube_001_anim_KeyAction_002;
extern CAMPOS level0_camPos_Camera; extern CAMPOS level0_camPos_Camera;
extern CAMPATH level0_camPath; extern CAMPATH level0_camPath;
extern MATRIX level0_lgtmat; extern MATRIX level0_lgtmat;
@ -16,14 +22,58 @@ extern PRIM level0_modelCube_index[];
extern BODY level0_modelCube_body; extern BODY level0_modelCube_body;
extern TMESH level0_modelCube; extern TMESH level0_modelCube;
extern MESH level0_meshCube; extern MESH level0_meshCube;
extern SVECTOR modelPlane_mesh[]; extern SVECTOR modelCube_001_mesh[];
extern SVECTOR level0_modelPlane_normal[]; extern SVECTOR level0_modelCube_001_normal[];
extern CVECTOR level0_modelPlane_color[]; extern CVECTOR level0_modelCube_001_color[];
extern PRIM level0_modelPlane_index[]; extern PRIM level0_modelCube_001_index[];
extern BODY level0_modelPlane_body; extern BODY level0_modelCube_001_body;
extern TMESH level0_modelPlane; extern TMESH level0_modelCube_001;
extern MESH level0_meshPlane; extern MESH level0_meshCube_001;
extern MESH * level0_meshes[2]; extern SVECTOR modelPlane_000_mesh[];
extern SVECTOR level0_modelPlane_000_normal[];
extern SVECTOR level0_modelPlane_000_uv[];
extern CVECTOR level0_modelPlane_000_color[];
extern PRIM level0_modelPlane_000_index[];
extern BODY level0_modelPlane_000_body;
extern TMESH level0_modelPlane_000;
extern unsigned long _binary_TIM_woods_tim_start[];
extern unsigned long _binary_TIM_woods_tim_end[];
extern unsigned long _binary_TIM_woods_tim_length;
extern TIM_IMAGE level0_tim_woods;
extern MESH level0_meshPlane_000;
extern SVECTOR modelPlane_001_mesh[];
extern SVECTOR level0_modelPlane_001_normal[];
extern SVECTOR level0_modelPlane_001_uv[];
extern CVECTOR level0_modelPlane_001_color[];
extern PRIM level0_modelPlane_001_index[];
extern BODY level0_modelPlane_001_body;
extern TMESH level0_modelPlane_001;
extern MESH level0_meshPlane_001;
extern SVECTOR modelPlane_002_mesh[];
extern SVECTOR level0_modelPlane_002_normal[];
extern SVECTOR level0_modelPlane_002_uv[];
extern CVECTOR level0_modelPlane_002_color[];
extern PRIM level0_modelPlane_002_index[];
extern BODY level0_modelPlane_002_body;
extern TMESH level0_modelPlane_002;
extern MESH level0_meshPlane_002;
extern SVECTOR modelPlane_005_mesh[];
extern SVECTOR level0_modelPlane_005_normal[];
extern SVECTOR level0_modelPlane_005_uv[];
extern CVECTOR level0_modelPlane_005_color[];
extern PRIM level0_modelPlane_005_index[];
extern BODY level0_modelPlane_005_body;
extern TMESH level0_modelPlane_005;
extern MESH level0_meshPlane_005;
extern SVECTOR modelPlane_006_mesh[];
extern SVECTOR level0_modelPlane_006_normal[];
extern SVECTOR level0_modelPlane_006_uv[];
extern CVECTOR level0_modelPlane_006_color[];
extern PRIM level0_modelPlane_006_index[];
extern BODY level0_modelPlane_006_body;
extern TMESH level0_modelPlane_006;
extern MESH level0_meshPlane_006;
extern MESH * level0_meshes[7];
extern int level0_meshes_length; extern int level0_meshes_length;
extern CAMANGLE level0_camAngle_Camera; extern CAMANGLE level0_camAngle_Camera;
extern CAMANGLE * level0_camAngles[0]; extern CAMANGLE * level0_camAngles[0];

File diff suppressed because it is too large Load Diff

View File

@ -5,6 +5,10 @@
extern LEVEL level1; extern LEVEL level1;
extern CVECTOR level1_BGc; extern CVECTOR level1_BGc;
extern VECTOR level1_BKc; extern VECTOR level1_BKc;
extern MESH_ANIMS_TRACKS level1_modelCube_anims;
extern VANIM level1_modelCube_anim_Cube;
extern MESH_ANIMS_TRACKS level1_modelCylindre_anims;
extern VANIM level1_modelCylindre_anim_Cylindre;
extern CAMPOS level1_camPos_camPath; extern CAMPOS level1_camPos_camPath;
extern CAMPOS level1_camPos_camPath_001; extern CAMPOS level1_camPos_camPath_001;
extern CAMPOS level1_camPos_camPath_002; extern CAMPOS level1_camPos_camPath_002;
@ -31,7 +35,6 @@ extern SVECTOR level1_modelCylindre_normal[];
extern SVECTOR level1_modelCylindre_uv[]; extern SVECTOR level1_modelCylindre_uv[];
extern CVECTOR level1_modelCylindre_color[]; extern CVECTOR level1_modelCylindre_color[];
extern PRIM level1_modelCylindre_index[]; extern PRIM level1_modelCylindre_index[];
extern VANIM level1_modelCylindre_anim;
extern BODY level1_modelCylindre_body; extern BODY level1_modelCylindre_body;
extern TMESH level1_modelCylindre; extern TMESH level1_modelCylindre;
extern unsigned long _binary_TIM_home_tim_start[]; extern unsigned long _binary_TIM_home_tim_start[];
@ -151,6 +154,14 @@ extern MESH * level1_meshes[15];
extern int level1_meshes_length; extern int level1_meshes_length;
extern CAMANGLE level1_camAngle_camPath_001; extern CAMANGLE level1_camAngle_camPath_001;
extern CAMANGLE * level1_camAngles[0]; 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_002_siblings;
extern CHILDREN level1_nodegnd_002_objects;
extern CHILDREN level1_nodegnd_002_rigidbodies;
extern NODE level1_nodegnd_002;
extern SIBLINGS level1_nodegnd_001_siblings; extern SIBLINGS level1_nodegnd_001_siblings;
extern CHILDREN level1_nodegnd_001_objects; extern CHILDREN level1_nodegnd_001_objects;
extern CHILDREN level1_nodegnd_001_rigidbodies; extern CHILDREN level1_nodegnd_001_rigidbodies;
@ -159,22 +170,12 @@ extern SIBLINGS level1_nodegnd_003_siblings;
extern CHILDREN level1_nodegnd_003_objects; extern CHILDREN level1_nodegnd_003_objects;
extern CHILDREN level1_nodegnd_003_rigidbodies; extern CHILDREN level1_nodegnd_003_rigidbodies;
extern NODE level1_nodegnd_003; extern NODE level1_nodegnd_003;
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_siblings;
extern CHILDREN level1_nodegnd_objects;
extern CHILDREN level1_nodegnd_rigidbodies;
extern NODE level1_nodegnd;
extern MESH * level1_actorPtr; extern MESH * level1_actorPtr;
extern MESH * level1_levelPtr; extern MESH * level1_levelPtr;
extern MESH * level1_propPtr; extern MESH * level1_propPtr;
extern CAMANGLE * level1_camPtr; extern CAMANGLE * level1_camPtr;
extern NODE * level1_curNode; extern NODE * level1_curNode;
extern NODE level1_nodegnd;
extern NODE level1_nodegnd_002;
extern NODE level1_nodegnd_001; extern NODE level1_nodegnd_001;
extern NODE level1_nodegnd_003; extern NODE level1_nodegnd_003;
extern NODE level1_nodegnd_002;
extern NODE level1_nodegnd;
extern VAGbank VAGBank1;
extern XAbank XABank1;

View File

@ -51,40 +51,54 @@ void set3VertexLerPos(MESH * mesh, long t){
// TODO : Pre-calculate lerp positions at runtime (for i in nframes, do calc) // TODO : Pre-calculate lerp positions at runtime (for i in nframes, do calc)
// Fixed point math precision // Fixed point math precision
short precision = 12; short precision = 12;
// Vertex 1 //~ mesh->tmesh->v[ mesh->index[ t ].order.vx ].vx = round(lerpD( mesh->currentAnim->data[mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[t].order.vx].vx << precision , mesh->currentAnim->data[(mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[t].order.vx].vx << precision, mesh->currentAnim->cursor << precision)) >> precision;
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 = round(lerpD( mesh->currentAnim->data[mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[t].order.vx].vz << precision , mesh->currentAnim->data[(mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[t].order.vx].vz << precision, mesh->currentAnim->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 = round(lerpD( mesh->currentAnim->data[mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[t].order.vx].vy << precision , mesh->currentAnim->data[(mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[t].order.vx].vy << precision, mesh->currentAnim->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
// Vertex 2 //~ mesh->tmesh->v[ mesh->index[ t ].order.vz ].vx = round(lerpD( mesh->currentAnim->data[mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[t].order.vz].vx << precision , mesh->currentAnim->data[(mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[t].order.vz].vx << precision, mesh->currentAnim->cursor << precision)) >> precision;
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 = round(lerpD( mesh->currentAnim->data[mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[t].order.vz].vz << precision , mesh->currentAnim->data[(mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[t].order.vz].vz << precision, mesh->currentAnim->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 = round(lerpD( mesh->currentAnim->data[mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[t].order.vz].vy << precision , mesh->currentAnim->data[(mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[t].order.vz].vy << precision, mesh->currentAnim->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
// Vertex 3 //~ mesh->tmesh->v[ mesh->index[ t ].order.vy ].vx = round(lerpD( mesh->currentAnim->data[mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[t].order.vy].vx << precision , mesh->currentAnim->data[(mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[t].order.vy].vx << precision, mesh->currentAnim->cursor << precision)) >> precision;
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 = round(lerpD( mesh->currentAnim->data[mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[t].order.vy].vz << precision , mesh->currentAnim->data[(mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[t].order.vy].vz << precision, mesh->currentAnim->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 = round(lerpD( mesh->currentAnim->data[mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[t].order.vy].vy << precision , mesh->currentAnim->data[(mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[t].order.vy].vy << precision, mesh->currentAnim->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; mesh->tmesh->v[ mesh->index[ t ].order.vx ].vx = (lerpD( mesh->currentAnim->data[mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[t].order.vx].vx << precision , mesh->currentAnim->data[(mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[t].order.vx].vx << precision, mesh->currentAnim->cursor << precision)) >> precision;
mesh->tmesh->v[ mesh->index[ t ].order.vx ].vz = (lerpD( mesh->currentAnim->data[mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[t].order.vx].vz << precision , mesh->currentAnim->data[(mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[t].order.vx].vz << precision, mesh->currentAnim->cursor << precision)) >> precision;
mesh->tmesh->v[ mesh->index[ t ].order.vx ].vy = (lerpD( mesh->currentAnim->data[mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[t].order.vx].vy << precision , mesh->currentAnim->data[(mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[t].order.vx].vy << precision, mesh->currentAnim->cursor << precision)) >> precision;
// Vertex 2
mesh->tmesh->v[ mesh->index[ t ].order.vz ].vx = (lerpD( mesh->currentAnim->data[mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[t].order.vz].vx << precision , mesh->currentAnim->data[(mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[t].order.vz].vx << precision, mesh->currentAnim->cursor << precision)) >> precision;
mesh->tmesh->v[ mesh->index[ t ].order.vz ].vz = (lerpD( mesh->currentAnim->data[mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[t].order.vz].vz << precision , mesh->currentAnim->data[(mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[t].order.vz].vz << precision, mesh->currentAnim->cursor << precision)) >> precision;
mesh->tmesh->v[ mesh->index[ t ].order.vz ].vy = (lerpD( mesh->currentAnim->data[mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[t].order.vz].vy << precision , mesh->currentAnim->data[(mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[t].order.vz].vy << precision, mesh->currentAnim->cursor << precision)) >> precision;
// Vertex 3
mesh->tmesh->v[ mesh->index[ t ].order.vy ].vx = (lerpD( mesh->currentAnim->data[mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[t].order.vy].vx << precision , mesh->currentAnim->data[(mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[t].order.vy].vx << precision, mesh->currentAnim->cursor << precision)) >> precision;
mesh->tmesh->v[ mesh->index[ t ].order.vy ].vz = (lerpD( mesh->currentAnim->data[mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[t].order.vy].vz << precision , mesh->currentAnim->data[(mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[t].order.vy].vz << precision, mesh->currentAnim->cursor << precision)) >> precision;
mesh->tmesh->v[ mesh->index[ t ].order.vy ].vy = (lerpD( mesh->currentAnim->data[mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[t].order.vy].vy << precision , mesh->currentAnim->data[(mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[t].order.vy].vy << precision, mesh->currentAnim->cursor << precision)) >> precision;
mesh->currentAnim->cursor += 24 * mesh->currentAnim->dir;
}; };
void set4VertexLerPos(MESH * mesh, long t){ void set4VertexLerPos(MESH * mesh, long t){
// Find and set 4 interpolated vertex value // Find and set 4 interpolated vertex value
short precision = 12; short precision = 12;
// Vertex 1 mesh->tmesh->v[ mesh->index[ t ].order.vx ].vx = lerpD( mesh->currentAnim->data[ mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[ t ].order.vx ].vx << precision ,
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->currentAnim->data[ (mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[ t ].order.vx ].vx << 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->currentAnim->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; mesh->tmesh->v[ mesh->index[ t ].order.vx ].vz = lerpD( mesh->currentAnim->data[ mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[ t ].order.vx ].vz << precision , mesh->currentAnim->data[ (mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[ t ].order.vx ].vz << precision, mesh->currentAnim->cursor << precision) >> precision;
mesh->tmesh->v[ mesh->index[ t ].order.vx ].vy = lerpD( mesh->currentAnim->data[ mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[ t ].order.vx ].vy << precision , mesh->currentAnim->data[ (mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[ t ].order.vx ].vy << precision, mesh->currentAnim->cursor << precision) >> precision;
// Vertex 2 // 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 ].vx = lerpD( mesh->currentAnim->data[ mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[ t ].order.vz ].vx << precision , mesh->currentAnim->data[ (mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[ t ].order.vz ].vx << precision, mesh->currentAnim->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 ].vz = lerpD( mesh->currentAnim->data[ mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[ t ].order.vz ].vz << precision , mesh->currentAnim->data[ (mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[ t ].order.vz ].vz << precision, mesh->currentAnim->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; mesh->tmesh->v[ mesh->index[ t ].order.vz ].vy = lerpD( mesh->currentAnim->data[ mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[ t ].order.vz ].vy << precision , mesh->currentAnim->data[ (mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[ t ].order.vz ].vy << precision, mesh->currentAnim->cursor << precision) >> precision;
// Vertex 3 // 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 ].vx = lerpD( mesh->currentAnim->data[ mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[ t ].order.vy ].vx << precision , mesh->currentAnim->data[ (mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[ t ].order.vy ].vx << precision, mesh->currentAnim->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 ].vz = lerpD( mesh->currentAnim->data[ mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[ t ].order.vy ].vz << precision , mesh->currentAnim->data[ (mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[ t ].order.vy ].vz << precision, mesh->currentAnim->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->tmesh->v[ mesh->index[ t ].order.vy ].vy = lerpD( mesh->currentAnim->data[ mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[ t ].order.vy ].vy << precision , mesh->currentAnim->data[ (mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[ t ].order.vy ].vy << precision, mesh->currentAnim->cursor << precision) >> precision;
// Vertex 4 // 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 << precision , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.pad ].vx << precision, mesh->anim->cursor << precision) >> precision; mesh->tmesh->v[ mesh->index[ t ].order.pad ].vx = lerpD( mesh->currentAnim->data[ mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[ t ].order.pad ].vx << precision , mesh->currentAnim->data[ (mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[ t ].order.pad ].vx << precision, mesh->currentAnim->cursor << precision) >> precision;
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 << precision , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.pad ].vz << precision, mesh->anim->cursor << precision) >> precision; mesh->tmesh->v[ mesh->index[ t ].order.pad ].vz = lerpD( mesh->currentAnim->data[ mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[ t ].order.pad ].vz << precision , mesh->currentAnim->data[ (mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[ t ].order.pad ].vz << precision, mesh->currentAnim->cursor << precision) >> precision;
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 << precision , mesh->anim->data[ (mesh->anim->lerpCursor + 1) * mesh->anim->nvert + mesh->index[ t ].order.pad ].vy << precision, mesh->anim->cursor << precision) >> precision; mesh->tmesh->v[ mesh->index[ t ].order.pad ].vy = lerpD( mesh->currentAnim->data[ mesh->currentAnim->lerpCursor * mesh->currentAnim->nvert + mesh->index[ t ].order.pad ].vy << precision , mesh->currentAnim->data[ (mesh->currentAnim->lerpCursor + 1) * mesh->currentAnim->nvert + mesh->index[ t ].order.pad ].vy << precision, mesh->currentAnim->cursor << precision) >> precision;
mesh->anim->cursor += 2 * mesh->anim->dir;
mesh->currentAnim->cursor += 24 * mesh->currentAnim->dir;
} }
long interpolateTri(POLY_GT3 * poly, MESH * mesh, long t){ long interpolateTri(POLY_GT3 * poly, MESH * mesh, long t){
long Flag, nclip = 0; long Flag, nclip = 0;
@ -93,16 +107,16 @@ long interpolateTri(POLY_GT3 * poly, MESH * mesh, long t){
//~ // mesh->anim->dir *= -1; //~ // mesh->anim->dir *= -1;
//~ //} //~ //}
// Find next keyframe // Find next keyframe
if (mesh->anim->cursor > (1 << 12)) { if (mesh->currentAnim->cursor > (1 << 12)) {
// There are still keyframes to interpolate between // There are still keyframes to interpolate between
if ( mesh->anim->lerpCursor < mesh->anim->nframes - 1 ) { if ( mesh->currentAnim->lerpCursor < mesh->currentAnim->nframes - 1 ) {
mesh->anim->lerpCursor ++; mesh->currentAnim->lerpCursor ++;
mesh->anim->cursor = 0; mesh->currentAnim->cursor = 0;
} }
// We've reached last frame, go back to first frame // We've reached last frame, go back to first frame
if ( mesh->anim->lerpCursor == mesh->anim->nframes - 1 ) { if ( mesh->currentAnim->lerpCursor == mesh->currentAnim->nframes - 1 ) {
mesh->anim->lerpCursor = 0; mesh->currentAnim->lerpCursor = 0;
mesh->anim->cursor = 0; mesh->currentAnim->cursor = 0;
} }
} }
// Find and set interpolated vertex value // Find and set interpolated vertex value
@ -127,14 +141,15 @@ long interpolateQuad(POLY_GT4 * poly4, MESH * mesh, long t){
//~ mesh->anim->dir *= -1; //~ mesh->anim->dir *= -1;
//~ } //~ }
short precision = 12; short precision = 12;
if ( mesh->anim->cursor > 1<<precision ) { //~ if ( mesh->anim->cursor > 1<<precision ) {
if ( mesh->anim->lerpCursor < mesh->anim->nframes - 1 ) { if ( mesh->currentAnim->cursor > (1 << 12) ) {
mesh->anim->lerpCursor ++; if ( mesh->currentAnim->lerpCursor < mesh->currentAnim->nframes - 1 ) {
mesh->anim->cursor = 0; mesh->currentAnim->lerpCursor ++;
mesh->currentAnim->cursor = 0;
} }
if ( mesh->anim->lerpCursor == mesh->anim->nframes - 1 ) { if ( mesh->currentAnim->lerpCursor == mesh->currentAnim->nframes - 1 ) {
mesh->anim->lerpCursor = 0; mesh->currentAnim->lerpCursor = 0;
mesh->anim->cursor = 0; mesh->currentAnim->cursor = 0;
} }
} }
// Find and set interpolated vertex value // Find and set interpolated vertex value
@ -346,17 +361,18 @@ long drawQuad(MESH * mesh, int atime, int * camMode, char ** nextpri, u_long * o
poly4 = (POLY_GT4 *)*nextpri; poly4 = (POLY_GT4 *)*nextpri;
// Vertex Anim // Vertex Anim
if (mesh->isAnim){ if (mesh->isAnim && mesh->currentAnim){
// with interpolation // with interpolation
if ( mesh->anim->interpolate ){ if ( mesh->anim_tracks->strips[0]->interpolate ){
interpolateQuad(poly4, mesh, t); nclip = interpolateQuad(poly4, mesh, t);
} else { } else {
// TODO : write playAnim()
// No interpolation, use all vertices coordinates in anim data // No interpolation, use all vertices coordinates in anim data
gte_RotAverageNclip4( gte_RotAverageNclip4(
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.pad ], &mesh->currentAnim->data[ atime % mesh->anim_tracks->strips[0]->nframes * mesh->anim_tracks->strips[0]->nvert + mesh->index[t].order.pad ],
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.vz ], &mesh->currentAnim->data[ atime % mesh->anim_tracks->strips[0]->nframes * mesh->anim_tracks->strips[0]->nvert + mesh->index[t].order.vz ],
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.vx ], &mesh->currentAnim->data[ atime % mesh->anim_tracks->strips[0]->nframes * mesh->anim_tracks->strips[0]->nvert + mesh->index[t].order.vx ],
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.vy ], &mesh->currentAnim->data[ atime % mesh->anim_tracks->strips[0]->nframes * mesh->anim_tracks->strips[0]->nvert + mesh->index[t].order.vy ],
( long* )&poly4->x0, ( long* )&poly4->x1, ( long* )&poly4->x2, ( long* )&poly4->x3, ( long* )&poly4->x0, ( long* )&poly4->x1, ( long* )&poly4->x2, ( long* )&poly4->x3,
&mesh->p, &mesh->p,
&mesh->OTz, &mesh->OTz,
@ -364,7 +380,7 @@ long drawQuad(MESH * mesh, int atime, int * camMode, char ** nextpri, u_long * o
&nclip &nclip
); );
} }
} else { } else {
// Mesh is sprite // Mesh is sprite
if (mesh->isSprite){ if (mesh->isSprite){
// Find inverse rotation matrix so that sprite always faces camera // Find inverse rotation matrix so that sprite always faces camera
@ -429,17 +445,17 @@ long drawTri(MESH * mesh, int atime, int * camMode, char ** nextpri, u_long * ot
if ( !( mesh->isBG ) || *camMode != 2) { if ( !( mesh->isBG ) || *camMode != 2) {
poly = (POLY_GT3 *)*nextpri; poly = (POLY_GT3 *)*nextpri;
// If Vertex Anim flag is set, use it // If Vertex Anim flag is set, use it
if (mesh->isAnim){ if (mesh->isAnim && mesh->currentAnim){
// If interpolation flag is set, use it // If interpolation flag is set, use it
if(mesh->anim->interpolate){ if(mesh->anim_tracks->strips[0]->interpolate){
nclip = interpolateTri(poly, mesh, t); nclip = interpolateTri(poly, mesh, t);
} else { } else {
// No interpolation // No interpolation
// Use the pre-calculated vertices coordinates from the animation data // Use the pre-calculated vertices coordinates from the animation data
gte_RotAverageNclip3( gte_RotAverageNclip3(
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.vx ], &mesh->currentAnim->data[ atime % mesh->currentAnim->nframes * mesh->currentAnim->nvert + mesh->index[t].order.vx ],
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.vz ], &mesh->currentAnim->data[ atime % mesh->currentAnim->nframes * mesh->currentAnim->nvert + mesh->index[t].order.vz ],
&mesh->anim->data[ atime % mesh->anim->nframes * mesh->anim->nvert + mesh->index[t].order.vy ], &mesh->currentAnim->data[ atime % mesh->currentAnim->nframes * mesh->currentAnim->nvert + mesh->index[t].order.vy ],
( long* ) &poly->x0, ( long* ) &poly->x1, ( long* ) &poly->x2, ( long* ) &poly->x0, ( long* ) &poly->x1, ( long* ) &poly->x2,
&mesh->p, &mesh->p,
&mesh->OTz, &mesh->OTz,
@ -599,3 +615,27 @@ void renderScene(LEVEL * curLvl, CAMERA * camera, int * camMode, char ** nextpri
} }
updateLight(); updateLight();
}; };
void playAnim(MESH * mesh, VANIM * anim, int loop){
if (mesh->isAnim){
// Set looping (-1 : infinite, n > 0 : loop n times )
if (mesh->currentAnim->loop == 0){
mesh->currentAnim->loop = loop;
}
// If anim not is not playing yet
if (mesh->currentAnim->cursor == -1){
// if cursor is -1, set to 0, start playback
mesh->currentAnim->cursor = 0;
} else {
}
// Anim is already playing
} else if (mesh->currentAnim == anim){
// If we're not in an infinite loop (-1)
if (mesh->currentAnim->loop > 0){
// Add loop iterations ?
mesh->currentAnim->loop = loop;
}
}
};

View File

@ -37,7 +37,7 @@ u_long overlaySize = 0;
#include "../levels/level1.h" #include "../levels/level1.h"
// Levels // Levels
u_char level = 1; u_char level = 0;
u_short levelWas = 0; u_short levelWas = 0;
u_short levelHasChanged = 0; u_short levelHasChanged = 0;
// Overlay // Overlay
@ -129,7 +129,7 @@ int main() {
} else if ( level == 1) { } else if ( level == 1) {
overlayFile = "\\level1.bin;1"; overlayFile = "\\level1.bin;1";
overlaySize = __lvl1_end; overlaySize = __lvl1_end;
loadLvl = &level1; //~ loadLvl = &level1;
} }
// Load overlay from cd // Load overlay from cd
#ifdef USECD #ifdef USECD
@ -142,7 +142,7 @@ int main() {
if ( level == 0 ) { if ( level == 0 ) {
LvlPtrSet( &curLvl, &level0); LvlPtrSet( &curLvl, &level0);
} else if ( level == 1) { } else if ( level == 1) {
LvlPtrSet( &curLvl, &level1); //~ LvlPtrSet( &curLvl, &level1);
} }
levelWas = level; levelWas = level;
// Copy light matrices / vector to scratchpad // Copy light matrices / vector to scratchpad
@ -214,7 +214,7 @@ int main() {
case 1: case 1:
overlayFile = "\\level1.bin;1"; overlayFile = "\\level1.bin;1";
overlaySize = __lvl1_end; overlaySize = __lvl1_end;
loadLvl = &level1; //~ loadLvl = &level1;
// Copy light matrices / vector to scratchpad // Copy light matrices / vector to scratchpad
break; break;
@ -250,7 +250,6 @@ int main() {
if (time % timediv == 0){ if (time % timediv == 0){
atime ++; atime ++;
} }
// TODO : put in a function
// Reset player/prop pos // Reset player/prop pos
if(curLvl.actorPtr->pos.vy >= 200){ if(curLvl.actorPtr->pos.vy >= 200){
playSFX(&voiceAttributes, curLvl.levelSounds->sounds[6]->VAGsample, curLvl.levelSounds->sounds[6]->volumeL, curLvl.levelSounds->sounds[6]->volumeR); playSFX(&voiceAttributes, curLvl.levelSounds->sounds[6]->VAGsample, curLvl.levelSounds->sounds[6]->volumeL, curLvl.levelSounds->sounds[6]->volumeR);
@ -388,6 +387,7 @@ int main() {
FntPrint("XA: %x\n", curLvl.XA); FntPrint("XA: %x\n", curLvl.XA);
FntPrint("Ofst: %d\n", curLvl.XA->banks[0]->offset); FntPrint("Ofst: %d\n", curLvl.XA->banks[0]->offset);
FntPrint("Vol: %d %d\n", curLvl.levelSounds->sounds[0]->volumeL, curLvl.levelSounds->sounds[0]->volumeR ); FntPrint("Vol: %d %d\n", curLvl.levelSounds->sounds[0]->volumeL, curLvl.levelSounds->sounds[0]->volumeR );
FntPrint("Curanim : %x", curLvl.meshes[1]->currentAnim);
FntFlush(-1); FntFlush(-1);
display( &disp[db], &draw[db], otdisc[db], primbuff[db], &nextpri, &db); display( &disp[db], &draw[db], otdisc[db], primbuff[db], &nextpri, &db);
@ -474,6 +474,16 @@ void callback() {
} }
if ( PAD & Square && !( lastPad & Square ) ){ if ( PAD & Square && !( lastPad & Square ) ){
playSFX(&voiceAttributes, curLvl.levelSounds->sounds[7]->VAGsample, curLvl.levelSounds->sounds[7]->volumeL, curLvl.levelSounds->sounds[7]->volumeR); playSFX(&voiceAttributes, curLvl.levelSounds->sounds[7]->VAGsample, curLvl.levelSounds->sounds[7]->volumeL, curLvl.levelSounds->sounds[7]->volumeR);
if ( curLvl.meshes[1]->currentAnim == 0 ||
curLvl.meshes[1]->currentAnim == curLvl.meshes[1]->anim_tracks->strips[0]
){
if (curLvl.meshes[1]->anim_tracks->index > 1) {
curLvl.meshes[1]->currentAnim = curLvl.meshes[1]->anim_tracks->strips[1];
}
} else {
//~ curLvl.meshes[1]->anim_tracks->strips[0]->interpolate = 1;
curLvl.meshes[1]->currentAnim = curLvl.meshes[1]->anim_tracks->strips[0];
}
//~ sample = 0; //~ sample = 0;
//~ setXAsample(&XABank.samples[sample], &filter); //~ setXAsample(&XABank.samples[sample], &filter);
lastPad = PAD; lastPad = PAD;
@ -500,17 +510,13 @@ void callback() {
if ( !(PAD & Circle) && lastPad & Circle ) { if ( !(PAD & Circle) && lastPad & Circle ) {
lastPad = PAD; lastPad = PAD;
} }
if ( PAD & PadLeft && !(lastPad & PadLeft) ) { //~ if ( PAD & PadLeft && !(lastPad & PadLeft) ) {
if (curLvl.actorPtr->anim->interpolate){
curLvl.actorPtr->anim->interpolate = 0; //~ lastPad = PAD;
} else { //~ }
curLvl.actorPtr->anim->interpolate = 1; //~ if ( !(PAD & PadLeft) && lastPad & PadLeft ) {
} //~ lastPad = PAD;
lastPad = PAD; //~ }
}
if ( !(PAD & PadLeft) && lastPad & PadLeft ) {
lastPad = PAD;
}
if (theControllers[0].type == 0x73){ if (theControllers[0].type == 0x73){
// Analog stick L up // Analog stick L up
if ( theControllers[0].analog3 >= 0 && theControllers[0].analog3 < (128 - DS_DZ/2)) { if ( theControllers[0].analog3 >= 0 && theControllers[0].analog3 < (128 - DS_DZ/2)) {

View File

@ -13,9 +13,11 @@ 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 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); static const long long C = 16777137; // 2^24 * cos(1 * 2pi / 2048) = C = f(1);
m_cosTable[1] = C; m_cosTable[1] = C;
for (int i = 2; i < 512; i++){ for (int i = 2; i < 511; i++){
m_cosTable[i] = ((C * m_cosTable[i - 1]) >> 23) - m_cosTable[i - 2]; m_cosTable[i] = ((C * m_cosTable[i - 1]) >> 23) - m_cosTable[i - 2];
m_cosTable[511] = 0; }
for (int i = 0; i < 512; i++){
m_cosTable[i] >>= 12;
} }
}; };
int ncos(unsigned int t) { int ncos(unsigned int t) {
@ -30,7 +32,7 @@ int ncos(unsigned int t) {
} else { } else {
r = m_cosTable[DC_2PI - 1 - t]; r = m_cosTable[DC_2PI - 1 - t];
}; };
return r >> 12; return r;
}; };
// sin(x) = cos(x - pi / 2) // sin(x) = cos(x - pi / 2)
int nsin(unsigned int t) { int nsin(unsigned int t) {
@ -106,7 +108,8 @@ int32_t lerpS(int32_t start, int32_t dest, unsigned pos) {
// precision = 2^24 - 2^x // precision = 2^24 - 2^x
// << x : 0 < pos < precision // << x : 0 < pos < precision
// https://discord.com/channels/642647820683444236/646765703143227394/811318550978494505 // 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 // 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) { int32_t lerpD(int32_t start, int32_t dest, int32_t pos) {
return dMul(start, 16777216 - pos) + dMul(dest, pos); return dMul(start, 16777216 - pos) + dMul(dest, pos);
}; };
@ -144,3 +147,36 @@ VECTOR getVectorTo( VECTOR actor, VECTOR target ) {
VectorNormal(&direction, &Ndirection); VectorNormal(&direction, &Ndirection);
return Ndirection ; return Ndirection ;
}; };
int32_t round( int32_t n){
// GRS - Action
// 0xx - round down = do nothing (x means any bit value, 0 or 1)
// 100 - this is a tie: round up if the mantissa's bit just before G is 1, else round down=do nothing
// 101 - round up
// 110 - round up
// 111 - round up
// source : https://stackoverflow.com/a/8984135
// e.g : n == 106 150 == 0000 0000 0000 0001 1001 1110 1010 0110
// Get GRS bits
// 0xe00 == 0000 1110 0000 0000
int8_t grs = ( n & 0xe00) >> 8 ; // 1110 0000 0000 >> 8
// GRS == 111(0)
// Get G value - 0x8 == 1000
if (grs & 0x8){
// GRS = 1xx
if ( // Get R value - 0x4 == 0100
// GRS == 11x ; round up
grs & 0x4 ||
// Get S value - 0x2 == 0010
// GRS == 101 ; round up
( !(grs & 0x4) && grs & 0x2)
) {
n += 0x800;
} else if ( !(n & 0x1000) ) {
// Get mantissa lsb - 0x1000 == 0001 0000 0000
// GRS == 100 ; tie, round up if mantissa lsb is 1
n += 0x800;
}
}
return n;
};