00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00030 #include <iostream>
00031
00032 #include <archon/math/vector.H>
00033 #include <archon/util/time.H>
00034 #include <archon/util/mutex.H>
00035 #include <archon/util/ref.H>
00036 #include <archon/util/options.H>
00037
00038 #include <archon/x3d/proxy/exception.H>
00039 #include <archon/x3d/proxy/proxy.H>
00040
00041 namespace Archon
00042 {
00043 namespace SaiTestApps
00044 {
00045 namespace Clock
00046 {
00047 using namespace std;
00048 using namespace Math;
00049 using namespace Utilities;
00050 using namespace X3D::Proxy;
00051
00052 static bool quit = false;
00053 static Ref<Material> quitMaterial;
00054
00055 static bool fastForward = false;
00056 static Ref<Material> fastForwardMaterial;
00057
00058 void quitIsOver(const bool v)
00059 {
00060 quitMaterial->diffuseColor = (v ? Vector3(1, 0, 0) : Vector3(0.8, 0.3, 0.3));
00061 }
00062
00063 void quitTouch(const Time)
00064 {
00065 quit = true;
00066 }
00067
00068 void fastForwardIsOver(const bool v)
00069 {
00070 fastForwardMaterial->diffuseColor = (v ? Vector3(0, 1, 0) : Vector3(0.3, 0.8, 0.3));
00071 }
00072
00073 void fastForwardTouch(const Time)
00074 {
00075 fastForward = !fastForward;
00076 }
00077
00078 int main(int argc, const char *argv[])
00079 {
00080 bool opt_help = false;
00081 int opt_corbaEndpointPort = -1;
00082 string opt_serverName = "archon";
00083
00084 Options o;
00085
00086 o.addSwitch("h", "help", opt_help, true,
00087 "Describe the parameters");
00088 o.addConfig("p", "corba-endpoint-port", opt_corbaEndpointPort, opt_corbaEndpointPort,
00089 "The TCP/IP port on which the CORBA Orb listens (-1 for auto assign)",
00090 Options::wantArg_always);
00091 o.addConfig("n", "server-name", opt_serverName, opt_serverName,
00092 "The name of the server to connect to",
00093 Options::wantArg_always);
00094
00095 if(o.processCommandLine(argc, argv))
00096 {
00097 cerr << "Try --help\n";
00098 return 1;
00099 }
00100
00101 if(opt_help)
00102 {
00103 cout <<
00104 "Test Application for 3D-Console by Brian Kristiansen & Kristian Spangsege\n"
00105 "\n"
00106 "Synopsis: " << argv[0] << "\n"
00107 "\n"
00108 "Available options:\n";
00109 cout << o.list();
00110 return 0;
00111 }
00112
00113 if(argc > 1)
00114 {
00115 cerr << "Too many aguments\n";
00116 cerr << "Try --help\n";
00117 return 1;
00118 }
00119
00120 Ref<Session> session =
00121 Session::create(opt_serverName, opt_corbaEndpointPort);
00122
00123 Ref<Application> application =
00124 Application::create(session, Uri());
00125
00126 session->beginUpdate();
00127
00128 Ref<Group> rootGroup = Group::create(application);
00129
00130 Ref<Transform> rootTransform = Transform::create(application);
00131 rootTransform->rotation = Rotation3(Vector3(1, 0, 0), M_PI/2);
00132 rootTransform->scale = Vector3(8, 8, 8);
00133 rootGroup->children.add(rootTransform);
00134
00135 {
00136 Ref<Cylinder> cyl = Cylinder::create(application);
00137 cyl->side = false;
00138 cyl->top = true;
00139 cyl->bottom = false;
00140 cyl->height = 0.1;
00141 Ref<Shape> shape = Shape::create(application);
00142 shape->geometry = cyl;
00143 Ref<Appearance> apperance = Appearance::create(application);
00144 apperance->material = Material::create(application);
00145 Ref<ImageTexture> texture = ImageTexture::create(application);
00146 texture->url.add("clock.png");
00147 apperance->texture = texture;
00148 shape->appearance = apperance;
00149 rootTransform->children.add(shape);
00150 }
00151
00152 {
00153 Ref<Cylinder> cyl = Cylinder::create(application);
00154 cyl->side = true;
00155 cyl->top = false;
00156 cyl->bottom = true;
00157 cyl->height = 0.1;
00158 Ref<Shape> shape = Shape::create(application);
00159 shape->geometry = cyl;
00160 Ref<Appearance> apperance = Appearance::create(application);
00161 apperance->material = Material::create(application);
00162 shape->appearance = apperance;
00163 rootTransform->children.add(shape);
00164 }
00165
00166
00167 {
00168 Ref<Cylinder> cyl = Cylinder::create(application);
00169 cyl->side = true;
00170 cyl->top = true;
00171 cyl->bottom = false;
00172 cyl->height = 0.1;
00173 cyl->radius = 0.04;
00174 Ref<Shape> shape = Shape::create(application);
00175 shape->geometry = cyl;
00176 Ref<Appearance> apperance = Appearance::create(application);
00177 quitMaterial = Material::create(application);
00178 quitMaterial->diffuseColor = Vector3(0.8, 0.3, 0.3);
00179 apperance->material = quitMaterial;
00180 shape->appearance = apperance;
00181 Ref<TouchSensor> touch = TouchSensor::create(application);
00182 touch->isOver.registerInterest<SFBool>(new FuncCaller<SFBool>(quitIsOver));
00183 touch->touchTime.registerInterest<SFTime>(new FuncCaller<SFTime>(quitTouch));
00184 Ref<Transform> transform = Transform::create(application);
00185 transform->children.add(shape);
00186 transform->children.add(touch);
00187 transform->translation = Vector3(0, 0, -1.03);
00188 transform->rotation = Rotation3(Vector3(-1, 0, 0), M_PI/2);
00189 rootTransform->children.add(transform);
00190 }
00191
00192
00193 {
00194 Ref<Cylinder> cyl = Cylinder::create(application);
00195 cyl->side = true;
00196 cyl->top = true;
00197 cyl->bottom = false;
00198 cyl->height = 0.1;
00199 cyl->radius = 0.04;
00200 Ref<Shape> shape = Shape::create(application);
00201 shape->geometry = cyl;
00202 Ref<Appearance> apperance = Appearance::create(application);
00203 fastForwardMaterial = Material::create(application);
00204 fastForwardMaterial->diffuseColor = Vector3(0.3, 0.8, 0.3);
00205 apperance->material = fastForwardMaterial;
00206 shape->appearance = apperance;
00207 Ref<TouchSensor> touch = TouchSensor::create(application);
00208 touch->isOver.registerInterest<SFBool>(new FuncCaller<SFBool>(fastForwardIsOver));
00209 touch->touchTime.registerInterest<SFTime>(new FuncCaller<SFTime>(fastForwardTouch));
00210 Ref<Transform> subTransform = Transform::create(application);
00211 subTransform->children.add(shape);
00212 subTransform->children.add(touch);
00213 subTransform->translation = Vector3(0, 0, -1.03);
00214 subTransform->rotation = Rotation3(Vector3(-1, 0, 0), M_PI/2);
00215 Ref<Transform> transform = Transform::create(application);
00216 transform->children.add(subTransform);
00217 transform->rotation = Rotation3(Vector3(0, -1, 0), M_PI/16);
00218 rootTransform->children.add(transform);
00219 }
00220
00221 Ref<ChildNode> pointer;
00222 {
00223 Ref<Box> box = Box::create(application);
00224 box->size = Vector3(0.05, 0.02, 0.9);
00225 Ref<Shape> shape = Shape::create(application);
00226 shape->geometry = box;
00227 Ref<Appearance> apperance = Appearance::create(application);
00228 Ref<Material> material = Material::create(application);
00229 material->diffuseColor = Vector3(0.5, 0.2, 0.2);
00230 apperance->material = material;
00231 shape->appearance = apperance;
00232 Ref<Transform> transform = Transform::create(application);
00233 transform->children.add(shape);
00234 transform->translation = Vector3(0, 0, -0.4);
00235 pointer = transform;
00236 }
00237
00238 Ref<Transform> seconds = Transform::create(application);
00239 seconds->children.add(pointer);
00240 seconds->translation = Vector3(0, 0.1, 0);
00241 seconds->scale = Vector3(0.3, 1, 1);
00242 rootTransform->children.add(seconds);
00243
00244 Ref<Transform> minutes = Transform::create(application);
00245 minutes->children.add(pointer);
00246 minutes->translation = Vector3(0, 0.08, 0);
00247 rootTransform->children.add(minutes);
00248
00249 Ref<Transform> hours = Transform::create(application);
00250 hours->children.add(pointer);
00251 hours->translation = Vector3(0, 0.06, 0);
00252 hours->scale = Vector3(1, 1, 0.6);
00253 rootTransform->children.add(hours);
00254
00255 session->endUpdate();
00256
00257 application->setRootGroup(rootGroup);
00258 application->launch();
00259
00260 long addition = 0;
00261
00262 Archon::Utilities::Time delay(0, 100000000l);
00263 while(!quit)
00264 {
00265 long sec, nsec;
00266 Time t = Time::now();
00267 if(fastForward) addition += 60000;
00268 t.addMilliSeconds(addition);
00269 t.get(sec, nsec);
00270 time_t t1 = sec;
00271 tm t2;
00272 localtime_r(&t1, &t2);
00273
00274 double n = nsec/1E9;
00275 double s = (t2.tm_sec + n)/60;
00276 double m = (t2.tm_min + s)/60;
00277 double h = (t2.tm_hour + m)/12;
00278
00279 session->beginUpdate();
00280
00281 seconds->rotation = Rotation3(Vector3(0, -1, 0), s*2*M_PI);
00282 minutes->rotation = Rotation3(Vector3(0, -1, 0), m*2*M_PI);
00283 hours->rotation = Rotation3(Vector3(0, -1, 0), h*2*M_PI);
00284
00285 session->endUpdate();
00286 Archon::Utilities::Thread::sleep(delay);
00287 }
00288
00289 return 0;
00290 }
00291 }
00292 }
00293 }
00294
00295 int main(int argc, const char *argv[]) throw()
00296 {
00297 using namespace std;
00298 using namespace Archon::Utilities;
00299 using namespace Archon::X3D;
00300
00301 set_unexpected(Exception::terminal<Proxy::exceptionCatchInfo>);
00302 set_terminate (Exception::terminal<Proxy::exceptionCatchInfo>);
00303
00304 return Archon::SaiTestApps::Clock::main(argc, argv);
00305 }