Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

some texture attributes, camera target fix

File size: 4.1 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 "camera.h"
26
27ObjectListDefinition(ScrollingScreen);
28CREATE_FACTORY(ScrollingScreen);
29
30
31
32/**
33 *
34 */
35ScrollingScreen::ScrollingScreen()
36{
37  this->init();
38}
39
40
41/**
42 *
43 */
44ScrollingScreen::ScrollingScreen(const TiXmlElement* root)
45{
46  this->init();
47
48  if( root != NULL)
49    this->loadParams(root);
50}
51
52
53/**
54 *
55 */
56ScrollingScreen::~ScrollingScreen()
57{}
58
59
60/**
61 *
62 */
63void ScrollingScreen::init()
64{
65  this->registerObject(this, ScrollingScreen::_objectList);
66  this->toList(OM_COMMON);
67
68  this->material = new Material();
69  this->material->setDiffuse(1,1,1);
70  this->material->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
71
72  this->isTransparent = false;
73  this->transparency = 1.0;
74  this->offset = 0.0;
75}
76
77
78/**
79 * loads the Settings of a MD2Creature from an XML-element.
80 * @param root the XML-element to load the MD2Creature's properties from
81 */
82void ScrollingScreen::loadParams(const TiXmlElement* root)
83{
84  WorldEntity::loadParams(root);
85
86  LoadParam(root, "setSpeed", this, ScrollingScreen, setSpeed);
87
88  LoadParam(root, "setHeight", this, ScrollingScreen, setViewHeight);
89
90  LoadParam(root, "setSize", this, ScrollingScreen, setSize);
91
92  LoadParam(root, "texture", this, ScrollingScreen, setTexture);
93}
94
95
96
97
98/**
99 * sets the texture
100 * @param texture name of tex
101 */
102void ScrollingScreen::setTexture(const std::string& texture)
103{
104  this->material->setDiffuseMap(texture);
105
106  Texture t = this->material->diffuseTexture();
107  this->ratio = t.getWidth() / t.getHeight();
108}
109
110
111
112
113void ScrollingScreen::draw() const
114{
115  glPushAttrib(GL_ENABLE_BIT);
116  glDisable(GL_LIGHTING);
117  glDisable(GL_FOG);
118  glEnable(GL_BLEND);
119
120  glMatrixMode(GL_MODELVIEW);
121  glPushMatrix();
122  /* translate */
123  glTranslatef (this->getAbsCoor ().x,
124                this->getAbsCoor ().y,
125                this->getAbsCoor ().z);
126  Vector tmpRot = this->getAbsDir().getSpacialAxis();
127  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
128
129  this->material->select();
130
131  float resize = (1. - (this->viewHeight + this->offset));
132  if( resize > 0.)
133    resize = 0.;
134
135
136  float texRes = 1- resize;
137
138
139  glBegin(GL_QUADS);
140
141    // unten links
142    glTexCoord2f(0., 1.);
143    glVertex3f(0., -this->xSize*0.5, -this->ySize*0.5);
144
145    // unten rechts
146    glTexCoord2f(1., 1.);
147    glVertex3f(0., -this->xSize*0.5, this->ySize*0.5);
148
149    // oben rechts
150    glTexCoord2f(1., 0.);
151    glVertex3f(0., this->xSize*0.5, this->ySize*0.5);
152
153    // oben links
154    glTexCoord2f(0., 0.);
155    glVertex3f(0., this->xSize*0.5, -this->ySize*0.5);
156
157  glEnd();
158
159  glPopAttrib();
160  glPopMatrix();
161}
162
163/**
164 *
165 */
166void ScrollingScreen::tick (float time)
167{
168  if( State::getCameraNode() != NULL && State::getCameraTargetNode() != NULL)
169  {
170    PNode* cam = State::getCameraNode();
171    PNode* tar = State::getCameraTargetNode();
172
173    Vector dir = tar->getAbsCoor() - cam->getAbsCoor();
174    dir.normalize();
175
176    float offset = 4.;
177
178    this->setAbsCoor( cam->getAbsCoor() + dir * offset);
179
180
181    Vector ddir = dir.cross( cam->getAbsDirV());
182    Quaternion q(ddir, cam->getAbsDirY());
183    this->setAbsDir( q);
184
185    // scroll the texture
186    this->offset += time * this->scrollingSpeed;
187    if( this->offset > 1.|| this->offset < -1.)
188      this->offset = 0.;
189
190/*    PRINTF(0)("offset %f, offset: %f\n", this->offset, time * this->scrollingSpeed);*/
191
192//     if( this->getParent() != cam)
193//     {
194//       this->setParent( cam);
195//       this->setRelCoor( 4.0, 0., 0.);
196//       this->setRelDir();
197//     }
198
199  }
200}
201
202void ScrollingScreen::fadeIn(float speed)
203{
204
205}
206
207void ScrollingScreen::fadeOut(float speed)
208{
209
210}
Note: See TracBrowser for help on using the repository browser.