Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: softDir/softCoor is now overwritten(deleted) if one sets the relCoor/relDir/absDir/absCoor
shell is also in smooth-mode now :)

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