Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/heathaze/src/lib/graphics/render2D/image_plane.cc @ 10585

Last change on this file since 10585 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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