Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4857 was 4856, checked in by bensch, 20 years ago

orxonox/trunk: text renders as good as before, but now as Element2D

File size: 2.4 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
24using namespace std;
25
26
27/**
28 * standard constructor
29 * @todo this constructor is not jet implemented - do it
30*/
31Element2D::Element2D ()
32{
33  this->init();
34}
35
36/**
37 * standard deconstructor
38*/
39Element2D::~Element2D ()
40{
41  // delete what has to be deleted here
42  Render2D::getInstance()->unregisterElement2D(this);
43}
44
45
46void Element2D::init()
47{
48  this->setClassID(CL_ELEMENT_2D, "Element2D");
49
50  this->setPosition2D(0,0);
51  this->setAlignment(E2D_ALIGN_CENTER);
52
53  Render2D::getInstance()->registerElement2D(this);
54}
55
56/**
57 * this sets the position of the Element on the screen.
58 * Use this in the your tick function, if you want the element to be automatically positioned.
59 */
60void Element2D::positioning()
61{
62
63  // setting the Position of this 2D-Element.
64  if (this->alignment == E2D_ALIGN_SCREEN_CENTER)
65  {
66    absPos2D.x = GraphicsEngine::getInstance()->getResolutionX()/2 + this->relPos2D[0];
67    absPos2D.y = GraphicsEngine::getInstance()->getResolutionY()/2 + this->relPos2D[1];
68    absPos2D.depth = 0;
69  }
70  else if (this->bindNode)
71  {
72    GLdouble projectPos[3];
73    gluProject(this->bindNode->getAbsCoor().x,
74               this->bindNode->getAbsCoor().y,
75               this->bindNode->getAbsCoor().z,
76               GraphicsEngine::modMat,
77               GraphicsEngine::projMat,
78               GraphicsEngine::viewPort,
79               projectPos,
80               projectPos+1,
81               projectPos+2);
82    absPos2D.x = projectPos[0] + this->relPos2D[0];
83    absPos2D.y = GraphicsEngine::getInstance()->getResolutionY() - projectPos[1] + this->relPos2D[1];
84    absPos2D.depth = projectPos[2];
85  }
86  else
87  {
88    absPos2D.x = this->relPos2D[0];
89    absPos2D.y = this->relPos2D[1];
90    absPos2D.depth = 0;
91  }
92}
93
94/**
95 * ticks the 2d-Element
96 * @param dt the time elapsed since the last tick
97 */
98void Element2D::tick(float dt)
99{
100  this->positioning();
101}
Note: See TracBrowser for help on using the repository browser.