Skip to content

Instantly share code, notes, and snippets.

@milesrout
Created June 23, 2023 11:12
Show Gist options
  • Save milesrout/bad9e29be7f66ff4a2ddf015caea247b to your computer and use it in GitHub Desktop.
Save milesrout/bad9e29be7f66ff4a2ddf015caea247b to your computer and use it in GitHub Desktop.
#pragma omp parallel for
for (int j = 0; j < num_instances; j++) {
mat4 mmodel = GLM_MAT4_IDENTITY_INIT;
#if 1
int i_x = j % instances_width;
int i_y = j / instances_width;
int x = 7.0f * ((f32)i_x - (f32)instances_width / 2.0f);
int y = 7.0f * ((f32)i_y - (f32)instances_width / 2.0f);
x += 2.0f * (2.0f * timeoffset[j][3] - 1.0f);
y += 2.0f * (2.0f * timeoffset[j][4] - 1.0f);
#else
int x = 7.0f * ((j % instances_width) - (instances_width - 1) / 2.0f);
int y = 7.0f * ((j / instances_width) - (instances_width - 1) / 2.0f);
#endif
/* fprintf(stderr, "j=%d x,y=%d,%d\n", j, x, y); */
vec3 scale = {0.20f, 0.20f, 0.20f};
vec3 offset = {x, y, 0.0f};
vec3 axis = {0.0f, 0.0f, 1.0f};
f32 modelangle = (timediff + timeoffset[j][1]) * GLM_PI_2;
glm_scale(mmodel, scale);
glm_translate(mmodel, offset);
glm_rotate(mmodel, modelangle, axis);
glm_mat4_mul(view, mmodel, dyn_ssbo_data[frame].transform[j].modelview);
float fv = (timeoffset[j][0] * (141.0f/24.0f) + timediff) * (model->anims[0].frame_rate / timeoffset[j][2]);
float f0_f;
float fi = modff(fv, &f0_f);
int f0 = (int)f0_f % model->anims[0].num_frames;
int f1 = (f0 + 1) % model->anims[0].num_frames;
dyn_ssbo_data[frame].compute[j].frame0 = model->num_joints * f0;
dyn_ssbo_data[frame].compute[j].frame1 = model->num_joints * f1;
dyn_ssbo_data[frame].compute[j].interp = fi;
/* fprintf(stderr, "j=%d f0=%d f1=%d fi=%.2f\n", j, */
/* dyn_ssbo_data[frame].compute[j].frame0, */
/* dyn_ssbo_data[frame].compute[j].frame1, */
/* dyn_ssbo_data[frame].compute[j].interp); */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment