#include #include #include #include #include #include #include #include #include #include #include #include #include #include "final1.h" /* Globals */ /* global lights */ extern GLfloat white_light []; extern GLfloat amb_light []; /* global colors */ extern float color [4]; extern float amb_color [4]; /* global lookat position */ extern float lookat [3]; /* global adjustment scales */ extern GtkAdjustment *light_scale; extern GtkAdjustment *ambient_scale; extern GtkAdjustment *red_scale; extern GtkAdjustment *green_scale; extern GtkAdjustment *blue_scale; extern GtkAdjustment *rotation_scale; /* signal handler functions */ void reset_controls (GtkWidget *widget, gpointer gdata) { /* this function resets all of the window controls */ /* first, reset the values to the original state */ init_values (); /* now, reset, the sliders in the window to reflect these reset values */ gtk_adjustment_set_value (rotation_scale, CAMERA_ROTATION_INIT); gtk_adjustment_set_value (light_scale, LIGHT_SCALE_INIT); /** RESET ambient_scale, red_scale, green_scale, AND blue_scale HERE **/ redraw (); } void light_change (GtkAdjustment *adj) { /* get the updated value and redraw the image */ white_light [0] = white_light [1] = white_light [2] = (GLfloat) adj->value; redraw (); } void ambient_change (GtkAdjustment *adj) { /** INSERT CODE HERE **/ } void red_change (GtkAdjustment *adj) { color [RED] = (GLfloat) adj->value; redraw (); } /** WRITE green_change AND blue_change USING THE ABOVE FUNCTIONS AS GUIDES; DON'T FORGET TO ADD THEIR FUNCTION PROTOTYPES TO THE final2.h FILE **/ void rotation_change (GtkAdjustment *adj) { /* this function rotates the camera around the origin when there is a change in the rotation slider */ float deg; float rad; deg = 180 + adj -> value; rad = (deg / 360.0) * 2 * PI; lookat [0] = 5 * fsin (rad); lookat [2] = 5 * fcos (rad); redraw (); } void init_values () { /* initialize white_light for the spotlight */ white_light [0] = white_light [1] = white_light [2] = LIGHT_SCALE_INIT; white_light [3] = 1.0; /** INITIALIZE amb_light **/ /* initialize sphere color */ color [0] = COLOR_R_INIT; color [1] = COLOR_G_INIT; color [2] = COLOR_B_INIT; color [3] = 1.0; /** INITIALIZE SPHERE amb_color **/ } gint destroyapp (GtkWidget *widget, gpointer gdata) { /* this function is called when the user quits */ g_print("Quitting...\n"); gtk_main_quit(); /* ... Ok to be closed. TRUE would prevent window from closing ... */ return(FALSE); }