Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10659 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
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*/
14
15#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
16
17#include "image_plane.h"
18
19#include "util/loading/load_param.h"
20#include "util/loading/factory.h"
21
22#include "graphics_engine.h"
23#include "p_node.h"
24
25ObjectListDefinition(ImagePlane);
26CREATE_FACTORY(ImagePlane);
27
28
29/**
30 * standart constructor
31 */
32ImagePlane::ImagePlane (const TiXmlElement* root)
33{
34  this->init();
35
36  if( root)
37    this->loadParams(root);
38}
39
40
41/**
42 * destroys a ImagePlane
43 */
44ImagePlane::~ImagePlane ()
45{
46}
47
48
49/**
50 * initializes the ImagePlane
51 */
52void ImagePlane::init()
53{
54  this->registerObject(this, ImagePlane::_objectList);
55  this->setName("ImagePlane");
56
57  this->setLayer(E2D_LAYER_TOP);
58  this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0, GraphicsEngine::getInstance()->getResolutionY()/10.0);
59
60  //this->setBindNode(this);
61  this->setTexture("textures/error_texture.png");
62}
63
64
65/**
66 *  load params
67 * @param root TiXmlElement object
68 */
69void ImagePlane::loadParams(const TiXmlElement* root)
70{
71  LoadParam(root, "texture", &this->material, Material, setDiffuseMap)
72      .describe("the texture-file to load onto the ImagePlane");
73
74  LoadParam(root, "size", this, ImagePlane, setSize)
75      .describe("the size of the ImagePlane in Pixels");
76}
77
78
79/**
80 * sets the size of the ImagePlane.
81 * @param size the size in pixels
82 */
83void ImagePlane::setSize(float sizeX, float sizeY)
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 */
93void ImagePlane::setTexture(const std::string& textureFile)
94{
95  this->material.setDiffuseMap(textureFile);
96}
97
98
99/**
100 * attaches this image_plane to a parent
101 * @param pNode node to attach to
102 */
103void ImagePlane::attachTo(PNode* pNode)
104{
105  this->source->setParent(pNode);
106}
107
108
109/**
110 * ticks the ImagePlane
111 * @param dt the time to ticks
112 */
113void ImagePlane::tick(float dt)
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/**
138 * draws the image_plane
139 */
140void ImagePlane::draw() const
141{
142  glPushMatrix();
143
144  glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
145  this->material.select();
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();
157
158  glPopMatrix();
159}
Note: See TracBrowser for help on using the repository browser.