Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8317 was 8255, checked in by bensch, 18 years ago

merged the atmos back with command: https://svn.orxonox.net/orxonox/branches/atmospheric_engine

File size: 3.4 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
26using namespace std;
27
28
29CREATE_FACTORY(Billboard, CL_BILLBOARD);
30
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->setClassID(CL_BILLBOARD, "Billboard");
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  glPushMatrix();
124
125  //glTranslatef(this->getAbsCoor().x, this->getAbsCoor().y, this->getAbsCoor().z);
126  //glTranslatef(0,0,0);
127  this->material->select();
128 
129  const PNode* camera = State::getCameraNode();  //!< @todo MUST be different
130  Vector cameraPos = camera->getAbsCoor();
131  Vector cameraTargetPos = State::getCameraTargetNode()->getAbsCoor();
132  Vector view = cameraTargetPos - cameraPos;
133  Vector up = Vector(0, 1, 0);
134  up = camera->getAbsDir().apply(up);
135  Vector h = up.cross(view);
136  Vector v = h.cross(view);
137  h.normalize();
138  v.normalize();
139 
140  v *= sizeX;
141  h *= sizeY;
142
143//v += this->getAbsCoor();
144    //PRINTF(0)("sizeX: %f sizeY: %f\n", sizeX, sizeY);
145  glBegin(GL_QUADS);
146  glTexCoord2f(0.0f, 0.0f);
147  glVertex3f(this->getAbsCoor().x - h.x - v.x,
148             this->getAbsCoor().y - h.y - v.y,
149             this->getAbsCoor().z - h.z - v.z);
150  glTexCoord2f(1.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, 1.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(0.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  glEnd();
163 
164 
165  glPopMatrix();
166}
Note: See TracBrowser for help on using the repository browser.