00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 #ifndef ARCHON_X3D_GROUP_H
00021 #define ARCHON_X3D_GROUP_H
00022 
00029 #include <vector>
00030 #include <string>
00031 
00032 #include <archon/math/rotation.H>
00033 
00034 #include <archon/x3d/server/core.H>
00035 
00036 namespace Archon
00037 {
00038   namespace X3D
00039   {
00040     using namespace Math;
00041 
00042 
00046     struct BoundedObject: virtual NodeBase
00047     {
00048       static const NodeType *type;
00049 
00050       const Vector3 &getBboxCenter() const { return bboxCenter; }
00051       const Vector3 &getBboxSize() const { return bboxSize; }
00052 
00053     protected:
00054       BoundedObject():
00055         bboxCenter(0, 0, 0), bboxSize(-1, -1, -1) {}
00056 
00057     private:
00058       friend void initializeGroupComponent();
00059 
00060       Vector3 bboxCenter;
00061       Vector3 bboxSize;
00062     };
00063 
00064 
00068     struct GroupingNode: virtual ChildNode
00069     {
00070       static const NodeType *type;
00071       static const NodeSequenceFieldBase *childrenField;
00072 
00073       typedef vector<Ref<ChildNode> >::iterator       iterator;
00074       typedef vector<Ref<ChildNode> >::const_iterator const_iterator;
00075 
00076       iterator       begin()       { return children.begin(); }
00077       const_iterator begin() const { return children.begin(); }
00078       iterator       end()         { return children.end(); }
00079       const_iterator end()   const { return children.end(); }
00080 
00081     protected:
00082       GroupingNode() {}
00083 
00084     private:
00085       friend void initializeGroupComponent();
00086 
00087       vector<Ref<ChildNode> > children;
00088 
00089       EventSource childrenChanged;
00090 
00091       Time childrenStamp;
00092 
00093       bool addChildren(const vector<Ref<ChildNode> > &, const Time &);
00094       bool removeChildren(const vector<Ref<ChildNode> > &, const Time &);
00095     };
00096 
00097 
00101     struct Group: GroupingNode, BoundedObject
00102     {
00103       static Ref<NodeBase> instantiate(BackRef<ExecutionContext> c)
00104       {
00105         return new Group(c);
00106       }
00107 
00108       static const NodeType *type;
00109       const NodeType *getType() const { return type; }
00110 
00111       Group(BackRef<ExecutionContext> c): NodeBase(c) {}
00112 
00113       friend void initializeGroupComponent();
00114     };
00115 
00116 
00120     struct Switch: GroupingNode, BoundedObject
00121     {
00122       static Ref<NodeBase> instantiate(BackRef<ExecutionContext> c)
00123       {
00124         return new Switch(c);
00125       }
00126 
00127       static const NodeType *type;
00128       const NodeType *getType() const { return type; }
00129 
00130       Switch(BackRef<ExecutionContext> c): NodeBase(c), whichChoice(-1) {}
00131 
00132       int getWhichChoise() const { return whichChoice; }
00133 
00134     private:
00135       friend void initializeGroupComponent();
00136 
00137       int whichChoice;
00138 
00139       EventSource whichChoiceChanged;
00140 
00141       Time whichChoiceStamp;
00142     };
00143 
00144 
00148     struct Transform: GroupingNode, BoundedObject
00149     {
00150       static Ref<NodeBase> instantiate(BackRef<ExecutionContext> c)
00151       {
00152         return new Transform(c);
00153       }
00154 
00155       static const NodeType *type;
00156       const NodeType *getType() const { return type; }
00157 
00158       Transform(BackRef<ExecutionContext> c):
00159         NodeBase(c),
00160         center(0, 0, 0),
00161         rotation(Rotation3(Vector3(0, 0, 1), 0)),
00162         scale(1, 1, 1),
00163         scaleOrientation(Rotation3(Vector3(0, 0, 1), 0)),
00164         translation(0, 0, 0) {}
00165 
00166       const Vector3 &getCenter()             const { return center; }
00167       const Rotation3 &getRotation()         const { return rotation; }
00168       const Vector3 &getScale()              const { return scale; }
00169       const Rotation3 &getScaleOrientation() const { return scaleOrientation; }
00170       const Vector3 &getTranslation()        const { return translation; }
00171 
00172     private:
00173       friend void initializeGroupComponent();
00174 
00175       Vector3   center;
00176       Rotation3 rotation;
00177       Vector3   scale;
00178       Rotation3 scaleOrientation;
00179       Vector3   translation;
00180 
00181       EventSource centerChanged;
00182       EventSource rotationChanged;
00183       EventSource scaleChanged;
00184       EventSource scaleOrientationChanged;
00185       EventSource translationChanged;
00186 
00187       Time centerStamp;
00188       Time rotationStamp;
00189       Time scaleStamp;
00190       Time scaleOrientationStamp;
00191       Time translationStamp;
00192     };
00193   }
00194 }
00195 
00196 #endif // ARCHON_X3D_GROUP_H