#include #include "Go.h" #include "GoGlutInterface.h" #include "GoSphere.h" class GoSphereDemo : public GoGlutInterface { public: GoSphere *sphere; int sphereType; GoMatrix currentModelview; int xStart; int yStart; enum { SMOOTH, FLAT, WIRE, SMOOTH_WITH_WIRE }; GoSphereDemo(int sphereType) { this->sphereType = sphereType; // // Create a sphere to illustrate this demo. // sphere = new GoSphere(1.0, 16, 16); // // Turn on LIGHT_0 // go->light(Go::LIGHT_0, true); go->light(Go::LIGHT_0, Go::DIRECTIONAL, 1.0, 1.0, 1.0); } // // Interface render method. // void render(void) { // // Clear. // go->clear(Go::IMAGE); // // Draw. // switch(sphereType) { case SMOOTH: go->color(0, 0, 1); // blue solid sphere->renderSolid(go); break; case FLAT: go->enable(Go::FLAT_SHADE); go->color(0, 0, 1); // blue solid sphere->renderSolid(go); go->disable(Go::FLAT_SHADE); break; case WIRE: go->color(1, 1, 0); // yellow wire sphere->renderWire(go); break; case SMOOTH_WITH_WIRE: go->color(0, 0, 1); // blue solid sphere->renderSolid(go); go->color(1, 1, 0); // yellow wire sphere->renderWire(go); break; } // // Display. // swap(); } // // Interface resized method. // void resized(int width, int height) { // // Setup projection matrix. // go->push(Go::MATRIX_MODE); go->matrixMode(Go::PROJECTION); go->identity(); if(width > height) { go->ortho(-1.0 * width / height, 1.0 * width / height, -1.0, 1.0, -1.0, 1.0); } else { go->ortho(-1.0, 1.0, -1.0 * height / width, 1.0 * height / width, -1.0, 1.0); } go->pop(Go::MATRIX_MODE); } // // Interface mousePressed method. // void mousePressed(int x, int y) { // // Save values that will be used to track the // mouse in the mouseDragged() method. // xStart = x; yStart = y; go->getModelview(¤tModelview); } // // Interface mouseDragged method. // void mouseDragged(int x, int y) { int xEnd = x; int yEnd = y; // // Setup modelview matrix based on mouse position. // go->identity(); double xTheta = (yEnd - yStart) / 2; double yTheta = (xEnd - xStart) / 2; go->rotate(xTheta, 1, 0, 0); go->rotate(yTheta, 0, 1, 0); // // Post multiply current modelview matrix. // go->multiply(¤tModelview); // // Redisplay. // rerender(); } }; void usage(void) { fprintf(stderr, "Usage: sphere [ smooth | flat | wire | smoothWithWire ]\n"); exit(1); } int main(int argc, char *argv[]) { if(argc != 2) { usage(); } GoGlutInterface::init(&argc, argv); if(strcmp(argv[1], "smooth") == 0) { new GoSphereDemo(GoSphereDemo::SMOOTH); } else if(strcmp(argv[1], "flat") == 0) { new GoSphereDemo(GoSphereDemo::FLAT); } else if(strcmp(argv[1], "wire") == 0) { new GoSphereDemo(GoSphereDemo::WIRE); } else if(strcmp(argv[1], "smoothWithWire") == 0) { new GoSphereDemo(GoSphereDemo::SMOOTH_WITH_WIRE); } else { usage(); } GoGlutInterface::mainLoop(); return(0); }