[6514] | 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 | |
---|
[7193] | 20 | #include "util/loading/load_param.h" |
---|
| 21 | #include "util/loading/factory.h" |
---|
[6514] | 22 | |
---|
| 23 | #include "graphics_engine.h" |
---|
| 24 | #include "material.h" |
---|
| 25 | #include "glincl.h" |
---|
| 26 | #include "state.h" |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | |
---|
[9406] | 31 | |
---|
[10114] | 32 | |
---|
| 33 | ObjectListDefinition(ImageEntity); |
---|
[9869] | 34 | CREATE_FACTORY(ImageEntity); |
---|
[6514] | 35 | |
---|
| 36 | |
---|
| 37 | /** |
---|
| 38 | * standart constructor |
---|
| 39 | */ |
---|
| 40 | ImageEntity::ImageEntity (const TiXmlElement* root) |
---|
| 41 | { |
---|
| 42 | this->init(); |
---|
[6852] | 43 | if(root != NULL) |
---|
[6841] | 44 | this->loadParams(root); |
---|
[6514] | 45 | } |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | /** |
---|
| 49 | * destroys a ImageEntity |
---|
| 50 | */ |
---|
| 51 | ImageEntity::~ImageEntity () |
---|
| 52 | { |
---|
[7751] | 53 | if (this->material) |
---|
| 54 | delete this->material; |
---|
[6514] | 55 | } |
---|
| 56 | |
---|
[7751] | 57 | |
---|
[6514] | 58 | /** |
---|
| 59 | * initializes the ImageEntity |
---|
| 60 | */ |
---|
| 61 | void ImageEntity::init() |
---|
| 62 | { |
---|
[9869] | 63 | this->registerObject(this, ImageEntity::_objectList); |
---|
[6514] | 64 | this->setName("ImageEntity"); |
---|
| 65 | |
---|
| 66 | this->setLayer(E2D_LAYER_TOP); |
---|
| 67 | this->setRotationSpeed(5); |
---|
[6520] | 68 | this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0, GraphicsEngine::getInstance()->getResolutionY()/10.0); |
---|
[6514] | 69 | |
---|
| 70 | this->setBindNode(this); |
---|
[7751] | 71 | this->material = new Material; |
---|
[10317] | 72 | this->setTexture("textures/error_texture.png"); |
---|
[6514] | 73 | this->bBillboarding = false; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | void ImageEntity::loadParams(const TiXmlElement* root) |
---|
| 78 | { |
---|
[6696] | 79 | PNode::loadParams(root); |
---|
[6851] | 80 | Element2D::loadParams(root); |
---|
[6514] | 81 | |
---|
[7751] | 82 | LoadParam(root, "texture", this, ImageEntity, setTexture) |
---|
| 83 | .describe("the texture-file to load onto the ImageEntity"); |
---|
[6514] | 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 | |
---|
[6815] | 91 | LoadParam(root, "billboarding", this, ImageEntity, toggleBillboarding) |
---|
| 92 | .describe("sets the Billboard to always look in the direction of the Player"); |
---|
[6514] | 93 | } |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | /** |
---|
| 97 | * sets the size of the ImageEntity. |
---|
| 98 | * @param size the size in pixels |
---|
| 99 | */ |
---|
[6520] | 100 | void ImageEntity::setSize(float sizeX, float sizeY) |
---|
[6514] | 101 | { |
---|
[6520] | 102 | this->setSize2D(sizeX, sizeY); |
---|
[6514] | 103 | } |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | /** |
---|
| 107 | * sets the material to load |
---|
| 108 | * @param textureFile The texture-file to load onto the crosshair |
---|
| 109 | */ |
---|
[7221] | 110 | void ImageEntity::setTexture(const std::string& textureFile) |
---|
[6514] | 111 | { |
---|
[7751] | 112 | this->material->setDiffuseMap(textureFile); |
---|
[6514] | 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 | */ |
---|
[6815] | 120 | void ImageEntity::toggleBillboarding() |
---|
[6514] | 121 | { |
---|
| 122 | this->bBillboarding = !this->bBillboarding; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | /** |
---|
| 127 | * ticks the ImageEntity |
---|
| 128 | * @param dt the time to ticks |
---|
| 129 | */ |
---|
| 130 | void ImageEntity::tick(float dt) |
---|
| 131 | { |
---|
| 132 | |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | /** |
---|
| 137 | * draws the crosshair |
---|
| 138 | */ |
---|
| 139 | void ImageEntity::draw() const |
---|
| 140 | { |
---|
[6848] | 141 | if( !this->isVisible()) |
---|
| 142 | return; |
---|
| 143 | |
---|
[6514] | 144 | glPushMatrix(); |
---|
| 145 | glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); |
---|
| 146 | |
---|
| 147 | //glRotatef(this->getAbsDir2D(), 0,0,1); |
---|
[7751] | 148 | this->material->select(); |
---|
[6514] | 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 | } |
---|