- Timestamp:
- Nov 12, 2008, 2:24:10 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Backlight.cc
r2171 r2182 30 30 #include "Backlight.h" 31 31 32 #include <OgreBillboard.h>33 32 #include <OgreRibbonTrail.h> 34 33 #include <OgreSceneManager.h> 35 34 35 #include "core/Core.h" 36 36 #include "core/CoreIncludes.h" 37 #include "core/ConfigValueIncludes.h" 38 #include "core/Executor.h" 39 #include "util/Math.h" 40 #include "GraphicsEngine.h" 37 #include "core/XMLPort.h" 38 #include "objects/Scene.h" 41 39 42 40 namespace orxonox … … 44 42 CreateFactory(Backlight); 45 43 44 Backlight::Backlight(BaseObject* creator) : Billboard(creator) 45 { 46 RegisterObject(Backlight); 47 48 this->ribbonTrail_ = 0; 49 this->ribbonTrailNode_ = 0; 50 51 this->width_ = 0; 52 this->length_ = 1.0f; 53 this->lifetime_ = 1.0f; 54 this->maxelements_ = 1; 55 56 if (Core::showsGraphics()) 57 { 58 assert(this->getScene()); 59 assert(this->getScene()->getSceneManager()); 60 assert(this->getScene()->getRootSceneNode()); 61 62 this->ribbonTrail_ = this->getScene()->getSceneManager()->createRibbonTrail(this->getNode()->getName()); 63 this->ribbonTrailNode_ = this->getScene()->getRootSceneNode()->createChildSceneNode(); 64 this->ribbonTrailNode_->attachObject(this->ribbonTrail_); 65 this->ribbonTrail_->addNode(this->getNode()); 66 67 this->ribbonTrail_->setMaxChainElements(this->maxelements_); 68 this->ribbonTrail_->setTrailLength(this->length_); 69 this->ribbonTrail_->setInitialWidth(0, this->width_); 70 } 71 72 this->registerVariables(); 73 } 74 75 Backlight::~Backlight() 76 { 77 if (this->isInitialized()) 78 { 79 if (this->ribbonTrail_) 80 { 81 if (this->ribbonTrailNode_) 82 { 83 this->ribbonTrailNode_->detachObject(this->ribbonTrail_); 84 this->getScene()->getSceneManager()->destroySceneNode(this->ribbonTrailNode_->getName()); 85 } 86 this->getScene()->getSceneManager()->destroyRibbonTrail(this->ribbonTrail_); 87 } 88 } 89 } 90 91 void Backlight::XMLPort(Element& xmlelement, XMLPort::Mode mode) 92 { 93 SUPER(Backlight, XMLPort, xmlelement, mode); 94 95 XMLPortParam(Backlight, "length", setLength, getLength, xmlelement, mode).defaultValues(100.0f); 96 XMLPortParam(Backlight, "width", setWidth, getWidth, xmlelement, mode).defaultValues(1.0f); 97 XMLPortParam(Backlight, "elements", setMaxElements, getMaxElements, xmlelement, mode).defaultValues(10); 98 XMLPortParam(Backlight, "lifetime", setLifetime, getLifetime, xmlelement, mode).defaultValues(1.0f); 99 XMLPortParam(Backlight, "trailmaterial", setTrailMaterial, getTrailMaterial, xmlelement, mode); 100 } 101 102 void Backlight::registerVariables() 103 { 104 REGISTERDATA (this->width_, direction::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_width)); 105 REGISTERDATA (this->lifetime_, direction::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_lifetime)); 106 REGISTERDATA (this->length_, direction::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_length)); 107 REGISTERDATA (this->maxelements_, direction::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_maxelements)); 108 REGISTERSTRING(this->trailmaterial_, direction::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_trailmaterial)); 109 } 110 111 void Backlight::changedColour() 112 { 113 Billboard::changedColour(); 114 115 if (this->ribbonTrail_ && this->isActive()) 116 this->ribbonTrail_->setInitialColour(0, this->getColour()); 117 } 118 119 void Backlight::update_width() 120 { 121 if (this->ribbonTrail_) 122 this->ribbonTrail_->setInitialWidth(0, this->width_); 123 this->update_lifetime(); 124 } 125 126 void Backlight::update_lifetime() 127 { 128 if (this->ribbonTrail_) 129 { 130 this->ribbonTrail_->setWidthChange(0, this->width_ / this->lifetime_/* * Backlight::timeFactor_s*/); 131 this->ribbonTrail_->setColourChange(0, 0, 0, 0, 1.0f / this->lifetime_/* * Backlight::timeFactor_s*/); 132 } 133 } 134 135 void Backlight::update_length() 136 { 137 // if (this->ribbonTrail_) 138 // this->ribbonTrail_->setTrailLength(this->length_); 139 } 140 141 void Backlight::update_maxelements() 142 { 143 if (this->ribbonTrail_) 144 this->ribbonTrail_->setMaxChainElements(this->maxelements_); 145 } 146 147 void Backlight::update_trailmaterial() 148 { 149 if (this->ribbonTrail_) 150 this->ribbonTrail_->setMaterialName(this->trailmaterial_); 151 } 152 153 void Backlight::changedVisibility() 154 { 155 SUPER(Backlight, changedVisibility); 156 157 if (this->ribbonTrail_) 158 this->ribbonTrail_->setVisible(this->isVisible()); 159 } 160 161 void Backlight::changedActivity() 162 { 163 SUPER(Backlight, changedActivity); 164 165 if (this->ribbonTrail_) 166 { 167 if (this->isActive()) 168 this->ribbonTrail_->setInitialColour(0, this->getColour()); 169 else 170 this->ribbonTrail_->setInitialColour(0, 0, 0, 0, 0); 171 } 172 } 173 174 void Backlight::notifyAttached() 175 { 176 Billboard::notifyAttached(); 177 178 // if (this->ribbonTrail_) 179 // this->ribbonTrail_->clearChain(0); 180 181 // if (this->ribbonTrail_) 182 // this->ribbonTrail_->setTrailLength(this->length_); 183 } 184 185 void Backlight::tick(float dt) 186 { 187 if (this->ribbonTrail_) 188 this->ribbonTrail_->setTrailLength(this->length_); 189 } 190 191 //------------------------------------------------------------------------------------ 192 /* 46 193 float Backlight::timeFactor_s = 1.0; 47 194 … … 52 199 this->setConfigValues(); 53 200 this->traillength_ = 1; 201 this->colour_ = ColourValue::White; 54 202 55 203 this->configure(maxspeed, brakingtime, scale); 56 204 } 57 205 58 206 bool Backlight::create(){ 59 207 if(!WorldEntity::create()) 60 208 return false; 61 209 62 210 this->getNode()->setInheritScale(false); 63 211 … … 76 224 //this->setTimeFactor(Orxonox::getInstance().getTimeFactor()); 77 225 this->setTimeFactor(1.0f); 78 226 79 227 this->ribbonTrail_->setMaxChainElements(this->maxTrailsegments_); 80 228 this->ribbonTrail_->setTrailLength(this->traillength_ = 2 * this->maxTrailsegments_); … … 113 261 this->ribbonTrail_->setColourChange(0, ColourValue(0, 0, 0, this->maxTraillength_ / this->traillength_ / this->maxLifeTime_ * Backlight::timeFactor_s)); 114 262 } 115 116 117 void Backlight::XMLPort(Element& xmlelement, XMLPort::Mode mode){118 SUPER(Backlight, XMLPort, xmlelement, mode);119 120 Backlight::create();121 }122 263 123 264 void Backlight::tick(float dt) … … 145 286 } 146 287 147 void Backlight::setColour(const ColourValue& colour)148 {149 this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour);150 this->ribbonTrail_->setInitialColour(0, ColourValue(colour.r / 4 + 0.75, colour.g / 4 + 0.75, colour.b / 4 + 0.75));151 }152 153 288 void Backlight::configure(float maxspeed, float brakingtime, float scale) 154 289 { … … 168 303 this->ribbonTrail_->setVisible(this->isVisible()); 169 304 } 305 */ 170 306 }
Note: See TracChangeset
for help on using the changeset viewer.