Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5412 was 5404, checked in by bensch, 20 years ago

orxonox/trunk: removed old unused functionality, and added some comments

File size: 11.4 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"
[1853]12
[4838]13// FORWARD DECLARATION
[4843]14class PNode;
[4858]15class TiXmlElement;
[5081]16template<class T> class tList;
[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);
[5081]136    /** @returns the absolute position */
137    inline const Vector& getAbsCoor2D () const { return this->absCoordinate; };
[5089]138    const Vector& getAbsCoor2Dpx () const;
139
[5083]140    void shiftCoor2D (const Vector& shift);
[5089]141    void shiftCoor2Dpx (int x, int y);
[5081]142
143    void setRelDir2D (float relDir);
144    void setRelDirSoft2D(float relDirSoft, float bias = 1.0);
145    /** @returns the relative Direction */
146    inline float getRelDir2D () const { return this->prevRelDirection; };
[5113]147    /** @returns the Relative Directional Destination */
148    inline float getRelDirSoft2D() const { return (this->toDirection)?*this->toDirection:this->relDirection; };
[5081]149    void setAbsDir2D (float absDir);
150    /** @returns the absolute Direction */
151    inline float getAbsDir2D () const { return this->absDirection; };
[5083]152    void shiftDir2D (float shiftDir);
[5081]153
154    /** @returns the Speed of the Node */
155    inline float getSpeed() const { return 0; };
156    /** @returns the Velocity of the Node */
157    inline const Vector& getVelocity() const { return this->velocity; };
158
159
[5403]160    void addChild2D (Element2D* child);
[5081]161    void addChild2D (const char* childName);
162    void removeChild2D (Element2D* child);
163    void remove2D();
164
165    void setParent2D (Element2D* parent);
166    void setParent2D (const char* parentName);
167    /** @returns the parent of this Element2D */
[5397]168    inline Element2D* getParent2D () const { return this->parent; };
[5387]169    /** @returns the List of Children of this Element2D */
170    inline const tList<Element2D>* getChildren2D() const { return this->children; };
[5081]171
[5382]172    void setParentSoft2D(Element2D* parentNode, float bias = 1.0);
173    void setParentSoft2D(const char* parentName, float bias = 1.0);
[5081]174
175    /** @param parentMode sets the parentingMode of this Node */
176    void setParentMode2D (E2D_PARENT_MODE parentMode) { this->parentMode = parentMode; };
177    void setParentMode2D (const char* parentingMode);
178    /** @returns the Parenting mode of this node */
179    int getParentMode2D() const { return this->parentMode; };
180
181    void update2D (float dt);
182
183    void debug (unsigned int depth = 1, unsigned int level = 0) const;
184    void debugDraw2D(unsigned int depth = 1, float size = 1.0, Vector color = Vector(1,1,1)) const;
185
186    // helper functions //
[5082]187    static const char* parentingModeToChar2D(int parentingMode);
188    static E2D_PARENT_MODE charToParentingMode2D(const char* parentingMode);
[5081]189
[5401]190    static const char* layer2DToChar(E2D_LAYER layer);
191    static E2D_LAYER charToLayer2D(const char* layer);
192
[5081]193  private:
194    /** tells the child that the parent's Coordinate has changed */
195    inline void parentCoorChanged () { this->bRelCoorChanged = true; }
196    /** tells the child that the parent's Direction has changed */
197    inline void parentDirChanged () { this->bRelDirChanged = true; }
198    /** @returns the last calculated coordinate */
199    inline Vector getLastAbsCoor() { return this->lastAbsCoordinate; }
200
[4840]201
[5401]202
[5378]203  private:
204    const PNode*            bindNode;           //!< a node over which to display this 2D-element
[5371]205    float                   sizeX;              //!< The size of the rendered item in x-direction
206    float                   sizeY;              //!< The size of the rendered Item in y-direction
207
[5089]208    E2D_ALIGNMENT           alignment;          //!< How the Element is aligned around its Position
[4856]209
[5089]210    bool                    visible;            //!< If the given Element2D is visible.
211    bool                    active;             //!< If the given Element2D is active.
212    E2D_LAYER               layer;              //!< What layer this Element2D is on.
[4856]213
[5089]214    bool                    bRelCoorChanged;    //!< If Relative Coordinate has changed since last time we checked
215    bool                    bRelDirChanged;     //!< If Relative Direction has changed since last time we checked
[5081]216
[5089]217    Vector                  relCoordinate;      //!< coordinates relative to the parent
218    Vector                  absCoordinate;      //!< absolute coordinates in the world ( from (0,0,0) )
219    float                   relDirection;       //!< direction relative to the parent
[5211]220    float                   absDirection;       //!< absolute diretion in the world ( from (0,0,1) )
[5081]221
[5089]222    Vector                  prevRelCoordinate;  //!< The last Relative Coordinate from the last update-Cycle.
223    Vector                  lastAbsCoordinate;  //!< this is used for speedcalculation, it stores the last coordinate
224    float                   prevRelDirection;   //!< The last Relative Direciton from the last update-Cycle.
[5081]225
[5089]226    Vector                  velocity;           //!< Saves the velocity.
[5081]227
[5382]228    Vector*                 toCoordinate;       //!< a position to which to iterate. (This is used in conjunction with setParentSoft.and set*CoorSoft)
229    float*                  toDirection;        //!< a direction to which to iterate. (This is used in conjunction with setParentSoft and set*DirSoft)
[5089]230    float                   bias;               //!< how fast to iterate to the given position (default is 1)
[5081]231
[5089]232    Element2D*              parent;             //!< a pointer to the parent node
233    tList<Element2D>*       children;           //!< list of the children of this Element2D
[5081]234
[5089]235    unsigned int            parentMode;         //!< the mode of the binding
[1853]236};
237
[5082]238//! The top joint of all Element2D's every Element2D is somehow connected to this one.
239class NullElement2D : public Element2D {
[4839]240
[5082]241  public:
242    /** @returns a Pointer to the only object of this Class */
[5285]243    inline static NullElement2D* getInstance() { if (!NullElement2D::singletonRef) NullElement2D::singletonRef = new NullElement2D();  return NullElement2D::singletonRef; };
244    inline static bool isInstanciated() { return (NullElement2D::singletonRef != NULL)?true:false; };
[5082]245    virtual ~NullElement2D ();
246
247  private:
248    NullElement2D ();
249    virtual void draw() const {};
250
251  private:
252    static NullElement2D* singletonRef;        //!< A reference to the NullElement2D
253
254};
255
[4838]256#endif /* _ELEMENT_2D_H */
Note: See TracBrowser for help on using the repository browser.