[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 | |
---|
[7193] | 20 | #include "util/loading/load_param.h" |
---|
| 21 | #include "util/loading/factory.h" |
---|
[6524] | 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" |
---|
[10432] | 31 | #include "effects/billboard.h" |
---|
[6524] | 32 | |
---|
[9869] | 33 | #include "debug.h" |
---|
[6524] | 34 | |
---|
[10114] | 35 | |
---|
| 36 | ObjectListDefinition(Planet); |
---|
[9869] | 37 | CREATE_FACTORY(Planet); |
---|
[6524] | 38 | |
---|
[9406] | 39 | |
---|
[6524] | 40 | /** |
---|
| 41 | * initializes a skybox from a XmlElement |
---|
| 42 | */ |
---|
| 43 | Planet::Planet(const TiXmlElement* root) |
---|
| 44 | { |
---|
[9869] | 45 | this->registerObject(this, Planet::_objectList); |
---|
[6524] | 46 | this->toList(OM_GROUP_01); |
---|
| 47 | |
---|
[10391] | 48 | this->rotSpeedPlanet = 0.0; |
---|
| 49 | this->rotSpeedCloud = 0.0; |
---|
[10392] | 50 | this->bClouds = false; |
---|
[10391] | 51 | |
---|
[10387] | 52 | //this->materialPlanet->setIllum(20); |
---|
| 53 | //this->materialPlanet->setAmbient(0.1, 0.1, 0.1); |
---|
[6524] | 54 | |
---|
[10387] | 55 | if( root != NULL) |
---|
| 56 | this->loadParams(root); |
---|
[6695] | 57 | |
---|
[10387] | 58 | PrimitiveModel* model = new PrimitiveModel(PRIM_SPHERE, this->size, 50); |
---|
| 59 | this->setModel(model); |
---|
[6695] | 60 | |
---|
[10424] | 61 | this->cloudModel = new PrimitiveModel(PRIM_SPHERE, this->size + 1, 50); |
---|
[6524] | 62 | } |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | /** |
---|
| 66 | * default destructor |
---|
| 67 | */ |
---|
| 68 | Planet::~Planet() |
---|
| 69 | { |
---|
| 70 | PRINTF(5)("Deleting Planet\n"); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | void Planet::loadParams(const TiXmlElement* root) |
---|
| 75 | { |
---|
[6696] | 76 | WorldEntity::loadParams(root); |
---|
[6524] | 77 | |
---|
| 78 | LoadParam(root, "texture", this, Planet, setTexture) |
---|
[10387] | 79 | .describe("Sets the materialPlanet on the Planet. The string must be the path relative to the data-dir, and without a trailing .jpg"); |
---|
[6524] | 80 | |
---|
[10432] | 81 | LoadParam(root, "size", this, Planet, setSize) |
---|
| 82 | .describe("Sets the Size of the Planet (normally this should be 90% of the maximal viewing Distance)."); |
---|
| 83 | |
---|
[10387] | 84 | LoadParam(root, "cloud-texture", this, Planet, setCloudTexture) |
---|
| 85 | .describe("Sets the cloud texture of the planet"); |
---|
| 86 | |
---|
[10391] | 87 | LoadParam(root, "cloud-rotation", this, Planet, setCloudRotation) |
---|
| 88 | .describe("Sets the cloud rotation speed"); |
---|
[6524] | 89 | } |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | /** |
---|
| 93 | * Defines which textures should be loaded onto the Planet. |
---|
| 94 | * @param textureName the top texture. |
---|
| 95 | */ |
---|
[7221] | 96 | void Planet::setTexture(const std::string& textureName) |
---|
[6524] | 97 | { |
---|
[10387] | 98 | this->materialPlanet.setDiffuseMap(textureName); |
---|
[6524] | 99 | } |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | /** |
---|
[10387] | 103 | * Defines which textures should be loaded onto the Planet. |
---|
| 104 | * @param textureName the top texture. |
---|
| 105 | */ |
---|
| 106 | void Planet::setCloudTexture(const std::string& textureName) |
---|
| 107 | { |
---|
[10432] | 108 | // this->materialCloud.setDiffuseMap(textureName); |
---|
| 109 | // this->halo = new Billboard(); |
---|
| 110 | // this->halo->setTexture( textureName); |
---|
| 111 | // this->halo->setSize(this->size + 5, this->size + 5); |
---|
| 112 | // this->halo->setParent( this); |
---|
[10392] | 113 | this->bClouds = true; |
---|
[10387] | 114 | } |
---|
| 115 | |
---|
| 116 | |
---|
[10391] | 117 | void Planet::setCloudRotation(float rotationSpeed) |
---|
| 118 | { |
---|
| 119 | this->rotSpeedCloud = rotationSpeed; |
---|
| 120 | } |
---|
| 121 | |
---|
[10387] | 122 | /** |
---|
[6524] | 123 | * @param size The new size of the Planet |
---|
| 124 | |
---|
| 125 | * do not forget to rebuild the Planet after this. |
---|
| 126 | */ |
---|
| 127 | void Planet::setSize(float size) |
---|
| 128 | { |
---|
| 129 | this->size = size; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | |
---|
[10391] | 133 | void Planet::tick( float dt) |
---|
| 134 | { |
---|
| 135 | if( dt != 0.) |
---|
| 136 | this->shiftDir( Quaternion( this->rotSpeedPlanet * dt, Vector(1,0,0))); |
---|
| 137 | } |
---|
[6524] | 138 | |
---|
[10391] | 139 | |
---|
| 140 | /** |
---|
| 141 | * draws the planet |
---|
| 142 | */ |
---|
[6524] | 143 | void Planet::draw() const |
---|
| 144 | { |
---|
[10391] | 145 | // draw the clouds |
---|
[10387] | 146 | this->materialPlanet.select(); |
---|
[10391] | 147 | WorldEntity::draw(); |
---|
[6524] | 148 | |
---|
[10432] | 149 | // if( this->bClouds) |
---|
| 150 | // { |
---|
| 151 | // glDisable(GL_LIGHTING); |
---|
| 152 | // this->materialCloud.select(); |
---|
| 153 | // WorldEntity::draw(this->cloudModel); |
---|
| 154 | // glEnable(GL_LIGHTING); |
---|
| 155 | // } |
---|
[6524] | 156 | } |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | |
---|