| [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 | |
|---|
| 28 | ObjectListDefinition(ScrollingScreen); |
|---|
| 29 | CREATE_FACTORY(ScrollingScreen); |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | /** |
|---|
| 34 | * |
|---|
| 35 | */ |
|---|
| 36 | ScrollingScreen::ScrollingScreen() |
|---|
| 37 | { |
|---|
| 38 | this->init(); |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | /** |
|---|
| 43 | * |
|---|
| 44 | */ |
|---|
| 45 | ScrollingScreen::ScrollingScreen(const TiXmlElement* root) |
|---|
| 46 | { |
|---|
| 47 | this->init(); |
|---|
| 48 | |
|---|
| 49 | if( root != NULL) |
|---|
| 50 | this->loadParams(root); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | /** |
|---|
| 55 | * |
|---|
| 56 | */ |
|---|
| 57 | ScrollingScreen::~ScrollingScreen() |
|---|
| 58 | {} |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | /** |
|---|
| 62 | * |
|---|
| 63 | */ |
|---|
| 64 | void 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 | |
|---|
| [10466] | 77 | this->xSize = 0.; |
|---|
| 78 | this->ySize = 0.; |
|---|
| [10464] | 79 | this->mode = SCSC_VIEW; |
|---|
| [10453] | 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 | */ |
|---|
| 87 | void 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 | |
|---|
| [10466] | 95 | LoadParam(root, "setSizeX", this, ScrollingScreen, setSizeX); |
|---|
| 96 | LoadParam(root, "setSizeY", this, ScrollingScreen, setSizeY); |
|---|
| [10455] | 97 | |
|---|
| 98 | LoadParam(root, "texture", this, ScrollingScreen, setTexture); |
|---|
| [10453] | 99 | } |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| [10455] | 104 | /** |
|---|
| 105 | * sets the texture |
|---|
| 106 | * @param texture name of tex |
|---|
| 107 | */ |
|---|
| 108 | void ScrollingScreen::setTexture(const std::string& texture) |
|---|
| 109 | { |
|---|
| [10460] | 110 | this->material->setDiffuseMap(texture); |
|---|
| 111 | |
|---|
| 112 | Texture t = this->material->diffuseTexture(); |
|---|
| 113 | this->ratio = t.getWidth() / t.getHeight(); |
|---|
| [10455] | 114 | } |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| [10453] | 119 | void ScrollingScreen::draw() const |
|---|
| 120 | { |
|---|
| [10464] | 121 | |
|---|
| 122 | if( this->mode == SCSC_FULL) |
|---|
| 123 | this->drawFull(); |
|---|
| 124 | else |
|---|
| 125 | this->drawView(); |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | void ScrollingScreen::drawFull() const |
|---|
| 129 | { |
|---|
| [10453] | 130 | glPushAttrib(GL_ENABLE_BIT); |
|---|
| 131 | glDisable(GL_LIGHTING); |
|---|
| [10457] | 132 | glDisable(GL_FOG); |
|---|
| 133 | glEnable(GL_BLEND); |
|---|
| [10453] | 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 | |
|---|
| [10457] | 146 | |
|---|
| [10453] | 147 | glBegin(GL_QUADS); |
|---|
| 148 | |
|---|
| [10460] | 149 | // unten links |
|---|
| 150 | glTexCoord2f(0., 1.); |
|---|
| [10457] | 151 | glVertex3f(0., -this->xSize*0.5, -this->ySize*0.5); |
|---|
| [10453] | 152 | |
|---|
| [10460] | 153 | // unten rechts |
|---|
| 154 | glTexCoord2f(1., 1.); |
|---|
| [10457] | 155 | glVertex3f(0., -this->xSize*0.5, this->ySize*0.5); |
|---|
| [10453] | 156 | |
|---|
| [10460] | 157 | // oben rechts |
|---|
| 158 | glTexCoord2f(1., 0.); |
|---|
| 159 | glVertex3f(0., this->xSize*0.5, this->ySize*0.5); |
|---|
| [10453] | 160 | |
|---|
| [10460] | 161 | // oben links |
|---|
| 162 | glTexCoord2f(0., 0.); |
|---|
| 163 | glVertex3f(0., this->xSize*0.5, -this->ySize*0.5); |
|---|
| [10453] | 164 | |
|---|
| 165 | glEnd(); |
|---|
| 166 | |
|---|
| [10457] | 167 | glPopAttrib(); |
|---|
| [10453] | 168 | glPopMatrix(); |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| [10464] | 171 | void 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 | |
|---|
| [10466] | 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 | } |
|---|
| [10464] | 202 | |
|---|
| [10467] | 203 | float borderTex = this->offset + ratio; |
|---|
| [10466] | 204 | // we are above/below |
|---|
| 205 | if( 1 - (offset + ratio) < 0) |
|---|
| 206 | { |
|---|
| [10467] | 207 | borderTex = 1.0; |
|---|
| [10466] | 208 | } |
|---|
| 209 | |
|---|
| [10464] | 210 | glBegin(GL_QUADS); |
|---|
| 211 | // unten links |
|---|
| [10467] | 212 | glTexCoord2f(0., borderTex); |
|---|
| [10466] | 213 | glVertex3f(0., -x*0.5, -y*0.5); |
|---|
| [10464] | 214 | |
|---|
| 215 | // unten rechts |
|---|
| [10467] | 216 | glTexCoord2f(1., borderTex); |
|---|
| [10466] | 217 | glVertex3f(0., -x*0.5, y*0.5); |
|---|
| [10464] | 218 | |
|---|
| 219 | // oben rechts |
|---|
| [10465] | 220 | glTexCoord2f(1., this->offset); |
|---|
| [10466] | 221 | glVertex3f(0., x*0.5, y*0.5); |
|---|
| [10464] | 222 | |
|---|
| 223 | // oben links |
|---|
| [10465] | 224 | glTexCoord2f(0., this->offset); |
|---|
| [10466] | 225 | glVertex3f(0., x*0.5, -y*0.5); |
|---|
| [10464] | 226 | |
|---|
| 227 | glEnd(); |
|---|
| 228 | |
|---|
| 229 | glPopAttrib(); |
|---|
| 230 | glPopMatrix(); |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | |
|---|
| [10453] | 234 | /** |
|---|
| 235 | * |
|---|
| 236 | */ |
|---|
| 237 | void ScrollingScreen::tick (float time) |
|---|
| 238 | { |
|---|
| 239 | |
|---|
| [10464] | 240 | CameraMan* cm = State::getCameraman(); |
|---|
| 241 | const Camera* cam = cm->getCurrentCam(); |
|---|
| 242 | PNode* tar = cam->getTargetNode(); |
|---|
| 243 | |
|---|
| [10455] | 244 | Vector dir = tar->getAbsCoor() - cam->getAbsCoor(); |
|---|
| [10464] | 245 | dir = dir.getNormalized(); |
|---|
| [10455] | 246 | |
|---|
| 247 | float offset = 4.; |
|---|
| 248 | |
|---|
| 249 | this->setAbsCoor( cam->getAbsCoor() + dir * offset); |
|---|
| 250 | |
|---|
| 251 | |
|---|
| [10456] | 252 | Vector ddir = dir.cross( cam->getAbsDirV()); |
|---|
| [10460] | 253 | Quaternion q(ddir, cam->getAbsDirY()); |
|---|
| [10456] | 254 | this->setAbsDir( q); |
|---|
| [10455] | 255 | |
|---|
| [10457] | 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 | |
|---|
| [10455] | 263 | // if( this->getParent() != cam) |
|---|
| 264 | // { |
|---|
| 265 | // this->setParent( cam); |
|---|
| 266 | // this->setRelCoor( 4.0, 0., 0.); |
|---|
| 267 | // this->setRelDir(); |
|---|
| 268 | // } |
|---|
| 269 | |
|---|
| [10464] | 270 | |
|---|
| [10453] | 271 | } |
|---|
| 272 | |
|---|
| 273 | void ScrollingScreen::fadeIn(float speed) |
|---|
| 274 | { |
|---|
| 275 | |
|---|
| 276 | } |
|---|
| 277 | |
|---|
| 278 | void ScrollingScreen::fadeOut(float speed) |
|---|
| 279 | { |
|---|
| 280 | |
|---|
| 281 | } |
|---|