Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/atmospheric_engine/src/world_entities/effects/billboard.cc @ 7981

Last change on this file since 7981 was 7981, checked in by hdavid, 18 years ago

branches/atmospheric_engine: billboard

File size: 4.6 KB
RevLine 
[7111]1/*
2   orxonox - the future of 3D-vertical-scrollers
3
[7951]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
[7951]11### File Specific:
12   main-programmer: David Hasenfratz
[7111]13*/
14
[7951]15#include "billboard.h"
[7111]16
[7951]17#include "util/loading/load_param.h"
18#include "util/loading/factory.h"
[7111]19
[7951]20#include "graphics_engine.h"
[7111]21#include "material.h"
[7951]22#include "glincl.h"
23#include "state.h"
[7111]24
[7112]25
[7951]26using namespace std;
[7112]27
28
[7951]29CREATE_FACTORY(Billboard, CL_BILLBOARD);
[7111]30
31
32/**
[7951]33 * standart constructor
34 */
35Billboard::Billboard (const TiXmlElement* root)
[7111]36{
[7951]37  this->init();
[7111]38
[7951]39  if( root)
40    this->loadParams(root);
41}
[7111]42
43
[7951]44/**
45 * destroys a Billboard
46 */
47Billboard::~Billboard ()
48{
49  if (this->material)
50    delete this->material;
51}
[7111]52
[7112]53
[7951]54/**
55 * initializes the Billboard
56 */
57void Billboard::init()
58{
59  this->setClassID(CL_BILLBOARD, "Billboard");
60  this->setName("Billboard");
[7112]61
[7965]62  this->toList(OM_COMMON);
63
[7951]64  this->material = new Material();
[7981]65  //this->setTexture("maps/lightning_bolt.png");
66  //this->setAbsCoor(0, 0, 0);
[7951]67  this->setVisibiliy(true);
68  this->setSize(10, 10);
[7111]69}
70
71
72/**
[7951]73 *  load params
74 * @param root TiXmlElement object
75 */
76void Billboard::loadParams(const TiXmlElement* root)
[7111]77{
[7951]78  LoadParam(root, "texture", this->material, Material, setDiffuseMap)
79      .describe("the texture-file to load onto the Billboard");
80
81  LoadParam(root, "size", this, Billboard, setSize)
82      .describe("the size of the Billboard in Pixels");
[7111]83}
84
[7951]85
86/**
87 * sets the size of the Billboard.
88 * @param size the size in pixels
89 */
90void Billboard::setSize(float sizeX, float sizeY)
[7111]91{
[7951]92  this->sizeX = sizeX;
93  this->sizeY = sizeY;
[7111]94}
95
96
[7951]97/**
98 * sets the material to load
99 * @param textureFile The texture-file to load
100 */
101void Billboard::setTexture(const std::string& textureFile)
[7111]102{
[7951]103  this->material->setDiffuseMap(textureFile);
[7111]104}
105
106
107/**
[7951]108 * ticks the Billboard
109 * @param dt the time to ticks
110 */
111void Billboard::tick(float dt)
112{/*
113  float z = 0.0f;
114  glReadPixels ((int)this->getAbsCoor2D().x,
115                 GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1,
116                 1,
117                 1,
118                 GL_DEPTH_COMPONENT,
119                 GL_FLOAT,
120                 &z);
[7111]121
[7951]122  GLdouble objX=.0, objY=.0, objZ=.0;
123  gluUnProject(this->getAbsCoor2D().x,
124               GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1,
125               .99,  // z
126               GraphicsEngine::modMat,
127               GraphicsEngine::projMat,
128               GraphicsEngine::viewPort,
129               &objX,
130               &objY,
131  &objZ );*/
[7111]132}
133
134
[7951]135/**
136 * draws the billboard
137 */
138void Billboard::draw() const
[7111]139{
[7951]140  if( !this->isVisible())
141    return;
[7111]142
[7951]143  glPushMatrix();
[7111]144
[7965]145  //glTranslatef(this->getAbsCoor().x, this->getAbsCoor().y, this->getAbsCoor().z);
146  glTranslatef(0,0,0);
[7951]147  this->material->select();
[7981]148  /*
[7951]149  glBegin(GL_QUADS);
150  glTexCoord2f(1.0f, 1.0f); glVertex3f(-sizeX/2, -sizeY/2,  0.0f);
151  glTexCoord2f(0.0f, 1.0f); glVertex3f( sizeX/2, -sizeY/2,  0.0f);
152  glTexCoord2f(0.0f, 0.0f); glVertex3f( sizeX/2,  sizeY/2,  0.0f);
153  glTexCoord2f(1.0f, 0.0f); glVertex3f(-sizeX/2,  sizeY/2,  0.0f);
154  glEnd();
[7981]155  */
156 
157  const PNode* camera = State::getCameraNode();  //!< @todo MUST be different
158  Vector cameraPos = camera->getAbsCoor();
159  Vector cameraTargetPos = State::getCameraTargetNode()->getAbsCoor();
160  Vector view = cameraTargetPos - cameraPos;
161  Vector up = Vector(0, 1, 0);
162  up = camera->getAbsDir().apply(up);
163  Vector h = up.cross(view);
164  Vector v = h.cross(view);
165  h.normalize();
166  v.normalize();
167 
168  float radius = 5;
169  v *= .5 * radius;
170  h *= .5 * radius;
171  /*
172  glBegin(GL_TRIANGLE_STRIP);
173  glTexCoord2i(1, 1);
174  glVertex3f(0 - h.x - v.x,
175             0 - h.y - v.y,
176             0 - h.z - v.z);
177  glTexCoord2i(0, 1);
178  glVertex3f(0 - h.x + v.x,
179             0 - h.y + v.y,
180             0 - h.z + v.z);
181  glTexCoord2i(1, 0);
182  glVertex3f(0 + h.x - v.x,
183             0 + h.y - v.y,
184             0 + h.z - v.z);
185  glTexCoord2i(0, 0);
186  glVertex3f(0 + h.x + v.x,
187             0 + h.y + v.y,
188             0 + h.z + v.z);
[7112]189
[7981]190  glEnd();*/
191 
192  glBegin(GL_QUADS);
193  glTexCoord2f(0.0f, 0.0f);
194  glVertex3f(0 - h.x - v.x,
195              0 - h.y - v.y,
196              0 - h.z - v.z);
197  glTexCoord2f(1.0f, 0.0f);
198  glVertex3f( 0 + h.x - v.x,
199              0 + h.y - v.y,
200              0 + h.z - v.z);
201  glTexCoord2f(1.0f, 1.0f);
202  glVertex3f(0 + h.x + v.x,
203             0 + h.y + v.y,
204             0 + h.z + v.z);
205  glTexCoord2f(0.0f, 1.0f);
206  glVertex3f(0 - h.x + v.x,
207             0 - h.y + v.y,
208             0 - h.z + v.z);
209  glEnd();
210 
211 
[7951]212  glPopMatrix();
[7111]213}
Note: See TracBrowser for help on using the repository browser.