add multiples objects instead of one
This commit is contained in:
parent
3d3ea8ccdf
commit
a3f04eda2b
1 changed files with 45 additions and 11 deletions
56
src/manif.c
56
src/manif.c
|
@ -2,11 +2,19 @@
|
||||||
|
|
||||||
static GLuint _pId = 0;
|
static GLuint _pId = 0;
|
||||||
static GLuint _planId = 0;
|
static GLuint _planId = 0;
|
||||||
static GLuint _herosId = 0;
|
|
||||||
|
|
||||||
static const char matrix_proj[] = "proj";
|
struct manifestant {
|
||||||
static const char matrix_model[] = "model";
|
GLuint corps, tete;
|
||||||
static const char matrix_view[] = "view";
|
// Offsets
|
||||||
|
GLfloat ox, oz;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define HEROS_NUMBER 70
|
||||||
|
static struct manifestant _herosId[HEROS_NUMBER];
|
||||||
|
|
||||||
|
static const char *matrix_proj = "proj";
|
||||||
|
static const char *matrix_model = "model";
|
||||||
|
static const char *matrix_view = "view";
|
||||||
|
|
||||||
static void init(void);
|
static void init(void);
|
||||||
static void draw(void);
|
static void draw(void);
|
||||||
|
@ -28,7 +36,17 @@ void manif(int state) {
|
||||||
|
|
||||||
static void init(void) {
|
static void init(void) {
|
||||||
_planId = gl4dgGenQuadf();
|
_planId = gl4dgGenQuadf();
|
||||||
_herosId = gl4dgGenConef(3, GL_FALSE);
|
|
||||||
|
// Last Offset X and Z
|
||||||
|
for (int i = 0; i < HEROS_NUMBER; ++i) {
|
||||||
|
_herosId[i].corps = gl4dgGenCubef();
|
||||||
|
_herosId[i].tete = gl4dgGenSpheref(20, 20);
|
||||||
|
_herosId[i].ox = ((GLfloat)rand() / (GLfloat)RAND_MAX) * -7;
|
||||||
|
_herosId[i].oz = ((GLfloat)rand() / (GLfloat)RAND_MAX) * 10;
|
||||||
|
|
||||||
|
/* printf("Generating #%d\t=> %f:%f\n", _herosId[i].corps,
|
||||||
|
(double)_herosId[i].ox, (double)_herosId[i].oz); */
|
||||||
|
}
|
||||||
_pId =
|
_pId =
|
||||||
gl4duCreateProgram("<vs>shaders/manif.vs", "<fs>shaders/manif.fs", NULL);
|
gl4duCreateProgram("<vs>shaders/manif.vs", "<fs>shaders/manif.fs", NULL);
|
||||||
|
|
||||||
|
@ -73,13 +91,29 @@ static void draw(void) {
|
||||||
glUniform4fv(couleur_gpu, 1, couleur_plan);
|
glUniform4fv(couleur_gpu, 1, couleur_plan);
|
||||||
gl4dgDraw(_planId);
|
gl4dgDraw(_planId);
|
||||||
|
|
||||||
bindAndLoadf(matrix_model);
|
for (int i = 0; i < HEROS_NUMBER; ++i) {
|
||||||
gl4duScalef(1, 1.5, 1);
|
bindAndLoadf(matrix_model);
|
||||||
gl4duRotatef((GLfloat)(180 * deplacement / M_PI), 0, 1, 0);
|
gl4duTranslatef(0, 1, -1);
|
||||||
|
gl4duScalef(0.1f, 0.7f, 0.2f);
|
||||||
|
|
||||||
|
// Apply hero position
|
||||||
|
move(_herosId[i].ox + (float)deplacement, 0, _herosId[i].oz, CORPS);
|
||||||
|
|
||||||
|
// Draw corps
|
||||||
|
gl4duSendMatrices();
|
||||||
|
glUniform4fv(couleur_gpu, 1, couleur_heros);
|
||||||
|
gl4dgDraw(_herosId[i].corps);
|
||||||
|
|
||||||
|
bindAndLoadf(matrix_model);
|
||||||
|
move(_herosId[i].ox + (float)deplacement, 0, _herosId[i].oz, TETE);
|
||||||
|
gl4duTranslatef(0, 1.9f, -1);
|
||||||
|
gl4duScalef(0.1f, 0.2f, 0.2f);
|
||||||
|
|
||||||
|
gl4duSendMatrices();
|
||||||
|
glUniform4fv(couleur_gpu, 1, couleur_heros);
|
||||||
|
gl4dgDraw(_herosId[i].tete);
|
||||||
|
}
|
||||||
|
|
||||||
gl4duSendMatrices();
|
|
||||||
glUniform4fv(couleur_gpu, 1, couleur_heros);
|
|
||||||
gl4dgDraw(_herosId);
|
|
||||||
deplacement += 0.4 * M_PI * dt;
|
deplacement += 0.4 * M_PI * dt;
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue