X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=demo_prior;a=blobdiff_plain;f=src%2Fpart_whitted.c;fp=src%2Fpart_whitted.c;h=7154abf7ce15fef40bcd34fc61d9336795fbaa42;hp=0000000000000000000000000000000000000000;hb=6a752049e496c93a61e0130348f71888583d743c;hpb=646e75fcb6bdb93c853f6706c23d809c2c63415c diff --git a/src/part_whitted.c b/src/part_whitted.c new file mode 100644 index 0000000..7154abf --- /dev/null +++ b/src/part_whitted.c @@ -0,0 +1,94 @@ +#include "opengl.h" +#include "demo.h" +#include "part.h" + +static int init(void); +static void destroy(void); +static void start(void); +static void stop(void); +static void draw(long tm); +static void mbutton(int bn, int st, int x, int y); +static void mmotion(int x, int y); + +static float cam_theta, cam_phi, cam_dist = 8; + +static int bnstate[8]; +static int mouse_x, mouse_y; + +static struct demo_part part = { + "whitted", + 0, 0, + init, destroy, + start, stop, + draw, + 0, 0, + 0, 0, + mbutton, mmotion +}; + +void reg_whitted(void) +{ + add_part(&part); +} + + +static int init(void) +{ + return 0; +} + +static void destroy(void) +{ +} + +static void start(void) +{ +} + +static void stop(void) +{ +} + +static void draw(long tm) +{ + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0, 0, -cam_dist); + glRotatef(cam_phi, 1, 0, 0); + glRotatef(cam_theta, 0, 1, 0); + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + glFrontFace(GL_CW); + glutSolidTeapot(1.0); + glFrontFace(GL_CCW); +} + +static void mbutton(int bn, int st, int x, int y) +{ + bnstate[bn] = st; + mouse_x = x; + mouse_y = y; +} + +static void mmotion(int x, int y) +{ + int dx = x - mouse_x; + int dy = y - mouse_y; + mouse_x = x; + mouse_y = y; + + if(!(dx | dy)) return; + + if(bnstate[0]) { + cam_theta += dx * 0.5; + cam_phi += dy * 0.5; + if(cam_phi < -90) cam_phi = -90; + if(cam_phi > 90) cam_phi = 90; + } + if(bnstate[2]) { + cam_dist += dy * 0.1; + if(cam_dist < 0) cam_dist = 0; + } +}