| 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 |  | 
|---|
| 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(); | 
|---|
| 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->mode = SCSC_VIEW; | 
|---|
| 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 |  */ | 
|---|
| 85 | void 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); | 
|---|
| 94 |  | 
|---|
| 95 |   LoadParam(root, "texture", this, ScrollingScreen, setTexture); | 
|---|
| 96 | } | 
|---|
| 97 |  | 
|---|
| 98 |  | 
|---|
| 99 |  | 
|---|
| 100 |  | 
|---|
| 101 | /** | 
|---|
| 102 |  * sets the texture | 
|---|
| 103 |  * @param texture name of tex | 
|---|
| 104 |  */ | 
|---|
| 105 | void ScrollingScreen::setTexture(const std::string& texture) | 
|---|
| 106 | { | 
|---|
| 107 |   this->material->setDiffuseMap(texture); | 
|---|
| 108 |  | 
|---|
| 109 |   Texture t = this->material->diffuseTexture(); | 
|---|
| 110 |   this->ratio = t.getWidth() / t.getHeight(); | 
|---|
| 111 | } | 
|---|
| 112 |  | 
|---|
| 113 |  | 
|---|
| 114 |  | 
|---|
| 115 |  | 
|---|
| 116 | void ScrollingScreen::draw() const | 
|---|
| 117 | { | 
|---|
| 118 |  | 
|---|
| 119 |   if( this->mode == SCSC_FULL) | 
|---|
| 120 |     this->drawFull(); | 
|---|
| 121 |   else | 
|---|
| 122 |     this->drawView(); | 
|---|
| 123 | } | 
|---|
| 124 |  | 
|---|
| 125 | void ScrollingScreen::drawFull() const | 
|---|
| 126 | { | 
|---|
| 127 |   glPushAttrib(GL_ENABLE_BIT); | 
|---|
| 128 |   glDisable(GL_LIGHTING); | 
|---|
| 129 |   glDisable(GL_FOG); | 
|---|
| 130 |   glEnable(GL_BLEND); | 
|---|
| 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 |  | 
|---|
| 143 |  | 
|---|
| 144 |   glBegin(GL_QUADS); | 
|---|
| 145 |  | 
|---|
| 146 |     // unten links | 
|---|
| 147 |     glTexCoord2f(0., 1.); | 
|---|
| 148 |     glVertex3f(0., -this->xSize*0.5, -this->ySize*0.5); | 
|---|
| 149 |  | 
|---|
| 150 |     // unten rechts | 
|---|
| 151 |     glTexCoord2f(1., 1.); | 
|---|
| 152 |     glVertex3f(0., -this->xSize*0.5, this->ySize*0.5); | 
|---|
| 153 |  | 
|---|
| 154 |     // oben rechts | 
|---|
| 155 |     glTexCoord2f(1., 0.); | 
|---|
| 156 |     glVertex3f(0., this->xSize*0.5, this->ySize*0.5); | 
|---|
| 157 |  | 
|---|
| 158 |     // oben links | 
|---|
| 159 |     glTexCoord2f(0., 0.); | 
|---|
| 160 |     glVertex3f(0., this->xSize*0.5, -this->ySize*0.5); | 
|---|
| 161 |  | 
|---|
| 162 |   glEnd(); | 
|---|
| 163 |  | 
|---|
| 164 |   glPopAttrib(); | 
|---|
| 165 |   glPopMatrix(); | 
|---|
| 166 | } | 
|---|
| 167 |  | 
|---|
| 168 | void 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 | 
|---|
| 193 |     glTexCoord2f(0., this->offset + ratio); | 
|---|
| 194 |     glVertex3f(0., -view*0.5, -this->ySize*0.5); | 
|---|
| 195 |  | 
|---|
| 196 |     // unten rechts | 
|---|
| 197 |     glTexCoord2f(1., this->offset + ratio); | 
|---|
| 198 |     glVertex3f(0., -view*0.5, this->ySize*0.5); | 
|---|
| 199 |  | 
|---|
| 200 |     // oben rechts | 
|---|
| 201 |     glTexCoord2f(1., this->offset); | 
|---|
| 202 |     glVertex3f(0., view*0.5, this->ySize*0.5); | 
|---|
| 203 |  | 
|---|
| 204 |     // oben links | 
|---|
| 205 |     glTexCoord2f(0., this->offset); | 
|---|
| 206 |     glVertex3f(0., view*0.5, -this->ySize*0.5); | 
|---|
| 207 |  | 
|---|
| 208 |   glEnd(); | 
|---|
| 209 |  | 
|---|
| 210 |   glPopAttrib(); | 
|---|
| 211 |   glPopMatrix(); | 
|---|
| 212 | } | 
|---|
| 213 |  | 
|---|
| 214 |  | 
|---|
| 215 | /** | 
|---|
| 216 |  * | 
|---|
| 217 |  */ | 
|---|
| 218 | void ScrollingScreen::tick (float time) | 
|---|
| 219 | { | 
|---|
| 220 |  | 
|---|
| 221 |     CameraMan* cm = State::getCameraman(); | 
|---|
| 222 |     const Camera* cam = cm->getCurrentCam(); | 
|---|
| 223 |     PNode* tar = cam->getTargetNode(); | 
|---|
| 224 |  | 
|---|
| 225 |     Vector dir = tar->getAbsCoor() - cam->getAbsCoor(); | 
|---|
| 226 |     dir = dir.getNormalized(); | 
|---|
| 227 |  | 
|---|
| 228 |     float offset = 4.; | 
|---|
| 229 |  | 
|---|
| 230 |     this->setAbsCoor( cam->getAbsCoor() + dir * offset); | 
|---|
| 231 |  | 
|---|
| 232 |  | 
|---|
| 233 |     Vector ddir = dir.cross( cam->getAbsDirV()); | 
|---|
| 234 |     Quaternion q(ddir, cam->getAbsDirY()); | 
|---|
| 235 |     this->setAbsDir( q); | 
|---|
| 236 |  | 
|---|
| 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 |  | 
|---|
| 244 | //     if( this->getParent() != cam) | 
|---|
| 245 | //     { | 
|---|
| 246 | //       this->setParent( cam); | 
|---|
| 247 | //       this->setRelCoor( 4.0, 0., 0.); | 
|---|
| 248 | //       this->setRelDir(); | 
|---|
| 249 | //     } | 
|---|
| 250 |  | 
|---|
| 251 |  | 
|---|
| 252 | } | 
|---|
| 253 |  | 
|---|
| 254 | void ScrollingScreen::fadeIn(float speed) | 
|---|
| 255 | { | 
|---|
| 256 |  | 
|---|
| 257 | } | 
|---|
| 258 |  | 
|---|
| 259 | void ScrollingScreen::fadeOut(float speed) | 
|---|
| 260 | { | 
|---|
| 261 |  | 
|---|
| 262 | } | 
|---|