Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/render2D/element_2d.cc @ 5081

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

orxonox/trunk: Element2D: PNode-style declaration

File size: 6.5 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
17
18#include "element_2d.h"
19#include "render_2d.h"
20
21#include "graphics_engine.h"
22#include "p_node.h"
23#include "load_param.h"
24#include "tinyxml.h"
25#include "class_list.h"
26
27using namespace std;
28
29
30/**
31 * standard constructor
32 * @todo this constructor is not jet implemented - do it
33*/
34Element2D::Element2D ()
35{
36  this->init();
37}
38
39/**
40 * standard deconstructor
41*/
42Element2D::~Element2D ()
43{
44  // delete what has to be deleted here
45  Render2D::getInstance()->unregisterElement2D(this);
46}
47
48
49/**
50 * initializes a Element2D
51 */
52void Element2D::init()
53{
54  this->setClassID(CL_ELEMENT_2D, "Element2D");
55
56  this->setVisibility(true);
57  this->setActiveness(true);
58  this->setPosition2D(0,0);
59  this->setAlignment(E2D_ALIGN_NONE);
60  this->layer = E2D_TOP;
61
62  Render2D::getInstance()->registerElement2D(this);
63}
64
65/**
66 * Loads the Parameters of an Element2D from...
67 * @param root The XML-element to load from
68 */
69void Element2D::loadParams(const TiXmlElement* root)
70{
71  LoadParam<Element2D>(root, "alignment", this, &Element2D::setAlignment)
72      .describe("loads the alignment: (either: center, left, right or screen-center)");
73
74  LoadParam<Element2D>(root, "layer", this, &Element2D::setLayer)
75      .describe("loads the layer onto which to project: (either: top, medium, bottom, below-all)");
76
77  LoadParam<Element2D>(root, "bind-node", this, &Element2D::setBindNode)
78      .describe("sets a node, this 2D-Element should be shown upon (name of the node)");
79
80  LoadParam<Element2D>(root, "2d-position", this, &Element2D::setPosition2D)
81      .describe("the _relative_ position (away from alignment) this 2d-element shows");
82
83  LoadParam<Element2D>(root, "visibility", this, &Element2D::setVisibility)
84      .describe("if the Element is visible or not");
85}
86
87/**
88 * sets the alignment of the 2D-element in form of a String
89 * @param alignment the alignment @see loadParams
90*/
91void Element2D::setAlignment(const char* alignment)
92{
93  if (!strcmp(alignment, "center"))
94    this->setAlignment(E2D_ALIGN_CENTER);
95  else if (!strcmp(alignment, "left"))
96    this->setAlignment(E2D_ALIGN_LEFT);
97  else if (!strcmp(alignment, "right"))
98    this->setAlignment(E2D_ALIGN_RIGHT);
99  else if (!strcmp(alignment, "screen-center"))
100    this->setAlignment(E2D_ALIGN_SCREEN_CENTER);
101}
102
103
104/**
105 * moves a Element to another layer
106 * @param layer the Layer this is drawn on
107 */
108void Element2D::setLayer(E2D_LAYER layer)
109{
110  Render2D::getInstance()->moveToLayer(this, layer);
111  this->layer = layer;
112}
113
114/**
115 * sets the layer onto which this 2D-element is projected to.
116 * @param layer the layer @see loadParams
117 */
118void Element2D::setLayer(const char* layer)
119{
120  if (!strcmp(layer, "top"))
121    this->setLayer(E2D_TOP);
122  else if (!strcmp(layer, "medium"))
123    this->setLayer(E2D_MEDIUM);
124  else if (!strcmp(layer, "bottom"))
125    this->setLayer(E2D_BOTTOM);
126  else if (!strcmp(layer, "below-all"))
127    this->setLayer(E2D_BELOW_ALL);
128}
129
130
131/**
132 * sets a node, this 2D-Element should be shown upon
133 * @param bindNode the name of the Node (should be existing)
134 */
135void Element2D::setBindNode(const char* bindNode)
136{
137  const PNode* tmpBindNode = dynamic_cast<const PNode*>(ClassList::getObject(bindNode, CL_PARENT_NODE));
138  if (tmpBindNode != NULL)
139    this->bindNode = tmpBindNode;
140}
141
142/**
143 * this sets the position of the Element on the screen.
144 * Use this in the your tick function, if you want the element to be automatically positioned.
145 */
146void Element2D::positioning()
147{
148  // setting the Position of this 2D-Element.
149  if (this->alignment == E2D_ALIGN_SCREEN_CENTER)
150  {
151    absPos2D.x = GraphicsEngine::getInstance()->getResolutionX()/2 + this->relPos2D[0];
152    absPos2D.y = GraphicsEngine::getInstance()->getResolutionY()/2 + this->relPos2D[1];
153    absPos2D.depth = 0;
154  }
155  else if (this->bindNode)
156  {
157    GLdouble projectPos[3];
158    gluProject(this->bindNode->getAbsCoor().x,
159               this->bindNode->getAbsCoor().y,
160               this->bindNode->getAbsCoor().z,
161               GraphicsEngine::modMat,
162               GraphicsEngine::projMat,
163               GraphicsEngine::viewPort,
164               projectPos,
165               projectPos+1,
166               projectPos+2);
167    absPos2D.x = projectPos[0] + this->relPos2D[0];
168    absPos2D.y = GraphicsEngine::getInstance()->getResolutionY() - projectPos[1] + this->relPos2D[1];
169    absPos2D.depth = projectPos[2];
170  }
171  else
172  {
173    absPos2D.x = this->relPos2D[0];
174    absPos2D.y = this->relPos2D[1];
175    absPos2D.depth = 0;
176  }
177}
178
179
180void Element2D::setRelCoor2D (const Vector& relCoord)
181{
182}
183
184
185void Element2D::setRelCoor2D (float x, float y, float z)
186{
187}
188
189void Element2D::setRelCoorSoft2D(const Vector& relCoordSoft, float bias)
190{
191}
192
193void Element2D::setRelCoorSoft2D(float x, float y, float dontCare, float bias)
194{
195}
196
197void Element2D::setAbsCoor2D (const Vector& absCoord)
198{
199}
200
201void Element2D::setAbsCoor2D (float x, float y, float depth)
202{
203}
204
205void Element2D::shiftCoor (const Vector& shift)
206{
207}
208
209
210void Element2D::setRelDir2D (float relDir)
211{
212}
213
214void Element2D::setRelDirSoft2D(float relDirSoft, float bias)
215{
216}
217
218void Element2D::setAbsDir2D (float absDir)
219{
220}
221
222void Element2D::shiftDir (float shiftDir)
223{
224}
225
226
227void Element2D::addChild2D (Element2D* child, int parentingMod)
228{
229}
230
231void Element2D::addChild2D (const char* childName)
232{
233}
234
235void Element2D::removeChild2D (Element2D* child)
236{
237}
238
239void Element2D::remove2D()
240{
241}
242
243
244void Element2D::setParent2D (Element2D* parent)
245{
246}
247
248void Element2D::setParent2D (const char* parentName)
249{
250}
251
252
253void Element2D::softReparent(PNode* parentNode, float bias)
254{
255}
256
257void Element2D::softReparent(const char* parentName, float bias)
258{
259}
260
261
262void Element2D::setParentMode2D (const char* parentingMode)
263{
264}
265
266
267void Element2D::update2D (float dt)
268{
269}
270
271
272void Element2D::debug (unsigned int depth, unsigned int level) const
273{
274}
275
276void Element2D::debugDraw2D(unsigned int depth, float size, Vector color) const
277{
278}
279
280
281// helper functions //
282const char* Element2D::parentingModeToChar(int parentingMode)
283{
284}
285
286E2D_PARENT_MODE Element2D::charToParentingMode(const char* parentingMode)
287{
288}
289
290
291
292
293
294
295/**
296 * ticks the 2d-Element
297 * @param dt the time elapsed since the last tick
298 */
299void Element2D::tick(float dt)
300{
301  this->positioning();
302}
Note: See TracBrowser for help on using the repository browser.