00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <stdexcept>
00011 #include <string>
00012 #include <vos/metaobjects/a3dl/a3dl.hh>
00013 #include "vostut8creature.hh"
00014
00015 using namespace VUtil;
00016 using namespace VOS;
00017 using namespace std;
00018
00019 #ifdef WIN32
00020 #define sleep _sleep
00021 #endif
00022
00023 int main(int, char**)
00024 {
00025 std::cout << "VOS Tutorial 8 Server\n\n";
00026
00027 Site site;
00028 site.addSiteExtension(new LocalVipSiteExtension());
00029
00030
00031
00032 site.setDefaultPolicy("core:accept-all,property:accept-all");
00033
00034
00035
00036
00037 vRef<Animal> coyote = site.createVobject2<Animal, A3DL::Model>("coyote");
00038 coyote->setDefaultPolicy("core:accept-all,property:accept-all");
00039
00040
00041
00042
00043 coyote->setGenus("Canis");
00044 coyote->setSpecies("latrans");
00045 coyote->setCommonName("Coyote");
00046 meta_cast<Creature>(coyote)->setDescription("Carnivore, member of the dog "
00047 "family. Coat long, course, grey and black. Long, narrow muzzle. Bushy "
00048 "tail, black tipped. Runs up to 40 miles per hour.");
00049 coyote->setLength(120);
00050 coyote->setTailLength(33);
00051
00052
00053 vRef<Animal> mouse = site.createVobject2<Animal, A3DL::Model>("mouse");
00054 mouse->setDefaultPolicy("core:accept-all,property:accept-all");
00055 mouse->setGenus("Peromyscus");
00056 mouse->setSpecies("leucopus");
00057 mouse->setCommonName("White-footed mouse");
00058 mouse->setDescription("Red-brown. Large eyes and ears. Tail long and "
00059 "finely haired. Nocturnal year round.");
00060 mouse->setLength(17.8);
00061 mouse->setTailLength(7.62);
00062
00063
00064
00065 vRef<Creature> mushroom = site.createVobject<Creature>("mushroom");
00066 mushroom->setDefaultPolicy("core:accept-all,property:accept-all");
00067 mushroom->setGenus("Amanita");
00068 mushroom->setSpecies("brunnescens");
00069 mushroom->setCommonName("Cleft-foot Amanita");
00070 mushroom->setDescription("Wide convex cap, white. Gills: free, close, "
00071 "broad. Universal white veil. Spores 7-10 microns. Possibly poisonous.");
00072 mushroom->setLength(10);
00073
00074
00075
00076 mushroom->getVobjectBase()->addMetaObjectExtension(new A3DL::Model(mushroom->getVobjectBase()));
00077
00078
00079 coyote->addPrey(mouse);
00080 mouse->addPredator(coyote);
00081
00082
00083 meta_cast<A3DL::Object3D>(coyote)->setPosition(6, 0, 6);
00084 try {
00085 meta_cast<A3DL::Model>(coyote)->setModelToFile("vostut8_coyote.3ds", "model/x-3ds");
00086 } catch(exception& e) {
00087 LOG("vostut8server", 0, "Error using model file \"vostut8_coyote.3ds\": " << e.what());
00088 }
00089
00090 meta_cast<A3DL::Object3D>(mouse)->setPosition(3, 0, 0);
00091 try {
00092 meta_cast<A3DL::Model>(mouse)->setModelToFile("vostut8_mouse.3ds", "model/x-3ds");
00093 } catch(exception& e) {
00094 LOG("vostut8server", 0, "Error using model file \"vostut8_mouse.3ds\": " << e.what());
00095 }
00096
00097 meta_cast<A3DL::Object3D>(mushroom)->setPosition(3, 0, 3);
00098 try {
00099 meta_cast<A3DL::Model>(mushroom)->setModelToFile("vostut8_mushroom.3ds", "model/x-3ds");
00100 } catch(exception& e) {
00101 LOG("vostut8server", 0, "Error using model file \"vostut8_mushroom.3ds\": " << e.what());
00102 }
00103
00104
00105
00106 vRef<A3DL::Sector> world = site.createVobject<A3DL::Sector>("world", "core:accept-all,property:accept-all");
00107 world->setAmbientLightColor(0.5, 0.5, 0.5);
00108 world->insertChild(-1, "coyote", coyote);
00109 world->insertChild(-1, "mouse", mouse);
00110 world->insertChild(-1, "mushroom", mushroom);
00111
00112 LOG("vostut8server", 2, "Ok, running. Try \"mesh " << world->getURLstr() << "\"");
00113 while(true) sleep(1000);
00114 }
00115