diff options
Diffstat (limited to 'glass.c')
-rw-r--r-- | glass.c | 22 |
1 files changed, 17 insertions, 5 deletions
@@ -43,6 +43,7 @@ #define DEFAULT_WIDTH 600 #define DEFAULT_HEIGHT 700 +#define NUM_RINGS 27 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) @@ -97,6 +98,7 @@ static GLUvec4 eye_center_world = {{0.0, 1.0, 2.0, 1.0}}; static GLUvec4 light_eye; GLUmat4 projection; GLUmat4 world_to_eye; +GLUmat4 ring_obj_to_world[NUM_RINGS]; static time_t start_tv_sec = 0; static float start_time, cur_time, last_fps_time = 0; @@ -187,12 +189,12 @@ do_ring_drawelements(void) } static void -install_transform(int instance) +calc_new_ring_transforms(int instance) { int x_index = (instance / 3) / 3 - 1; int y_index = (instance / 3) % 3 - 1; int z_index = instance % 3; - GLUmat4 mv, mvp, obj_to_world, temp; + GLUmat4 obj_to_world, temp; /* Have the ring spinning on its axis slowly. */ obj_to_world = gluRotate4v(&z_axis, cur_time * 2 * M_PI / 20); @@ -221,10 +223,16 @@ install_transform(int instance) temp = gluTranslate3(x_index * 5.0, 10 + y_index * 5.0, 7.0 + z_index * 5.0); - obj_to_world = gluMult4m_4m(&temp, &obj_to_world); + ring_obj_to_world[instance] = gluMult4m_4m(&temp, &obj_to_world); +} + +static void +install_transform(int instance) +{ + GLUmat4 mv, mvp; /* Generate the whole mvp */ - mv = gluMult4m_4m(&world_to_eye, &obj_to_world); + mv = gluMult4m_4m(&world_to_eye, &ring_obj_to_world[instance]); mvp = gluMult4m_4m(&projection, &mv); glUniformMatrix4fv(uniforms[UNIFORM_MV].location, 1, 0, @@ -245,7 +253,7 @@ draw_rings(void) glBindVertexArray(ring.array_obj); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, ring.vbo); - for (instance = 0; instance < 27; instance++) { + for (instance = 0; instance < NUM_RINGS; instance++) { install_transform(instance); do_ring_drawelements(); } @@ -255,6 +263,8 @@ draw_rings(void) static void draw(void) { + int instance; + glClearColor(0.0, 0.0, 0.8, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -262,6 +272,8 @@ draw(void) glEnable(GL_DEPTH_TEST); update_light_position(); + for (instance = 0; instance < NUM_RINGS; instance++) + calc_new_ring_transforms(instance); glViewport(0, 0, win_width, win_height); |