Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10466 was 10466, checked in by patrick, 17 years ago

better implementation, scalable in both dim

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