Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/render2D/element_2d.h @ 6146

Last change on this file since 6146 was 6142, checked in by bensch, 19 years ago

orxonox/trunk: merge the ObjectManager to the trunk
merged with command:
svn merge -r6082:HEAD objectmanager/ ../trunk/

conflicts resolution was easy this time :)
but specially merged the world to network_world

File size: 11.6 KB
RevLine 
[4838]1/*!
[4839]2 * @file element_2d.h
[5081]3 * Definition of the 2D elements rendered on top through the GraphicsEngine
[5401]4 */
[1853]5
[4838]6#ifndef _ELEMENT_2D_H
7#define _ELEMENT_2D_H
[1853]8
[3543]9#include "base_object.h"
[5089]10
[5081]11#include "vector.h"
[5775]12#include <list>
[1853]13
[4838]14// FORWARD DECLARATION
[4843]15class PNode;
[4858]16class TiXmlElement;
[3543]17
[4839]18//!< An enumerator defining the Depth of a 2D-element.
19typedef enum
20{
[5398]21  E2D_LAYER_BELOW_ALL           =     0,        //!< Will be rendered below the 3D-scene. @todo make this work.
22  E2D_LAYER_BOTTOM              =     1,        //!< Will be rendered on the bottom Layer
23  E2D_LAYER_MEDIUM              =     2,        //!< Will be rendered on the medium Layer.
24  E2D_LAYER_TOP                 =     3,        //!< Will be rendered on top of everything else
[4848]25
[5398]26  E2D_LAYER_COUNT               =     4,         //!< The count of Layers.
[4862]27} E2D_LAYER;
[5398]28#define E2D_DEFAULT_LAYER       E2D_LAYER_MEDIUM
[5404]29#define E2D_LAYER_ALL           4
[4839]30
[4843]31typedef enum
32{
[4856]33  E2D_ALIGN_NONE                =     0,
34  E2D_ALIGN_LEFT                =     1,
35  E2D_ALIGN_RIGHT               =     2,
36  E2D_ALIGN_CENTER              =     4,
37  E2D_ALIGN_SCREEN_CENTER       =     8
[4848]38} E2D_ALIGNMENT;
[4843]39
[5081]40typedef enum
41{
[5215]42  E2D_PARENT_NONE               =   0,
[5082]43  E2D_PARENT_LOCAL_ROTATE       =   1,    //!< Rotates all the children around their centers.
44  E2D_PARENT_ROTATE_MOVEMENT    =   2,    //!< Moves all the children around the center of their parent, without the rotation around their own centers.
[5081]45
[5082]46  E2D_PARENT_MOVEMENT           =   4,    //!< Moves all children along with the parent.
[5081]47// special linkage modes
[5082]48  E2D_PARENT_ALL                =   3,    //!< Moves all children around the center of their parent, and also rotates their centers
49  E2D_PARENT_ROTATE_AND_MOVE    =   5     //!< Rotates all children around their axis, and moves them as the Parent Moves, but does not rotate around the center of their parent.
[5081]50} E2D_PARENT_MODE;
[5082]51#define     E2D_DEFAULT_PARENTING_MODE  E2D_PARENT_ALL
[5081]52
[4847]53//! A Struct defining the Position of an Element in 2D-space
54struct Position2D
55{
56  float       x;                 //!< The x-coordinate.
57  float       y;                 //!< The y-coordinate.
58  float       depth;             //!< The distance from the viewing plane.
59};
60
[5404]61//! A class for 2D-elements
62/**
63 * this class mainly tries to imitate PNode in its functionality, but on a 2D-level
64 * it extends PNode in the Sense of the tick-ability/draw-alility layering (and size)
65 *
66 * Layering: Layers are sorted into the Tree. e.g:
67 * the roor is in the lowest Layer, the leaves in the highest (of each branche)
68 * the first child of each node is in the lowest layer of all children, the last in the highest
69 * -> the tree is sorted on insertion of a new Child: @see Element2D::addChild2D()
70 */
[4849]71class Element2D : virtual public BaseObject {
[1853]72
[4850]73  public:
[5089]74    Element2D();
[5402]75    Element2D(Element2D* parent, E2D_LAYER layer = E2D_DEFAULT_LAYER);
[4850]76    virtual ~Element2D();
[1853]77
[5089]78    void init();
[4858]79    void loadParams(const TiXmlElement* root);
80
[4856]81    /** @param alignment the new Alignment of the 2D-Element */
82    inline void setAlignment(E2D_ALIGNMENT alignment) { this->alignment = alignment; };
[4858]83    void setAlignment(const char* alignment);
[5089]84    inline E2D_ALIGNMENT getAlignment() const { return this->alignment; };
[4862]85
86    void setLayer(E2D_LAYER layer);
[4858]87    void setLayer(const char* layer);
[4862]88    /** @returns the Layer this Element is drawn to */
[5398]89    inline E2D_LAYER getLayer() const { return this->layer; };
[4862]90
[4850]91    /** @param visible true if the Element should be visible false otherwise (will not be rendered) */
92    inline void setVisibility(bool visible) { this->visible = visible; };
[5068]93    /** @param active true if the Element should be active, false otherwise (will not be ticked) */
94    inline void setActiveness(bool active) { this->active = active; };
[4862]95
[5068]96
[4850]97    /** @param bindNode the Node this 2D-element should follow. if NULL the Element will not follow anything */
[4856]98    inline void setBindNode(const PNode* bindNode) { this->bindNode = bindNode; };
[4858]99    void setBindNode(const char* bindNode);
[5089]100    inline const PNode* getBindNode() const { return this->bindNode; };
[4840]101
[4850]102    /** @returns the visibility state */
103    inline bool isVisible() { return this->visible; };
[5068]104    /** @returns the active-State */
105    inline bool isActive() { return this->active; };
[4840]106
[5081]107
[5378]108    inline void setSize2D(float x, float y) { this->sizeX = x, this->sizeY = y; };
109    inline void setSizeX2D(float x) { this->sizeX = x; };
110    inline void setSizeY2D(float y) { this->sizeY = y; };
111    inline float getSizeX2D() const { return this->sizeX; };
112    inline float getSizeY2D() const { return this->sizeY; };
113
[5401]114  public:
115    virtual void tick(float dt) {};
116    virtual void draw() const = 0;
117    void tick2D(float dt);
[5404]118    void draw2D(short layer) const;
[5401]119
[5081]120    // LIKE PNODE
121  public:
122    void setRelCoor2D (const Vector& relCoord);
[5089]123    void setRelCoor2D (float x, float y, float dontCare = 1.0);
124    void setRelCoor2Dpx (int x, int y);
125    void setRelCoorSoft2D (const Vector& relCoordSoft, float bias = 1.0);
126    void setRelCoorSoft2D (float x, float y, float dontCare = 1.0, float bias = 1.0);
127    void setRelCoorSoft2Dpx (int x, int y, float bias = 1.0);
[5081]128    /** @returns the relative position */
129    inline const Vector& getRelCoor2D () const { return this->prevRelCoordinate; };
[5113]130    /** @returns the Relative Coordinate Destination */
131    inline const Vector& getRelCoorSoft2D() const { return (this->toCoordinate)?*this->toCoordinate:this->relCoordinate; };
[5089]132    const Vector& getRelCoor2Dpx() const;
[5081]133    void setAbsCoor2D (const Vector& absCoord);
[5089]134    void setAbsCoor2D (float x, float y, float depth = 1.0);
135    void setAbsCoor2Dpx (int x, int y);
[5414]136    void setAbsCoorSoft2D (const Vector& absCoordSoft, float bias = 1.0);
137    void setAbsCoorSoft2D (float x, float y, float depth = 1.0, float bias = 1.0);
[5081]138    /** @returns the absolute position */
139    inline const Vector& getAbsCoor2D () const { return this->absCoordinate; };
[5089]140    const Vector& getAbsCoor2Dpx () const;
141
[5083]142    void shiftCoor2D (const Vector& shift);
[5089]143    void shiftCoor2Dpx (int x, int y);
[5081]144
145    void setRelDir2D (float relDir);
146    void setRelDirSoft2D(float relDirSoft, float bias = 1.0);
147    /** @returns the relative Direction */
148    inline float getRelDir2D () const { return this->prevRelDirection; };
[5113]149    /** @returns the Relative Directional Destination */
150    inline float getRelDirSoft2D() const { return (this->toDirection)?*this->toDirection:this->relDirection; };
[5081]151    void setAbsDir2D (float absDir);
[5414]152    void setAbsDirSoft2D (float absDirSoft, float bias = 1.0);
[5081]153    /** @returns the absolute Direction */
154    inline float getAbsDir2D () const { return this->absDirection; };
[5083]155    void shiftDir2D (float shiftDir);
[5081]156
157    /** @returns the Speed of the Node */
158    inline float getSpeed() const { return 0; };
159    /** @returns the Velocity of the Node */
160    inline const Vector& getVelocity() const { return this->velocity; };
161
162
[5403]163    void addChild2D (Element2D* child);
[5081]164    void addChild2D (const char* childName);
165    void removeChild2D (Element2D* child);
166    void remove2D();
167
168    void setParent2D (Element2D* parent);
169    void setParent2D (const char* parentName);
170    /** @returns the parent of this Element2D */
[5397]171    inline Element2D* getParent2D () const { return this->parent; };
[5387]172    /** @returns the List of Children of this Element2D */
[5775]173    inline const std::list<Element2D*>& getChildren2D() const { return this->children; };
[5081]174
[5382]175    void setParentSoft2D(Element2D* parentNode, float bias = 1.0);
176    void setParentSoft2D(const char* parentName, float bias = 1.0);
[5081]177
178    /** @param parentMode sets the parentingMode of this Node */
179    void setParentMode2D (E2D_PARENT_MODE parentMode) { this->parentMode = parentMode; };
180    void setParentMode2D (const char* parentingMode);
181    /** @returns the Parenting mode of this node */
182    int getParentMode2D() const { return this->parentMode; };
183
184    void update2D (float dt);
185
186    void debug (unsigned int depth = 1, unsigned int level = 0) const;
[5417]187    void debugDraw2D(unsigned int depth = 1, float size = 1.0, Vector color = Vector(1,0,0), unsigned int level = 0) const;
[5081]188
189    // helper functions //
[5082]190    static const char* parentingModeToChar2D(int parentingMode);
191    static E2D_PARENT_MODE charToParentingMode2D(const char* parentingMode);
[5081]192
[5401]193    static const char* layer2DToChar(E2D_LAYER layer);
194    static E2D_LAYER charToLayer2D(const char* layer);
195
[5081]196  private:
[6142]197    void eraseChild(Element2D* child);
[5081]198    /** tells the child that the parent's Coordinate has changed */
199    inline void parentCoorChanged () { this->bRelCoorChanged = true; }
200    /** tells the child that the parent's Direction has changed */
201    inline void parentDirChanged () { this->bRelDirChanged = true; }
202    /** @returns the last calculated coordinate */
203    inline Vector getLastAbsCoor() { return this->lastAbsCoordinate; }
204
[4840]205
[5401]206
[5378]207  private:
208    const PNode*            bindNode;           //!< a node over which to display this 2D-element
[5371]209    float                   sizeX;              //!< The size of the rendered item in x-direction
210    float                   sizeY;              //!< The size of the rendered Item in y-direction
211
[5089]212    E2D_ALIGNMENT           alignment;          //!< How the Element is aligned around its Position
[4856]213
[5089]214    bool                    visible;            //!< If the given Element2D is visible.
215    bool                    active;             //!< If the given Element2D is active.
216    E2D_LAYER               layer;              //!< What layer this Element2D is on.
[4856]217
[5089]218    bool                    bRelCoorChanged;    //!< If Relative Coordinate has changed since last time we checked
219    bool                    bRelDirChanged;     //!< If Relative Direction has changed since last time we checked
[5081]220
[5089]221    Vector                  relCoordinate;      //!< coordinates relative to the parent
222    Vector                  absCoordinate;      //!< absolute coordinates in the world ( from (0,0,0) )
223    float                   relDirection;       //!< direction relative to the parent
[5211]224    float                   absDirection;       //!< absolute diretion in the world ( from (0,0,1) )
[5081]225
[5089]226    Vector                  prevRelCoordinate;  //!< The last Relative Coordinate from the last update-Cycle.
227    Vector                  lastAbsCoordinate;  //!< this is used for speedcalculation, it stores the last coordinate
228    float                   prevRelDirection;   //!< The last Relative Direciton from the last update-Cycle.
[5081]229
[5089]230    Vector                  velocity;           //!< Saves the velocity.
[5081]231
[5382]232    Vector*                 toCoordinate;       //!< a position to which to iterate. (This is used in conjunction with setParentSoft.and set*CoorSoft)
233    float*                  toDirection;        //!< a direction to which to iterate. (This is used in conjunction with setParentSoft and set*DirSoft)
[5089]234    float                   bias;               //!< how fast to iterate to the given position (default is 1)
[5081]235
[5089]236    Element2D*              parent;             //!< a pointer to the parent node
[5775]237    std::list<Element2D*>   children;           //!< list of the children of this Element2D
[5081]238
[5089]239    unsigned int            parentMode;         //!< the mode of the binding
[1853]240};
241
[5082]242//! The top joint of all Element2D's every Element2D is somehow connected to this one.
243class NullElement2D : public Element2D {
[4839]244
[5082]245  public:
246    /** @returns a Pointer to the only object of this Class */
[5285]247    inline static NullElement2D* getInstance() { if (!NullElement2D::singletonRef) NullElement2D::singletonRef = new NullElement2D();  return NullElement2D::singletonRef; };
248    inline static bool isInstanciated() { return (NullElement2D::singletonRef != NULL)?true:false; };
[5082]249    virtual ~NullElement2D ();
250
251  private:
252    NullElement2D ();
253    virtual void draw() const {};
254
255  private:
256    static NullElement2D* singletonRef;        //!< A reference to the NullElement2D
257
258};
259
[4838]260#endif /* _ELEMENT_2D_H */
Note: See TracBrowser for help on using the repository browser.