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 | |
---|
27 | ObjectListDefinition(ScrollingScreen); |
---|
28 | CREATE_FACTORY(ScrollingScreen); |
---|
29 | |
---|
30 | |
---|
31 | |
---|
32 | /** |
---|
33 | * |
---|
34 | */ |
---|
35 | ScrollingScreen::ScrollingScreen() |
---|
36 | { |
---|
37 | this->init(); |
---|
38 | } |
---|
39 | |
---|
40 | |
---|
41 | /** |
---|
42 | * |
---|
43 | */ |
---|
44 | ScrollingScreen::ScrollingScreen(const TiXmlElement* root) |
---|
45 | { |
---|
46 | this->init(); |
---|
47 | |
---|
48 | if( root != NULL) |
---|
49 | this->loadParams(root); |
---|
50 | } |
---|
51 | |
---|
52 | |
---|
53 | /** |
---|
54 | * |
---|
55 | */ |
---|
56 | ScrollingScreen::~ScrollingScreen() |
---|
57 | {} |
---|
58 | |
---|
59 | |
---|
60 | /** |
---|
61 | * |
---|
62 | */ |
---|
63 | void 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 | */ |
---|
82 | void 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 | */ |
---|
102 | void ScrollingScreen::setTexture(const std::string& texture) |
---|
103 | { |
---|
104 | this->material->setDiffuseMap( texture); |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | |
---|
109 | |
---|
110 | void ScrollingScreen::draw() const |
---|
111 | { |
---|
112 | glPushAttrib(GL_ENABLE_BIT); |
---|
113 | glDisable(GL_LIGHTING); |
---|
114 | glDisable(GL_FOG); |
---|
115 | glEnable(GL_BLEND); |
---|
116 | |
---|
117 | glMatrixMode(GL_MODELVIEW); |
---|
118 | glPushMatrix(); |
---|
119 | /* translate */ |
---|
120 | glTranslatef (this->getAbsCoor ().x, |
---|
121 | this->getAbsCoor ().y, |
---|
122 | this->getAbsCoor ().z); |
---|
123 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
124 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
125 | |
---|
126 | this->material->select(); |
---|
127 | |
---|
128 | float resize = -(1. - (this->viewHeight + this->offset)); |
---|
129 | if( resize < 0.) |
---|
130 | resize = 1.; |
---|
131 | else resize = 1 - resize; |
---|
132 | |
---|
133 | float texRes = 1 - resize; |
---|
134 | |
---|
135 | |
---|
136 | glBegin(GL_QUADS); |
---|
137 | |
---|
138 | glTexCoord2f(this->offset, 0.); |
---|
139 | glVertex3f(0., -this->xSize*0.5, -this->ySize*0.5); |
---|
140 | |
---|
141 | glTexCoord2f(this->offset, 1.); |
---|
142 | glVertex3f(0., -this->xSize*0.5, this->ySize*0.5); |
---|
143 | |
---|
144 | glTexCoord2f(this->offset + this->viewHeight - texRes, 1.); |
---|
145 | glVertex3f(0., this->xSize*0.5 - (resize*this->xSize*0.5), this->ySize*0.5); |
---|
146 | |
---|
147 | glTexCoord2f(this->offset + this->viewHeight - texRes, 0.); |
---|
148 | glVertex3f(0., this->xSize*0.5 - (resize*this->xSize*0.5), -this->ySize*0.5); |
---|
149 | |
---|
150 | glEnd(); |
---|
151 | |
---|
152 | glPopAttrib(); |
---|
153 | glPopMatrix(); |
---|
154 | } |
---|
155 | |
---|
156 | /** |
---|
157 | * |
---|
158 | */ |
---|
159 | void ScrollingScreen::tick (float time) |
---|
160 | { |
---|
161 | if( State::getCameraNode() != NULL && State::getCameraTargetNode() != NULL) |
---|
162 | { |
---|
163 | PNode* cam = State::getCameraNode(); |
---|
164 | PNode* tar = State::getCameraTargetNode(); |
---|
165 | |
---|
166 | Vector dir = tar->getAbsCoor() - cam->getAbsCoor(); |
---|
167 | dir.normalize(); |
---|
168 | |
---|
169 | float offset = 4.; |
---|
170 | |
---|
171 | this->setAbsCoor( cam->getAbsCoor() + dir * offset); |
---|
172 | |
---|
173 | |
---|
174 | Vector ddir = dir.cross( cam->getAbsDirV()); |
---|
175 | Quaternion q(ddir, cam->getAbsDirV()); |
---|
176 | this->setAbsDir( q); |
---|
177 | |
---|
178 | // scroll the texture |
---|
179 | this->offset += time * this->scrollingSpeed; |
---|
180 | if( this->offset > 1.|| this->offset < -1.) |
---|
181 | this->offset = 0.; |
---|
182 | |
---|
183 | /* PRINTF(0)("offset %f, offset: %f\n", this->offset, time * this->scrollingSpeed);*/ |
---|
184 | |
---|
185 | // if( this->getParent() != cam) |
---|
186 | // { |
---|
187 | // this->setParent( cam); |
---|
188 | // this->setRelCoor( 4.0, 0., 0.); |
---|
189 | // this->setRelDir(); |
---|
190 | // } |
---|
191 | |
---|
192 | } |
---|
193 | } |
---|
194 | |
---|
195 | void ScrollingScreen::fadeIn(float speed) |
---|
196 | { |
---|
197 | |
---|
198 | } |
---|
199 | |
---|
200 | void ScrollingScreen::fadeOut(float speed) |
---|
201 | { |
---|
202 | |
---|
203 | } |
---|