[7111] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
[8255] | 4 | Copyright (C) 2006 orx |
---|
[7111] | 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 | |
---|
[8255] | 11 | ### File Specific: |
---|
| 12 | main-programmer: David Hasenfratz |
---|
[10698] | 13 | co-programmer: Nicolas Schlumberger |
---|
[7111] | 14 | */ |
---|
| 15 | |
---|
[8255] | 16 | #include "billboard.h" |
---|
[7111] | 17 | |
---|
[8255] | 18 | #include "util/loading/load_param.h" |
---|
| 19 | #include "util/loading/factory.h" |
---|
[7111] | 20 | |
---|
[8255] | 21 | #include "graphics_engine.h" |
---|
[7111] | 22 | #include "material.h" |
---|
[8255] | 23 | #include "glincl.h" |
---|
| 24 | #include "state.h" |
---|
[10618] | 25 | #include "tools/cameraman.h" |
---|
| 26 | #include "tools/camera.h" |
---|
[7111] | 27 | |
---|
[10433] | 28 | #include "debug.h" |
---|
[7112] | 29 | |
---|
| 30 | |
---|
[10114] | 31 | ObjectListDefinition(Billboard); |
---|
[9869] | 32 | CREATE_FACTORY(Billboard); |
---|
[9406] | 33 | |
---|
[7111] | 34 | /** |
---|
[8255] | 35 | * standart constructor |
---|
| 36 | */ |
---|
| 37 | Billboard::Billboard (const TiXmlElement* root) |
---|
[7111] | 38 | { |
---|
[8255] | 39 | this->init(); |
---|
[7111] | 40 | |
---|
[8255] | 41 | if( root) |
---|
| 42 | this->loadParams(root); |
---|
| 43 | } |
---|
[7111] | 44 | |
---|
| 45 | |
---|
[8255] | 46 | /** |
---|
| 47 | * destroys a Billboard |
---|
| 48 | */ |
---|
| 49 | Billboard::~Billboard () |
---|
| 50 | { |
---|
| 51 | if (this->material) |
---|
| 52 | delete this->material; |
---|
| 53 | } |
---|
[7111] | 54 | |
---|
[7112] | 55 | |
---|
[8255] | 56 | /** |
---|
| 57 | * initializes the Billboard |
---|
| 58 | */ |
---|
| 59 | void Billboard::init() |
---|
| 60 | { |
---|
[9869] | 61 | this->registerObject(this, Billboard::_objectList); |
---|
[8255] | 62 | this->setName("Billboard"); |
---|
[7112] | 63 | |
---|
[8255] | 64 | this->toList(OM_COMMON); |
---|
[7112] | 65 | |
---|
[8255] | 66 | this->material = new Material(); |
---|
| 67 | this->setAbsCoor(0, 0, 0); |
---|
| 68 | //this->setVisibiliy(true); |
---|
| 69 | this->setSize(5, 5); |
---|
[10433] | 70 | |
---|
| 71 | this->texColor = NULL; |
---|
[10698] | 72 | |
---|
| 73 | this->pulseMagnitude = .5; |
---|
| 74 | this->bPulse = false; |
---|
| 75 | |
---|
| 76 | this->angularSpeed = M_2_PI; //360; |
---|
| 77 | this->angle = 0; |
---|
| 78 | |
---|
| 79 | this->setUpdateFunction((*sinf)); |
---|
[7111] | 80 | } |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | /** |
---|
[8255] | 84 | * load params |
---|
| 85 | * @param root TiXmlElement object |
---|
| 86 | */ |
---|
| 87 | void Billboard::loadParams(const TiXmlElement* root) |
---|
[7111] | 88 | { |
---|
[8255] | 89 | /*LoadParam(root, "texture", this->material, Material, setDiffuseMap) |
---|
| 90 | .describe("the texture-file to load onto the Billboard"); |
---|
| 91 | |
---|
| 92 | LoadParam(root, "size", this, Billboard, setSize) |
---|
| 93 | .describe("the size of the Billboard in Pixels");*/ |
---|
[7111] | 94 | } |
---|
| 95 | |
---|
[8255] | 96 | |
---|
| 97 | /** |
---|
| 98 | * sets the size of the Billboard. |
---|
| 99 | * @param size the size in pixels |
---|
| 100 | */ |
---|
| 101 | void Billboard::setSize(float sizeX, float sizeY) |
---|
[7111] | 102 | { |
---|
[8255] | 103 | this->sizeX = sizeX; |
---|
| 104 | this->sizeY = sizeY; |
---|
[7111] | 105 | } |
---|
| 106 | |
---|
| 107 | |
---|
[8255] | 108 | /** |
---|
| 109 | * sets the material to load |
---|
| 110 | * @param textureFile The texture-file to load |
---|
| 111 | */ |
---|
| 112 | void Billboard::setTexture(const std::string& textureFile) |
---|
[7111] | 113 | { |
---|
[8255] | 114 | this->material->setDiffuseMap(textureFile); |
---|
[7111] | 115 | } |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | /** |
---|
[8255] | 119 | * ticks the Billboard |
---|
| 120 | * @param dt the time to ticks |
---|
| 121 | */ |
---|
| 122 | void Billboard::tick(float dt) |
---|
[7111] | 123 | { |
---|
[10698] | 124 | this->angle += dt * this->angularSpeed; |
---|
| 125 | if (this->angle > M_2_PI) |
---|
| 126 | this->angle -= M_2_PI; |
---|
| 127 | // curMagnitude = updatePulse(this->angle); |
---|
[7111] | 128 | } |
---|
| 129 | |
---|
| 130 | |
---|
[8255] | 131 | /** |
---|
| 132 | * draws the billboard |
---|
| 133 | */ |
---|
| 134 | void Billboard::draw() const |
---|
[7111] | 135 | { |
---|
[8255] | 136 | if( !this->isVisible()) |
---|
| 137 | return; |
---|
[7111] | 138 | |
---|
[8495] | 139 | glPushAttrib(GL_ENABLE_BIT); |
---|
| 140 | glDisable(GL_LIGHTING); |
---|
| 141 | glDisable(GL_FOG); |
---|
[9869] | 142 | |
---|
[8255] | 143 | glPushMatrix(); |
---|
[7111] | 144 | |
---|
[8255] | 145 | //glTranslatef(this->getAbsCoor().x, this->getAbsCoor().y, this->getAbsCoor().z); |
---|
| 146 | //glTranslatef(0,0,0); |
---|
| 147 | this->material->select(); |
---|
[9869] | 148 | |
---|
[10618] | 149 | const Camera* camera = State::getCamera(); |
---|
[8255] | 150 | Vector cameraPos = camera->getAbsCoor(); |
---|
[10501] | 151 | Vector cameraTargetPos = camera->getTarget()->getAbsCoor(); |
---|
[8255] | 152 | Vector view = cameraTargetPos - cameraPos; |
---|
| 153 | Vector up = Vector(0, 1, 0); |
---|
| 154 | up = camera->getAbsDir().apply(up); |
---|
| 155 | Vector h = up.cross(view); |
---|
| 156 | Vector v = h.cross(view); |
---|
| 157 | h.normalize(); |
---|
| 158 | v.normalize(); |
---|
[9869] | 159 | |
---|
[10698] | 160 | float tmp = 1; |
---|
| 161 | if (this->bPulse) |
---|
| 162 | tmp += this->pulseMagnitude * sinf(this->angle); //updatePulse(this->angle); |
---|
[7111] | 163 | |
---|
[10698] | 164 | v *= sizeX * tmp; |
---|
| 165 | h *= sizeY * tmp; |
---|
| 166 | |
---|
[8255] | 167 | //v += this->getAbsCoor(); |
---|
| 168 | //PRINTF(0)("sizeX: %f sizeY: %f\n", sizeX, sizeY); |
---|
[10433] | 169 | |
---|
| 170 | // changes the color of the texture (if any is set) |
---|
| 171 | if(this->texColor != NULL) |
---|
[10491] | 172 | glColor4ub((GLubyte)(this->texColor->r()*255.0f), (GLubyte)(this->texColor->g()*255.0f), (GLubyte)(this->texColor->b()*255.0f), (GLubyte)(this->texColor->a()*255)); |
---|
[10433] | 173 | |
---|
[8255] | 174 | glBegin(GL_QUADS); |
---|
| 175 | glTexCoord2f(0.0f, 0.0f); |
---|
| 176 | glVertex3f(this->getAbsCoor().x - h.x - v.x, |
---|
| 177 | this->getAbsCoor().y - h.y - v.y, |
---|
| 178 | this->getAbsCoor().z - h.z - v.z); |
---|
| 179 | glTexCoord2f(1.0f, 0.0f); |
---|
| 180 | glVertex3f( this->getAbsCoor().x + h.x - v.x, |
---|
| 181 | this->getAbsCoor().y + h.y - v.y, |
---|
| 182 | this->getAbsCoor().z + h.z - v.z); |
---|
| 183 | glTexCoord2f(1.0f, 1.0f); |
---|
| 184 | glVertex3f(this->getAbsCoor().x + h.x + v.x, |
---|
| 185 | this->getAbsCoor().y + h.y + v.y, |
---|
| 186 | this->getAbsCoor().z + h.z + v.z); |
---|
| 187 | glTexCoord2f(0.0f, 1.0f); |
---|
| 188 | glVertex3f(this->getAbsCoor().x - h.x + v.x, |
---|
| 189 | this->getAbsCoor().y - h.y + v.y, |
---|
| 190 | this->getAbsCoor().z - h.z + v.z); |
---|
| 191 | glEnd(); |
---|
[9869] | 192 | |
---|
| 193 | |
---|
[8255] | 194 | glPopMatrix(); |
---|
[9869] | 195 | |
---|
[8495] | 196 | glPopAttrib(); |
---|
[7111] | 197 | } |
---|
[10433] | 198 | |
---|
| 199 | |
---|
| 200 | /** |
---|
| 201 | * changes the texture color |
---|
| 202 | * @param col color for the texture |
---|
| 203 | */ |
---|
| 204 | void Billboard::colorTexture(const Color col) |
---|
| 205 | { |
---|
| 206 | this->texColor = new Color(col.r(), col.g(), col.b(), col.a()); |
---|
| 207 | } |
---|