Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/effects/billboard.cc @ 10726

Last change on this file since 10726 was 10698, checked in by snellen, 17 years ago

merged adm, hud, vs-enhancements : beni's responsible for this commit. blame him!

File size: 4.5 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2006 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: David Hasenfratz
13   co-programmer: Nicolas Schlumberger
14*/
15
16#include "billboard.h"
17
18#include "util/loading/load_param.h"
19#include "util/loading/factory.h"
20
21#include "graphics_engine.h"
22#include "material.h"
23#include "glincl.h"
24#include "state.h"
25#include "tools/cameraman.h"
26#include "tools/camera.h"
27
28#include "debug.h"
29
30
31ObjectListDefinition(Billboard);
32CREATE_FACTORY(Billboard);
33
34/**
35 * standart constructor
36 */
37Billboard::Billboard (const TiXmlElement* root)
38{
39  this->init();
40
41  if( root)
42    this->loadParams(root);
43}
44
45
46/**
47 * destroys a Billboard
48 */
49Billboard::~Billboard ()
50{
51  if (this->material)
52    delete this->material;
53}
54
55
56/**
57 * initializes the Billboard
58 */
59void Billboard::init()
60{
61  this->registerObject(this, Billboard::_objectList);
62  this->setName("Billboard");
63
64  this->toList(OM_COMMON);
65
66  this->material = new Material();
67  this->setAbsCoor(0, 0, 0);
68  //this->setVisibiliy(true);
69  this->setSize(5, 5);
70
71  this->texColor = NULL;
72
73  this->pulseMagnitude = .5;
74  this->bPulse = false;
75
76  this->angularSpeed = M_2_PI; //360;
77  this->angle = 0;
78
79  this->setUpdateFunction((*sinf));
80}
81
82
83/**
84 *  load params
85 * @param root TiXmlElement object
86 */
87void Billboard::loadParams(const TiXmlElement* root)
88{
89  /*LoadParam(root, "texture", this->material, Material, setDiffuseMap)
90      .describe("the texture-file to load onto the Billboard");
91
92  LoadParam(root, "size", this, Billboard, setSize)
93  .describe("the size of the Billboard in Pixels");*/
94}
95
96
97/**
98 * sets the size of the Billboard.
99 * @param size the size in pixels
100 */
101void Billboard::setSize(float sizeX, float sizeY)
102{
103  this->sizeX = sizeX;
104  this->sizeY = sizeY;
105}
106
107
108/**
109 * sets the material to load
110 * @param textureFile The texture-file to load
111 */
112void Billboard::setTexture(const std::string& textureFile)
113{
114  this->material->setDiffuseMap(textureFile);
115}
116
117
118/**
119 * ticks the Billboard
120 * @param dt the time to ticks
121 */
122void Billboard::tick(float dt)
123{
124  this->angle += dt * this->angularSpeed;
125  if (this->angle > M_2_PI)
126    this->angle -= M_2_PI;
127//   curMagnitude = updatePulse(this->angle);
128}
129
130
131/**
132 * draws the billboard
133 */
134void Billboard::draw() const
135{
136  if( !this->isVisible())
137    return;
138
139  glPushAttrib(GL_ENABLE_BIT);
140  glDisable(GL_LIGHTING);
141  glDisable(GL_FOG);
142
143  glPushMatrix();
144
145  //glTranslatef(this->getAbsCoor().x, this->getAbsCoor().y, this->getAbsCoor().z);
146  //glTranslatef(0,0,0);
147  this->material->select();
148
149  const Camera* camera = State::getCamera();
150  Vector cameraPos = camera->getAbsCoor();
151  Vector cameraTargetPos = camera->getTarget()->getAbsCoor();
152  Vector view = cameraTargetPos - cameraPos;
153  Vector up = Vector(0, 1, 0);
154  up = camera->getAbsDir().apply(up);
155  Vector h = up.cross(view);
156  Vector v = h.cross(view);
157  h.normalize();
158  v.normalize();
159
160  float tmp = 1;
161  if (this->bPulse)
162    tmp += this->pulseMagnitude * sinf(this->angle); //updatePulse(this->angle);
163
164  v *= sizeX * tmp;
165  h *= sizeY * tmp;
166
167//v += this->getAbsCoor();
168    //PRINTF(0)("sizeX: %f sizeY: %f\n", sizeX, sizeY);
169
170  // changes the color of the texture (if any is set)
171  if(this->texColor != NULL)
172    glColor4ub((GLubyte)(this->texColor->r()*255.0f), (GLubyte)(this->texColor->g()*255.0f), (GLubyte)(this->texColor->b()*255.0f), (GLubyte)(this->texColor->a()*255));
173
174  glBegin(GL_QUADS);
175  glTexCoord2f(0.0f, 0.0f);
176  glVertex3f(this->getAbsCoor().x - h.x - v.x,
177             this->getAbsCoor().y - h.y - v.y,
178             this->getAbsCoor().z - h.z - v.z);
179  glTexCoord2f(1.0f, 0.0f);
180  glVertex3f( this->getAbsCoor().x + h.x - v.x,
181              this->getAbsCoor().y + h.y - v.y,
182              this->getAbsCoor().z + h.z - v.z);
183  glTexCoord2f(1.0f, 1.0f);
184  glVertex3f(this->getAbsCoor().x + h.x + v.x,
185             this->getAbsCoor().y + h.y + v.y,
186             this->getAbsCoor().z + h.z + v.z);
187  glTexCoord2f(0.0f, 1.0f);
188  glVertex3f(this->getAbsCoor().x - h.x + v.x,
189             this->getAbsCoor().y - h.y + v.y,
190             this->getAbsCoor().z - h.z + v.z);
191  glEnd();
192
193
194  glPopMatrix();
195
196  glPopAttrib();
197}
198
199
200/**
201 * changes the texture color
202 * @param col color for the texture
203 */
204void Billboard::colorTexture(const Color col)
205{
206  this->texColor = new Color(col.r(), col.g(), col.b(), col.a());
207}
Note: See TracBrowser for help on using the repository browser.