TorusScene.cpp

00001 #include "TorusScene.h"
00002 #include "SimpleArrow.h"
00003 #include "Torus.h"
00004 #include "Cube.h"
00005 #include "Icosahedron.h"
00006 #include "Teapot.h"
00007 #include "TerminalObject.h"
00008 #include "DLODObject.h"
00009 #include "Textures.h"
00010 
00011 #include "TorusGenerator.h"
00012 
00013 void TorusScene::Init ()
00014 {
00015         Torus2 * torus1, * torus2, * torus3, * torus4, * torus5, *torus6;
00016         GraphicalObject * terminal_object;
00017         DLODObject * dlod_object;
00018 
00019         RawObject * space;
00020 
00021         RawObject * torus;
00022         RawObject * arrow;
00023         RawObject * cube;
00024         RawObject * icosahedron;
00025         RawObject * teapot;
00026 
00027         Light * light;
00028 
00029         GraphicalObject * big_torus;
00030 
00031 
00032         // create the different levels of detail
00033         torus1 = new Torus2 (2.0f, 1.0f, 6, 6);
00034         torus1->SetTexture (Textures::GetId (T_PERLIN3));
00035         torus1->SetColor (1.0f, 1.0f, 1.0f, 1.0f);
00036         torus2 = new Torus2 (2.0f, 1.0f, 10, 10);
00037         torus2->SetTexture (Textures::GetId (T_PERLIN3));
00038         torus2->SetColor (1.0f, 1.0f, 1.0f, 1.0f);
00039         torus3 = new Torus2 (2.0f, 1.0f, 16, 16);
00040         torus3->SetTexture (Textures::GetId (T_PERLIN3));
00041         torus3->SetColor (1.0f, 1.0f, 1.0f, 1.0f);
00042         torus4 = new Torus2 (2.0f, 1.0f, 32, 32);
00043         torus4->SetTexture (Textures::GetId (T_PERLIN3));
00044         torus4->SetColor (1.0f, 1.0f, 1.0f, 1.0f);
00045         torus5 = new Torus2 (2.0f, 1.0f, 64, 64);
00046         torus5->SetTexture (Textures::GetId (T_PERLIN3));
00047         torus5->SetColor (1.0f, 1.0f, 1.0f, 1.0f);
00048 
00049         dlod_object = new DLODObject (torus5);
00050         dlod_object->AddLevel (torus4, 30.0f);
00051         dlod_object->AddLevel (torus3, 80.0f);
00052         dlod_object->AddLevel (torus2, 160.0f);
00053         dlod_object->AddLevel (torus1, 360.0f);
00054         
00055         // create the big torus consisting of the small toruses
00056         big_torus = TorusGenerator::CreateTorus (dlod_object, 100.0f, 25.0f, 32, 16);
00057         big_torus->CalculateRelativePositions ();
00058         big_torus->position->StartPath (0, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
00059         big_torus->position->SetGlobalTransition (PP_LINEAR, 0.0f);
00060         big_torus->position->SetDuration (50000);
00061         big_torus->position->AddCheckpoint (0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 75.0f);
00062         big_torus->position->SetDuration (10000);
00063         big_torus->position->SetGlobalTransition (PP_COSINE, 0.0f);
00064         big_torus->position->CompletePath (0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1600.0f);
00065         AddObject (big_torus);
00066 
00067         // add the universe
00068         space = new TexturedCube (5000.0f, Textures::GetId (T_SPACE), false);
00069         terminal_object = new TerminalObject (space);
00070         terminal_object->position->SetConstantPosition (0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 90.0f);
00071         AddObject (terminal_object);
00072 
00073         // set up camera
00074         camera = new Camera ();
00075         camera->SetAttributes (45, 1.333, 1.0, 8000.0);
00076         camera->position->StartPath (0, -7.0f, 117.0f, 3.0f, 0.0f, 10.0f, 122.0f);
00077         camera->position->SetDuration (9000);
00078         camera->position->SetGlobalTransition (PP_LINEAR, 0.0f);
00079         camera->position->AddCheckpoint (-7.0f, 117.0f, 3.0f, 0.0f, 10.0f, 122.0f);
00080         camera->position->SetDuration (5000);
00081         camera->position->SetGlobalTransition (PP_COSINE, 0.0f);
00082         camera->position->AddCheckpoint (-7.0, 117.0, 3.0f, 0.0f, 5.0f, 162.0f);
00083         camera->position->SetDuration (5000);
00084         camera->position->SetGlobalTransition (PP_SINE, 0.0f);
00085         camera->position->AddCheckpoint (-7.0, 117.0, 3.0f, 0.0f, 0.0f, 190.0f);
00086         camera->position->SetDuration (1000);
00087         camera->position->SetGlobalTransition (PP_LINEAR, 0.0f);
00088         camera->position->AddCheckpoint (-7.0, 117.0, 3.0f, 0.0f, 0.0f, 190.0f);                        // Accelerate
00089         camera->position->SetDuration (4000);
00090         camera->position->SetGlobalTransition (PP_COSINE, 0.0f);
00091         camera->position->AddCheckpoint (-7.0f, 80.0f, 3.0f, 0.0f, 0.0f, 188.0f);                       // start raising and going back
00092         camera->position->SetDuration (4000);
00093         camera->position->SetTransitionModes (PP_COSINE, PP_LINEAR, PP_COSINE, PP_LINEAR, PP_LINEAR, PP_LINEAR);
00094         camera->position->SetParameters (0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
00095         camera->position->AddCheckpoint (40.0f, 30.0f, 18.0f, 0.0f, 0.0f, 186.0f);                      // stop, only increase x
00096         camera->position->SetDuration (3500);
00097         camera->position->SetTransitionModes (PP_LINEAR, PP_SINE, PP_SINE, PP_LINEAR, PP_LINEAR, PP_LINEAR);
00098         camera->position->SetParameters (0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
00099         camera->position->AddCheckpoint (85.0f, -6.0f, 30.0f, 0.0f, 0.0f, 184.0f);
00100         camera->position->SetDuration (2500);
00101         camera->position->SetGlobalTransition (PP_SINE, 0.0f);
00102         camera->position->AddCheckpoint (107.0f, -7.0f, 27.0f, 0.0f, 0.0f, 184.0f);
00103         camera->position->SetDuration (3000);
00104         camera->position->AddCheckpoint (107.0f, -7.0f, 27.0f, 0.0f, 0.0f, 184.0f);
00105         camera->position->SetDuration (7000);
00106         camera->position->SetTransitionModes (PP_COSINE, PP_COSINE, PP_COSINE, PP_LINEAR, PP_LINEAR, PP_LINEAR);
00107         camera->position->SetParameters (0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
00108         camera->position->AddCheckpoint (280.0f, -6.0f, 140.0f, 0.0f, 20.0f, 182.0f);
00109         camera->position->SetDuration (6000);
00110         camera->position->SetTransitionModes (PP_LINEAR, PP_LINEAR, PP_LINEAR, PP_SINE, PP_SINE, PP_SINE);
00111         camera->position->SetParameters (0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
00112         camera->position->AddCheckpoint (600.0f, -6.0f, 280.0f, 0.0f, 27.0f, 180.0f);
00113         camera->position->SetDuration (10000);
00114         camera->position->SetGlobalTransition (PP_LINEAR, 0.0f);
00115         camera->position->CompletePath (600.0f, -6.0f, 280.0f, 0.0f, 27.0f, 180.0f);
00116 
00117         // add one light
00118         light = new Light ();
00119         light->position->StartPath (0.0f, 100.0f, 0.0f, 70.0f, 0.0f, 0.0f, 0.0f);
00120         light->position->SetGlobalTransition (PP_JUMP, 1.0f);
00121         light->position->SetDuration (60000);
00122         light->position->CompletePath (0.0f, 0.0f, 70.0f, 0.0f, 0.0f, 0.0f);
00123         light->SetAmbient (0.8f, 0.8f, 0.8f, 1.0f);
00124         AddLight (light);
00125 
00126         //PrintToConsole ();
00127 
00128 }
00129 
00130 void TorusScene::TorusTest (RawObject * raw_object, double r_t, double r_p, int rings, int slices)
00131 {
00132         GroupObject * group;
00133         GroupObject * group2;
00134         GraphicalObject * obj;
00135         Point   point;
00136 
00137         int counter = 0;
00138         int max = slices / 2;
00139         group = new GroupObject ();
00140 
00141         int counter2 = 0;
00142         int max2 = 2;
00143         group2 = new GroupObject ();
00144 
00145         TorusGenerator::StartTorus (r_t, r_p, rings, slices);
00146 
00147         while (TorusGenerator::HasMore ())
00148         {
00149                 obj = new TerminalObject (raw_object);
00150                 point = TorusGenerator::GetNextPoint ();
00151                 obj->position->SetConstantPosition (point.x, point.y, point.z, 0.0f, 0.0f, 0.0f);
00152 
00153                 group->AddChild (obj);
00154 
00155                 counter++;
00156                 if (counter == max)
00157                 {
00158                         group2->AddChild (group);
00159                         group = new GroupObject ();
00160                         counter = 0;
00161                         counter2++;
00162                 }
00163 
00164                 if (counter2 == max2)
00165                 {
00166                         AddObject (group2);
00167                         group2 = new GroupObject ();
00168                         counter2 = 0;
00169                 }
00170 
00171         }
00172 }

Generated on Sun Jul 2 13:20:39 2006 for Demo by  doxygen 1.4.6-NO