Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/world_entities/image_entity.cc @ 6514

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

network: added the ImageEntity WorldEntity class which will soon display an image

File size: 4.1 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(ImageEntity, CL_IMAGE_ENTITY);
33
34
35/**
36 * standart constructor
37 */
38ImageEntity::ImageEntity (const TiXmlElement* root)
39{
40  this->init();
41  this->loadParams(root);
42}
43
44
45/**
46 * destroys a ImageEntity
47*/
48ImageEntity::~ImageEntity ()
49{
50  if (this->material)
51  delete this->material;
52
53  // delete what has to be deleted here
54
55  GraphicsEngine::showMouse(true);
56  GraphicsEngine::stealWMEvents(false);
57}
58
59
60/**
61 * initializes the ImageEntity
62 */
63void ImageEntity::init()
64{
65  this->setClassID(CL_IMAGE_ENTITY, "ImageEntity");
66  this->setName("ImageEntity");
67
68  this->setLayer(E2D_LAYER_TOP);
69  this->setRotationSpeed(5);
70  this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0);
71
72  this->setBindNode(this);
73  this->material = new Material;
74  this->bBillboarding = false;
75}
76
77
78void ImageEntity::loadParams(const TiXmlElement* root)
79{
80  static_cast<PNode*>(this)->loadParams(root);
81
82  if( root == NULL)
83    this->setTexture("maps/error_texture.png");
84
85  LoadParam(root, "texture", this, ImageEntity, setTexture)
86      .describe("the texture-file to load onto the ImageEntity");
87
88  LoadParam(root, "size", this, ImageEntity, setSize)
89      .describe("the size of the ImageEntity in Pixels");
90
91  LoadParam(root, "rotation-speed", this, ImageEntity, setRotationSpeed)
92      .describe("the Speed with which the ImageEntity should rotate");
93
94  LoadParam(root, "billboarding", this, ImageEntity, toggleBillboard)
95      .describe("sets the ImageEntity to always look in the direction of the Player");
96}
97
98
99/**
100 * sets the size of the ImageEntity.
101 * @param size the size in pixels
102 */
103void ImageEntity::setSize(float size)
104{
105  this->setSize2D(size/2, size/2);
106}
107
108
109/**
110 * sets the material to load
111 * @param textureFile The texture-file to load onto the crosshair
112 */
113void ImageEntity::setTexture(const char* textureFile)
114{
115  this->material->setDiffuseMap(textureFile);
116}
117
118
119/** this turns on/off the billboarding of this WorldEntity
120 *
121 * This means that the image will always look in the direction of the Player
122 */
123void ImageEntity::toggleBillboard()
124{
125  this->bBillboarding = !this->bBillboarding;
126}
127
128
129/**
130 * ticks the ImageEntity
131 * @param dt the time to ticks
132 */
133void ImageEntity::tick(float dt)
134{
135  // let the crosshair rotate
136  //this->shiftDir2D(dt * rotationSpeed);
137
138
139  float z = 0.0f;
140  glReadPixels ((int)this->getAbsCoor2D().x,
141                 GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1,
142                 1,
143                 1,
144                 GL_DEPTH_COMPONENT,
145                 GL_FLOAT,
146                 &z);
147
148
149  GLdouble objX=.0, objY=.0, objZ=.0;
150  gluUnProject(this->getAbsCoor2D().x,
151               GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1,
152               .99,  // z
153               GraphicsEngine::modMat,
154               GraphicsEngine::projMat,
155               GraphicsEngine::viewPort,
156               &objX,
157               &objY,
158               &objZ );
159
160  //this->setAbsCoor(objX, objY, objZ);
161}
162
163
164/**
165 * draws the crosshair
166 */
167void ImageEntity::draw() const
168{
169  glPushMatrix();
170  glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
171
172  //glRotatef(this->getAbsDir2D(), 0,0,1);
173  this->material->select();
174  glBegin(GL_TRIANGLE_STRIP);
175  glTexCoord2f(0, 0);
176  glVertex2f(-this->getSizeX2D(), -this->getSizeY2D());
177  glTexCoord2f(1, 0);
178  glVertex2f(this->getSizeX2D(), -this->getSizeY2D());
179  glTexCoord2f(0, 1);
180  glVertex2f(-this->getSizeX2D(), this->getSizeY2D());
181  glTexCoord2f(1, 1);
182  glVertex2f(this->getSizeX2D(), this->getSizeY2D());
183  glEnd();
184  glPopMatrix();
185
186}
Note: See TracBrowser for help on using the repository browser.