Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

blinki: hacky

File size: 4.0 KB
RevLine 
[7111]1/*
2   orxonox - the future of 3D-vertical-scrollers
3
[8255]4   Copyright (C) 2006 orx
[7111]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
[8255]11### File Specific:
12   main-programmer: David Hasenfratz
[7111]13*/
14
[8255]15#include "billboard.h"
[7111]16
[8255]17#include "util/loading/load_param.h"
18#include "util/loading/factory.h"
[7111]19
[8255]20#include "graphics_engine.h"
[7111]21#include "material.h"
[8255]22#include "glincl.h"
23#include "state.h"
[7111]24
[7112]25
[10433]26#include "debug.h"
[7112]27
28
[10114]29ObjectListDefinition(Billboard);
[9869]30CREATE_FACTORY(Billboard);
[9406]31
[7111]32/**
[8255]33 * standart constructor
34 */
35Billboard::Billboard (const TiXmlElement* root)
[7111]36{
[8255]37  this->init();
[7111]38
[8255]39  if( root)
40    this->loadParams(root);
41}
[7111]42
43
[8255]44/**
45 * destroys a Billboard
46 */
47Billboard::~Billboard ()
48{
49  if (this->material)
50    delete this->material;
51}
[7111]52
[7112]53
[8255]54/**
55 * initializes the Billboard
56 */
57void Billboard::init()
58{
[9869]59  this->registerObject(this, Billboard::_objectList);
[8255]60  this->setName("Billboard");
[7112]61
[8255]62  this->toList(OM_COMMON);
[7112]63
[8255]64  this->material = new Material();
65  this->setAbsCoor(0, 0, 0);
66  //this->setVisibiliy(true);
67  this->setSize(5, 5);
[10433]68
69  this->texColor = NULL;
[7111]70}
71
72
73/**
[8255]74 *  load params
75 * @param root TiXmlElement object
76 */
77void Billboard::loadParams(const TiXmlElement* root)
[7111]78{
[8255]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");*/
[7111]84}
85
[8255]86
87/**
88 * sets the size of the Billboard.
89 * @param size the size in pixels
90 */
91void Billboard::setSize(float sizeX, float sizeY)
[7111]92{
[8255]93  this->sizeX = sizeX;
94  this->sizeY = sizeY;
[7111]95}
96
97
[8255]98/**
99 * sets the material to load
100 * @param textureFile The texture-file to load
101 */
102void Billboard::setTexture(const std::string& textureFile)
[7111]103{
[8255]104  this->material->setDiffuseMap(textureFile);
[7111]105}
106
107
108/**
[8255]109 * ticks the Billboard
110 * @param dt the time to ticks
111 */
112void Billboard::tick(float dt)
[7111]113{
114}
115
116
[8255]117/**
118 * draws the billboard
119 */
120void Billboard::draw() const
[7111]121{
[8255]122  if( !this->isVisible())
123    return;
[7111]124
[8495]125  glPushAttrib(GL_ENABLE_BIT);
126  glDisable(GL_LIGHTING);
127  glDisable(GL_FOG);
[9869]128
[8255]129  glPushMatrix();
[7111]130
[8255]131  //glTranslatef(this->getAbsCoor().x, this->getAbsCoor().y, this->getAbsCoor().z);
132  //glTranslatef(0,0,0);
133  this->material->select();
[9869]134
[8255]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();
[9869]145
[8255]146  v *= sizeX;
147  h *= sizeY;
[7111]148
[8255]149//v += this->getAbsCoor();
150    //PRINTF(0)("sizeX: %f sizeY: %f\n", sizeX, sizeY);
[10433]151
152  // changes the color of the texture (if any is set)
153  if(this->texColor != NULL)
[10490]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));
[10433]155
[8255]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();
[9869]174
175
[8255]176  glPopMatrix();
[9869]177
[8495]178  glPopAttrib();
[7111]179}
[10433]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.