Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5235 was 5215, checked in by bensch, 19 years ago

orxonox/trunk: some more fixing of the Errors reported by valgrind
removed some stuff in patrick's collision-detection.
also changed Vector* to Vector in Rectangle (patrick tell me, if this is not ok - but i doubt it :))

File size: 10.0 KB
Line 
1/*!
2 * @file element_2d.h
3 * Definition of the 2D elements rendered on top through the GraphicsEngine
4 *
5 * @todo reimplement it, so it looks just like PNode.
6*/
7
8#ifndef _ELEMENT_2D_H
9#define _ELEMENT_2D_H
10
11#include "base_object.h"
12
13#include "vector.h"
14
15// FORWARD DECLARATION
16class PNode;
17class TiXmlElement;
18template<class T> class tList;
19
20//!< An enumerator defining the Depth of a 2D-element.
21typedef enum
22{
23  E2D_BELOW_ALL                 =     1,        //!< Will be rendered below the 3D-scene. @todo make this work.
24  E2D_BOTTOM                    =     2,        //!< Will be rendered on the bottom Layer
25  E2D_MEDIUM                    =     4,        //!< Will be rendered on the medium Layer.
26  E2D_TOP                       =     8,        //!< Will be rendered on top of everything else
27
28  E2D_LAYER_COUNT               =     4         //!< The count of Layers.
29} E2D_LAYER;
30#define E2D_DEFAULT_LAYER       E2D_TOP
31#define E2D_ALL_LAYERS          E2D_TOP | E2D_MEDIUM | E2D_BOTTOM | E2D_BELOW_ALL
32
33typedef enum
34{
35  E2D_ALIGN_NONE                =     0,
36  E2D_ALIGN_LEFT                =     1,
37  E2D_ALIGN_RIGHT               =     2,
38  E2D_ALIGN_CENTER              =     4,
39  E2D_ALIGN_SCREEN_CENTER       =     8
40} E2D_ALIGNMENT;
41
42typedef enum
43{
44  E2D_PARENT_NONE               =   0,
45  E2D_PARENT_LOCAL_ROTATE       =   1,    //!< Rotates all the children around their centers.
46  E2D_PARENT_ROTATE_MOVEMENT    =   2,    //!< Moves all the children around the center of their parent, without the rotation around their own centers.
47
48  E2D_PARENT_MOVEMENT           =   4,    //!< Moves all children along with the parent.
49// special linkage modes
50  E2D_PARENT_ALL                =   3,    //!< Moves all children around the center of their parent, and also rotates their centers
51  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.
52} E2D_PARENT_MODE;
53#define     E2D_DEFAULT_PARENTING_MODE  E2D_PARENT_ALL
54
55//! A Struct defining the Position of an Element in 2D-space
56struct Position2D
57{
58  float       x;                 //!< The x-coordinate.
59  float       y;                 //!< The y-coordinate.
60  float       depth;             //!< The distance from the viewing plane.
61};
62
63//! A class for ...
64class Element2D : virtual public BaseObject {
65
66  public:
67    Element2D();
68    Element2D(Element2D* parent);
69    virtual ~Element2D();
70
71    void init();
72    void loadParams(const TiXmlElement* root);
73
74    /** @param alignment the new Alignment of the 2D-Element */
75    inline void setAlignment(E2D_ALIGNMENT alignment) { this->alignment = alignment; };
76    void setAlignment(const char* alignment);
77    inline E2D_ALIGNMENT getAlignment() const { return this->alignment; };
78
79    void setLayer(E2D_LAYER layer);
80    void setLayer(const char* layer);
81    /** @returns the Layer this Element is drawn to */
82    inline E2D_LAYER getLayer() { return this->layer; };
83
84    /** @param visible true if the Element should be visible false otherwise (will not be rendered) */
85    inline void setVisibility(bool visible) { this->visible = visible; };
86    /** @param active true if the Element should be active, false otherwise (will not be ticked) */
87    inline void setActiveness(bool active) { this->active = active; };
88
89
90    /** @param bindNode the Node this 2D-element should follow. if NULL the Element will not follow anything */
91    inline void setBindNode(const PNode* bindNode) { this->bindNode = bindNode; };
92    void setBindNode(const char* bindNode);
93    inline const PNode* getBindNode() const { return this->bindNode; };
94
95    /** @returns the visibility state */
96    inline bool isVisible() { return this->visible; };
97    /** @returns the active-State */
98    inline bool isActive() { return this->active; };
99
100
101    // LIKE PNODE
102  public:
103    void setRelCoor2D (const Vector& relCoord);
104    void setRelCoor2D (float x, float y, float dontCare = 1.0);
105    void setRelCoor2Dpx (int x, int y);
106    void setRelCoorSoft2D (const Vector& relCoordSoft, float bias = 1.0);
107    void setRelCoorSoft2D (float x, float y, float dontCare = 1.0, float bias = 1.0);
108    void setRelCoorSoft2Dpx (int x, int y, float bias = 1.0);
109    /** @returns the relative position */
110    inline const Vector& getRelCoor2D () const { return this->prevRelCoordinate; };
111    /** @returns the Relative Coordinate Destination */
112    inline const Vector& getRelCoorSoft2D() const { return (this->toCoordinate)?*this->toCoordinate:this->relCoordinate; };
113    const Vector& getRelCoor2Dpx() const;
114    void setAbsCoor2D (const Vector& absCoord);
115    void setAbsCoor2D (float x, float y, float depth = 1.0);
116    void setAbsCoor2Dpx (int x, int y);
117    /** @returns the absolute position */
118    inline const Vector& getAbsCoor2D () const { return this->absCoordinate; };
119    const Vector& getAbsCoor2Dpx () const;
120
121    void shiftCoor2D (const Vector& shift);
122    void shiftCoor2Dpx (int x, int y);
123
124    void setRelDir2D (float relDir);
125    void setRelDirSoft2D(float relDirSoft, float bias = 1.0);
126    /** @returns the relative Direction */
127    inline float getRelDir2D () const { return this->prevRelDirection; };
128    /** @returns the Relative Directional Destination */
129    inline float getRelDirSoft2D() const { return (this->toDirection)?*this->toDirection:this->relDirection; };
130    void setAbsDir2D (float absDir);
131    /** @returns the absolute Direction */
132    inline float getAbsDir2D () const { return this->absDirection; };
133    void shiftDir2D (float shiftDir);
134
135    /** @returns the Speed of the Node */
136    inline float getSpeed() const { return 0; };
137    /** @returns the Velocity of the Node */
138    inline const Vector& getVelocity() const { return this->velocity; };
139
140
141    void addChild2D (Element2D* child, int parentingMode = E2D_PARENT_NONE);
142    void addChild2D (const char* childName);
143    void removeChild2D (Element2D* child);
144    void remove2D();
145
146    void setParent2D (Element2D* parent);
147    void setParent2D (const char* parentName);
148    /** @returns the parent of this Element2D */
149    Element2D* getParent () const { return this->parent; };
150
151    void softReparent2D(Element2D* parentNode, float bias = 1.0);
152    void softReparent2D(const char* parentName, float bias = 1.0);
153
154    /** @param parentMode sets the parentingMode of this Node */
155    void setParentMode2D (E2D_PARENT_MODE parentMode) { this->parentMode = parentMode; };
156    void setParentMode2D (const char* parentingMode);
157    /** @returns the Parenting mode of this node */
158    int getParentMode2D() const { return this->parentMode; };
159
160    void update2D (float dt);
161
162    void debug (unsigned int depth = 1, unsigned int level = 0) const;
163    void debugDraw2D(unsigned int depth = 1, float size = 1.0, Vector color = Vector(1,1,1)) const;
164
165    // helper functions //
166    static const char* parentingModeToChar2D(int parentingMode);
167    static E2D_PARENT_MODE charToParentingMode2D(const char* parentingMode);
168
169  private:
170    /** tells the child that the parent's Coordinate has changed */
171    inline void parentCoorChanged () { this->bRelCoorChanged = true; }
172    /** tells the child that the parent's Direction has changed */
173    inline void parentDirChanged () { this->bRelDirChanged = true; }
174    /** @returns the last calculated coordinate */
175    inline Vector getLastAbsCoor() { return this->lastAbsCoordinate; }
176
177  public:
178    virtual void tick(float dt);
179    virtual void draw() const = NULL;
180
181  private:
182    const PNode*            bindNode;           //!< a node over which to display this 2D-element
183
184    E2D_ALIGNMENT           alignment;          //!< How the Element is aligned around its Position
185
186    bool                    visible;            //!< If the given Element2D is visible.
187    bool                    active;             //!< If the given Element2D is active.
188    E2D_LAYER               layer;              //!< What layer this Element2D is on.
189
190    bool                    bRelCoorChanged;    //!< If Relative Coordinate has changed since last time we checked
191    bool                    bRelDirChanged;     //!< If Relative Direction has changed since last time we checked
192
193    Vector                  relCoordinate;      //!< coordinates relative to the parent
194    Vector                  absCoordinate;      //!< absolute coordinates in the world ( from (0,0,0) )
195    float                   relDirection;       //!< direction relative to the parent
196    float                   absDirection;       //!< absolute diretion in the world ( from (0,0,1) )
197
198    Vector                  prevRelCoordinate;  //!< The last Relative Coordinate from the last update-Cycle.
199    Vector                  lastAbsCoordinate;  //!< this is used for speedcalculation, it stores the last coordinate
200    float                   prevRelDirection;   //!< The last Relative Direciton from the last update-Cycle.
201//  float                   lastAbsDirection;
202
203    Vector                  velocity;           //!< Saves the velocity.
204
205    Vector*                 toCoordinate;       //!< a position to which to iterate. (This is used in conjunction with softReparent.and set*CoorSoft)
206    float*                  toDirection;        //!< a direction to which to iterate. (This is used in conjunction with softReparent and set*DirSoft)
207    float                   bias;               //!< how fast to iterate to the given position (default is 1)
208
209    Element2D*              parent;             //!< a pointer to the parent node
210    tList<Element2D>*       children;           //!< list of the children of this Element2D
211
212    unsigned int            parentMode;         //!< the mode of the binding
213};
214
215//! The top joint of all Element2D's every Element2D is somehow connected to this one.
216class NullElement2D : public Element2D {
217
218  public:
219    /** @returns a Pointer to the only object of this Class */
220    inline static NullElement2D* getInstance() { if (!singletonRef) singletonRef = new NullElement2D();  return singletonRef; };
221    virtual ~NullElement2D ();
222
223  private:
224    NullElement2D ();
225    virtual void draw() const {};
226
227  private:
228    static NullElement2D* singletonRef;        //!< A reference to the NullElement2D
229
230};
231
232#endif /* _ELEMENT_2D_H */
Note: See TracBrowser for help on using the repository browser.