remove unnneded headers; reorganization

This commit is contained in:
2025-11-30 01:20:14 -06:00
parent 5fd83c6928
commit c1534dfe44
42 changed files with 617 additions and 1101 deletions

126
model.c
View File

@@ -1,9 +1,7 @@
#include "model.h"
#include "cell.h"
#include "stb_ds.h"
#include "render.h"
#include "HandmadeMath.h"
#include "math.h"
@@ -16,6 +14,128 @@
#include <stdlib.h>
#include <string.h>
struct keyframe {
double time;
double val;
};
#define LINEAR 0
#define STEP 1
#define CUBICSPLINE 2
#define SLERP 3
typedef struct sampler {
float *times;
HMM_Vec4 *data;
int type;
} sampler;
struct anim_channel {
HMM_Vec4 *target;
int comps;
struct sampler *sampler;
};
typedef struct animation {
double time;
struct anim_channel *channels;
sampler *samplers;
} animation;
HMM_Vec4 sample_cubicspline(sampler *sampler, float t, int prev, int next)
{
HMM_Vec4 ret;
HMM_Quat qv = HMM_SLerp(HMM_QV4(sampler->data[prev]), t, HMM_QV4(sampler->data[next]));
memcpy(ret.e, qv.e, sizeof(ret.e));
return ret;
}
HMM_Vec4 sample_sampler(sampler *sampler, float time)
{
if (arrlen(sampler->data) == 0) return v4zero;
if (arrlen(sampler->data) == 1) return sampler->data[0];
int previous_time=0;
int next_time=0;
for (int i = 1; i < arrlen(sampler->times); i++) {
if (time < sampler->times[i]) {
previous_time = i-1;
next_time = i;
break;
}
}
float td = sampler->times[next_time]-sampler->times[previous_time];
float t = (time - sampler->times[previous_time])/td;
HMM_Vec4 ret;
HMM_Quat qv;
switch(sampler->type) {
case LINEAR:
return HMM_LerpV4(sampler->data[previous_time],time,sampler->data[next_time]);
break;
case STEP:
return sampler->data[previous_time];
break;
case CUBICSPLINE:
return sample_cubicspline(sampler,t, previous_time, next_time);
break;
case SLERP:
qv = HMM_SLerp(sampler->data[previous_time].quat, time, sampler->data[next_time].quat);
memcpy(ret.e,qv.e,sizeof(ret.e));
return ret;
break;
}
return sample_cubicspline(sampler,t, previous_time, next_time);
}
void animation_run(struct animation *anim, float now)
{
float elapsed = now - anim->time;
elapsed = fmod(elapsed,2);
if (!anim->channels) return;
for (int i = 0; i < arrlen(anim->channels); i++) {
struct anim_channel *ch = anim->channels+i;
HMM_Vec4 s = sample_sampler(ch->sampler, elapsed);
*(ch->target) = s;
}
}
#define MAT_POS 0
#define MAT_UV 1
#define MAT_NORM 2
#define MAT_BONE 3
#define MAT_WEIGHT 4
#define MAT_COLOR 5
#define MAT_TAN 6
#define MAT_ANGLE 7
#define MAT_WH 8
#define MAT_ST 9
#define MAT_PPOS 10
#define MAT_SCALE 11
#define MAT_INDEX 100
typedef struct md5joint {
struct md5joint *parent;
HMM_Vec4 pos;
HMM_Quat rot;
HMM_Vec4 scale;
HMM_Mat4 t;
} md5joint;
typedef struct skin {
md5joint *joints;
HMM_Mat4 *invbind;
HMM_Mat4 binds[50]; /* binds = joint * invbind */
animation *anim;
} skin;
SDL_GPUBuffer *texcoord_floats(float *f, int n)
{
return NULL;