Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

some changes…

File size: 3.9 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
[10407]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);
[10407]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);
[10407]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(255, 0, 0, 255);
155  }
156
[8255]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();
[9869]175
176
[8255]177  glPopMatrix();
[9869]178
[8495]179  glPopAttrib();
[7111]180}
[10407]181
182
183/**
184 * changes the texture color
185 * @param col color for the texture
186 */
187void Billboard::colorTexture(Color col)
188{
189  this->texColor = &col;
190}
Note: See TracBrowser for help on using the repository browser.