Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6566 was 6520, checked in by patrick, 19 years ago

network: the simple menu now works. now i need more graphics, more effects and more sound

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