01 #include 02 #include 03 #include 04 #include 05 #include 06 #include 07 #include 08 #include 09 #include 10 #include 11 #include 12 #include 13 14 // Insert Code for Listing 1 and 2 here 15 16 int main(int argc, char ** argv) 17 { 18 // Initialize SoQt (creates a Qt window) 19 QWidget *window = SoQt::init("main"); 20 21 // Create scene graph 22 SoSeparator *root = new SoSeparator; 23 root->ref(); 24 25 // Spotlight scene: also creates shadow 26 SoSpotLight *light = new SoSpotLight; 27 light->location.setValue(0,0,2); 28 light->direction.setValue(0,0,-1); 29 light->cutOffAngle = 1.5; 30 root->addChild(light); 31 32 // Group node for rotating earth 33 SoSeparator *earth = new SoSeparator; 34 35 // Set rotation node 36 SoRotationXYZ *earthrotation = new SoRotationXYZ; 37 earthrotation->axis.setValue("Y"); 38 earth->addChild(earthrotation); 39 40 // Add earth to scene 41 earth->addChild(drawEarth()); 42 43 // Set Counter 44 SoTimeCounter *counter = new SoTimeCounter; 45 counter->max=360; 46 counter->step=1; 47 counter->frequency=0.03; 48 49 // Convert values: Degrees -> Rad 50 SoCalculator *converter = new SoCalculator; 51 converter->a.connectFrom(&counter->output); 52 converter->expression.set1Value(0,"oa=a/(2*M_PI)"); 53 54 // Connect counter to earth rotation node 55 earthrotation->angle.connectFrom(&converter->oa); 56 57 // Add earth group node 58 root->addChild(earth); 59 60 // Create group node for plane 61 SoSeparator *plane = new SoSeparator; 62 63 // Move plane from center of scene 64 SoTranslation *altitude = new SoTranslation; 65 altitude->translation.setValue(0,0,1.2); 66 plane->addChild(altitude); 67 68 // Scale plane down and turn through 90 69 SoScale *scale = new SoScale; 70 scale->scaleFactor.setValue(0.0025,0.0025,0.0025); 71 plane->addChild(scale); 72 SoRotationXYZ *course = new SoRotationXYZ; 73 course->axis.setValue("Y"); 74 course->angle = 1.5707963; 75 plane->addChild(course); 76 77 // Read plane geometry from file 78 plane->addChild(loadGeometry("boeing767.iv")); 79 80 // Add plane to scene 81 root->addChild(plane); 82 83 // Create viewer 84 SoQtExaminerViewer *b = new SoQtExaminerViewer(window); 85 b->setSceneGraph(root); 86 b->setHeadlight(FALSE); 87 b->show(); 88 89 // Show windows and wait for "Exit" 90 SoQt::show(window); 91 SoQt::mainLoop(); 92 93 // Delete viewer and scene reference 94 delete b; 95 root->unref(); 96 97 return 0; 98 }