/* * ex2.c -- A more complex example program for SOOGL. * * Draw a pulsing teapot in the middle of the screen. * There is a point light spinning around the teapot. * * Copyright (c) Blair MacIntyre, The Georgia Institute of Technology, 1999. */ #include "soogl.h" #include /* A dynamic property that rotates around the z axis from (-50..10) degrees * every half second. We will use this to simulate pouring tea. */ void pour(int time, GLfloat *returnMatrix) { GLfloat rz = sin(time/500.0)*30.0 - 20.0; sooglRotateZMatrix(rz, returnMatrix); } /* These two dynamic properties, when applied together, send the attached * nodes (the lights, in this case) in a looping spin about the origin. */ void spinY(int time, GLfloat *returnMatrix) { GLfloat ry = (time/3333.0)*360.0; sooglRotateYMatrix(ry, returnMatrix); } void spinZ(int time, GLfloat *returnMatrix) { GLfloat rz = (time/2000.0)*360.0; sooglRotateZMatrix(rz, returnMatrix); } int main(int argc, char **argv) { int camera, window, root, lightAmb, light1, group1, group2, group3, teapot, sphere; /* initialize the retained mode package, including initializing GLUT */ sooglInit(&argc, argv); /* create a window */ glutInitWindowPosition(10, 10); glutInitWindowSize(500, 500); window = glutCreateWindow("Lit teapot"); /* create a camera */ camera = sooglNewCamera(0.0, 0.0, 30.0, /* eye is at (0,0,30) */ 0.0, 0.0, 0.0, /* center is at (0,0,0) */ 0.0, 1.0, 0.0, /* up is in positive Y direction */ 40.0, /* field of view in degree */ 1.0, /* aspect ratio */ 1.0, /* Z near */ 100.0);/* Z far */ /* create a root object, using this window and camera, and using a viewport that covers the entire window */ root = sooglNewRoot(window, camera); sooglSetShadeModel(root, SOOGL_SMOOTH_SHADE); /* create an ambient light */ lightAmb = sooglNewAmbient(0.25, 0.25, 0.25); sooglAddChild(root, lightAmb); /*********************** * Create two moving point light sources, with little icons for them (small * spheres). ***********************/ /* First, create two groups, and set them to rotating about the Y and Z axes. * Add the top group to the root. */ group3 = sooglNewGroup(); sooglAddChild(root, group3); group1 = sooglNewGroup(); sooglAddChild(group3, group1); sooglSetTransformationFunc(group3, spinY); sooglSetTransformationFunc(group1, spinZ); /* Next add a small green sphere to group1, and translate it to (6,0,0) */ sphere = sooglNewSphere(0.25, 10); sooglTranslate(sphere, 6, 0.0, 0.0); sooglSetMaterial(sphere, 0.2, 1.0, 0.2); /* Next, add a green point light at (6,0,0) to the second. */ light1 = sooglNewPositionalLight(0.6, 1.5, 0.4, /* green-tinted */ 6.0, 0.0, 0.0, /* out on the x axis */ 1.0, 0.0, 0.0); sooglAddChild(group1, sphere); sooglAddChild(group1, light1); /* Create a 2nd moving red point light source that is on the opposite side * of the teapot. */ sphere = sooglNewSphere(0.25, 10); sooglTranslate(sphere, -6.0, 0.0, 0.0); sooglSetMaterial(sphere, 1.0, 0.2, 0.2); light1 = sooglNewPositionalLight(1.5, 0.4, 0.6, /* red-tinted */ -6.0, 0.0, 0.0, /* out on the x axis */ 1.0, 0.0, 0.0); sooglAddChild(group1, sphere); sooglAddChild(group1, light1); /****************** * Add a rocking group containing a teapot to the root ******************/ /* First, create a group, and set it to pulsing (from 0.5 .. 0.1) */ group2 = sooglNewGroup(); sooglAddChild(root, group2); sooglSetTransformationFunc(group2, pour); teapot = sooglNewTeapot(4.0); sooglAddChild(group2, teapot); /* go! */ glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }