- Timestamp:
- Nov 12, 2008, 2:24:10 AM (16 years ago)
- Location:
- code/branches/objecthierarchy2/src/orxonox/objects/worldentities
- Files:
-
- 7 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 } -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Backlight.h
r2171 r2182 31 31 32 32 #include "OrxonoxPrereqs.h" 33 34 #include "PositionableEntity.h" 35 #include "tools/BillboardSet.h" 33 #include "Billboard.h" 34 #include "objects/Tickable.h" 36 35 37 36 namespace orxonox 38 37 { 39 class _OrxonoxExport Backlight : public PositionableEntity38 class _OrxonoxExport Backlight : public Billboard, public Tickable 40 39 { 40 public: 41 Backlight(BaseObject* creator); 42 virtual ~Backlight(); 43 44 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 45 void registerVariables(); 46 47 virtual void tick(float dt); 48 virtual void changedActivity(); 49 virtual void changedVisibility(); 50 51 inline void setWidth(float width) 52 { this->width_ = width; this->update_width(); } 53 inline float getWidth() const 54 { return this->width_; } 55 56 inline void setLifetime(float lifetime) 57 { this->lifetime_ = lifetime; this->update_lifetime(); } 58 inline float getLifetime() const 59 { return this->lifetime_; } 60 61 inline void setLength(float length) 62 { this->length_ = length; this->update_length(); } 63 inline float getLength() const 64 { return this->length_; } 65 66 inline void setMaxElements(size_t maxelements) 67 { this->maxelements_ = maxelements; this->update_maxelements(); } 68 inline size_t getMaxElements() const 69 { return this->maxelements_; } 70 71 inline void setTrailMaterial(const std::string& material) 72 { this->trailmaterial_ = material; this->update_trailmaterial(); } 73 inline const std::string& getTrailMaterial() const 74 { return this->trailmaterial_; } 75 76 protected: 77 virtual void notifyAttached(); 78 79 private: 80 virtual void changedColour(); 81 void update_width(); 82 void update_lifetime(); 83 void update_length(); 84 void update_maxelements(); 85 void update_trailmaterial(); 86 87 Ogre::RibbonTrail* ribbonTrail_; 88 Ogre::SceneNode* ribbonTrailNode_; 89 float width_; 90 float length_; 91 float lifetime_; 92 size_t maxelements_; 93 std::string trailmaterial_; 94 }; 95 96 97 /* 41 98 public: 42 99 Backlight(float maxspeed = 1.0, float brakingtime = 1.0, float scale = 1.0); … … 49 106 virtual bool create(); 50 107 51 void setColour(const ColourValue& colour); 108 52 109 void setTimeFactor(float factor); 53 110 … … 60 117 Ogre::SceneNode* ribbonTrailNode_; 61 118 Ogre::RibbonTrail* ribbonTrail_; 119 62 120 63 121 float maxLifeTime_; … … 72 130 size_t maxTrailsegments_; 73 131 }; 132 */ 74 133 } 75 134 -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Billboard.cc
r2171 r2182 41 41 { 42 42 RegisterObject(Billboard); 43 44 this->material_ = ""; 45 this->colour_ = ColourValue::White; 43 46 44 47 this->registerVariables(); … … 88 91 if (!this->billboard_.getBillboardSet()) 89 92 { 90 if (this->getScene() && this->getScene()->getSceneManager() )93 if (this->getScene() && this->getScene()->getSceneManager() && (this->material_ != "")) 91 94 { 92 95 this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1); -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Billboard.h
r2087 r2182 61 61 { return this->colour_; } 62 62 63 protected: 64 virtual void changedColour(); 65 63 66 private: 64 67 void changedMaterial(); 65 void changedColour();66 68 67 69 BillboardSet billboard_; -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/CMakeLists.txt
r2131 r2182 4 4 MovableEntity.cc 5 5 ControllableEntity.cc 6 Model.cc 6 7 Backlight.cc 7 8 Billboard.cc 8 9 BlinkingBillboard.cc … … 10 11 Camera.cc 11 12 CameraPosition.cc 12 SpawnPoint.cc13 Model.cc 13 14 ParticleEmitter.cc 14 15 ParticleSpawner.cc 15 # Backlight.cc16 SpawnPoint.cc 16 17 ) 17 18 -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/WorldEntity.cc
r2171 r2182 131 131 object->parent_ = this; 132 132 object->parentID_ = this->getObjectID(); 133 134 object->notifyAttached(); 133 135 } 134 136 -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/WorldEntity.h
r2171 r2182 139 139 140 140 protected: 141 virtual void notifyAttached() {} 142 141 143 Ogre::SceneNode* node_; 142 144
Note: See TracChangeset
for help on using the changeset viewer.