Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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