This commit is contained in:
Mylloon 2023-05-12 17:46:25 +02:00
parent cd3b290942
commit 59dcac9bac
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 29 additions and 36 deletions

View file

@ -12,17 +12,17 @@ void bindAndLoadf(const char *name);
/* Move something in space
*
* +x = movement to right
* `+x` => movement to right
*
* -x = movement to left
* `-x` => movement to left
*
* +y = movement to top (fly)
* `+y` => movement to top (fly)
*
* -y = movement to bottom (sink)
* `-y` => movement to bottom (sink)
*
* +z = move closer
* `+z` => move closer
*
* -z = move away */
* `-z` => move away */
void move(GLfloat x, GLfloat y, GLfloat z);
#endif

View file

@ -18,7 +18,6 @@ void main() {
fragColor = vec4(1);
for(int i = 0; i < max; i++) {
vec3 torche = normalize(pos_model.xyz - lum_pos[i].xyz);
float intensite_lumineuse = clamp(dot(vec_normal, -torche), 0., 1.);
vec3 reflet = (transpose(inverse(view)) * vec4(reflect(torche, vec_normal), 0)).xyz;

View file

@ -9,7 +9,7 @@ struct manifestant {
GLfloat ox, oz;
};
#define HEROS_NUMBER 1 // should change in fragment shader too
#define HEROS_NUMBER 10 // should change in fragment shader too
static struct manifestant _herosId[HEROS_NUMBER];
static const char *matrix_proj = "proj";
@ -52,8 +52,8 @@ static void init(void) {
_herosId[i].jambe_d = gl4dgGenCubef();
// Coordinates
_herosId[i].ox = ((GLfloat)rand() / (GLfloat)RAND_MAX) * -7;
_herosId[i].oz = ((GLfloat)rand() / (GLfloat)RAND_MAX) * 10;
_herosId[i].ox = ((GLfloat)rand() / (GLfloat)RAND_MAX) * -50;
_herosId[i].oz = 30 - ((GLfloat)rand() / (GLfloat)RAND_MAX) * 50;
}
_pId =
gl4duCreateProgram("<vs>shaders/manif.vs", "<fs>shaders/manif.fs", NULL);
@ -83,9 +83,9 @@ static void draw(void) {
gl4duFrustumf(-1, 1, -ratio, ratio, 1, 1000);
bindAndLoadf(matrix_view);
const GLfloat distance = 2;
const GLfloat distance = 4; // distance from the scene
gl4duLookAtf(0, distance, distance, 0, 0, 0, 0, 1, 0);
// gl4duRotatef(-30, 0, 1, 0); // rotation caméra
// gl4duRotatef(-90, 0, 1, 0); // rotation camera
bindAndLoadf(matrix_model);
gl4duRotatef(-90, 1, 0, 0);
@ -95,77 +95,71 @@ static void draw(void) {
glUniform4fv(couleur_gpu, 1, couleur_plan);
gl4dgDraw(_planId);
GLfloat lumpos[1][4], lumcolor[1][4];
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
const GLfloat lumpos_i[] = {0, 1, -0.5f, 0};
const GLfloat lumpos_i[] = {0, 1 + (float)deplacement, -0.5f, 0};
memcpy(lumpos[i], lumpos_i, sizeof(lumpos_i));
// Color
/* const GLfloat lumcolor_red[] = {1, 0, 0, 1}; */
const GLfloat lumcolor_blue[] = {0, 0, 1, 1};
memcpy(lumcolor[i], /* rand() % 2 == 0 ? lumcolor_red : */ lumcolor_blue,
sizeof(lumcolor_blue));
const GLfloat lumcolor_red[] = {1, (float)deplacement, 0, 1};
memcpy(lumcolor[i], lumcolor_red, sizeof(lumcolor_red));
// Draw corps
bindAndLoadf(matrix_model);
gl4duTranslatef(0, 1.2f, -1);
gl4duScalef(0.1f, 0.5f, 0.2f);
gl4duTranslatef(0, 3, -1);
move(_herosId[i].ox + (float)deplacement, 0, _herosId[i].oz);
gl4duSendMatrices();
glUniform4fv(couleur_gpu, 1, couleur_heros);
gl4dgDraw(_herosId[i].corps);
// Draw head
bindAndLoadf(matrix_model);
gl4duTranslatef(0, 1.9f, -1);
gl4duScalef(0.1f, 0.2f, 0.2f);
gl4duTranslatef(0, 10.9f, -1);
move(_herosId[i].ox + (float)deplacement, 0, _herosId[i].oz);
gl4duSendMatrices();
glUniform4fv(couleur_gpu, 1, couleur_heros);
gl4dgDraw(_herosId[i].tete);
// Draw leg left
bindAndLoadf(matrix_model);
gl4duTranslatef(0, 0.3f, -1.1f);
gl4duScalef(0.1f, 0.4f, 0.05f);
move(_herosId[i].ox + (float)deplacement, 0, _herosId[i].oz);
gl4duScalef(0.1f, 1, 0.05f);
gl4duTranslatef(0, 0, -1);
move(_herosId[i].ox + (float)deplacement, 0, _herosId[i].oz * part_mult);
gl4duSendMatrices();
glUniform4fv(couleur_gpu, 1, couleur_heros);
gl4dgDraw(_herosId[i].jambe_g);
// Draw leg right
bindAndLoadf(matrix_model);
gl4duTranslatef(0, 0.3f, -0.9f);
gl4duScalef(0.1f, 0.4f, 0.05f);
move(_herosId[i].ox + (float)deplacement, 0, _herosId[i].oz);
gl4duScalef(0.1f, 1, 0.05f);
gl4duTranslatef(0, 0, -7);
move(_herosId[i].ox + (float)deplacement, 0, _herosId[i].oz * part_mult);
gl4duSendMatrices();
glUniform4fv(couleur_gpu, 1, couleur_heros);
gl4dgDraw(_herosId[i].jambe_d);
// Draw arm left
bindAndLoadf(matrix_model);
gl4duTranslatef(0, 1.25f, -1.2f);
gl4duScalef(0.1f, 0.4f, 0.05f);
move(_herosId[i].ox + (float)deplacement, 0, _herosId[i].oz);
gl4duTranslatef(0, 4, 1);
move(_herosId[i].ox + (float)deplacement, 0, _herosId[i].oz * part_mult);
gl4duSendMatrices();
glUniform4fv(couleur_gpu, 1, couleur_heros);
gl4dgDraw(_herosId[i].bras_g);
// Draw arm right
bindAndLoadf(matrix_model);
gl4duTranslatef(0, 1.25f, -0.8f);
gl4duScalef(0.1f, 0.4f, 0.05f);
move(_herosId[i].ox + (float)deplacement, 0, _herosId[i].oz);
gl4duTranslatef(0, 4, -8);
move(_herosId[i].ox + (float)deplacement, 0, _herosId[i].oz * part_mult);
gl4duSendMatrices();
glUniform4fv(couleur_gpu, 1, couleur_heros);
gl4dgDraw(_herosId[i].bras_d);
}