Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/render2D/billboard.cc @ 7142

Last change on this file since 7142 was 6889, checked in by patrick, 19 years ago

trunk: lenseflare is not drawn if behind the camera

File size: 3.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: Patrick Boenzli
13*/
14
15#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
16
17#include "billboard.h"
18
19#include "load_param.h"
20#include "factory.h"
21
22#include "graphics_engine.h"
23#include "material.h"
24#include "glincl.h"
25#include "state.h"
26#include "p_node.h"
27
28
29using namespace std;
30
31
32CREATE_FACTORY(Billboard, CL_IMAGE_ENTITY);
33
34
35/**
36 * standart constructor
37 */
38Billboard::Billboard (const TiXmlElement* root)
39{
40  this->init();
41
42  if( root)
43    this->loadParams(root);
44}
45
46
47/**
48 * destroys a Billboard
49 */
50Billboard::~Billboard ()
51{
52  if (this->material)
53    delete this->material;
54}
55
56
57/**
58 * initializes the Billboard
59 */
60void Billboard::init()
61{
62  this->setClassID(CL_BILLBOARD, "Billboard");
63  this->setName("Billboard");
64
65  this->setLayer(E2D_LAYER_TOP);
66  this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0, GraphicsEngine::getInstance()->getResolutionY()/10.0);
67
68  //this->setBindNode(this);
69  this->material = new Material();
70  this->setTexture("pictures/error_texture.png");
71}
72
73
74/**
75 *  load params
76 * @param root TiXmlElement object
77 */
78void Billboard::loadParams(const TiXmlElement* root)
79{
80  LoadParam(root, "texture", this, Billboard, setTexture)
81      .describe("the texture-file to load onto the Billboard");
82
83  LoadParam(root, "size", this, Billboard, setSize)
84      .describe("the size of the Billboard in Pixels");
85}
86
87
88/**
89 * sets the size of the Billboard.
90 * @param size the size in pixels
91 */
92void Billboard::setSize(float sizeX, float sizeY)
93{
94  this->setSize2D(sizeX, sizeY);
95}
96
97
98/**
99 * sets the material to load
100 * @param textureFile The texture-file to load onto the crosshair
101 */
102void Billboard::setTexture(const char* textureFile)
103{
104  this->material->setDiffuseMap(textureFile);
105}
106
107
108/**
109 * attaches this billboard to a parent
110 * @param pNode node to attach to
111 */
112void Billboard::attachTo(PNode* pNode)
113{
114  this->source->setParent(pNode);
115}
116
117
118/**
119 * ticks the Billboard
120 * @param dt the time to ticks
121 */
122void Billboard::tick(float dt)
123{
124  float z = 0.0f;
125  glReadPixels ((int)this->getAbsCoor2D().x,
126                 GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1,
127                 1,
128                 1,
129                 GL_DEPTH_COMPONENT,
130                 GL_FLOAT,
131                 &z);
132
133  GLdouble objX=.0, objY=.0, objZ=.0;
134  gluUnProject(this->getAbsCoor2D().x,
135               GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1,
136               .99,  // z
137               GraphicsEngine::modMat,
138               GraphicsEngine::projMat,
139               GraphicsEngine::viewPort,
140               &objX,
141               &objY,
142               &objZ );
143}
144
145
146/**
147 * draws the billboard
148 */
149void Billboard::draw() const
150{
151  if( !this->isVisible())
152    return;
153
154  glPushMatrix();
155
156  glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
157  this->material->select();
158
159  glBegin(GL_TRIANGLE_STRIP);
160  glTexCoord2f(0, 0);
161  glVertex2f(-this->getSizeX2D(), -this->getSizeY2D());
162  glTexCoord2f(1, 0);
163  glVertex2f(this->getSizeX2D(), -this->getSizeY2D());
164  glTexCoord2f(0, 1);
165  glVertex2f(-this->getSizeX2D(), this->getSizeY2D());
166  glTexCoord2f(1, 1);
167  glVertex2f(this->getSizeX2D(), this->getSizeY2D());
168  glEnd();
169
170  glPopMatrix();
171}
Note: See TracBrowser for help on using the repository browser.