diff --git a/includes/animations.h b/includes/animations.h index b63242e..928c7b1 100644 --- a/includes/animations.h +++ b/includes/animations.h @@ -33,4 +33,8 @@ struct manifestant { // Génère un manifestant void genManifestant(struct manifestant *); +// Dessine un manifestant +void drawManifestant(const char *, const struct manifestant *, const float, + const GLboolean); + #endif diff --git a/src/animations.c b/src/animations.c index f780f5f..d9b37f3 100644 --- a/src/animations.c +++ b/src/animations.c @@ -123,3 +123,68 @@ void genManifestant(struct manifestant *hero) { hero->jambe_g = gl4dgGenCubef(); hero->jambe_d = gl4dgGenCubef(); } + +void drawManifestant(const char *matrix_model, const struct manifestant *hero, + const float deplacement, const GLboolean oscillate) { + const GLfloat oscillation = oscillate ? ((float)sin(2 * deplacement) + 1) : 0; + const float x = hero->ox + deplacement; + const float z = hero->oz * 4; + + // Draw corps + bindAndLoadf(matrix_model); + gl4duScalef(0.1f, 0.5f, 0.2f); + gl4duTranslatef(0, 3, -1); + move(x, 0, hero->oz); + + gl4duSendMatrices(); + gl4dgDraw(hero->corps); + + // Draw head + bindAndLoadf(matrix_model); + gl4duScalef(0.1f, 0.2f, 0.2f); + gl4duTranslatef(0, 10.9f, -1); + move(x, 0, hero->oz); + + gl4duSendMatrices(); + gl4dgDraw(hero->tete); + + // Draw leg left + bindAndLoadf(matrix_model); + gl4duScalef(0.1f, 1, 0.05f); + gl4duTranslatef(0, 0, -1); + move(x, 0, z); + gl4duRotatef(-oscillation * 90, 0, 0, 1); + + gl4duSendMatrices(); + gl4dgDraw(hero->jambe_g); + + // Draw leg right + bindAndLoadf(matrix_model); + gl4duScalef(0.1f, 1, 0.05f); + gl4duTranslatef(0, 0, -7); + move(x, 0, z); + gl4duRotatef(oscillation * 90, 0, 0, 1); + + gl4duSendMatrices(); + gl4dgDraw(hero->jambe_d); + + // Draw arm left + bindAndLoadf(matrix_model); + gl4duScalef(0.1f, 0.4f, 0.05f); + gl4duTranslatef(0, 4, 1); + move(x, 0, z); + gl4duRotatef(oscillation * 90, 0, 0, 1); + + gl4duSendMatrices(); + gl4dgDraw(hero->bras_g); + + // Draw arm right + bindAndLoadf(matrix_model); + gl4duScalef(0.1f, 0.4f, 0.05f); + gl4duTranslatef(0, 4, -8); + move(x, 0, z); + gl4duRotatef(-oscillation * 90, 0, 0, 1); + + gl4duSendMatrices(); + gl4dgDraw(hero->bras_d); +} diff --git a/src/manif.c b/src/manif.c index d19a58e..3ad185b 100644 --- a/src/manif.c +++ b/src/manif.c @@ -80,7 +80,6 @@ static void draw(void) { GLfloat lumpos[HEROS_NUMBER][4], lumcolor[HEROS_NUMBER][4]; glUniform4fv(couleur_gpu, 1, couleur_heros); - GLfloat part_mult = 4; for (int i = 0; i < HEROS_NUMBER; ++i) { // Torchs // Position @@ -94,65 +93,7 @@ static void draw(void) { const GLfloat lumcolor_red[] = {1, 0, 0, 1}; memcpy(lumcolor[i], lumcolor_red, sizeof(lumcolor_red)); - GLfloat oscillation = ((float)sin(2 * deplacement) + 1); - - // Draw corps - bindAndLoadf(matrix_model); - gl4duScalef(0.1f, 0.5f, 0.2f); - gl4duTranslatef(0, 3, -1); - move(_herosId[i].ox + deplacement, 0, _herosId[i].oz); - - gl4duSendMatrices(); - gl4dgDraw(_herosId[i].corps); - - // Draw head - bindAndLoadf(matrix_model); - gl4duScalef(0.1f, 0.2f, 0.2f); - gl4duTranslatef(0, 10.9f, -1); - move(_herosId[i].ox + deplacement, 0, _herosId[i].oz); - - gl4duSendMatrices(); - gl4dgDraw(_herosId[i].tete); - - // Draw leg left - bindAndLoadf(matrix_model); - gl4duScalef(0.1f, 1, 0.05f); - gl4duTranslatef(0, 0, -1); - move(_herosId[i].ox + deplacement, 0, _herosId[i].oz * part_mult); - gl4duRotatef(-oscillation * 90, 0, 0, 1); - - gl4duSendMatrices(); - gl4dgDraw(_herosId[i].jambe_g); - - // Draw leg right - bindAndLoadf(matrix_model); - gl4duScalef(0.1f, 1, 0.05f); - gl4duTranslatef(0, 0, -7); - move(_herosId[i].ox + deplacement, 0, _herosId[i].oz * part_mult); - gl4duRotatef(oscillation * 90, 0, 0, 1); - - gl4duSendMatrices(); - gl4dgDraw(_herosId[i].jambe_d); - - // Draw arm left - bindAndLoadf(matrix_model); - gl4duScalef(0.1f, 0.4f, 0.05f); - gl4duTranslatef(0, 4, 1); - move(_herosId[i].ox + deplacement, 0, _herosId[i].oz * part_mult); - gl4duRotatef(oscillation * 90, 0, 0, 1); - - gl4duSendMatrices(); - gl4dgDraw(_herosId[i].bras_g); - - // Draw arm right - bindAndLoadf(matrix_model); - gl4duScalef(0.1f, 0.4f, 0.05f); - gl4duTranslatef(0, 4, -8); - move(_herosId[i].ox + deplacement, 0, _herosId[i].oz * part_mult); - gl4duRotatef(-oscillation * 90, 0, 0, 1); - - gl4duSendMatrices(); - gl4dgDraw(_herosId[i].bras_d); + drawManifestant(matrix_model, &_herosId[i], deplacement, GL_TRUE); } int max_gpu = 3; // HEROS_NUMBER;