Homework 5 |
Modified: |

GLfloat fy( GLFloat x, GLfloat z) { return 2*x*x+2*z*z-1.0; }
when plotted for values x=-1..1 and z=-1..1 produces a 3D graph similar to the figure at right centered at the origin, when looking directly down the negative z-axis.
Hint: To implement a general function plotter requires passing the function to be plotted. A function f can be passed a function as parameter p in C or C++ by defined as:
void f( int p( int ), int y ) { printf( "%d", p( y ) ); }
int square( int x ) { return x*x; }
f( square, 3); // Prints 9
There should be two viewing modes, one from a viewpoint on a hemisphere (from Question 1) viewing both cubes, the second from the small cube able to view its surroundings.
Hints:
- glutSpecialFunc(specialKey);
and:
- void specialKey(int key, int x, int y) {
if(key==GLUT_KEY_UP) { ... }
3. Modify Question 2 solution so that the big cube is replaced by the function plot from Question 1 and that the small cube can move through the plot.