Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged cleanup into trunk (only improvements)

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"
[10618]24#include "tools/cameraman.h"
25#include "tools/camera.h"
[7111]26
[10433]27#include "debug.h"
[7112]28
29
[10114]30ObjectListDefinition(Billboard);
[9869]31CREATE_FACTORY(Billboard);
[9406]32
[7111]33/**
[8255]34 * standart constructor
35 */
36Billboard::Billboard (const TiXmlElement* root)
[7111]37{
[8255]38  this->init();
[7111]39
[8255]40  if( root)
41    this->loadParams(root);
42}
[7111]43
44
[8255]45/**
46 * destroys a Billboard
47 */
48Billboard::~Billboard ()
49{
50  if (this->material)
51    delete this->material;
52}
[7111]53
[7112]54
[8255]55/**
56 * initializes the Billboard
57 */
58void Billboard::init()
59{
[9869]60  this->registerObject(this, Billboard::_objectList);
[8255]61  this->setName("Billboard");
[7112]62
[8255]63  this->toList(OM_COMMON);
[7112]64
[8255]65  this->material = new Material();
66  this->setAbsCoor(0, 0, 0);
67  //this->setVisibiliy(true);
68  this->setSize(5, 5);
[10433]69
70  this->texColor = NULL;
[7111]71}
72
73
74/**
[8255]75 *  load params
76 * @param root TiXmlElement object
77 */
78void Billboard::loadParams(const TiXmlElement* root)
[7111]79{
[8255]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");*/
[7111]85}
86
[8255]87
88/**
89 * sets the size of the Billboard.
90 * @param size the size in pixels
91 */
92void Billboard::setSize(float sizeX, float sizeY)
[7111]93{
[8255]94  this->sizeX = sizeX;
95  this->sizeY = sizeY;
[7111]96}
97
98
[8255]99/**
100 * sets the material to load
101 * @param textureFile The texture-file to load
102 */
103void Billboard::setTexture(const std::string& textureFile)
[7111]104{
[8255]105  this->material->setDiffuseMap(textureFile);
[7111]106}
107
108
109/**
[8255]110 * ticks the Billboard
111 * @param dt the time to ticks
112 */
113void Billboard::tick(float dt)
[7111]114{
115}
116
117
[8255]118/**
119 * draws the billboard
120 */
121void Billboard::draw() const
[7111]122{
[8255]123  if( !this->isVisible())
124    return;
[7111]125
[8495]126  glPushAttrib(GL_ENABLE_BIT);
127  glDisable(GL_LIGHTING);
128  glDisable(GL_FOG);
[9869]129
[8255]130  glPushMatrix();
[7111]131
[8255]132  //glTranslatef(this->getAbsCoor().x, this->getAbsCoor().y, this->getAbsCoor().z);
133  //glTranslatef(0,0,0);
134  this->material->select();
[9869]135
[10618]136  const Camera* camera = State::getCamera();
[8255]137  Vector cameraPos = camera->getAbsCoor();
[10501]138  Vector cameraTargetPos = camera->getTarget()->getAbsCoor();
[8255]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();
[9869]146
[8255]147  v *= sizeX;
148  h *= sizeY;
[7111]149
[8255]150//v += this->getAbsCoor();
151    //PRINTF(0)("sizeX: %f sizeY: %f\n", sizeX, sizeY);
[10433]152
153  // changes the color of the texture (if any is set)
154  if(this->texColor != NULL)
[10491]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));
[10433]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}
[10433]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.