Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10491 was 10491, checked in by patrick, 17 years ago

merged blinki branche back to trunk

File size: 4.1 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"
[10473]24#include "cameraman.h"
25#include "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
[10473]136  const CameraMan* man = State::getCameraman();
137  const Camera* camera = man->getCurrentCam(); //!< @todo MUST be different
[8255]138  Vector cameraPos = camera->getAbsCoor();
[10473]139  Vector cameraTargetPos = camera->getAbsCoor();
[8255]140  Vector view = cameraTargetPos - cameraPos;
141  Vector up = Vector(0, 1, 0);
142  up = camera->getAbsDir().apply(up);
143  Vector h = up.cross(view);
144  Vector v = h.cross(view);
145  h.normalize();
146  v.normalize();
[9869]147
[8255]148  v *= sizeX;
149  h *= sizeY;
[7111]150
[8255]151//v += this->getAbsCoor();
152    //PRINTF(0)("sizeX: %f sizeY: %f\n", sizeX, sizeY);
[10433]153
154  // changes the color of the texture (if any is set)
155  if(this->texColor != NULL)
[10491]156    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]157
[8255]158  glBegin(GL_QUADS);
159  glTexCoord2f(0.0f, 0.0f);
160  glVertex3f(this->getAbsCoor().x - h.x - v.x,
161             this->getAbsCoor().y - h.y - v.y,
162             this->getAbsCoor().z - h.z - v.z);
163  glTexCoord2f(1.0f, 0.0f);
164  glVertex3f( this->getAbsCoor().x + h.x - v.x,
165              this->getAbsCoor().y + h.y - v.y,
166              this->getAbsCoor().z + h.z - v.z);
167  glTexCoord2f(1.0f, 1.0f);
168  glVertex3f(this->getAbsCoor().x + h.x + v.x,
169             this->getAbsCoor().y + h.y + v.y,
170             this->getAbsCoor().z + h.z + v.z);
171  glTexCoord2f(0.0f, 1.0f);
172  glVertex3f(this->getAbsCoor().x - h.x + v.x,
173             this->getAbsCoor().y - h.y + v.y,
174             this->getAbsCoor().z - h.z + v.z);
175  glEnd();
[9869]176
177
[8255]178  glPopMatrix();
[9869]179
[8495]180  glPopAttrib();
[7111]181}
[10433]182
183
184/**
185 * changes the texture color
186 * @param col color for the texture
187 */
188void Billboard::colorTexture(const Color col)
189{
190  this->texColor = new Color(col.r(), col.g(), col.b(), col.a());
191}
Note: See TracBrowser for help on using the repository browser.