Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

branches/atmospheric_engine: work on the billboard

File size: 3.2 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->material = new Material();
63  this->setTexture("pictures/error_texture.png");
64  this->setAbsCoor(0, 0, 0);
65  this->setVisibiliy(true);
66  this->setSize(10, 10);
67}
68
69
70/**
71 *  load params
72 * @param root TiXmlElement object
73 */
74void Billboard::loadParams(const TiXmlElement* root)
75{
76  LoadParam(root, "texture", this->material, Material, setDiffuseMap)
77      .describe("the texture-file to load onto the Billboard");
78
79  LoadParam(root, "size", this, Billboard, setSize)
80      .describe("the size of the Billboard in Pixels");
81}
82
83
84/**
85 * sets the size of the Billboard.
86 * @param size the size in pixels
87 */
88void Billboard::setSize(float sizeX, float sizeY)
89{
90  this->sizeX = sizeX;
91  this->sizeY = sizeY;
92}
93
94
95/**
96 * sets the material to load
97 * @param textureFile The texture-file to load
98 */
99void Billboard::setTexture(const std::string& textureFile)
100{
101  this->material->setDiffuseMap(textureFile);
102}
103
104
105/**
106 * ticks the Billboard
107 * @param dt the time to ticks
108 */
109void Billboard::tick(float dt)
110{/*
111  float z = 0.0f;
112  glReadPixels ((int)this->getAbsCoor2D().x,
113                 GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1,
114                 1,
115                 1,
116                 GL_DEPTH_COMPONENT,
117                 GL_FLOAT,
118                 &z);
119
120  GLdouble objX=.0, objY=.0, objZ=.0;
121  gluUnProject(this->getAbsCoor2D().x,
122               GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1,
123               .99,  // z
124               GraphicsEngine::modMat,
125               GraphicsEngine::projMat,
126               GraphicsEngine::viewPort,
127               &objX,
128               &objY,
129  &objZ );*/
130}
131
132
133/**
134 * draws the billboard
135 */
136void Billboard::draw() const
137{
138  if( !this->isVisible())
139    return;
140
141  glPushMatrix();
142
143  glTranslatef(this->getAbsCoor().x, this->getAbsCoor().y, this->getAbsCoor().z);
144  this->material->select();
145
146  glBegin(GL_QUADS);
147  glTexCoord2f(1.0f, 1.0f); glVertex3f(-sizeX/2, -sizeY/2,  0.0f);
148  glTexCoord2f(0.0f, 1.0f); glVertex3f( sizeX/2, -sizeY/2,  0.0f);
149  glTexCoord2f(0.0f, 0.0f); glVertex3f( sizeX/2,  sizeY/2,  0.0f);
150  glTexCoord2f(1.0f, 0.0f); glVertex3f(-sizeX/2,  sizeY/2,  0.0f);
151  glEnd();
152
153  glPopMatrix();
154}
Note: See TracBrowser for help on using the repository browser.