[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 |
---|
[7111] | 13 | */ |
---|
| 14 | |
---|
[8255] | 15 | #include "billboard.h" |
---|
[7111] | 16 | |
---|
[8255] | 17 | #include "util/loading/load_param.h" |
---|
| 18 | #include "util/loading/factory.h" |
---|
[7111] | 19 | |
---|
[8255] | 20 | #include "graphics_engine.h" |
---|
[7111] | 21 | #include "material.h" |
---|
[8255] | 22 | #include "glincl.h" |
---|
| 23 | #include "state.h" |
---|
[7111] | 24 | |
---|
[7112] | 25 | |
---|
[8255] | 26 | using namespace std; |
---|
[7112] | 27 | |
---|
| 28 | |
---|
[8255] | 29 | CREATE_FACTORY(Billboard, CL_BILLBOARD); |
---|
[7111] | 30 | |
---|
| 31 | |
---|
| 32 | /** |
---|
[8255] | 33 | * standart constructor |
---|
| 34 | */ |
---|
| 35 | Billboard::Billboard (const TiXmlElement* root) |
---|
[7111] | 36 | { |
---|
[8255] | 37 | this->init(); |
---|
[7111] | 38 | |
---|
[8255] | 39 | if( root) |
---|
| 40 | this->loadParams(root); |
---|
| 41 | } |
---|
[7111] | 42 | |
---|
| 43 | |
---|
[8255] | 44 | /** |
---|
| 45 | * destroys a Billboard |
---|
| 46 | */ |
---|
| 47 | Billboard::~Billboard () |
---|
| 48 | { |
---|
| 49 | if (this->material) |
---|
| 50 | delete this->material; |
---|
| 51 | } |
---|
[7111] | 52 | |
---|
[7112] | 53 | |
---|
[8255] | 54 | /** |
---|
| 55 | * initializes the Billboard |
---|
| 56 | */ |
---|
| 57 | void Billboard::init() |
---|
| 58 | { |
---|
| 59 | this->setClassID(CL_BILLBOARD, "Billboard"); |
---|
| 60 | this->setName("Billboard"); |
---|
[7112] | 61 | |
---|
[8255] | 62 | this->toList(OM_COMMON); |
---|
[7112] | 63 | |
---|
[8255] | 64 | this->material = new Material(); |
---|
| 65 | this->setAbsCoor(0, 0, 0); |
---|
| 66 | //this->setVisibiliy(true); |
---|
| 67 | this->setSize(5, 5); |
---|
[7111] | 68 | } |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | /** |
---|
[8255] | 72 | * load params |
---|
| 73 | * @param root TiXmlElement object |
---|
| 74 | */ |
---|
| 75 | void Billboard::loadParams(const TiXmlElement* root) |
---|
[7111] | 76 | { |
---|
[8255] | 77 | /*LoadParam(root, "texture", this->material, Material, setDiffuseMap) |
---|
| 78 | .describe("the texture-file to load onto the Billboard"); |
---|
| 79 | |
---|
| 80 | LoadParam(root, "size", this, Billboard, setSize) |
---|
| 81 | .describe("the size of the Billboard in Pixels");*/ |
---|
[7111] | 82 | } |
---|
| 83 | |
---|
[8255] | 84 | |
---|
| 85 | /** |
---|
| 86 | * sets the size of the Billboard. |
---|
| 87 | * @param size the size in pixels |
---|
| 88 | */ |
---|
| 89 | void Billboard::setSize(float sizeX, float sizeY) |
---|
[7111] | 90 | { |
---|
[8255] | 91 | this->sizeX = sizeX; |
---|
| 92 | this->sizeY = sizeY; |
---|
[7111] | 93 | } |
---|
| 94 | |
---|
| 95 | |
---|
[8255] | 96 | /** |
---|
| 97 | * sets the material to load |
---|
| 98 | * @param textureFile The texture-file to load |
---|
| 99 | */ |
---|
| 100 | void Billboard::setTexture(const std::string& textureFile) |
---|
[7111] | 101 | { |
---|
[8255] | 102 | this->material->setDiffuseMap(textureFile); |
---|
[7111] | 103 | } |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | /** |
---|
[8255] | 107 | * ticks the Billboard |
---|
| 108 | * @param dt the time to ticks |
---|
| 109 | */ |
---|
| 110 | void Billboard::tick(float dt) |
---|
[7111] | 111 | { |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | |
---|
[8255] | 115 | /** |
---|
| 116 | * draws the billboard |
---|
| 117 | */ |
---|
| 118 | void Billboard::draw() const |
---|
[7111] | 119 | { |
---|
[8255] | 120 | if( !this->isVisible()) |
---|
| 121 | return; |
---|
[7111] | 122 | |
---|
[8255] | 123 | glPushMatrix(); |
---|
[7111] | 124 | |
---|
[8255] | 125 | //glTranslatef(this->getAbsCoor().x, this->getAbsCoor().y, this->getAbsCoor().z); |
---|
| 126 | //glTranslatef(0,0,0); |
---|
| 127 | this->material->select(); |
---|
| 128 | |
---|
| 129 | const PNode* camera = State::getCameraNode(); //!< @todo MUST be different |
---|
| 130 | Vector cameraPos = camera->getAbsCoor(); |
---|
| 131 | Vector cameraTargetPos = State::getCameraTargetNode()->getAbsCoor(); |
---|
| 132 | Vector view = cameraTargetPos - cameraPos; |
---|
| 133 | Vector up = Vector(0, 1, 0); |
---|
| 134 | up = camera->getAbsDir().apply(up); |
---|
| 135 | Vector h = up.cross(view); |
---|
| 136 | Vector v = h.cross(view); |
---|
| 137 | h.normalize(); |
---|
| 138 | v.normalize(); |
---|
| 139 | |
---|
| 140 | v *= sizeX; |
---|
| 141 | h *= sizeY; |
---|
[7111] | 142 | |
---|
[8255] | 143 | //v += this->getAbsCoor(); |
---|
| 144 | //PRINTF(0)("sizeX: %f sizeY: %f\n", sizeX, sizeY); |
---|
| 145 | glBegin(GL_QUADS); |
---|
| 146 | glTexCoord2f(0.0f, 0.0f); |
---|
| 147 | glVertex3f(this->getAbsCoor().x - h.x - v.x, |
---|
| 148 | this->getAbsCoor().y - h.y - v.y, |
---|
| 149 | this->getAbsCoor().z - h.z - v.z); |
---|
| 150 | glTexCoord2f(1.0f, 0.0f); |
---|
| 151 | glVertex3f( this->getAbsCoor().x + h.x - v.x, |
---|
| 152 | this->getAbsCoor().y + h.y - v.y, |
---|
| 153 | this->getAbsCoor().z + h.z - v.z); |
---|
| 154 | glTexCoord2f(1.0f, 1.0f); |
---|
| 155 | glVertex3f(this->getAbsCoor().x + h.x + v.x, |
---|
| 156 | this->getAbsCoor().y + h.y + v.y, |
---|
| 157 | this->getAbsCoor().z + h.z + v.z); |
---|
| 158 | glTexCoord2f(0.0f, 1.0f); |
---|
| 159 | glVertex3f(this->getAbsCoor().x - h.x + v.x, |
---|
| 160 | this->getAbsCoor().y - h.y + v.y, |
---|
| 161 | this->getAbsCoor().z - h.z + v.z); |
---|
| 162 | glEnd(); |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | glPopMatrix(); |
---|
[7111] | 166 | } |
---|