Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain/src/world_entities/elements/image_entity.cc @ 10651

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

merged network back to trunk

File size: 3.4 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 "util/loading/load_param.h"
21#include "util/loading/factory.h"
22
23#include "graphics_engine.h"
24#include "material.h"
25#include "glincl.h"
26#include "state.h"
27
28
29
30
31
32
33ObjectListDefinition(ImageEntity);
34CREATE_FACTORY(ImageEntity);
35
36
37/**
38 * standart constructor
39 */
40ImageEntity::ImageEntity (const TiXmlElement* root)
41{
42  this->init();
43  if(root != NULL)
44    this->loadParams(root);
45}
46
47
48/**
49 * destroys a ImageEntity
50*/
51ImageEntity::~ImageEntity ()
52{
53  if (this->material)
54    delete this->material;
55}
56
57
58/**
59 * initializes the ImageEntity
60 */
61void ImageEntity::init()
62{
63  this->registerObject(this, ImageEntity::_objectList);
64  this->setName("ImageEntity");
65
66  this->setLayer(E2D_LAYER_TOP);
67  this->setRotationSpeed(5);
68  this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0, GraphicsEngine::getInstance()->getResolutionY()/10.0);
69
70  this->setBindNode(this);
71  this->material = new Material;
72  this->setTexture("pictures/error_texture.png");
73  this->bBillboarding = false;
74}
75
76
77void ImageEntity::loadParams(const TiXmlElement* root)
78{
79  PNode::loadParams(root);
80  Element2D::loadParams(root);
81
82  LoadParam(root, "texture", this, ImageEntity, setTexture)
83      .describe("the texture-file to load onto the ImageEntity");
84
85  LoadParam(root, "size", this, ImageEntity, setSize)
86      .describe("the size of the ImageEntity in Pixels");
87
88  LoadParam(root, "rotation-speed", this, ImageEntity, setRotationSpeed)
89      .describe("the Speed with which the ImageEntity should rotate");
90
91  LoadParam(root, "billboarding", this, ImageEntity, toggleBillboarding)
92      .describe("sets the Billboard to always look in the direction of the Player");
93}
94
95
96/**
97 * sets the size of the ImageEntity.
98 * @param size the size in pixels
99 */
100void ImageEntity::setSize(float sizeX, float sizeY)
101{
102  this->setSize2D(sizeX, sizeY);
103}
104
105
106/**
107 * sets the material to load
108 * @param textureFile The texture-file to load onto the crosshair
109 */
110void ImageEntity::setTexture(const std::string& textureFile)
111{
112  this->material->setDiffuseMap(textureFile);
113}
114
115
116/** this turns on/off the billboarding of this WorldEntity
117 *
118 * This means that the image will always look in the direction of the Player
119 */
120void ImageEntity::toggleBillboarding()
121{
122  this->bBillboarding = !this->bBillboarding;
123}
124
125
126/**
127 * ticks the ImageEntity
128 * @param dt the time to ticks
129 */
130void ImageEntity::tick(float dt)
131{
132
133}
134
135
136/**
137 * draws the crosshair
138 */
139void ImageEntity::draw() const
140{
141  if( !this->isVisible())
142    return;
143
144  glPushMatrix();
145  glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
146
147  //glRotatef(this->getAbsDir2D(), 0,0,1);
148  this->material->select();
149  glBegin(GL_TRIANGLE_STRIP);
150  glTexCoord2f(0, 0);
151  glVertex2f(-this->getSizeX2D(), -this->getSizeY2D());
152  glTexCoord2f(1, 0);
153  glVertex2f(this->getSizeX2D(), -this->getSizeY2D());
154  glTexCoord2f(0, 1);
155  glVertex2f(-this->getSizeX2D(), this->getSizeY2D());
156  glTexCoord2f(1, 1);
157  glVertex2f(this->getSizeX2D(), this->getSizeY2D());
158  glEnd();
159  glPopMatrix();
160
161}
Note: See TracBrowser for help on using the repository browser.