Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10156 was 10114, checked in by patrick, 18 years ago

merged network back to trunk

File size: 3.5 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2006 orx
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
11### File Specific:
12   main-programmer: David Hasenfratz
13*/
14
15#include "billboard.h"
16
17#include "util/loading/load_param.h"
18#include "util/loading/factory.h"
19
20#include "graphics_engine.h"
21#include "material.h"
22#include "glincl.h"
23#include "state.h"
24
25
26
27
28
29ObjectListDefinition(Billboard);
30CREATE_FACTORY(Billboard);
31
32/**
33 * standart constructor
34 */
35Billboard::Billboard (const TiXmlElement* root)
36{
37  this->init();
38
39  if( root)
40    this->loadParams(root);
41}
42
43
44/**
45 * destroys a Billboard
46 */
47Billboard::~Billboard ()
48{
49  if (this->material)
50    delete this->material;
51}
52
53
54/**
55 * initializes the Billboard
56 */
57void Billboard::init()
58{
59  this->registerObject(this, Billboard::_objectList);
60  this->setName("Billboard");
61
62  this->toList(OM_COMMON);
63
64  this->material = new Material();
65  this->setAbsCoor(0, 0, 0);
66  //this->setVisibiliy(true);
67  this->setSize(5, 5);
68}
69
70
71/**
72 *  load params
73 * @param root TiXmlElement object
74 */
75void Billboard::loadParams(const TiXmlElement* root)
76{
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");*/
82}
83
84
85/**
86 * sets the size of the Billboard.
87 * @param size the size in pixels
88 */
89void Billboard::setSize(float sizeX, float sizeY)
90{
91  this->sizeX = sizeX;
92  this->sizeY = sizeY;
93}
94
95
96/**
97 * sets the material to load
98 * @param textureFile The texture-file to load
99 */
100void Billboard::setTexture(const std::string& textureFile)
101{
102  this->material->setDiffuseMap(textureFile);
103}
104
105
106/**
107 * ticks the Billboard
108 * @param dt the time to ticks
109 */
110void Billboard::tick(float dt)
111{
112}
113
114
115/**
116 * draws the billboard
117 */
118void Billboard::draw() const
119{
120  if( !this->isVisible())
121    return;
122
123  glPushAttrib(GL_ENABLE_BIT);
124  glDisable(GL_LIGHTING);
125  glDisable(GL_FOG);
126
127  glPushMatrix();
128
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;
146
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();
170
171  glPopAttrib();
172}
Note: See TracBrowser for help on using the repository browser.