Animation refactoring
This commit is contained in:
parent
9ae3857fad
commit
411f47831f
@ -11,6 +11,7 @@
|
||||
#include <inline_n.h>
|
||||
#include <gtemac.h>
|
||||
#include "../include/defines.h"
|
||||
#include <stdint.h>
|
||||
#include "../custom_types.h"
|
||||
|
||||
// PSX setup
|
||||
|
17
include/stdint.h
Normal file
17
include/stdint.h
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* STDINT based on ansi c for PSYQ
|
||||
*
|
||||
* John Convertino
|
||||
* https://github.com/electrobs/PSYQ_Examples/blob/master/PSYQ_MODS/STDINT.h
|
||||
*/
|
||||
#ifndef STDINT_H
|
||||
#define STDINT_H
|
||||
typedef char int8_t;
|
||||
typedef short int16_t;
|
||||
typedef int int32_t;
|
||||
typedef long long int64_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
#endif
|
@ -8,9 +8,9 @@ MESH_ANIMS_TRACKS level0_modelCube_001_anims = {
|
||||
5,
|
||||
{
|
||||
&level0_modelCube_001_anim_KeyAction,
|
||||
&level0_modelCube_001_anim_KeyAction_001,
|
||||
&level0_modelCube_001_anim_KeyAction_003,
|
||||
&level0_modelCube_001_anim_KeyAction_004,
|
||||
&level0_modelCube_001_anim_KeyAction_003,
|
||||
&level0_modelCube_001_anim_KeyAction_001,
|
||||
&level0_modelCube_001_anim_KeyAction_002
|
||||
}
|
||||
};
|
||||
@ -23,8 +23,8 @@ VANIM level0_modelCube_001_anim_KeyAction = {
|
||||
0, // loop : if -1 , infinite loop, if n > 0, loop n times
|
||||
1, // playback direction (1 or -1)
|
||||
0, // ping pong animation (A>B>A)
|
||||
1, // use lerp to interpolate keyframes
|
||||
{ // vertex pos as SVECTORs e.g 20 * 21 SVECTORS
|
||||
0, // use lerp to interpolate keyframes
|
||||
{ // vertex pos as BVECTORs e.g 20 * 21 BVECTORS
|
||||
//Frame 0
|
||||
{ -6,33,-6 },
|
||||
{ -27,-19,-27 },
|
||||
@ -176,7 +176,7 @@ VANIM level0_modelCube_001_anim_KeyAction_004 = {
|
||||
1, // playback direction (1 or -1)
|
||||
0, // ping pong animation (A>B>A)
|
||||
0, // use lerp to interpolate keyframes
|
||||
{ // vertex pos as SVECTORs e.g 20 * 21 SVECTORS
|
||||
{ // vertex pos as BVECTORs e.g 20 * 21 BVECTORS
|
||||
//Frame 0
|
||||
{ -6,33,-6 },
|
||||
{ -27,-19,-27 },
|
||||
@ -298,7 +298,7 @@ VANIM level0_modelCube_001_anim_KeyAction_003 = {
|
||||
1, // playback direction (1 or -1)
|
||||
0, // ping pong animation (A>B>A)
|
||||
0, // use lerp to interpolate keyframes
|
||||
{ // vertex pos as SVECTORs e.g 20 * 21 SVECTORS
|
||||
{ // vertex pos as BVECTORs e.g 20 * 21 BVECTORS
|
||||
//Frame 0
|
||||
{ -6,33,-6 },
|
||||
{ -27,-19,-27 },
|
||||
@ -400,7 +400,7 @@ VANIM level0_modelCube_001_anim_KeyAction_001 = {
|
||||
1, // playback direction (1 or -1)
|
||||
0, // ping pong animation (A>B>A)
|
||||
0, // use lerp to interpolate keyframes
|
||||
{ // vertex pos as SVECTORs e.g 20 * 21 SVECTORS
|
||||
{ // vertex pos as BVECTORs e.g 20 * 21 BVECTORS
|
||||
//Frame 0
|
||||
{ -9,33,-9 },
|
||||
{ -25,-19,-25 },
|
||||
@ -582,7 +582,7 @@ VANIM level0_modelCube_001_anim_KeyAction_002 = {
|
||||
1, // playback direction (1 or -1)
|
||||
0, // ping pong animation (A>B>A)
|
||||
0, // use lerp to interpolate keyframes
|
||||
{ // vertex pos as SVECTORs e.g 20 * 21 SVECTORS
|
||||
{ // vertex pos as BVECTORs e.g 20 * 21 BVECTORS
|
||||
//Frame 0
|
||||
{ -9,33,-9 },
|
||||
{ -25,-19,-25 },
|
||||
@ -941,7 +941,7 @@ MESH level0_meshCube_001 = {
|
||||
0, // otz
|
||||
&level0_modelCube_001_body,
|
||||
&level0_modelCube_001_anims, // Mesh anim tracks
|
||||
&level0_modelCube_001_anim_KeyAction, // Current VANIM
|
||||
0, // Current VANIM
|
||||
&level0_nodePlane,
|
||||
0 // Screen space coordinates
|
||||
};
|
||||
@ -5032,11 +5032,11 @@ SIBLINGS level0_nodePlane_siblings = {
|
||||
CHILDREN level0_nodePlane_objects = {
|
||||
5,
|
||||
{
|
||||
&level0_meshCube_001,
|
||||
&level0_meshPlane_000,
|
||||
&level0_meshPlane_005,
|
||||
&level0_meshPlane_002,
|
||||
&level0_meshPlane_006,
|
||||
&level0_meshCube_001,
|
||||
&level0_meshPlane_000
|
||||
&level0_meshPlane_006
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -363,16 +363,16 @@ long drawQuad(MESH * mesh, int atime, int * camMode, char ** nextpri, u_long * o
|
||||
// Vertex Anim
|
||||
if (mesh->isAnim && mesh->currentAnim){
|
||||
// with interpolation
|
||||
if ( mesh->anim_tracks->strips[0]->interpolate ){
|
||||
if ( mesh->currentAnim->interpolate ){
|
||||
nclip = interpolateQuad(poly4, mesh, t);
|
||||
} else {
|
||||
// TODO : write playAnim()
|
||||
// No interpolation, use all vertices coordinates in anim data
|
||||
gte_RotAverageNclip4(
|
||||
&mesh->currentAnim->data[ atime % mesh->anim_tracks->strips[0]->nframes * mesh->anim_tracks->strips[0]->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.vz ],
|
||||
&mesh->currentAnim->data[ atime % mesh->anim_tracks->strips[0]->nframes * mesh->anim_tracks->strips[0]->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.vy ],
|
||||
&mesh->currentAnim->data[ atime % mesh->currentAnim->nframes * mesh->currentAnim->nvert + mesh->index[t].order.pad ],
|
||||
&mesh->currentAnim->data[ atime % mesh->currentAnim->nframes * mesh->currentAnim->nvert + mesh->index[t].order.vz ],
|
||||
&mesh->currentAnim->data[ atime % mesh->currentAnim->nframes * mesh->currentAnim->nvert + mesh->index[t].order.vx ],
|
||||
&mesh->currentAnim->data[ atime % mesh->currentAnim->nframes * mesh->currentAnim->nvert + mesh->index[t].order.vy ],
|
||||
( long* )&poly4->x0, ( long* )&poly4->x1, ( long* )&poly4->x2, ( long* )&poly4->x3,
|
||||
&mesh->p,
|
||||
&mesh->OTz,
|
||||
@ -447,7 +447,7 @@ long drawTri(MESH * mesh, int atime, int * camMode, char ** nextpri, u_long * ot
|
||||
// If Vertex Anim flag is set, use it
|
||||
if (mesh->isAnim && mesh->currentAnim){
|
||||
// If interpolation flag is set, use it
|
||||
if(mesh->anim_tracks->strips[0]->interpolate){
|
||||
if(mesh->currentAnim->interpolate){
|
||||
nclip = interpolateTri(poly, mesh, t);
|
||||
} else {
|
||||
// No interpolation
|
||||
|
15
src/main.c
15
src/main.c
@ -245,9 +245,9 @@ int main() {
|
||||
}
|
||||
//~ FntPrint("Ovl:%s\nLvl : %x\nLvl: %d %d \n%x", overlayFile, &level, level, levelWas, loadLvl);
|
||||
// atime is used for animations timing
|
||||
timediv = 1;
|
||||
timediv = 2;
|
||||
// If timediv is > 1, animation time will be slower
|
||||
if (time % timediv == 0){
|
||||
if (time++ % timediv == 0){
|
||||
atime ++;
|
||||
}
|
||||
// Reset player/prop pos
|
||||
@ -384,10 +384,11 @@ int main() {
|
||||
//~ FntPrint("XA : %d\n", (XA_CDSPEED)/((400/(dt+1))+1) );
|
||||
//~ FntPrint("XA : %d\n", curLvl.XA->samples[sample].cursor );
|
||||
FntPrint("CamAngle : %d\n", curCamAngle);
|
||||
FntPrint("XA: %x\n", curLvl.XA);
|
||||
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("Curanim : %x", curLvl.meshes[1]->currentAnim);
|
||||
//~ FntPrint("XA: %x\n", curLvl.XA);
|
||||
//~ 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("Curanim : %x\n", curLvl.meshes[1]->currentAnim);
|
||||
//~ FntPrint("Anims : %x %x", curLvl.meshes[1]->anim_tracks->strips[3], curLvl.meshes[1]->anim_tracks->strips[4]);
|
||||
FntFlush(-1);
|
||||
display( &disp[db], &draw[db], otdisc[db], primbuff[db], &nextpri, &db);
|
||||
|
||||
@ -478,7 +479,7 @@ void callback() {
|
||||
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];
|
||||
curLvl.meshes[1]->currentAnim = curLvl.meshes[1]->anim_tracks->strips[4];
|
||||
}
|
||||
} else {
|
||||
//~ curLvl.meshes[1]->anim_tracks->strips[0]->interpolate = 1;
|
||||
|
71
src/math.c
71
src/math.c
@ -148,35 +148,44 @@ VECTOR getVectorTo( VECTOR actor, VECTOR target ) {
|
||||
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;
|
||||
// 20.12 fixed point to 20.12 fixed point rounding
|
||||
int32_t round(int32_t n) {
|
||||
return (n + 2048) & 0xfffff000;
|
||||
};
|
||||
|
||||
// 20.12 fixed point to int, rounding first
|
||||
static inline int32_t toint(int32_t n) {
|
||||
return (n + 2048) >> 12;
|
||||
};
|
||||
//~ 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;
|
||||
//~ };
|
||||
|
Loading…
Reference in New Issue
Block a user