Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9853 was 9406, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

File size: 3.5 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
26
27
[9406]28
[8255]29CREATE_FACTORY(Billboard, CL_BILLBOARD);
[7111]30
31
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{
59  this->setClassID(CL_BILLBOARD, "Billboard");
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);
[7111]68}
69
70
71/**
[8255]72 *  load params
73 * @param root TiXmlElement object
74 */
75void Billboard::loadParams(const TiXmlElement* root)
[7111]76{
[8255]77  /*LoadParam(root, "texture", this->material, Material, setDiffuseMap)
78      .describe("the texture-file to load onto the Billboard");
79
80  LoadParam(root, "size", this, Billboard, setSize)
81  .describe("the size of the Billboard in Pixels");*/
[7111]82}
83
[8255]84
85/**
86 * sets the size of the Billboard.
87 * @param size the size in pixels
88 */
89void Billboard::setSize(float sizeX, float sizeY)
[7111]90{
[8255]91  this->sizeX = sizeX;
92  this->sizeY = sizeY;
[7111]93}
94
95
[8255]96/**
97 * sets the material to load
98 * @param textureFile The texture-file to load
99 */
100void Billboard::setTexture(const std::string& textureFile)
[7111]101{
[8255]102  this->material->setDiffuseMap(textureFile);
[7111]103}
104
105
106/**
[8255]107 * ticks the Billboard
108 * @param dt the time to ticks
109 */
110void Billboard::tick(float dt)
[7111]111{
112}
113
114
[8255]115/**
116 * draws the billboard
117 */
118void Billboard::draw() const
[7111]119{
[8255]120  if( !this->isVisible())
121    return;
[7111]122
[8495]123  glPushAttrib(GL_ENABLE_BIT);
124  glDisable(GL_LIGHTING);
125  glDisable(GL_FOG);
126 
[8255]127  glPushMatrix();
[7111]128
[8255]129  //glTranslatef(this->getAbsCoor().x, this->getAbsCoor().y, this->getAbsCoor().z);
130  //glTranslatef(0,0,0);
131  this->material->select();
132 
133  const PNode* camera = State::getCameraNode();  //!< @todo MUST be different
134  Vector cameraPos = camera->getAbsCoor();
135  Vector cameraTargetPos = State::getCameraTargetNode()->getAbsCoor();
136  Vector view = cameraTargetPos - cameraPos;
137  Vector up = Vector(0, 1, 0);
138  up = camera->getAbsDir().apply(up);
139  Vector h = up.cross(view);
140  Vector v = h.cross(view);
141  h.normalize();
142  v.normalize();
143 
144  v *= sizeX;
145  h *= sizeY;
[7111]146
[8255]147//v += this->getAbsCoor();
148    //PRINTF(0)("sizeX: %f sizeY: %f\n", sizeX, sizeY);
149  glBegin(GL_QUADS);
150  glTexCoord2f(0.0f, 0.0f);
151  glVertex3f(this->getAbsCoor().x - h.x - v.x,
152             this->getAbsCoor().y - h.y - v.y,
153             this->getAbsCoor().z - h.z - v.z);
154  glTexCoord2f(1.0f, 0.0f);
155  glVertex3f( this->getAbsCoor().x + h.x - v.x,
156              this->getAbsCoor().y + h.y - v.y,
157              this->getAbsCoor().z + h.z - v.z);
158  glTexCoord2f(1.0f, 1.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(0.0f, 1.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  glEnd();
167 
168 
169  glPopMatrix();
[8495]170 
171  glPopAttrib();
[7111]172}
Note: See TracBrowser for help on using the repository browser.