main.C

Go to the documentation of this file.
00001 /*
00002  * This file is part of the "Archon" framework.
00003  * (http://files3d.sourceforge.net)
00004  *
00005  * Copyright © 2002 by Kristian Spangsege and Brian Kristiansen.
00006  *
00007  * Permission to use, copy, modify, and distribute this software and
00008  * its documentation under the terms of the GNU General Public License is
00009  * hereby granted. No representations are made about the suitability of
00010  * this software for any purpose. It is provided "as is" without express
00011  * or implied warranty. See the GNU General Public License
00012  * (http://www.gnu.org/copyleft/gpl.html) for more details.
00013  *
00014  * The characters in this file are ISO8859-1 encoded.
00015  *
00016  * The documentation in this file is in "Doxygen" style
00017  * (http://www.doxygen.org).
00018  */
00019 
00036 #include <iostream>
00037 
00038 #include <archon/math/vector.H>
00039 #include <archon/util/time.H>
00040 #include <archon/util/thread.H>
00041 #include <archon/util/ref.H>
00042 #include <archon/util/options.H>
00043 #include <archon/util/polygon_mesher.H>
00044 
00045 #include <archon/x3d/proxy/exception.H>
00046 #include <archon/x3d/proxy/proxy.H>
00047 
00048 using namespace std;
00049 using namespace Archon;
00050 using namespace Archon::Math;
00051 using namespace Archon::Utilities;
00052 using namespace Archon::X3D::Proxy;
00053 
00054 namespace Archon
00055 {
00056   namespace SaiTestApps
00057   {
00058     namespace Spot
00059     {
00060       static bool quit = false;
00061 
00062       Ref<SpotLight> redSpot;
00063       Ref<SpotLight> greenSpot;
00064       Ref<SpotLight> blueSpot;
00065 
00066       void toggleRed(Time)
00067       {
00068         static bool on = true;
00069         on = !on;
00070         if(redSpot) redSpot->on = on;
00071       }
00072 
00073       void toggleGreen(Time)
00074       {
00075         static bool on = true;
00076         on = !on;
00077         if(greenSpot) greenSpot->on = on;
00078       }
00079 
00080       void toggleBlue(Time)
00081       {
00082         static bool on = true;
00083         on = !on;
00084         if(blueSpot) blueSpot->on = on;
00085       }
00086 
00087       int main(int argc, const char *argv[])
00088       {
00089         bool   opt_help              = false;
00090         int    opt_corbaEndpointPort = -1; // Auto assign
00091         string opt_serverName        = "archon";
00092         
00093         Options o;
00094 
00095         o.addSwitch("h", "help", opt_help, true,
00096                     "Describe the parameters");
00097         o.addConfig("p", "corba-endpoint-port", opt_corbaEndpointPort, opt_corbaEndpointPort,
00098                     "The TCP/IP port on which the CORBA Orb listens (-1 for auto assign)",
00099                     Options::wantArg_always);
00100         o.addConfig("n", "server-name", opt_serverName, opt_serverName,
00101                     "The name of the server to connect to",
00102                     Options::wantArg_always);
00103         
00104         if(o.processCommandLine(argc, argv))
00105         {
00106           cerr << "Try --help\n";
00107           return 1;
00108         }
00109 
00110         if(opt_help)
00111         {
00112           cout <<
00113             "Test Application for 3D-Console by Brian Kristiansen & Kristian Spangsege\n"
00114             "\n"
00115             "Synopsis: " << argv[0] << "\n"
00116             "\n"
00117             "Available options:\n";
00118           cout << o.list();
00119           return 0;
00120         }
00121 
00122         if(argc > 1)
00123         {
00124           cerr << "Too many aguments\n";
00125           cerr << "Try --help\n";
00126           return 1;
00127         }
00128 
00129         // Create a mesh
00130         double a = 10;
00131         vector<Vector3> outline;
00132         for(unsigned i=0; i<50; ++i)
00133         {
00134           double v = 2*M_PI/50*i;
00135           outline.push_back(Vector3(a*cos(v), 0, -a*sin(v)));
00136         }
00137         vector<Vector3> meshVertices;
00138         vector<int> meshPolygons;
00139         meshPolygon(outline, 0.25, meshVertices, meshPolygons);
00140 
00141         Ref<Session> session =
00142           Session::create(opt_serverName, opt_corbaEndpointPort);
00143 
00144         Ref<Application> application =
00145           Application::create(session, Uri());
00146 
00147         session->beginUpdate();
00148 
00149         Ref<Group> rootGroup = Group::create(application);
00150 
00151         Ref<Transform> rootTransform = Transform::create(application);
00152         rootTransform->scale = Vector3(1, 1, 1);
00153         rootTransform->translation = Vector3(0, -6, 0);
00154         rootGroup->children.add(rootTransform);
00155 
00156         Ref<Coordinate> coord = Coordinate::create(application);
00157         coord->point = meshVertices;
00158         Ref<IndexedFaceSet> indexedFaceSet = IndexedFaceSet::create(application);
00159         indexedFaceSet->coord = coord;
00160         indexedFaceSet->coordIndex = meshPolygons;
00161         Ref<Shape> shape = Shape::create(application);
00162         shape->geometry = indexedFaceSet;
00163         Ref<Appearance> appearance = Appearance::create(application);
00164         appearance->material = Material::create(application);
00165 
00166         /*
00167           Ref<ImageTexture> texture = ImageTexture::create(context);
00168           vector<string> url;
00169           url.push_back("clock.png");
00170           texture->setUrl(url);
00171           apperance->setTexture(texture);
00172         */
00173 
00174         shape->appearance = appearance;
00175 
00176         vector<Ref<ChildNode> > children1;
00177         children1.push_back(shape);
00178 
00179         vector<double> keys;
00180         keys.push_back(0.0/3);
00181         keys.push_back(1.0/3);
00182         keys.push_back(2.0/3);
00183         keys.push_back(3.0/3);
00184 
00185         vector<Rotation3> keyValues;
00186         keyValues.push_back(Rotation3(Vector3(cos(2*M_PI*0/3), 0, -sin(2*M_PI*0/3)), 0.3));
00187         keyValues.push_back(Rotation3(Vector3(cos(2*M_PI*1/3), 0, -sin(2*M_PI*1/3)), 0.3));
00188         keyValues.push_back(Rotation3(Vector3(cos(2*M_PI*2/3), 0, -sin(2*M_PI*2/3)), 0.3));
00189         keyValues.push_back(Rotation3(Vector3(cos(2*M_PI*3/3), 0, -sin(2*M_PI*3/3)), 0.3));
00190 
00191         {
00192           Ref<SpotLight> spot = SpotLight::create(application);
00193           redSpot = spot;
00194           spot->color = Vector3(1, 0, 0);
00195           spot->beamWidth = M_PI*1/8;
00196           spot->cutOffAngle = M_PI*3/8;
00197           spot->direction = Vector3(0, -1, 0);
00198           Ref<Transform> transform = Transform::create(application);
00199           transform->translation = Vector3(2*cos(2*M_PI*0/3), 10, -2*sin(2*M_PI*0/3));
00200           Ref<OrientationInterpolator> orient = OrientationInterpolator::create(application);
00201           orient->key = keys;
00202           orient->keyValue = keyValues;
00203           application->createRoute(orient->value_changed, transform->rotation);
00204           Ref<TimeSensor> time = TimeSensor::create(application);
00205           time->cycleInterval = Time(2.1);
00206           application->createRoute(time->fraction_changed, orient->set_fraction);
00207           time->loop = true;
00208    
00209     
00210           Ref<Cylinder> cyl = Cylinder::create(application);
00211           cyl->radius = 0.2;
00212           cyl->height = 0.5;
00213           Ref<Material> mat = Material::create(application);
00214           mat->diffuseColor = Vector3(1, 0.5, 0.5);
00215           Ref<Appearance> appearance = Appearance::create(application);
00216           appearance->material = mat;
00217           Ref<Shape> shape = Shape::create(application);
00218           shape->geometry = cyl;
00219           shape->appearance = appearance;
00220     
00221           Ref<TouchSensor> touch = TouchSensor::create(application);
00222           touch->touchTime.registerInterest<SFTime>(new FuncCaller<SFTime>(toggleRed));
00223 
00224           vector<Ref<ChildNode> > children;
00225           children.push_back(spot);
00226           children.push_back(orient);
00227           children.push_back(time);
00228           children.push_back(shape);
00229           children.push_back(touch);
00230           transform->children = children;
00231           children1.push_back(transform);
00232         }
00233 
00234         {
00235           Ref<SpotLight> spot = SpotLight::create(application);
00236           greenSpot = spot;
00237           spot->color = Vector3(0, 1, 0);
00238           spot->beamWidth = M_PI*1/8;
00239           spot->cutOffAngle = M_PI*3/8;
00240           spot->direction = Vector3(0, -1, 0);
00241           Ref<Transform> transform = Transform::create(application);
00242           transform->translation = Vector3(2*cos(2*M_PI*1/3), 10, -2*sin(2*M_PI*1/3));
00243           Ref<OrientationInterpolator> orient = OrientationInterpolator::create(application);
00244           orient->key = keys;
00245           orient->keyValue = keyValues;
00246           application->createRoute(orient->value_changed, transform->rotation);
00247           Ref<TimeSensor> time = TimeSensor::create(application);
00248           time->cycleInterval = Time(2.4);
00249           application->createRoute(time->fraction_changed, orient->set_fraction);
00250           time->loop = true;
00251 
00252           Ref<Cylinder> cyl = Cylinder::create(application);
00253           cyl->radius = 0.2;
00254           cyl->height = 0.5;
00255           Ref<Material> mat = Material::create(application);
00256           mat->diffuseColor = Vector3(0.5, 1, 0.5);
00257           Ref<Appearance> appearance = Appearance::create(application);
00258           appearance->material = mat;
00259           Ref<Shape> shape = Shape::create(application);
00260           shape->geometry = cyl;
00261           shape->appearance = appearance;
00262 
00263           Ref<TouchSensor> touch = TouchSensor::create(application);
00264           touch->touchTime.registerInterest<SFTime>(new FuncCaller<SFTime>(toggleGreen));
00265     
00266           vector<Ref<ChildNode> > children;
00267           children.push_back(spot);
00268           children.push_back(orient);
00269           children.push_back(time);
00270           children.push_back(shape);
00271           children.push_back(touch);
00272           transform->children = children;
00273           children1.push_back(transform);
00274         }
00275 
00276         {
00277           Ref<SpotLight> spot = SpotLight::create(application);
00278           blueSpot = spot;
00279           spot->color = Vector3(0, 0, 1);
00280           spot->beamWidth = M_PI*1/8;
00281           spot->cutOffAngle = M_PI*3/8;
00282           spot->direction = Vector3(0, -1, 0);
00283           Ref<Transform> transform = Transform::create(application);
00284           transform->translation = Vector3(2*cos(2*M_PI*2/3), 10, -2*sin(2*M_PI*2/3));
00285           Ref<OrientationInterpolator> orient = OrientationInterpolator::create(application);
00286           orient->key = keys;
00287           orient->keyValue = keyValues;
00288           application->createRoute(orient->value_changed, transform->rotation);
00289           Ref<TimeSensor> time = TimeSensor::create(application);
00290           time->cycleInterval = Time(2.7);
00291           application->createRoute(time->fraction_changed, orient->set_fraction);
00292           time->loop = true;
00293 
00294           Ref<Cylinder> cyl = Cylinder::create(application);
00295           cyl->radius = 0.2;
00296           cyl->height = 0.5;
00297           Ref<Material> mat = Material::create(application);
00298           mat->diffuseColor = Vector3(0.5, 0.5, 1);
00299           Ref<Appearance> appearance = Appearance::create(application);
00300           appearance->material = mat;
00301           Ref<Shape> shape = Shape::create(application);
00302           shape->geometry = cyl;
00303           shape->appearance = appearance;
00304 
00305           Ref<TouchSensor> touch = TouchSensor::create(application);
00306           touch->touchTime.registerInterest<SFTime>(new FuncCaller<SFTime>(toggleBlue));
00307 
00308           vector<Ref<ChildNode> > children;
00309           children.push_back(spot);
00310           children.push_back(orient);
00311           children.push_back(time);
00312           children.push_back(shape);
00313           children.push_back(touch);
00314           transform->children = children;
00315           children1.push_back(transform);
00316         }
00317 
00318         rootTransform->children = children1;
00319         session->endUpdate();
00320 
00321         application->setRootGroup(rootGroup);
00322         application->launch();
00323 
00324         Archon::Utilities::Time delay(0, 100000000l);
00325         while(!quit)
00326         {
00327           session->beginUpdate();
00328           session->endUpdate();
00329 
00330           Archon::Utilities::Thread::sleep(delay);
00331         }
00332 
00333         return 0;
00334       }
00335     }
00336   }
00337 }
00338 
00339 int main(int argc, const char *argv[]) throw()
00340 {
00341   using namespace Archon::X3D;
00342 
00343   set_unexpected(Exception::terminal<Proxy::exceptionCatchInfo>);
00344   set_terminate (Exception::terminal<Proxy::exceptionCatchInfo>);
00345 
00346   return Archon::SaiTestApps::Spot::main(argc, argv);
00347 }

Generated on Sun Jul 30 22:55:41 2006 for Archon by  doxygen 1.4.4