Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/blink/src/world_entities/effects/billboard.cc @ 10651

Last change on this file since 10651 was 10490, checked in by stefalie, 18 years ago

blinki: hacky

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
25
26#include "debug.h"
27
28
29ObjectListDefinition(Billboard);
30CREATE_FACTORY(Billboard);
31
32/**
33 * standart constructor
34 */
35Billboard::Billboard (const TiXmlElement* root)
36{
37  this->init();
38
39  if( root)
40    this->loadParams(root);
41}
42
43
44/**
45 * destroys a Billboard
46 */
47Billboard::~Billboard ()
48{
49  if (this->material)
50    delete this->material;
51}
52
53
54/**
55 * initializes the Billboard
56 */
57void Billboard::init()
58{
59  this->registerObject(this, Billboard::_objectList);
60  this->setName("Billboard");
61
62  this->toList(OM_COMMON);
63
64  this->material = new Material();
65  this->setAbsCoor(0, 0, 0);
66  //this->setVisibiliy(true);
67  this->setSize(5, 5);
68
69  this->texColor = NULL;
70}
71
72
73/**
74 *  load params
75 * @param root TiXmlElement object
76 */
77void Billboard::loadParams(const TiXmlElement* root)
78{
79  /*LoadParam(root, "texture", this->material, Material, setDiffuseMap)
80      .describe("the texture-file to load onto the Billboard");
81
82  LoadParam(root, "size", this, Billboard, setSize)
83  .describe("the size of the Billboard in Pixels");*/
84}
85
86
87/**
88 * sets the size of the Billboard.
89 * @param size the size in pixels
90 */
91void Billboard::setSize(float sizeX, float sizeY)
92{
93  this->sizeX = sizeX;
94  this->sizeY = sizeY;
95}
96
97
98/**
99 * sets the material to load
100 * @param textureFile The texture-file to load
101 */
102void Billboard::setTexture(const std::string& textureFile)
103{
104  this->material->setDiffuseMap(textureFile);
105}
106
107
108/**
109 * ticks the Billboard
110 * @param dt the time to ticks
111 */
112void Billboard::tick(float dt)
113{
114}
115
116
117/**
118 * draws the billboard
119 */
120void Billboard::draw() const
121{
122  if( !this->isVisible())
123    return;
124
125  glPushAttrib(GL_ENABLE_BIT);
126  glDisable(GL_LIGHTING);
127  glDisable(GL_FOG);
128
129  glPushMatrix();
130
131  //glTranslatef(this->getAbsCoor().x, this->getAbsCoor().y, this->getAbsCoor().z);
132  //glTranslatef(0,0,0);
133  this->material->select();
134
135  const PNode* camera = State::getCameraNode();  //!< @todo MUST be different
136  Vector cameraPos = camera->getAbsCoor();
137  Vector cameraTargetPos = State::getCameraTargetNode()->getAbsCoor();
138  Vector view = cameraTargetPos - cameraPos;
139  Vector up = Vector(0, 1, 0);
140  up = camera->getAbsDir().apply(up);
141  Vector h = up.cross(view);
142  Vector v = h.cross(view);
143  h.normalize();
144  v.normalize();
145
146  v *= sizeX;
147  h *= sizeY;
148
149//v += this->getAbsCoor();
150    //PRINTF(0)("sizeX: %f sizeY: %f\n", sizeX, sizeY);
151
152  // changes the color of the texture (if any is set)
153  if(this->texColor != NULL)
154    glColor4ub((GLubyte)(this->texColor->r()*255.0f), (GLubyte)(this->texColor->g()*255.0f), (GLubyte)(this->texColor->b()*255.0f), (GLubyte)(this->texColor->a()*255));
155
156  glBegin(GL_QUADS);
157  glTexCoord2f(0.0f, 0.0f);
158  glVertex3f(this->getAbsCoor().x - h.x - v.x,
159             this->getAbsCoor().y - h.y - v.y,
160             this->getAbsCoor().z - h.z - v.z);
161  glTexCoord2f(1.0f, 0.0f);
162  glVertex3f( this->getAbsCoor().x + h.x - v.x,
163              this->getAbsCoor().y + h.y - v.y,
164              this->getAbsCoor().z + h.z - v.z);
165  glTexCoord2f(1.0f, 1.0f);
166  glVertex3f(this->getAbsCoor().x + h.x + v.x,
167             this->getAbsCoor().y + h.y + v.y,
168             this->getAbsCoor().z + h.z + v.z);
169  glTexCoord2f(0.0f, 1.0f);
170  glVertex3f(this->getAbsCoor().x - h.x + v.x,
171             this->getAbsCoor().y - h.y + v.y,
172             this->getAbsCoor().z - h.z + v.z);
173  glEnd();
174
175
176  glPopMatrix();
177
178  glPopAttrib();
179}
180
181
182/**
183 * changes the texture color
184 * @param col color for the texture
185 */
186void Billboard::colorTexture(const Color col)
187{
188  this->texColor = new Color(col.r(), col.g(), col.b(), col.a());
189}
Note: See TracBrowser for help on using the repository browser.