[4744] | 1 | /* |
---|
[1853] | 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. |
---|
[1855] | 10 | |
---|
| 11 | ### File Specific: |
---|
[4838] | 12 | main-programmer: Benjamin Grauer |
---|
[1855] | 13 | co-programmer: ... |
---|
[1853] | 14 | */ |
---|
| 15 | |
---|
[3955] | 16 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ |
---|
[1853] | 17 | |
---|
[4839] | 18 | #include "element_2d.h" |
---|
[4840] | 19 | #include "render_2d.h" |
---|
[1853] | 20 | |
---|
[4843] | 21 | #include "graphics_engine.h" |
---|
| 22 | #include "p_node.h" |
---|
[4858] | 23 | #include "load_param.h" |
---|
| 24 | #include "tinyxml.h" |
---|
| 25 | #include "class_list.h" |
---|
[4843] | 26 | |
---|
[1856] | 27 | using namespace std; |
---|
[1853] | 28 | |
---|
[1856] | 29 | |
---|
[3245] | 30 | /** |
---|
[4838] | 31 | * standard constructor |
---|
| 32 | * @todo this constructor is not jet implemented - do it |
---|
[3245] | 33 | */ |
---|
[4838] | 34 | Element2D::Element2D () |
---|
[3365] | 35 | { |
---|
[4847] | 36 | this->init(); |
---|
[3365] | 37 | } |
---|
[1853] | 38 | |
---|
[3245] | 39 | /** |
---|
[4838] | 40 | * standard deconstructor |
---|
[3245] | 41 | */ |
---|
[4838] | 42 | Element2D::~Element2D () |
---|
[3543] | 43 | { |
---|
| 44 | // delete what has to be deleted here |
---|
[4840] | 45 | Render2D::getInstance()->unregisterElement2D(this); |
---|
[3543] | 46 | } |
---|
[4843] | 47 | |
---|
| 48 | |
---|
[4858] | 49 | /** |
---|
| 50 | * initializes a Element2D |
---|
| 51 | */ |
---|
[4847] | 52 | void Element2D::init() |
---|
| 53 | { |
---|
| 54 | this->setClassID(CL_ELEMENT_2D, "Element2D"); |
---|
| 55 | |
---|
[4861] | 56 | this->setVisibility(true); |
---|
[5068] | 57 | this->setActiveness(true); |
---|
[4856] | 58 | this->setPosition2D(0,0); |
---|
[4861] | 59 | this->setAlignment(E2D_ALIGN_NONE); |
---|
[4862] | 60 | this->layer = E2D_TOP; |
---|
[4856] | 61 | |
---|
[4847] | 62 | Render2D::getInstance()->registerElement2D(this); |
---|
| 63 | } |
---|
| 64 | |
---|
[4843] | 65 | /** |
---|
[4858] | 66 | * Loads the Parameters of an Element2D from... |
---|
| 67 | * @param root The XML-element to load from |
---|
| 68 | */ |
---|
| 69 | void Element2D::loadParams(const TiXmlElement* root) |
---|
| 70 | { |
---|
| 71 | LoadParam<Element2D>(root, "alignment", this, &Element2D::setAlignment) |
---|
| 72 | .describe("loads the alignment: (either: center, left, right or screen-center)"); |
---|
| 73 | |
---|
| 74 | LoadParam<Element2D>(root, "layer", this, &Element2D::setLayer) |
---|
| 75 | .describe("loads the layer onto which to project: (either: top, medium, bottom, below-all)"); |
---|
| 76 | |
---|
| 77 | LoadParam<Element2D>(root, "bind-node", this, &Element2D::setBindNode) |
---|
| 78 | .describe("sets a node, this 2D-Element should be shown upon (name of the node)"); |
---|
| 79 | |
---|
| 80 | LoadParam<Element2D>(root, "2d-position", this, &Element2D::setPosition2D) |
---|
| 81 | .describe("the _relative_ position (away from alignment) this 2d-element shows"); |
---|
| 82 | |
---|
[4860] | 83 | LoadParam<Element2D>(root, "visibility", this, &Element2D::setVisibility) |
---|
| 84 | .describe("if the Element is visible or not"); |
---|
[4858] | 85 | } |
---|
| 86 | |
---|
| 87 | /** |
---|
| 88 | * sets the alignment of the 2D-element in form of a String |
---|
| 89 | * @param alignment the alignment @see loadParams |
---|
| 90 | */ |
---|
| 91 | void Element2D::setAlignment(const char* alignment) |
---|
| 92 | { |
---|
| 93 | if (!strcmp(alignment, "center")) |
---|
| 94 | this->setAlignment(E2D_ALIGN_CENTER); |
---|
| 95 | else if (!strcmp(alignment, "left")) |
---|
| 96 | this->setAlignment(E2D_ALIGN_LEFT); |
---|
| 97 | else if (!strcmp(alignment, "right")) |
---|
| 98 | this->setAlignment(E2D_ALIGN_RIGHT); |
---|
| 99 | else if (!strcmp(alignment, "screen-center")) |
---|
| 100 | this->setAlignment(E2D_ALIGN_SCREEN_CENTER); |
---|
| 101 | } |
---|
| 102 | |
---|
[4862] | 103 | |
---|
[4858] | 104 | /** |
---|
[4862] | 105 | * moves a Element to another layer |
---|
| 106 | * @param layer the Layer this is drawn on |
---|
| 107 | */ |
---|
| 108 | void Element2D::setLayer(E2D_LAYER layer) |
---|
| 109 | { |
---|
| 110 | Render2D::getInstance()->moveToLayer(this, layer); |
---|
| 111 | this->layer = layer; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | /** |
---|
[4858] | 115 | * sets the layer onto which this 2D-element is projected to. |
---|
| 116 | * @param layer the layer @see loadParams |
---|
| 117 | */ |
---|
| 118 | void Element2D::setLayer(const char* layer) |
---|
| 119 | { |
---|
| 120 | if (!strcmp(layer, "top")) |
---|
| 121 | this->setLayer(E2D_TOP); |
---|
| 122 | else if (!strcmp(layer, "medium")) |
---|
| 123 | this->setLayer(E2D_MEDIUM); |
---|
| 124 | else if (!strcmp(layer, "bottom")) |
---|
| 125 | this->setLayer(E2D_BOTTOM); |
---|
| 126 | else if (!strcmp(layer, "below-all")) |
---|
| 127 | this->setLayer(E2D_BELOW_ALL); |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | /** |
---|
| 132 | * sets a node, this 2D-Element should be shown upon |
---|
| 133 | * @param bindNode the name of the Node (should be existing) |
---|
| 134 | */ |
---|
| 135 | void Element2D::setBindNode(const char* bindNode) |
---|
| 136 | { |
---|
| 137 | const PNode* tmpBindNode = dynamic_cast<const PNode*>(ClassList::getObject(bindNode, CL_PARENT_NODE)); |
---|
| 138 | if (tmpBindNode != NULL) |
---|
| 139 | this->bindNode = tmpBindNode; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | /** |
---|
[4843] | 143 | * this sets the position of the Element on the screen. |
---|
[4847] | 144 | * Use this in the your tick function, if you want the element to be automatically positioned. |
---|
[4843] | 145 | */ |
---|
| 146 | void Element2D::positioning() |
---|
| 147 | { |
---|
[4856] | 148 | // setting the Position of this 2D-Element. |
---|
| 149 | if (this->alignment == E2D_ALIGN_SCREEN_CENTER) |
---|
[4843] | 150 | { |
---|
[4856] | 151 | absPos2D.x = GraphicsEngine::getInstance()->getResolutionX()/2 + this->relPos2D[0]; |
---|
| 152 | absPos2D.y = GraphicsEngine::getInstance()->getResolutionY()/2 + this->relPos2D[1]; |
---|
| 153 | absPos2D.depth = 0; |
---|
| 154 | } |
---|
| 155 | else if (this->bindNode) |
---|
| 156 | { |
---|
[4843] | 157 | GLdouble projectPos[3]; |
---|
[4847] | 158 | gluProject(this->bindNode->getAbsCoor().x, |
---|
| 159 | this->bindNode->getAbsCoor().y, |
---|
| 160 | this->bindNode->getAbsCoor().z, |
---|
| 161 | GraphicsEngine::modMat, |
---|
| 162 | GraphicsEngine::projMat, |
---|
| 163 | GraphicsEngine::viewPort, |
---|
| 164 | projectPos, |
---|
| 165 | projectPos+1, |
---|
| 166 | projectPos+2); |
---|
| 167 | absPos2D.x = projectPos[0] + this->relPos2D[0]; |
---|
| 168 | absPos2D.y = GraphicsEngine::getInstance()->getResolutionY() - projectPos[1] + this->relPos2D[1]; |
---|
| 169 | absPos2D.depth = projectPos[2]; |
---|
[4843] | 170 | } |
---|
| 171 | else |
---|
| 172 | { |
---|
[4847] | 173 | absPos2D.x = this->relPos2D[0]; |
---|
| 174 | absPos2D.y = this->relPos2D[1]; |
---|
| 175 | absPos2D.depth = 0; |
---|
[4843] | 176 | } |
---|
[4847] | 177 | } |
---|
[4843] | 178 | |
---|
[5081] | 179 | |
---|
| 180 | void Element2D::setRelCoor2D (const Vector& relCoord) |
---|
| 181 | { |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | |
---|
| 185 | void Element2D::setRelCoor2D (float x, float y, float z) |
---|
| 186 | { |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | void Element2D::setRelCoorSoft2D(const Vector& relCoordSoft, float bias) |
---|
| 190 | { |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | void Element2D::setRelCoorSoft2D(float x, float y, float dontCare, float bias) |
---|
| 194 | { |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | void Element2D::setAbsCoor2D (const Vector& absCoord) |
---|
| 198 | { |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | void Element2D::setAbsCoor2D (float x, float y, float depth) |
---|
| 202 | { |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | void Element2D::shiftCoor (const Vector& shift) |
---|
| 206 | { |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | |
---|
| 210 | void Element2D::setRelDir2D (float relDir) |
---|
| 211 | { |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | void Element2D::setRelDirSoft2D(float relDirSoft, float bias) |
---|
| 215 | { |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | void Element2D::setAbsDir2D (float absDir) |
---|
| 219 | { |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | void Element2D::shiftDir (float shiftDir) |
---|
| 223 | { |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | |
---|
| 227 | void Element2D::addChild2D (Element2D* child, int parentingMod) |
---|
| 228 | { |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | void Element2D::addChild2D (const char* childName) |
---|
| 232 | { |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | void Element2D::removeChild2D (Element2D* child) |
---|
| 236 | { |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | void Element2D::remove2D() |
---|
| 240 | { |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | |
---|
| 244 | void Element2D::setParent2D (Element2D* parent) |
---|
| 245 | { |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | void Element2D::setParent2D (const char* parentName) |
---|
| 249 | { |
---|
| 250 | } |
---|
| 251 | |
---|
| 252 | |
---|
| 253 | void Element2D::softReparent(PNode* parentNode, float bias) |
---|
| 254 | { |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | void Element2D::softReparent(const char* parentName, float bias) |
---|
| 258 | { |
---|
| 259 | } |
---|
| 260 | |
---|
| 261 | |
---|
| 262 | void Element2D::setParentMode2D (const char* parentingMode) |
---|
| 263 | { |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | |
---|
| 267 | void Element2D::update2D (float dt) |
---|
| 268 | { |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | |
---|
| 272 | void Element2D::debug (unsigned int depth, unsigned int level) const |
---|
| 273 | { |
---|
| 274 | } |
---|
| 275 | |
---|
| 276 | void Element2D::debugDraw2D(unsigned int depth, float size, Vector color) const |
---|
| 277 | { |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | |
---|
| 281 | // helper functions // |
---|
| 282 | const char* Element2D::parentingModeToChar(int parentingMode) |
---|
| 283 | { |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | E2D_PARENT_MODE Element2D::charToParentingMode(const char* parentingMode) |
---|
| 287 | { |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | |
---|
| 291 | |
---|
| 292 | |
---|
| 293 | |
---|
| 294 | |
---|
[4847] | 295 | /** |
---|
| 296 | * ticks the 2d-Element |
---|
| 297 | * @param dt the time elapsed since the last tick |
---|
| 298 | */ |
---|
| 299 | void Element2D::tick(float dt) |
---|
| 300 | { |
---|
| 301 | this->positioning(); |
---|
[4843] | 302 | } |
---|