[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" |
---|
| 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(); |
---|
[10457] | 69 | this->material->setDiffuse(1,1,1); |
---|
[10453] | 70 | this->material->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
---|
| 71 | |
---|
| 72 | this->isTransparent = false; |
---|
| 73 | this->transparency = 1.0; |
---|
[10457] | 74 | this->offset = 0.0; |
---|
[10453] | 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); |
---|
[10455] | 91 | |
---|
| 92 | LoadParam(root, "texture", this, ScrollingScreen, setTexture); |
---|
[10453] | 93 | } |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | |
---|
[10455] | 98 | /** |
---|
| 99 | * sets the texture |
---|
| 100 | * @param texture name of tex |
---|
| 101 | */ |
---|
| 102 | void ScrollingScreen::setTexture(const std::string& texture) |
---|
| 103 | { |
---|
[10460] | 104 | this->material->setDiffuseMap(texture); |
---|
| 105 | |
---|
| 106 | Texture t = this->material->diffuseTexture(); |
---|
| 107 | this->ratio = t.getWidth() / t.getHeight(); |
---|
[10455] | 108 | } |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | |
---|
[10453] | 113 | void ScrollingScreen::draw() const |
---|
| 114 | { |
---|
| 115 | glPushAttrib(GL_ENABLE_BIT); |
---|
| 116 | glDisable(GL_LIGHTING); |
---|
[10457] | 117 | glDisable(GL_FOG); |
---|
| 118 | glEnable(GL_BLEND); |
---|
[10453] | 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 | |
---|
[10460] | 131 | float resize = (1. - (this->viewHeight + this->offset)); |
---|
| 132 | if( resize > 0.) |
---|
| 133 | resize = 0.; |
---|
[10457] | 134 | |
---|
| 135 | |
---|
[10460] | 136 | float texRes = 1- resize; |
---|
[10457] | 137 | |
---|
[10460] | 138 | |
---|
[10453] | 139 | glBegin(GL_QUADS); |
---|
| 140 | |
---|
[10460] | 141 | // unten links |
---|
| 142 | glTexCoord2f(0., 1.); |
---|
[10457] | 143 | glVertex3f(0., -this->xSize*0.5, -this->ySize*0.5); |
---|
[10453] | 144 | |
---|
[10460] | 145 | // unten rechts |
---|
| 146 | glTexCoord2f(1., 1.); |
---|
[10457] | 147 | glVertex3f(0., -this->xSize*0.5, this->ySize*0.5); |
---|
[10453] | 148 | |
---|
[10460] | 149 | // oben rechts |
---|
| 150 | glTexCoord2f(1., 0.); |
---|
| 151 | glVertex3f(0., this->xSize*0.5, this->ySize*0.5); |
---|
[10453] | 152 | |
---|
[10460] | 153 | // oben links |
---|
| 154 | glTexCoord2f(0., 0.); |
---|
| 155 | glVertex3f(0., this->xSize*0.5, -this->ySize*0.5); |
---|
[10453] | 156 | |
---|
| 157 | glEnd(); |
---|
| 158 | |
---|
[10457] | 159 | glPopAttrib(); |
---|
[10453] | 160 | glPopMatrix(); |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | /** |
---|
| 164 | * |
---|
| 165 | */ |
---|
| 166 | void ScrollingScreen::tick (float time) |
---|
| 167 | { |
---|
[10455] | 168 | if( State::getCameraNode() != NULL && State::getCameraTargetNode() != NULL) |
---|
| 169 | { |
---|
| 170 | PNode* cam = State::getCameraNode(); |
---|
| 171 | PNode* tar = State::getCameraTargetNode(); |
---|
[10453] | 172 | |
---|
[10455] | 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 | |
---|
[10456] | 181 | Vector ddir = dir.cross( cam->getAbsDirV()); |
---|
[10460] | 182 | Quaternion q(ddir, cam->getAbsDirY()); |
---|
[10456] | 183 | this->setAbsDir( q); |
---|
[10455] | 184 | |
---|
[10457] | 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 | |
---|
[10455] | 192 | // if( this->getParent() != cam) |
---|
| 193 | // { |
---|
| 194 | // this->setParent( cam); |
---|
| 195 | // this->setRelCoor( 4.0, 0., 0.); |
---|
| 196 | // this->setRelDir(); |
---|
| 197 | // } |
---|
| 198 | |
---|
| 199 | } |
---|
[10453] | 200 | } |
---|
| 201 | |
---|
| 202 | void ScrollingScreen::fadeIn(float speed) |
---|
| 203 | { |
---|
| 204 | |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | void ScrollingScreen::fadeOut(float speed) |
---|
| 208 | { |
---|
| 209 | |
---|
| 210 | } |
---|