| [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); | 
|---|
| [6524] | 60 | } | 
|---|
 | 61 |  | 
|---|
 | 62 |  | 
|---|
 | 63 | /** | 
|---|
 | 64 |  *  default destructor | 
|---|
 | 65 | */ | 
|---|
 | 66 | Planet::~Planet() | 
|---|
 | 67 | { | 
|---|
 | 68 |   PRINTF(5)("Deleting Planet\n"); | 
|---|
 | 69 | } | 
|---|
 | 70 |  | 
|---|
 | 71 |  | 
|---|
 | 72 | void Planet::loadParams(const TiXmlElement* root) | 
|---|
 | 73 | { | 
|---|
| [6696] | 74 |   WorldEntity::loadParams(root); | 
|---|
| [6524] | 75 |  | 
|---|
 | 76 |   LoadParam(root, "texture", this, Planet, setTexture) | 
|---|
| [10387] | 77 |       .describe("Sets the materialPlanet on the Planet. The string must be the path relative to the data-dir, and without a trailing .jpg"); | 
|---|
| [6524] | 78 |  | 
|---|
| [10432] | 79 |     LoadParam(root, "size", this, Planet, setSize) | 
|---|
 | 80 |       .describe("Sets the Size of the Planet (normally this should be 90% of the maximal viewing Distance)."); | 
|---|
 | 81 |  | 
|---|
| [10387] | 82 |   LoadParam(root, "cloud-texture", this, Planet, setCloudTexture) | 
|---|
 | 83 |       .describe("Sets the cloud texture of the planet"); | 
|---|
 | 84 |  | 
|---|
| [10391] | 85 |   LoadParam(root, "cloud-rotation", this, Planet, setCloudRotation) | 
|---|
 | 86 |       .describe("Sets the cloud rotation speed"); | 
|---|
| [6524] | 87 | } | 
|---|
 | 88 |  | 
|---|
 | 89 |  | 
|---|
 | 90 | /** | 
|---|
 | 91 |  *  Defines which textures should be loaded onto the Planet. | 
|---|
 | 92 |  * @param textureName the top texture. | 
|---|
 | 93 | */ | 
|---|
| [7221] | 94 | void Planet::setTexture(const std::string& textureName) | 
|---|
| [6524] | 95 | { | 
|---|
| [10387] | 96 |   this->materialPlanet.setDiffuseMap(textureName); | 
|---|
| [6524] | 97 | } | 
|---|
 | 98 |  | 
|---|
 | 99 |  | 
|---|
 | 100 | /** | 
|---|
| [10387] | 101 |  *  Defines which textures should be loaded onto the Planet. | 
|---|
 | 102 |  * @param textureName the top texture. | 
|---|
 | 103 | */ | 
|---|
 | 104 | void Planet::setCloudTexture(const std::string& textureName) | 
|---|
 | 105 | { | 
|---|
| [10432] | 106 | //   this->materialCloud.setDiffuseMap(textureName); | 
|---|
 | 107 | //   this->halo = new Billboard(); | 
|---|
 | 108 | //   this->halo->setTexture( textureName); | 
|---|
 | 109 | //   this->halo->setSize(this->size + 5, this->size + 5); | 
|---|
 | 110 | //   this->halo->setParent( this); | 
|---|
| [10392] | 111 |   this->bClouds = true; | 
|---|
| [10387] | 112 | } | 
|---|
 | 113 |  | 
|---|
 | 114 |  | 
|---|
| [10391] | 115 | void Planet::setCloudRotation(float rotationSpeed) | 
|---|
 | 116 | { | 
|---|
 | 117 |   this->rotSpeedCloud = rotationSpeed; | 
|---|
 | 118 | } | 
|---|
 | 119 |  | 
|---|
| [10387] | 120 | /** | 
|---|
| [6524] | 121 |  * @param size The new size of the Planet | 
|---|
 | 122 |  | 
|---|
 | 123 |  * do not forget to rebuild the Planet after this. | 
|---|
 | 124 | */ | 
|---|
 | 125 | void Planet::setSize(float size) | 
|---|
 | 126 | { | 
|---|
 | 127 |   this->size = size; | 
|---|
 | 128 | } | 
|---|
 | 129 |  | 
|---|
 | 130 |  | 
|---|
| [10391] | 131 | void Planet::tick( float dt) | 
|---|
 | 132 | { | 
|---|
 | 133 |   if( dt != 0.) | 
|---|
 | 134 |     this->shiftDir( Quaternion( this->rotSpeedPlanet * dt, Vector(1,0,0))); | 
|---|
 | 135 | } | 
|---|
| [6524] | 136 |  | 
|---|
| [10391] | 137 |  | 
|---|
 | 138 | /** | 
|---|
 | 139 |  * draws the planet | 
|---|
 | 140 |  */ | 
|---|
| [6524] | 141 | void Planet::draw() const | 
|---|
 | 142 | { | 
|---|
| [10391] | 143 |   // draw the clouds | 
|---|
| [10387] | 144 |   this->materialPlanet.select(); | 
|---|
| [10391] | 145 |   WorldEntity::draw(); | 
|---|
| [6524] | 146 |  | 
|---|
| [10432] | 147 | //   if( this->bClouds) | 
|---|
 | 148 | //   { | 
|---|
 | 149 | //     glDisable(GL_LIGHTING); | 
|---|
 | 150 | //     this->materialCloud.select(); | 
|---|
 | 151 | //     WorldEntity::draw(this->cloudModel); | 
|---|
 | 152 | //     glEnable(GL_LIGHTING); | 
|---|
 | 153 | //   } | 
|---|
| [6524] | 154 | } | 
|---|
 | 155 |  | 
|---|
 | 156 |  | 
|---|
 | 157 |  | 
|---|