Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10575 was 10468, checked in by patrick, 18 years ago

added scriptable stuff to the now finished scrollertext. thx silvan for the good tutorial, it realy is complete

File size: 5.6 KB
RevLine 
[10453]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"
[10464]25#include "cameraman.h"
26#include "camera.h"
[10453]27
[10468]28#include "script_class.h"
29
30
[10453]31ObjectListDefinition(ScrollingScreen);
32CREATE_FACTORY(ScrollingScreen);
33
[10468]34CREATE_SCRIPTABLE_CLASS(ScrollingScreen,
35                        addMethod("start", Executor0<ScrollingScreen, lua_State*>(&ScrollingScreen::start))
36                       );
[10453]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
[10468]66void ScrollingScreen::start()
67{
68  this->bRun = true;
69}
[10453]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();
[10457]80  this->material->setDiffuse(1,1,1);
[10453]81  this->material->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
82
83  this->isTransparent = false;
84  this->transparency = 1.0;
[10457]85  this->offset = 0.0;
[10464]86
[10466]87  this->xSize = 0.;
88  this->ySize = 0.;
[10464]89  this->mode = SCSC_VIEW;
[10468]90  this->bRun = false;
[10453]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
[10466]106  LoadParam(root, "setSizeX", this, ScrollingScreen, setSizeX);
107  LoadParam(root, "setSizeY", this, ScrollingScreen, setSizeY);
[10455]108
109  LoadParam(root, "texture", this, ScrollingScreen, setTexture);
[10453]110}
111
112
113
114
[10455]115/**
116 * sets the texture
117 * @param texture name of tex
118 */
119void ScrollingScreen::setTexture(const std::string& texture)
120{
[10460]121  this->material->setDiffuseMap(texture);
122
123  Texture t = this->material->diffuseTexture();
124  this->ratio = t.getWidth() / t.getHeight();
[10455]125}
126
127
128
129
[10453]130void ScrollingScreen::draw() const
131{
[10464]132
[10468]133  if( this->offset - this->ratio > 1.|| this->offset < -1. || !this->bRun)
134    return;
135
[10464]136  if( this->mode == SCSC_FULL)
137    this->drawFull();
138  else
139    this->drawView();
140}
141
142void ScrollingScreen::drawFull() const
143{
[10453]144  glPushAttrib(GL_ENABLE_BIT);
145  glDisable(GL_LIGHTING);
[10457]146  glDisable(GL_FOG);
147  glEnable(GL_BLEND);
[10453]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
[10457]160
[10453]161  glBegin(GL_QUADS);
162
[10468]163  // unten links
164  glTexCoord2f(0., 1.);
165  glVertex3f(0., -this->xSize*0.5, -this->ySize*0.5);
[10453]166
[10468]167  // unten rechts
168  glTexCoord2f(1., 1.);
169  glVertex3f(0., -this->xSize*0.5, this->ySize*0.5);
[10453]170
[10468]171  // oben rechts
172  glTexCoord2f(1., 0.);
173  glVertex3f(0., this->xSize*0.5, this->ySize*0.5);
[10453]174
[10468]175  // oben links
176  glTexCoord2f(0., 0.);
177  glVertex3f(0., this->xSize*0.5, -this->ySize*0.5);
[10453]178
179  glEnd();
180
[10457]181  glPopAttrib();
[10453]182  glPopMatrix();
183}
184
[10464]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
[10466]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  }
[10464]216
[10468]217  float ratShift = 0.;
[10467]218  float borderTex = this->offset + ratio;
[10466]219  // we are above/below
220  if( 1 - (offset + ratio) < 0)
221  {
[10467]222    borderTex = 1.0;
[10468]223    ratShift = 1. - (1.-offset)/ratio;
[10466]224  }
225
[10464]226  glBegin(GL_QUADS);
[10468]227  // unten links
228  glTexCoord2f(0., borderTex);
229  glVertex3f(0., -(x*0.5 - x*ratShift), -y*0.5);
[10464]230
[10468]231  // unten rechts
232  glTexCoord2f(1., borderTex);
233  glVertex3f(0., -(x*0.5 - x*ratShift), y*0.5);
[10464]234
[10468]235  // oben rechts
236  glTexCoord2f(1., this->offset);
237  glVertex3f(0., x*0.5, y*0.5);
[10464]238
[10468]239  // oben links
240  glTexCoord2f(0., this->offset);
241  glVertex3f(0., x*0.5, -y*0.5);
[10464]242
243  glEnd();
244
245  glPopAttrib();
246  glPopMatrix();
247}
248
249
[10453]250/**
251 *
252 */
253void ScrollingScreen::tick (float time)
254{
255
[10468]256  if( !this->bRun)
257    return;
[10464]258
[10468]259  CameraMan* cm = State::getCameraman();
260  const Camera* cam = cm->getCurrentCam();
261  PNode* tar = cam->getTargetNode();
[10455]262
[10468]263  Vector dir = tar->getAbsCoor() - cam->getAbsCoor();
264  dir = dir.getNormalized();
[10455]265
[10468]266  float offset = 6.;
[10455]267
[10468]268  this->setAbsCoor( cam->getAbsCoor() + dir * offset);
[10455]269
270
[10468]271  Vector ddir = dir.cross( cam->getAbsDirV());
272  Quaternion q(ddir, cam->getAbsDirY());
273  this->setAbsDir( q);
[10457]274
[10468]275  // scroll the texture
276  this->offset += time * this->scrollingSpeed;
277  //     if( this->offset - this->ratio > 1.|| this->offset < -1.)
278  //       this->offset = 0.;
[10457]279
[10453]280}
281
282void ScrollingScreen::fadeIn(float speed)
283{
284}
285
286void ScrollingScreen::fadeOut(float speed)
287{
288}
Note: See TracBrowser for help on using the repository browser.