Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/render2D/image_plane.cc @ 10549

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

merged branche data-fix back to trunk. this breaks compatibility with the old data/trunk data repository! be sure to update your data trunk

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