Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

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

File size: 4.2 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  PRINTF(0)("Created a ImageEntity\n");
83
84  if( root == NULL)
85    this->setTexture("maps/error_texture.png");
86
87  LoadParam(root, "texture", this, ImageEntity, setTexture)
88      .describe("the texture-file to load onto the ImageEntity");
89
90  LoadParam(root, "size", this, ImageEntity, setSize)
91      .describe("the size of the ImageEntity in Pixels");
92
93  LoadParam(root, "rotation-speed", this, ImageEntity, setRotationSpeed)
94      .describe("the Speed with which the ImageEntity should rotate");
95
96  LoadParam(root, "billboarding", this, ImageEntity, toggleBillboard)
97      .describe("sets the ImageEntity to always look in the direction of the Player");
98}
99
100
101/**
102 * sets the size of the ImageEntity.
103 * @param size the size in pixels
104 */
105void ImageEntity::setSize(float size)
106{
107  this->setSize2D(size/2, size/2);
108}
109
110
111/**
112 * sets the material to load
113 * @param textureFile The texture-file to load onto the crosshair
114 */
115void ImageEntity::setTexture(const char* textureFile)
116{
117  this->material->setDiffuseMap(textureFile);
118}
119
120
121/** this turns on/off the billboarding of this WorldEntity
122 *
123 * This means that the image will always look in the direction of the Player
124 */
125void ImageEntity::toggleBillboard()
126{
127  this->bBillboarding = !this->bBillboarding;
128}
129
130
131/**
132 * ticks the ImageEntity
133 * @param dt the time to ticks
134 */
135void ImageEntity::tick(float dt)
136{
137  // let the crosshair rotate
138  //this->shiftDir2D(dt * rotationSpeed);
139
140
141  float z = 0.0f;
142  glReadPixels ((int)this->getAbsCoor2D().x,
143                 GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1,
144                 1,
145                 1,
146                 GL_DEPTH_COMPONENT,
147                 GL_FLOAT,
148                 &z);
149
150
151  GLdouble objX=.0, objY=.0, objZ=.0;
152  gluUnProject(this->getAbsCoor2D().x,
153               GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1,
154               .99,  // z
155               GraphicsEngine::modMat,
156               GraphicsEngine::projMat,
157               GraphicsEngine::viewPort,
158               &objX,
159               &objY,
160               &objZ );
161
162  //this->setAbsCoor(objX, objY, objZ);
163}
164
165
166/**
167 * draws the crosshair
168 */
169void ImageEntity::draw() const
170{
171  glPushMatrix();
172  glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
173
174  //glRotatef(this->getAbsDir2D(), 0,0,1);
175  this->material->select();
176  glBegin(GL_TRIANGLE_STRIP);
177  glTexCoord2f(0, 0);
178  glVertex2f(-this->getSizeX2D(), -this->getSizeY2D());
179  glTexCoord2f(1, 0);
180  glVertex2f(this->getSizeX2D(), -this->getSizeY2D());
181  glTexCoord2f(0, 1);
182  glVertex2f(-this->getSizeX2D(), this->getSizeY2D());
183  glTexCoord2f(1, 1);
184  glVertex2f(this->getSizeX2D(), this->getSizeY2D());
185  glEnd();
186  glPopMatrix();
187
188}
Note: See TracBrowser for help on using the repository browser.