Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9698 was 9406, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

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"
23#include "glincl.h"
[6782]24#include "p_node.h"
[6779]25
26
27
28
[9406]29
[7807]30CREATE_FACTORY(ImagePlane, CL_IMAGE_ENTITY);
[6779]31
32
33/**
34 * standart constructor
35 */
[7807]36ImagePlane::ImagePlane (const TiXmlElement* root)
[6779]37{
38  this->init();
[6782]39
40  if( root)
41    this->loadParams(root);
[6779]42}
43
44
45/**
[7807]46 * destroys a ImagePlane
[6779]47 */
[7807]48ImagePlane::~ImagePlane ()
[6779]49{
50}
51
52
53/**
[7807]54 * initializes the ImagePlane
[6779]55 */
[7807]56void ImagePlane::init()
[6779]57{
[7807]58  this->setClassID(CL_IMAGE_PLANE, "ImagePlane");
59  this->setName("ImagePlane");
[6779]60
61  this->setLayer(E2D_LAYER_TOP);
62  this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0, GraphicsEngine::getInstance()->getResolutionY()/10.0);
63
[6782]64  //this->setBindNode(this);
[6779]65  this->setTexture("pictures/error_texture.png");
66}
67
68
[6782]69/**
70 *  load params
71 * @param root TiXmlElement object
72 */
[7807]73void ImagePlane::loadParams(const TiXmlElement* root)
[6779]74{
[7843]75  LoadParam(root, "texture", &this->material, Material, setDiffuseMap)
[7807]76      .describe("the texture-file to load onto the ImagePlane");
[6779]77
[7807]78  LoadParam(root, "size", this, ImagePlane, setSize)
79      .describe("the size of the ImagePlane in Pixels");
[6779]80}
81
82
83/**
[7807]84 * sets the size of the ImagePlane.
[6779]85 * @param size the size in pixels
86 */
[7807]87void ImagePlane::setSize(float sizeX, float sizeY)
[6779]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 */
[7807]97void ImagePlane::setTexture(const std::string& textureFile)
[6779]98{
[7843]99  this->material.setDiffuseMap(textureFile);
[6779]100}
101
102
[6782]103/**
[7807]104 * attaches this image_plane to a parent
[6782]105 * @param pNode node to attach to
[6779]106 */
[7807]107void ImagePlane::attachTo(PNode* pNode)
[6779]108{
[6782]109  this->source->setParent(pNode);
[6779]110}
111
112
113/**
[7807]114 * ticks the ImagePlane
[6779]115 * @param dt the time to ticks
116 */
[7807]117void ImagePlane::tick(float dt)
[6779]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/**
[7807]142 * draws the image_plane
[6779]143 */
[7807]144void ImagePlane::draw() const
[6779]145{
146  glPushMatrix();
[6782]147
[6779]148  glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
[7843]149  this->material.select();
[6779]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();
[6782]161
[6779]162  glPopMatrix();
163}
Note: See TracBrowser for help on using the repository browser.