Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/lib/graphics/render2D/billboard.cc @ 6781

Last change on this file since 6781 was 6781, checked in by patrick, 18 years ago

network: billboard compiles again

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