Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8087 was 8050, checked in by hdavid, 19 years ago

branches/atmospheric_engine: basic lightening effect with billboard works

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
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  PRINTF(0)("sizeX: %f sizeY: %f", sizeX, sizeY);
95}
96
97
98/**
99 * sets the material to load
100 * @param textureFile The texture-file to load
101 */
102void Billboard::setTexture(const std::string& textureFile)
103{
104  this->material->setDiffuseMap(textureFile);
105}
106
107
108/**
109 * ticks the Billboard
110 * @param dt the time to ticks
111 */
112void Billboard::tick(float dt)
113{
114}
115
116
117/**
118 * draws the billboard
119 */
120void Billboard::draw() const
121{
122  if( !this->isVisible())
123    return;
124
125  glPushMatrix();
126
127  //glTranslatef(this->getAbsCoor().x, this->getAbsCoor().y, this->getAbsCoor().z);
128  //glTranslatef(0,0,0);
129  this->material->select();
130 
131  const PNode* camera = State::getCameraNode();  //!< @todo MUST be different
132  Vector cameraPos = camera->getAbsCoor();
133  Vector cameraTargetPos = State::getCameraTargetNode()->getAbsCoor();
134  Vector view = cameraTargetPos - cameraPos;
135  Vector up = Vector(0, 1, 0);
136  up = camera->getAbsDir().apply(up);
137  Vector h = up.cross(view);
138  Vector v = h.cross(view);
139  h.normalize();
140  v.normalize();
141 
142  v *= sizeX;
143  h *= sizeY;
144
145//v += this->getAbsCoor();
146    //PRINTF(0)("sizeX: %f sizeY: %f\n", sizeX, sizeY);
147  glBegin(GL_QUADS);
148  glTexCoord2f(0.0f, 0.0f);
149  glVertex3f(this->getAbsCoor().x - h.x - v.x,
150             this->getAbsCoor().y - h.y - v.y,
151             this->getAbsCoor().z - h.z - v.z);
152  glTexCoord2f(1.0f, 0.0f);
153  glVertex3f( this->getAbsCoor().x + h.x - v.x,
154              this->getAbsCoor().y + h.y - v.y,
155              this->getAbsCoor().z + h.z - v.z);
156  glTexCoord2f(1.0f, 1.0f);
157  glVertex3f(this->getAbsCoor().x + h.x + v.x,
158             this->getAbsCoor().y + h.y + v.y,
159             this->getAbsCoor().z + h.z + v.z);
160  glTexCoord2f(0.0f, 1.0f);
161  glVertex3f(this->getAbsCoor().x - h.x + v.x,
162             this->getAbsCoor().y - h.y + v.y,
163             this->getAbsCoor().z - h.z + v.z);
164  glEnd();
165 
166 
167  glPopMatrix();
168}
Note: See TracBrowser for help on using the repository browser.