interreality.org [VOS]
[Home] [About]
[Screenshots]
[Download]
[News]
[Community]
[Documentation] [Manual]
[Bugs & Requests] [Wiki]

/home/tetron/hack/vos/apps/tutorials/vostut8creature.hh

Go to the documentation of this file.
00001 /* Eighth VOS tutorial.  Creating your own MetaObjects II
00002 
00003    This tutorial file covers:
00004    - Creating simple metaobjects that contain Properties
00005    - Creating a metaobject for a subtype
00006    - Vobjects with more than one type
00007    - A first glimpse at A3DL
00008 
00009    This file (vostut8creature.hh) is released into the public domain.  No
00010    restrictions are placed on its use, distribution or inclusion into
00011    other works.
00012 */
00013 
00014 #ifndef _VOSTUT8_CREATURE_HH_
00015 #define _VOSTUT8_CREATURE_HH_
00016 
00017 #include <string>
00018 #include <vos/vos/vos.hh>
00019 
00020 /* In this tutorial we demonstrate a common metaobject pattern, which
00021    turns out to actually be simpler than the metaobject created in
00022    tutorial 7.  These metaobjects will be used as part of a (very tiny)
00023    database of animals.  It will simply have a certain set of Property
00024    objects as children, which together will describe a species of animal
00025    or plant and it's relation to other animals and plants. You could
00026    create such objects and modify its properties without a special
00027     metaobject class fairly easily, but it can be convenient
00028    and improve maintainability to abstract the object type and provide
00029    a specialized API.
00030 
00031    Furthermore, in this tutorial we will see how to make a Vobject with
00032     more than one MetaObject type, specifically, 3D object types.
00033 
00034    After reviewing this metaobject's header (vostut8creature.hh), take
00035    a look at it's implementation (vostut8creature.cc), then on to
00036    the "server" (vostut8server.cc). After running the server, connect
00037    to it with mesh and look around.
00038 
00039    This file declares two metaobjects.  One is called Creature, which we
00040    will use for all living things.  The second is called Animal and contains
00041    some properties specific to animals.
00042 
00043    The properties of Creature are:
00044     * Genus
00045     * Species
00046     * Common Name
00047     * Description
00048     * Image
00049 
00050    Creatures have predators, that is, creatures that eat them. We will
00051    use Hypercard objects to create indirect links to those predator creatures.
00052    Any number of predator hypercards will be allowed.
00053 
00054    The properties of Animal are:
00055     * Range
00056 
00057    Animals have prey, that is, creatures that they eat. We will use
00058    Hypercard objects to create indirect links to those creature objects.
00059    Any number of prey hypercards will be allowed.
00060 
00061    After looking through this tutorial, try expanding it. Here are some
00062    suggestions:
00063 
00064     Excersise 1: Add a new property or properties to Creature that describes
00065         the creature's usual habitat (whether, terrain, etc.). Give the
00066         examples in vostut8server.cc values for their habitat properties.
00067 
00068     Excercise 2: Create a new MetaObject which is a subtype of Creature
00069         to represent Plants. Modify vostut8server.cc to create some plants.
00070 
00071     Excersise 3: Create a new MetaObject which will contain groups of animals.
00072         Examples of such groups are Mammals, Trees, Fungi, Insects. These
00073         group MetaObjects will contain Creature objects as children.
00074         Modify vostut8server.cc to place your plants and animals in groups.
00075 
00076     Excersise 4: In addition to Creatures and 3D Models, let's have these
00077         objects also form a Hypertext: use the HyperVOS types to form
00078         a set of web pages about the creatures.
00079 
00080     From here you could build a proper taxonomic structure, you could
00081     implement some algorithm for positioning the 3D models for each
00082     creature according to its taxonomic structure, or position in a food
00083     chain.   You could build a model ecosystem and watch it move and change.
00084 
00085     The only limit is your imagination!
00086 
00087 */
00088 
00089 /* These macros are a bit esoteric: they force any program which #includes
00090    this header file to also perfrom any deferred linking of this
00091    library, and static initialization of the factory registration objects.
00092    The argument to this macro MUST match the argument to the BEGIN_ and
00093    END_REGISTER_METAOBJECT_FACTORIES macros used in vostut8creature.cc.
00094 */
00095 //IMPORT_METAOBJECT_FACTORIES(CreaturesEtc)
00096 
00097 /* Since this class is simply a container for properties, its local
00098    and remote behaviors will be identical. Therefore we only need one
00099    class for local and remote objects */
00100 class Creature : public VOS::MetaObject
00101 {
00102 protected:
00103     Creature(VOS::VobjectBase* superobject);
00104 
00105 
00106 public:
00107     virtual const std::string getVOSType();
00108 
00109     /* Set genus */
00110     void setGenus(const std::string& value);
00111 
00112     /* Get genus */
00113     void getGenus(std::string& value);
00114 
00115     /* Set species */
00116     void setSpecies(const std::string& value);
00117 
00118     /* Get species */
00119     void getSpecies(std::string& value);
00120 
00121     /* Set common name */
00122     void setCommonName(const std::string& value);
00123 
00124     /* Get common name */
00125     void getCommonName(std::string& value);
00126 
00127     /* Set description */
00128     void setDescription(const std::string& value, const std::string& datatype = "string");
00129 
00130     /* Get description */
00131     void getDescription(std::string& value, std::string& datatype);
00132 
00133     /* Set image data */
00134     void setImage(const std::string& data, const std::string& datatype = "image/jpeg");
00135 
00136     /* Get image data */
00137     void getImage(std::string& value, std::string& datatype);
00138 
00139     /* Add a pedator (something that eats this creature) */
00140     void addPredator(Creature* p);
00141 
00142     /** Set length (cm) */
00143     void setLength(double l);
00144 
00145     /** Get length */
00146     double getLength();
00147 
00148     static VOS::MetaObject* new_Creature(VOS::VobjectBase* superobject,
00149         const std::string& type);
00150 };
00151 
00152 
00153 class Animal : public Creature
00154 {
00155 protected:
00156 
00157     Animal(VOS::VobjectBase* superobject);
00158 
00159 public:
00160 
00161     /** Set length of animal's tail (cm). (Default is 0) */
00162     void setTailLength(double l);
00163 
00164     /** Get tail length */
00165     double getTailLength();
00166 
00167     /** Add prey (something that this animal eats) */
00168     void addPrey(Creature* p);
00169 
00170     virtual const std::string getVOSType();
00171 
00172     static VOS::MetaObject* new_Animal(VOS::VobjectBase* superobject,
00173         const std::string& type);
00174 };
00175 
00176 
00177 #endif