[6524] | 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: Patrick Boenzli |
---|
| 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
| 17 | |
---|
| 18 | #include "planet.h" |
---|
| 19 | |
---|
| 20 | #include "load_param.h" |
---|
| 21 | #include "factory.h" |
---|
| 22 | #include "static_model.h" |
---|
| 23 | |
---|
| 24 | #include "material.h" |
---|
| 25 | #include "texture.h" |
---|
| 26 | |
---|
| 27 | #include "network_game_manager.h" |
---|
| 28 | #include "converter.h" |
---|
[6695] | 29 | #include "vertex_array_model.h" |
---|
| 30 | #include "primitive_model.h" |
---|
[6524] | 31 | |
---|
| 32 | using namespace std; |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | CREATE_FACTORY(Planet, CL_PLANET); |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | /** |
---|
| 40 | * initializes a skybox from a XmlElement |
---|
| 41 | */ |
---|
| 42 | Planet::Planet(const TiXmlElement* root) |
---|
| 43 | { |
---|
| 44 | this->setClassID(CL_PLANET, "Planet"); |
---|
| 45 | this->toList(OM_GROUP_01); |
---|
| 46 | |
---|
| 47 | this->material = new Material(); |
---|
[6695] | 48 | //this->material->setIllum(20); |
---|
| 49 | //this->material->setAmbient(0.1, 0.1, 0.1); |
---|
[6524] | 50 | |
---|
[6695] | 51 | |
---|
| 52 | |
---|
| 53 | //st float radius, const unsigned int loops, const unsigned int segmentsPerLoop |
---|
| 54 | |
---|
[6524] | 55 | this->loadParams(root); |
---|
[6695] | 56 | |
---|
| 57 | // VertexArrayModel* model = new VertexArrayModel(); |
---|
| 58 | // model->spiralSphere(this->size, 10, 10); |
---|
| 59 | // this->setModel(model); |
---|
| 60 | // model->debug(); |
---|
| 61 | // |
---|
| 62 | PrimitiveModel* model = new PrimitiveModel(PRIM_SPHERE, this->size, 50); |
---|
| 63 | this->setModel(model); |
---|
[6524] | 64 | } |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | /** |
---|
| 68 | * default destructor |
---|
| 69 | */ |
---|
| 70 | Planet::~Planet() |
---|
| 71 | { |
---|
| 72 | PRINTF(5)("Deleting Planet\n"); |
---|
[6525] | 73 | if( this->material) |
---|
| 74 | delete this->material; |
---|
[6524] | 75 | } |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | void Planet::loadParams(const TiXmlElement* root) |
---|
| 79 | { |
---|
[6696] | 80 | WorldEntity::loadParams(root); |
---|
[6524] | 81 | |
---|
| 82 | LoadParam(root, "texture", this, Planet, setTexture) |
---|
| 83 | .describe("Sets the material on the Planet. The string must be the path relative to the data-dir, and without a trailing .jpg"); |
---|
| 84 | |
---|
| 85 | LoadParam(root, "size", this, Planet, setSize) |
---|
| 86 | .describe("Sets the Size of the Planet (normally this should be 90% of the maximal viewing Distance)."); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | /** |
---|
| 91 | * Defines which textures should be loaded onto the Planet. |
---|
| 92 | * @param textureName the top texture. |
---|
| 93 | */ |
---|
| 94 | void Planet::setTexture(const char* textureName) |
---|
| 95 | { |
---|
| 96 | this->material->setDiffuseMap(textureName); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | /** |
---|
| 101 | * @param size The new size of the Planet |
---|
| 102 | |
---|
| 103 | * do not forget to rebuild the Planet after this. |
---|
| 104 | */ |
---|
| 105 | void Planet::setSize(float size) |
---|
| 106 | { |
---|
| 107 | this->size = size; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | void Planet::draw() const |
---|
| 113 | { |
---|
| 114 | |
---|
[6695] | 115 | |
---|
[6524] | 116 | glMatrixMode(GL_MODELVIEW); |
---|
| 117 | glPushMatrix(); |
---|
| 118 | |
---|
[6695] | 119 | glShadeModel(GL_SMOOTH); |
---|
| 120 | |
---|
[6524] | 121 | /* translate */ |
---|
| 122 | glTranslatef (this->getAbsCoor ().x, |
---|
| 123 | this->getAbsCoor ().y, |
---|
| 124 | this->getAbsCoor ().z); |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | this->material->select(); |
---|
| 128 | |
---|
[6695] | 129 | // /WorldEntity::draw(); |
---|
| 130 | this->getModel(0)->draw(); |
---|
| 131 | // static_cast<VertexArrayModel*>(this->getModel(0))->debug(); |
---|
[6780] | 132 | |
---|
| 133 | glPopMatrix(); |
---|
[6524] | 134 | } |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | |
---|