From 1472c11a0a361e791714ed2fa40e51d912e0d320 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 25 May 2023 10:29:35 +0200 Subject: [PATCH] tourne et manege --- includes/animations.h | 3 +++ main.c | 10 +++++----- shaders/rotation.fs | 25 +++++++++++++++++++++++++ src/animations.c | 26 ++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 shaders/rotation.fs diff --git a/includes/animations.h b/includes/animations.h index 267de78..3add1e6 100644 --- a/includes/animations.h +++ b/includes/animations.h @@ -23,6 +23,9 @@ void transitionsInit(void); // Transition zoom void zoomIn(void (*)(int), void (*)(int), Uint32, Uint32, const int); +// Transition qui tourne +void rotation(void (*)(int), void (*)(int), Uint32, Uint32, const int); + // Personnage struct manifestant { GLuint corps, tete, jambe_g, jambe_d, bras_g, bras_d; diff --git a/main.c b/main.c index fbb8c41..973b599 100644 --- a/main.c +++ b/main.c @@ -20,11 +20,11 @@ int main(const int argc, char *argv[]) { } // Animations - GL4DHanime animations[] = {{10000, manif, NULL, NULL}, // Manifestation - {2000, manif, tag, zoomIn}, // Transition - {10000, tag, NULL, NULL}, // Tag - {2000, tag, credits, zoomIn}, // Transition - {9500, credits, NULL, NULL}, // Crédits + GL4DHanime animations[] = {{10000, manif, NULL, NULL}, // Manifestation + {2000, manif, tag, zoomIn}, // Transition + {10000, tag, NULL, NULL}, // Tag + {2000, tag, credits, rotation}, // Transition + {9500, credits, NULL, NULL}, // Crédits {0, NULL, NULL, NULL}}; gl4dhInit(animations, _dims[0], _dims[1], init); diff --git a/shaders/rotation.fs b/shaders/rotation.fs new file mode 100644 index 0000000..d8d63b3 --- /dev/null +++ b/shaders/rotation.fs @@ -0,0 +1,25 @@ +#version 330 + +uniform sampler2D tex0; +uniform sampler2D tex1; +uniform float progress; + +in vec2 vsoTexCoord; +out vec4 fragColor; + +void main() { + vec2 center = vec2(.5); + vec2 offset = vsoTexCoord - center; + + float angle = progress * radians(180) * 2; + float sinTheta = sin(angle); + float cosTheta = cos(angle); + vec2 rotatedOffset = vec2(cosTheta * offset.x - sinTheta * offset.y, sinTheta * offset.x + cosTheta * offset.y); + + vec2 distortedTexCoord = center + rotatedOffset; + + vec4 color1 = texture(tex0, vsoTexCoord); + vec4 color2 = texture(tex1, distortedTexCoord); + + fragColor = mix(color1, color2, smoothstep(0., 1., progress)); +} diff --git a/src/animations.c b/src/animations.c index 60efd9d..889bca9 100644 --- a/src/animations.c +++ b/src/animations.c @@ -195,3 +195,29 @@ void drawManifestant(const char *matrix_model, const struct manifestant *hero, gl4duSendMatrices(); gl4dgDraw(hero->bras_d); } + +void rotation(void (*a0)(int), void (*a1)(int), Uint32 t, Uint32 et, + const int state) { + const int gpu = 1; + static GLuint tex[2]; + switch (state) { + case GL4DH_INIT: + transition_init("rotation", gpu, tex); + break; + + case GL4DH_DRAW: + transition_draw(a0, a1, t, et, state, gpu, tex); + break; + + case GL4DH_FREE: + transition_deinit(tex); + break; + + case GL4DH_UPDATE_WITH_AUDIO: + update_with_audio(a0, a1, state); + break; + + default: + break; + } +}