Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10425 was 10425, checked in by stefalie, 17 years ago

blink: 1 bug less

File size: 4.1 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  if(this->texColor != NULL)
152  {
153    //glColor4ub((int)(this->texColor->r() * 255), (int)(this->texColor->g() * 255), (int)(this->texColor->b() * 255), (int)(this->texColor->a() * 255));
154    glColor4ub((GLubyte)this->texColor->r()*255, (GLubyte)this->texColor->g()*255, (GLubyte)this->texColor->b()*255, 255);
155    PRINTF(0)("\n\n\n\n::%f,%f,%f\n\n\n\n", this->texColor->r()*255, this->texColor->g()*255, this->texColor->b()*255);
156
157  }
158
159  glBegin(GL_QUADS);
160  glTexCoord2f(0.0f, 0.0f);
161  glVertex3f(this->getAbsCoor().x - h.x - v.x,
162             this->getAbsCoor().y - h.y - v.y,
163             this->getAbsCoor().z - h.z - v.z);
164  glTexCoord2f(1.0f, 0.0f);
165  glVertex3f( this->getAbsCoor().x + h.x - v.x,
166              this->getAbsCoor().y + h.y - v.y,
167              this->getAbsCoor().z + h.z - v.z);
168  glTexCoord2f(1.0f, 1.0f);
169  glVertex3f(this->getAbsCoor().x + h.x + v.x,
170             this->getAbsCoor().y + h.y + v.y,
171             this->getAbsCoor().z + h.z + v.z);
172  glTexCoord2f(0.0f, 1.0f);
173  glVertex3f(this->getAbsCoor().x - h.x + v.x,
174             this->getAbsCoor().y - h.y + v.y,
175             this->getAbsCoor().z - h.z + v.z);
176  glEnd();
177
178
179  glPopMatrix();
180
181  glPopAttrib();
182}
183
184
185/**
186 * changes the texture color
187 * @param col color for the texture
188 */
189void Billboard::colorTexture(Color col)
190{
191  this->texColor = &col;
192}
Note: See TracBrowser for help on using the repository browser.