| 481 | | |
| | 481 | === Exercises #3 === |
| | 482 | 1. Introduce zoom in/out functionality of the viewer by adding mouse wheel events to the end of `mouse()` |
| | 483 | {{{ |
| | 484 | #!c |
| | 485 | if (button == 3 && state == GLUT_DOWN) |
| | 486 | { zoom *= 1.1; glutPostRedisplay(); } |
| | 487 | else if (button == 4 && state == GLUT_DOWN) |
| | 488 | { zoom /= 1.1; glutPostRedisplay(); } |
| | 489 | }}} |
| | 490 | and introduction of global variable `float zoom = 1.0;` that is communicated to GPU by additional `uniform float Zoom;` in the `vertex_shader[]`. Last line is replaced by |
| | 491 | {{{ |
| | 492 | #!c |
| | 493 | gl_Position = gl_ProjectionMatrix * RotationMatrix \ |
| | 494 | * gl_ModelViewMatrix*vec4(Zoom*gl_Vertex.xyz, 1.0); \ |
| | 495 | }}} |
| | 496 | In the `display()` we add zooming by |
| | 497 | {{{ |
| | 498 | #!c |
| | 499 | location = glGetUniformLocation(p, "Zoom"); |
| | 500 | if (location >= 0) glUniform1f(location, zoom); |
| | 501 | }}} |