Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/tools/scrolling_screen.cc @ 10754

Last change on this file since 10754 was 10618, checked in by bknecht, 18 years ago

merged cleanup into trunk (only improvements)

File size: 5.6 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: Filip Gospodinov
13   co-programmer:
14*/
15#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
16
17#include "scrolling_screen.h"
18
19#include "util/loading/factory.h"
20#include "util/loading/load_param.h"
21
22#include "debug.h"
23#include "material.h"
24#include "state.h"
25#include "cameraman.h"
26#include "camera.h"
27
28#include "script_class.h"
29
30
31ObjectListDefinition(ScrollingScreen);
32CREATE_FACTORY(ScrollingScreen);
33
34CREATE_SCRIPTABLE_CLASS(ScrollingScreen,
35                        addMethod("start", Executor0<ScrollingScreen, lua_State*>(&ScrollingScreen::start))
36                       );
37
38
39/**
40 *
41 */
42ScrollingScreen::ScrollingScreen()
43{
44  this->init();
45}
46
47
48/**
49 *
50 */
51ScrollingScreen::ScrollingScreen(const TiXmlElement* root)
52{
53  this->init();
54
55  if( root != NULL)
56    this->loadParams(root);
57}
58
59
60/**
61 *
62 */
63ScrollingScreen::~ScrollingScreen()
64{}
65
66void ScrollingScreen::start()
67{
68  this->bRun = true;
69}
70
71/**
72 *
73 */
74void ScrollingScreen::init()
75{
76  this->registerObject(this, ScrollingScreen::_objectList);
77  this->toList(OM_COMMON);
78
79  this->material = new Material();
80  this->material->setDiffuse(1,1,1);
81  this->material->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
82
83  this->isTransparent = false;
84  this->transparency = 1.0;
85  this->offset = 0.0;
86
87  this->xSize = 0.;
88  this->ySize = 0.;
89  this->mode = SCSC_VIEW;
90  this->bRun = false;
91}
92
93
94/**
95 * loads the Settings of a MD2Creature from an XML-element.
96 * @param root the XML-element to load the MD2Creature's properties from
97 */
98void ScrollingScreen::loadParams(const TiXmlElement* root)
99{
100  WorldEntity::loadParams(root);
101
102  LoadParam(root, "setSpeed", this, ScrollingScreen, setSpeed);
103
104  LoadParam(root, "setHeight", this, ScrollingScreen, setViewHeight);
105
106  LoadParam(root, "setSizeX", this, ScrollingScreen, setSizeX);
107  LoadParam(root, "setSizeY", this, ScrollingScreen, setSizeY);
108
109  LoadParam(root, "texture", this, ScrollingScreen, setTexture);
110}
111
112
113
114
115/**
116 * sets the texture
117 * @param texture name of tex
118 */
119void ScrollingScreen::setTexture(const std::string& texture)
120{
121  this->material->setDiffuseMap(texture);
122
123  Texture t = this->material->diffuseTexture();
124  this->ratio = t.getWidth() / t.getHeight();
125}
126
127
128
129
130void ScrollingScreen::draw() const
131{
132
133  if( this->offset - this->ratio > 1.|| this->offset < -1. || !this->bRun)
134    return;
135
136  if( this->mode == SCSC_FULL)
137    this->drawFull();
138  else
139    this->drawView();
140}
141
142void ScrollingScreen::drawFull() const
143{
144  glPushAttrib(GL_ENABLE_BIT);
145  glDisable(GL_LIGHTING);
146  glDisable(GL_FOG);
147  glEnable(GL_BLEND);
148
149  glMatrixMode(GL_MODELVIEW);
150  glPushMatrix();
151  /* translate */
152  glTranslatef (this->getAbsCoor ().x,
153                this->getAbsCoor ().y,
154                this->getAbsCoor ().z);
155  Vector tmpRot = this->getAbsDir().getSpacialAxis();
156  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
157
158  this->material->select();
159
160
161  glBegin(GL_QUADS);
162
163  // unten links
164  glTexCoord2f(0., 1.);
165  glVertex3f(0., -this->xSize*0.5, -this->ySize*0.5);
166
167  // unten rechts
168  glTexCoord2f(1., 1.);
169  glVertex3f(0., -this->xSize*0.5, this->ySize*0.5);
170
171  // oben rechts
172  glTexCoord2f(1., 0.);
173  glVertex3f(0., this->xSize*0.5, this->ySize*0.5);
174
175  // oben links
176  glTexCoord2f(0., 0.);
177  glVertex3f(0., this->xSize*0.5, -this->ySize*0.5);
178
179  glEnd();
180
181  glPopAttrib();
182  glPopMatrix();
183}
184
185void ScrollingScreen::drawView() const
186{
187  glPushAttrib(GL_ENABLE_BIT);
188  glDisable(GL_LIGHTING);
189  glDisable(GL_FOG);
190  glEnable(GL_BLEND);
191
192  glMatrixMode(GL_MODELVIEW);
193  glPushMatrix();
194  /* translate */
195  glTranslatef (this->getAbsCoor ().x,
196                this->getAbsCoor ().y,
197                this->getAbsCoor ().z);
198  Vector tmpRot = this->getAbsDir().getSpacialAxis();
199  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
200
201  this->material->select();
202
203  float resize = (1. - (this->viewHeight + this->offset));
204
205  float x,y;
206  if( this->xSize != 0.)
207  {
208    x = this->xSize;
209    y = x * this->ratio;
210  }
211  else
212  {
213    y = this->ySize;
214    x = y * this->ratio;
215  }
216
217  float ratShift = 0.;
218  float borderTex = this->offset + ratio;
219  // we are above/below
220  if( 1 - (offset + ratio) < 0)
221  {
222    borderTex = 1.0;
223    ratShift = 1. - (1.-offset)/ratio;
224  }
225
226  glBegin(GL_QUADS);
227  // unten links
228  glTexCoord2f(0., borderTex);
229  glVertex3f(0., -(x*0.5 - x*ratShift), -y*0.5);
230
231  // unten rechts
232  glTexCoord2f(1., borderTex);
233  glVertex3f(0., -(x*0.5 - x*ratShift), y*0.5);
234
235  // oben rechts
236  glTexCoord2f(1., this->offset);
237  glVertex3f(0., x*0.5, y*0.5);
238
239  // oben links
240  glTexCoord2f(0., this->offset);
241  glVertex3f(0., x*0.5, -y*0.5);
242
243  glEnd();
244
245  glPopAttrib();
246  glPopMatrix();
247}
248
249
250/**
251 *
252 */
253void ScrollingScreen::tick (float time)
254{
255
256  if( !this->bRun)
257    return;
258
259  Camera* cam = State::getCamera();
260  PNode* tar = cam->getTargetNode();
261
262  Vector dir = tar->getAbsCoor() - cam->getAbsCoor();
263  dir = dir.getNormalized();
264
265  float offset = 6.;
266
267  this->setAbsCoor( cam->getAbsCoor() + dir * offset);
268
269
270  Vector ddir = dir.cross( cam->getAbsDirV());
271  Quaternion q(ddir, cam->getAbsDirY());
272  this->setAbsDir( q);
273
274  // scroll the texture
275  this->offset += time * this->scrollingSpeed;
276  //     if( this->offset - this->ratio > 1.|| this->offset < -1.)
277  //       this->offset = 0.;
278
279}
280
281void ScrollingScreen::fadeIn(float speed)
282{
283}
284
285void ScrollingScreen::fadeOut(float speed)
286{
287}
Note: See TracBrowser for help on using the repository browser.