Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk:restoring the trunk…

File size: 10.0 KB
RevLine 
[4838]1/*!
[4839]2 * @file element_2d.h
[5081]3 * Definition of the 2D elements rendered on top through the GraphicsEngine
[5084]4 *
[5081]5 * @todo reimplement it, so it looks just like PNode.
[3245]6*/
[1853]7
[4838]8#ifndef _ELEMENT_2D_H
9#define _ELEMENT_2D_H
[1853]10
[3543]11#include "base_object.h"
[5089]12
[5081]13#include "vector.h"
[1853]14
[4838]15// FORWARD DECLARATION
[4843]16class PNode;
[4858]17class TiXmlElement;
[5081]18template<class T> class tList;
[3543]19
[4839]20//!< An enumerator defining the Depth of a 2D-element.
21typedef enum
22{
[4862]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
[4848]27
[4862]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
[4839]32
[4843]33typedef enum
34{
[4856]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
[4848]40} E2D_ALIGNMENT;
[4843]41
[5081]42typedef enum
43{
[5082]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.
[5081]46
[5082]47  E2D_PARENT_MOVEMENT           =   4,    //!< Moves all children along with the parent.
[5081]48// special linkage modes
[5082]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.
[5081]51} E2D_PARENT_MODE;
[5082]52#define     E2D_DEFAULT_PARENTING_MODE  E2D_PARENT_ALL
[5081]53
[4847]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
[3955]62//! A class for ...
[4849]63class Element2D : virtual public BaseObject {
[1853]64
[4850]65  public:
[5089]66    Element2D();
67    Element2D(Element2D* parent);
[4850]68    virtual ~Element2D();
[1853]69
[5089]70    void init();
[4858]71    void loadParams(const TiXmlElement* root);
72
[4856]73    /** @param alignment the new Alignment of the 2D-Element */
74    inline void setAlignment(E2D_ALIGNMENT alignment) { this->alignment = alignment; };
[4858]75    void setAlignment(const char* alignment);
[5089]76    inline E2D_ALIGNMENT getAlignment() const { return this->alignment; };
[4862]77
78    void setLayer(E2D_LAYER layer);
[4858]79    void setLayer(const char* layer);
[4862]80    /** @returns the Layer this Element is drawn to */
81    inline E2D_LAYER getLayer() { return this->layer; };
82
[4850]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; };
[5068]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; };
[4862]87
[5068]88
[4850]89    /** @param bindNode the Node this 2D-element should follow. if NULL the Element will not follow anything */
[4856]90    inline void setBindNode(const PNode* bindNode) { this->bindNode = bindNode; };
[4858]91    void setBindNode(const char* bindNode);
[5089]92    inline const PNode* getBindNode() const { return this->bindNode; };
[4840]93
[4850]94    /** @returns the visibility state */
95    inline bool isVisible() { return this->visible; };
[5068]96    /** @returns the active-State */
97    inline bool isActive() { return this->active; };
[4840]98
[5081]99
100    // LIKE PNODE
101  public:
102    void setRelCoor2D (const Vector& relCoord);
[5089]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);
[5081]108    /** @returns the relative position */
109    inline const Vector& getRelCoor2D () const { return this->prevRelCoordinate; };
[5113]110    /** @returns the Relative Coordinate Destination */
111    inline const Vector& getRelCoorSoft2D() const { return (this->toCoordinate)?*this->toCoordinate:this->relCoordinate; };
[5089]112    const Vector& getRelCoor2Dpx() const;
[5081]113    void setAbsCoor2D (const Vector& absCoord);
[5089]114    void setAbsCoor2D (float x, float y, float depth = 1.0);
115    void setAbsCoor2Dpx (int x, int y);
[5081]116    /** @returns the absolute position */
117    inline const Vector& getAbsCoor2D () const { return this->absCoordinate; };
[5089]118    const Vector& getAbsCoor2Dpx () const;
119
[5083]120    void shiftCoor2D (const Vector& shift);
[5089]121    void shiftCoor2Dpx (int x, int y);
[5081]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; };
[5113]127    /** @returns the Relative Directional Destination */
128    inline float getRelDirSoft2D() const { return (this->toDirection)?*this->toDirection:this->relDirection; };
[5081]129    void setAbsDir2D (float absDir);
130    /** @returns the absolute Direction */
131    inline float getAbsDir2D () const { return this->absDirection; };
[5083]132    void shiftDir2D (float shiftDir);
[5081]133
134    /** @returns the Speed of the Node */
135    inline float getSpeed() const { return 0; };
136    /** @returns the Velocity of the Node */
137    inline const Vector& getVelocity() const { return this->velocity; };
138
139
140    void addChild2D (Element2D* child, int parentingMode = E2D_DEFAULT_PARENTING_MODE);
141    void addChild2D (const char* childName);
142    void removeChild2D (Element2D* child);
143    void remove2D();
144
145    void setParent2D (Element2D* parent);
146    void setParent2D (const char* parentName);
147    /** @returns the parent of this Element2D */
148    Element2D* getParent () const { return this->parent; };
149
[5082]150    void softReparent2D(Element2D* parentNode, float bias = 1.0);
151    void softReparent2D(const char* parentName, float bias = 1.0);
[5081]152
153    /** @param parentMode sets the parentingMode of this Node */
154    void setParentMode2D (E2D_PARENT_MODE parentMode) { this->parentMode = parentMode; };
155    void setParentMode2D (const char* parentingMode);
156    /** @returns the Parenting mode of this node */
157    int getParentMode2D() const { return this->parentMode; };
158
159    void update2D (float dt);
160
161    void debug (unsigned int depth = 1, unsigned int level = 0) const;
162    void debugDraw2D(unsigned int depth = 1, float size = 1.0, Vector color = Vector(1,1,1)) const;
163
164    // helper functions //
[5082]165    static const char* parentingModeToChar2D(int parentingMode);
166    static E2D_PARENT_MODE charToParentingMode2D(const char* parentingMode);
[5081]167
168  private:
169    /** tells the child that the parent's Coordinate has changed */
170    inline void parentCoorChanged () { this->bRelCoorChanged = true; }
171    /** tells the child that the parent's Direction has changed */
172    inline void parentDirChanged () { this->bRelDirChanged = true; }
173    /** @returns the last calculated coordinate */
174    inline Vector getLastAbsCoor() { return this->lastAbsCoordinate; }
175
176  public:
[4850]177    virtual void tick(float dt);
178    virtual void draw() const = NULL;
[4840]179
[5089]180  private:
181    const PNode*            bindNode;           //!< a node over which to display this 2D-element
[4847]182
[5089]183    E2D_ALIGNMENT           alignment;          //!< How the Element is aligned around its Position
[4856]184
[5089]185    bool                    visible;            //!< If the given Element2D is visible.
186    bool                    active;             //!< If the given Element2D is active.
187    E2D_LAYER               layer;              //!< What layer this Element2D is on.
[4856]188
[5089]189    bool                    bRelCoorChanged;    //!< If Relative Coordinate has changed since last time we checked
190    bool                    bRelDirChanged;     //!< If Relative Direction has changed since last time we checked
[5081]191
[5089]192    Vector                  relCoordinate;      //!< coordinates relative to the parent
193    Vector                  absCoordinate;      //!< absolute coordinates in the world ( from (0,0,0) )
194    float                   relDirection;       //!< direction relative to the parent
195    float                   absDirection;       //!< absolute direvtion in the world ( from (0,0,1) )
[5081]196
[5089]197    Vector                  prevRelCoordinate;  //!< The last Relative Coordinate from the last update-Cycle.
198    Vector                  lastAbsCoordinate;  //!< this is used for speedcalculation, it stores the last coordinate
199    float                   prevRelDirection;   //!< The last Relative Direciton from the last update-Cycle.
200//  float                   lastAbsDirection;
[5081]201
[5089]202    Vector                  velocity;           //!< Saves the velocity.
[5081]203
[5089]204    Vector*                 toCoordinate;       //!< a position to which to iterate. (This is used in conjunction with softReparent.and set*CoorSoft)
205    float*                  toDirection;        //!< a direction to which to iterate. (This is used in conjunction with softReparent and set*DirSoft)
206    float                   bias;               //!< how fast to iterate to the given position (default is 1)
[5081]207
[5089]208    Element2D*              parent;             //!< a pointer to the parent node
209    tList<Element2D>*       children;           //!< list of the children of this Element2D
[5081]210
[5089]211    unsigned int            parentMode;         //!< the mode of the binding
[1853]212};
213
[5082]214//! The top joint of all Element2D's every Element2D is somehow connected to this one.
215class NullElement2D : public Element2D {
[4839]216
[5082]217  public:
218    /** @returns a Pointer to the only object of this Class */
219    inline static NullElement2D* getInstance() { if (!singletonRef) singletonRef = new NullElement2D();  return singletonRef; };
220    virtual ~NullElement2D ();
221
222  private:
223    NullElement2D ();
224    virtual void draw() const {};
225
226  private:
227    static NullElement2D* singletonRef;        //!< A reference to the NullElement2D
228
229};
230
[4838]231#endif /* _ELEMENT_2D_H */
Note: See TracBrowser for help on using the repository browser.