Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10663 was 10618, checked in by bknecht, 18 years ago

merged cleanup into trunk (only improvements)

File size: 4.0 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*/
14
15#include "billboard.h"
16
17#include "util/loading/load_param.h"
18#include "util/loading/factory.h"
19
20#include "graphics_engine.h"
21#include "material.h"
22#include "glincl.h"
23#include "state.h"
24#include "tools/cameraman.h"
25#include "tools/camera.h"
26
27#include "debug.h"
28
29
30ObjectListDefinition(Billboard);
31CREATE_FACTORY(Billboard);
32
33/**
34 * standart constructor
35 */
36Billboard::Billboard (const TiXmlElement* root)
37{
38  this->init();
39
40  if( root)
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->registerObject(this, Billboard::_objectList);
61  this->setName("Billboard");
62
63  this->toList(OM_COMMON);
64
65  this->material = new Material();
66  this->setAbsCoor(0, 0, 0);
67  //this->setVisibiliy(true);
68  this->setSize(5, 5);
69
70  this->texColor = NULL;
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->material, Material, setDiffuseMap)
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->sizeX = sizeX;
95  this->sizeY = sizeY;
96}
97
98
99/**
100 * sets the material to load
101 * @param textureFile The texture-file to load
102 */
103void Billboard::setTexture(const std::string& textureFile)
104{
105  this->material->setDiffuseMap(textureFile);
106}
107
108
109/**
110 * ticks the Billboard
111 * @param dt the time to ticks
112 */
113void Billboard::tick(float dt)
114{
115}
116
117
118/**
119 * draws the billboard
120 */
121void Billboard::draw() const
122{
123  if( !this->isVisible())
124    return;
125
126  glPushAttrib(GL_ENABLE_BIT);
127  glDisable(GL_LIGHTING);
128  glDisable(GL_FOG);
129
130  glPushMatrix();
131
132  //glTranslatef(this->getAbsCoor().x, this->getAbsCoor().y, this->getAbsCoor().z);
133  //glTranslatef(0,0,0);
134  this->material->select();
135
136  const Camera* camera = State::getCamera();
137  Vector cameraPos = camera->getAbsCoor();
138  Vector cameraTargetPos = camera->getTarget()->getAbsCoor();
139  Vector view = cameraTargetPos - cameraPos;
140  Vector up = Vector(0, 1, 0);
141  up = camera->getAbsDir().apply(up);
142  Vector h = up.cross(view);
143  Vector v = h.cross(view);
144  h.normalize();
145  v.normalize();
146
147  v *= sizeX;
148  h *= sizeY;
149
150//v += this->getAbsCoor();
151    //PRINTF(0)("sizeX: %f sizeY: %f\n", sizeX, sizeY);
152
153  // changes the color of the texture (if any is set)
154  if(this->texColor != NULL)
155    glColor4ub((GLubyte)(this->texColor->r()*255.0f), (GLubyte)(this->texColor->g()*255.0f), (GLubyte)(this->texColor->b()*255.0f), (GLubyte)(this->texColor->a()*255));
156
157  glBegin(GL_QUADS);
158  glTexCoord2f(0.0f, 0.0f);
159  glVertex3f(this->getAbsCoor().x - h.x - v.x,
160             this->getAbsCoor().y - h.y - v.y,
161             this->getAbsCoor().z - h.z - v.z);
162  glTexCoord2f(1.0f, 0.0f);
163  glVertex3f( this->getAbsCoor().x + h.x - v.x,
164              this->getAbsCoor().y + h.y - v.y,
165              this->getAbsCoor().z + h.z - v.z);
166  glTexCoord2f(1.0f, 1.0f);
167  glVertex3f(this->getAbsCoor().x + h.x + v.x,
168             this->getAbsCoor().y + h.y + v.y,
169             this->getAbsCoor().z + h.z + v.z);
170  glTexCoord2f(0.0f, 1.0f);
171  glVertex3f(this->getAbsCoor().x - h.x + v.x,
172             this->getAbsCoor().y - h.y + v.y,
173             this->getAbsCoor().z - h.z + v.z);
174  glEnd();
175
176
177  glPopMatrix();
178
179  glPopAttrib();
180}
181
182
183/**
184 * changes the texture color
185 * @param col color for the texture
186 */
187void Billboard::colorTexture(const Color col)
188{
189  this->texColor = new Color(col.r(), col.g(), col.b(), col.a());
190}
Note: See TracBrowser for help on using the repository browser.