Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/lib/graphics/render2D/billboard.cc @ 6779

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

network: adding a billboard

File size: 4.0 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 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: Patrick Boenzli
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
17
18#include "image_entity.h"
19
20#include "load_param.h"
21#include "factory.h"
22
23#include "graphics_engine.h"
24#include "material.h"
25#include "glincl.h"
26#include "state.h"
27
28
29using namespace std;
30
31
32CREATE_FACTORY(Billboard, CL_IMAGE_ENTITY);
33
34
35/**
36 * standart constructor
37 */
38Billboard::Billboard (const TiXmlElement* root)
39{
40  this->init();
41  this->loadParams(root);
42}
43
44
45/**
46 * destroys a Billboard
47 */
48Billboard::~Billboard ()
49{
50  if (this->material)
51    delete this->material;
52}
53
54
55/**
56 * initializes the Billboard
57 */
58void Billboard::init()
59{
60  this->setClassID(CL_BILLBOARD, "Billboard");
61  this->setName("Billboard");
62
63  this->setLayer(E2D_LAYER_TOP);
64  this->setRotationSpeed(5);
65  this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0, GraphicsEngine::getInstance()->getResolutionY()/10.0);
66
67  this->setBindNode(this);
68  this->material = new Material;
69  this->setTexture("pictures/error_texture.png");
70  this->bBillboarding = false;
71}
72
73
74void Billboard::loadParams(const TiXmlElement* root)
75{
76  PNode::loadParams(root);
77
78  LoadParam(root, "texture", this, Billboard, setTexture)
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");
83
84  LoadParam(root, "rotation-speed", this, Billboard, setRotationSpeed)
85      .describe("the Speed with which the Billboard should rotate");
86
87  LoadParam(root, "billboarding", this, Billboard, toggleBillboard)
88      .describe("sets the Billboard to always look in the direction of the Player");
89}
90
91
92/**
93 * sets the size of the Billboard.
94 * @param size the size in pixels
95 */
96void Billboard::setSize(float sizeX, float sizeY)
97{
98  this->setSize2D(sizeX, sizeY);
99}
100
101
102/**
103 * sets the material to load
104 * @param textureFile The texture-file to load onto the crosshair
105 */
106void Billboard::setTexture(const char* textureFile)
107{
108  this->material->setDiffuseMap(textureFile);
109}
110
111
112/** this turns on/off the billboarding of this WorldEntity
113 *
114 * This means that the image will always look in the direction of the Player
115 */
116void Billboard::toggleBillboard()
117{
118  this->bBillboarding = !this->bBillboarding;
119}
120
121
122/**
123 * ticks the Billboard
124 * @param dt the time to ticks
125 */
126void Billboard::tick(float dt)
127{
128  // let the crosshair rotate
129  //this->shiftDir2D(dt * rotationSpeed);
130
131
132  float z = 0.0f;
133  glReadPixels ((int)this->getAbsCoor2D().x,
134                 GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1,
135                 1,
136                 1,
137                 GL_DEPTH_COMPONENT,
138                 GL_FLOAT,
139                 &z);
140
141
142  GLdouble objX=.0, objY=.0, objZ=.0;
143  gluUnProject(this->getAbsCoor2D().x,
144               GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1,
145               .99,  // z
146               GraphicsEngine::modMat,
147               GraphicsEngine::projMat,
148               GraphicsEngine::viewPort,
149               &objX,
150               &objY,
151               &objZ );
152
153  //this->setAbsCoor(objX, objY, objZ);
154}
155
156
157/**
158 * draws the crosshair
159 */
160void Billboard::draw() const
161{
162  glPushMatrix();
163  glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
164
165  //glRotatef(this->getAbsDir2D(), 0,0,1);
166  this->material->select();
167  glBegin(GL_TRIANGLE_STRIP);
168  glTexCoord2f(0, 0);
169  glVertex2f(-this->getSizeX2D(), -this->getSizeY2D());
170  glTexCoord2f(1, 0);
171  glVertex2f(this->getSizeX2D(), -this->getSizeY2D());
172  glTexCoord2f(0, 1);
173  glVertex2f(-this->getSizeX2D(), this->getSizeY2D());
174  glTexCoord2f(1, 1);
175  glVertex2f(this->getSizeX2D(), this->getSizeY2D());
176  glEnd();
177  glPopMatrix();
178
179}
Note: See TracBrowser for help on using the repository browser.