Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10465 was 10465, checked in by patrick, 19 years ago

much better now

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