Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7897 was 7843, checked in by bensch, 19 years ago

compiles

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