| [6779] | 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 | */ | 
|---|
|  | 14 |  | 
|---|
|  | 15 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON | 
|---|
|  | 16 |  | 
|---|
| [7807] | 17 | #include "image_plane.h" | 
|---|
| [6779] | 18 |  | 
|---|
| [7193] | 19 | #include "util/loading/load_param.h" | 
|---|
|  | 20 | #include "util/loading/factory.h" | 
|---|
| [6779] | 21 |  | 
|---|
|  | 22 | #include "graphics_engine.h" | 
|---|
|  | 23 | #include "material.h" | 
|---|
|  | 24 | #include "glincl.h" | 
|---|
|  | 25 | #include "state.h" | 
|---|
| [6782] | 26 | #include "p_node.h" | 
|---|
| [6779] | 27 |  | 
|---|
|  | 28 |  | 
|---|
|  | 29 | using namespace std; | 
|---|
|  | 30 |  | 
|---|
|  | 31 |  | 
|---|
| [7807] | 32 | CREATE_FACTORY(ImagePlane, CL_IMAGE_ENTITY); | 
|---|
| [6779] | 33 |  | 
|---|
|  | 34 |  | 
|---|
|  | 35 | /** | 
|---|
|  | 36 | * standart constructor | 
|---|
|  | 37 | */ | 
|---|
| [7807] | 38 | ImagePlane::ImagePlane (const TiXmlElement* root) | 
|---|
| [6779] | 39 | { | 
|---|
|  | 40 | this->init(); | 
|---|
| [6782] | 41 |  | 
|---|
|  | 42 | if( root) | 
|---|
|  | 43 | this->loadParams(root); | 
|---|
| [6779] | 44 | } | 
|---|
|  | 45 |  | 
|---|
|  | 46 |  | 
|---|
|  | 47 | /** | 
|---|
| [7807] | 48 | * destroys a ImagePlane | 
|---|
| [6779] | 49 | */ | 
|---|
| [7807] | 50 | ImagePlane::~ImagePlane () | 
|---|
| [6779] | 51 | { | 
|---|
|  | 52 | if (this->material) | 
|---|
|  | 53 | delete this->material; | 
|---|
|  | 54 | } | 
|---|
|  | 55 |  | 
|---|
|  | 56 |  | 
|---|
|  | 57 | /** | 
|---|
| [7807] | 58 | * initializes the ImagePlane | 
|---|
| [6779] | 59 | */ | 
|---|
| [7807] | 60 | void ImagePlane::init() | 
|---|
| [6779] | 61 | { | 
|---|
| [7807] | 62 | this->setClassID(CL_IMAGE_PLANE, "ImagePlane"); | 
|---|
|  | 63 | this->setName("ImagePlane"); | 
|---|
| [6779] | 64 |  | 
|---|
|  | 65 | this->setLayer(E2D_LAYER_TOP); | 
|---|
|  | 66 | this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0, GraphicsEngine::getInstance()->getResolutionY()/10.0); | 
|---|
|  | 67 |  | 
|---|
| [6782] | 68 | //this->setBindNode(this); | 
|---|
|  | 69 | this->material = new Material(); | 
|---|
| [6779] | 70 | this->setTexture("pictures/error_texture.png"); | 
|---|
|  | 71 | } | 
|---|
|  | 72 |  | 
|---|
|  | 73 |  | 
|---|
| [6782] | 74 | /** | 
|---|
|  | 75 | *  load params | 
|---|
|  | 76 | * @param root TiXmlElement object | 
|---|
|  | 77 | */ | 
|---|
| [7807] | 78 | void ImagePlane::loadParams(const TiXmlElement* root) | 
|---|
| [6779] | 79 | { | 
|---|
| [7221] | 80 | LoadParam(root, "texture", this->material, Material, setDiffuseMap) | 
|---|
| [7807] | 81 | .describe("the texture-file to load onto the ImagePlane"); | 
|---|
| [6779] | 82 |  | 
|---|
| [7807] | 83 | LoadParam(root, "size", this, ImagePlane, setSize) | 
|---|
|  | 84 | .describe("the size of the ImagePlane in Pixels"); | 
|---|
| [6779] | 85 | } | 
|---|
|  | 86 |  | 
|---|
|  | 87 |  | 
|---|
|  | 88 | /** | 
|---|
| [7807] | 89 | * sets the size of the ImagePlane. | 
|---|
| [6779] | 90 | * @param size the size in pixels | 
|---|
|  | 91 | */ | 
|---|
| [7807] | 92 | void ImagePlane::setSize(float sizeX, float sizeY) | 
|---|
| [6779] | 93 | { | 
|---|
|  | 94 | this->setSize2D(sizeX, sizeY); | 
|---|
|  | 95 | } | 
|---|
|  | 96 |  | 
|---|
|  | 97 |  | 
|---|
|  | 98 | /** | 
|---|
|  | 99 | * sets the material to load | 
|---|
|  | 100 | * @param textureFile The texture-file to load onto the crosshair | 
|---|
|  | 101 | */ | 
|---|
| [7807] | 102 | void ImagePlane::setTexture(const std::string& textureFile) | 
|---|
| [6779] | 103 | { | 
|---|
|  | 104 | this->material->setDiffuseMap(textureFile); | 
|---|
|  | 105 | } | 
|---|
|  | 106 |  | 
|---|
|  | 107 |  | 
|---|
| [6782] | 108 | /** | 
|---|
| [7807] | 109 | * attaches this image_plane to a parent | 
|---|
| [6782] | 110 | * @param pNode node to attach to | 
|---|
| [6779] | 111 | */ | 
|---|
| [7807] | 112 | void ImagePlane::attachTo(PNode* pNode) | 
|---|
| [6779] | 113 | { | 
|---|
| [6782] | 114 | this->source->setParent(pNode); | 
|---|
| [6779] | 115 | } | 
|---|
|  | 116 |  | 
|---|
|  | 117 |  | 
|---|
|  | 118 | /** | 
|---|
| [7807] | 119 | * ticks the ImagePlane | 
|---|
| [6779] | 120 | * @param dt the time to ticks | 
|---|
|  | 121 | */ | 
|---|
| [7807] | 122 | void ImagePlane::tick(float dt) | 
|---|
| [6779] | 123 | { | 
|---|
|  | 124 | float z = 0.0f; | 
|---|
|  | 125 | glReadPixels ((int)this->getAbsCoor2D().x, | 
|---|
|  | 126 | GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1, | 
|---|
|  | 127 | 1, | 
|---|
|  | 128 | 1, | 
|---|
|  | 129 | GL_DEPTH_COMPONENT, | 
|---|
|  | 130 | GL_FLOAT, | 
|---|
|  | 131 | &z); | 
|---|
|  | 132 |  | 
|---|
|  | 133 | GLdouble objX=.0, objY=.0, objZ=.0; | 
|---|
|  | 134 | gluUnProject(this->getAbsCoor2D().x, | 
|---|
|  | 135 | GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1, | 
|---|
|  | 136 | .99,  // z | 
|---|
|  | 137 | GraphicsEngine::modMat, | 
|---|
|  | 138 | GraphicsEngine::projMat, | 
|---|
|  | 139 | GraphicsEngine::viewPort, | 
|---|
|  | 140 | &objX, | 
|---|
|  | 141 | &objY, | 
|---|
|  | 142 | &objZ ); | 
|---|
|  | 143 | } | 
|---|
|  | 144 |  | 
|---|
|  | 145 |  | 
|---|
|  | 146 | /** | 
|---|
| [7807] | 147 | * draws the image_plane | 
|---|
| [6779] | 148 | */ | 
|---|
| [7807] | 149 | void ImagePlane::draw() const | 
|---|
| [6779] | 150 | { | 
|---|
| [6889] | 151 | if( !this->isVisible()) | 
|---|
|  | 152 | return; | 
|---|
|  | 153 |  | 
|---|
| [6779] | 154 | glPushMatrix(); | 
|---|
| [6782] | 155 |  | 
|---|
| [6779] | 156 | glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); | 
|---|
| [6782] | 157 | this->material->select(); | 
|---|
| [6779] | 158 |  | 
|---|
|  | 159 | glBegin(GL_TRIANGLE_STRIP); | 
|---|
|  | 160 | glTexCoord2f(0, 0); | 
|---|
|  | 161 | glVertex2f(-this->getSizeX2D(), -this->getSizeY2D()); | 
|---|
|  | 162 | glTexCoord2f(1, 0); | 
|---|
|  | 163 | glVertex2f(this->getSizeX2D(), -this->getSizeY2D()); | 
|---|
|  | 164 | glTexCoord2f(0, 1); | 
|---|
|  | 165 | glVertex2f(-this->getSizeX2D(), this->getSizeY2D()); | 
|---|
|  | 166 | glTexCoord2f(1, 1); | 
|---|
|  | 167 | glVertex2f(this->getSizeX2D(), this->getSizeY2D()); | 
|---|
|  | 168 | glEnd(); | 
|---|
| [6782] | 169 |  | 
|---|
| [6779] | 170 | glPopMatrix(); | 
|---|
|  | 171 | } | 
|---|