From be76a975de342649e0eff3f0c39ae8ae90c98236 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 19 May 2023 11:13:37 +0200 Subject: [PATCH] idk? rotate lights so it move --- includes/utils.h | 3 +++ src/manif.c | 5 +++-- src/utils.c | 11 +++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/includes/utils.h b/includes/utils.h index 3f4ee18..4cdac30 100644 --- a/includes/utils.h +++ b/includes/utils.h @@ -25,4 +25,7 @@ void bindAndLoadf(const char *name); * `-z` => move away */ void move(GLfloat x, GLfloat y, GLfloat z); +/* Rotate a vector XYZ */ +void rotate_vec(GLfloat *, GLfloat); + #endif diff --git a/src/manif.c b/src/manif.c index 74b0c4f..2b8492e 100644 --- a/src/manif.c +++ b/src/manif.c @@ -101,8 +101,9 @@ static void draw(void) { for (int i = 0; i < HEROS_NUMBER; ++i) { // Torchs // Position - const GLfloat lumpos_i[] = {(_herosId[i].ox / 10) + (deplacement / 10), 1, - (_herosId[i].oz / 20) - 1, 0}; + GLfloat lumpos_i[] = {(_herosId[i].ox / 10) + (deplacement / 10), 1, + ((_herosId[i].oz / 20) - 1)}; + rotate_vec(lumpos_i, 2 * ((float)sin(deplacement) + 1) / 2); memcpy(lumpos[i], lumpos_i, sizeof(lumpos_i)); // Color diff --git a/src/utils.c b/src/utils.c index e3cc442..cf035fc 100644 --- a/src/utils.c +++ b/src/utils.c @@ -15,3 +15,14 @@ void bindAndLoadf(const char *name) { } void move(GLfloat x, GLfloat y, GLfloat z) { gl4duTranslatef(x, y, z); } + +void rotate_vec(GLfloat *vec, GLfloat angle) { + GLfloat y = vec[1]; + GLfloat z = vec[2]; + + GLfloat cosTheta = (GLfloat)cos(angle); + GLfloat sinTheta = (GLfloat)sin(angle); + + vec[1] = y * cosTheta - z * sinTheta; + vec[2] = y * sinTheta + z * cosTheta; +}