Changeset 2212
- Timestamp:
- Nov 16, 2008, 7:10:28 PM (16 years ago)
- Location:
- code/branches/objecthierarchy2/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy2/src/core/Super.h
r2171 r2212 233 233 #define SUPER_processEvent(classname, functionname, ...) \ 234 234 SUPER_ARGS(classname, functionname, __VA_ARGS__) 235 236 #define SUPER_changedScale(classname, functionname, ...) \ 237 SUPER_NOARGS(classname, functionname) 235 238 // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 236 239 … … 441 444 (event) 442 445 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 446 447 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(5, changedScale, false) 448 () 449 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 443 450 // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 444 451 … … 488 495 SUPER_INTRUSIVE_DECLARATION(changedVisibility); 489 496 SUPER_INTRUSIVE_DECLARATION(processEvent); 497 SUPER_INTRUSIVE_DECLARATION(changedScale); 490 498 // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 491 499 -
code/branches/objecthierarchy2/src/orxonox/gamestates/GSDedicated.cc
r2175 r2212 49 49 { 50 50 RegisterObject(GSDedicated); 51 51 52 52 this->setConfigValues(); 53 53 } … … 82 82 { 83 83 static int timeSinceLastTick = 0; // in microseconds 84 const int tickPeriod = 1000000. / this->tickrate_; // in microseconds85 84 const int tickPeriod = (int)(1000000.0f / this->tickrate_); // in microseconds 85 86 86 GSLevel::ticked(time); 87 87 88 88 timeSinceLastTick += time.getDeltaTimeMicroseconds(); 89 89 if ( timeSinceLastTick >= tickPeriod ) … … 96 96 { 97 97 unsigned int sleepTime; 98 98 99 99 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 100 100 if ( tickPeriod-timeSinceLastTick < MIN_WIN32_SLEEP_TIME ) 101 sleepTime = MIN_WIN32_SLEEP_TIME*1000000;101 sleepTime = (unsigned int)(MIN_WIN32_SLEEP_TIME * 1000000); 102 102 else 103 103 sleepTime = tickPeriod - timeSinceLastTick; 104 104 msleep( sleepTime / 1000 ); 105 105 106 106 #else /* unix */ 107 107 sleepTime = tickPeriod - timeSinceLastTick; 108 108 usleep( sleepTime ); 109 109 #endif 110 110 111 111 } 112 112 113 113 this->tickChild(time); 114 114 } 115 115 116 116 void GSDedicated::setConfigValues() 117 117 { -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Backlight.cc
r2207 r2212 66 66 67 67 this->ribbonTrail_ = this->getScene()->getSceneManager()->createRibbonTrail(this->getNode()->getName()); 68 this->ribbonTrail_->addNode(this->getNode()); 68 69 69 this->ribbonTrailNode_ = this->getScene()->getRootSceneNode()->createChildSceneNode(); 70 70 this->ribbonTrailNode_->attachObject(this->ribbonTrail_); 71 72 this->ribbonTrail_->setMaxChainElements(this->maxelements_); 73 this->ribbonTrail_->setTrailLength(this->length_); 71 74 this->ribbonTrail_->setInitialWidth(0, 0); 72 75 } … … 123 126 { 124 127 if (this->ribbonTrail_ && this->tickcount_ >= 2) 125 this->ribbonTrail_->setInitialWidth(0, this->width_ );128 this->ribbonTrail_->setInitialWidth(0, this->width_ * this->getWorldScale()); 126 129 this->update_lifetime(); 127 130 } … … 131 134 if (this->ribbonTrail_ && this->tickcount_ >= 2) 132 135 { 133 this->ribbonTrail_->setWidthChange(0, this->width_ / this->lifetime_/* * Backlight::timeFactor_s*/);136 this->ribbonTrail_->setWidthChange(0, this->width_ * this->getWorldScale() / this->lifetime_/* * Backlight::timeFactor_s*/); 134 137 this->ribbonTrail_->setColourChange(0, 0, 0, 0, 1.0f / this->lifetime_/* * Backlight::timeFactor_s*/); 135 138 } … … 139 142 { 140 143 if (this->ribbonTrail_ && this->tickcount_ >= 2) 141 this->ribbonTrail_->setTrailLength(this->length_ );144 this->ribbonTrail_->setTrailLength(this->length_ * this->getWorldScale()); 142 145 } 143 146 … … 176 179 } 177 180 } 181 } 182 183 void Backlight::changedScale() 184 { 185 SUPER(Backlight, changedScale); 186 187 this->update_width(); 188 this->update_length(); 178 189 } 179 190 … … 196 207 this->update_maxelements(); 197 208 this->update_trailmaterial(); 209 if (this->ribbonTrail_) 210 this->ribbonTrail_->addNode(this->getNode()); 198 211 } 199 212 } … … 204 217 } 205 218 } 206 207 //------------------------------------------------------------------------------------208 /*209 float Backlight::timeFactor_s = 1.0;210 211 Backlight::Backlight(float maxspeed, float brakingtime, float scale)212 {213 RegisterObject(Backlight);214 215 this->setConfigValues();216 this->traillength_ = 1;217 this->colour_ = ColourValue::White;218 219 this->configure(maxspeed, brakingtime, scale);220 }221 222 bool Backlight::create(){223 if(!WorldEntity::create())224 return false;225 226 this->getNode()->setInheritScale(false);227 228 this->billboard_.setBillboardSet("Flares/backlightflare");229 this->attachObject(this->billboard_.getBillboardSet());230 231 this->ribbonTrail_ = GraphicsEngine::getInstance().getLevelSceneManager()->createRibbonTrail(this->getName() + "RibbonTrail");232 this->ribbonTrailNode_ = GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName() + "RibbonTrailNode");233 this->ribbonTrailNode_->attachObject(this->ribbonTrail_);234 this->ribbonTrail_->addNode(this->getNode());235 236 237 this->ribbonTrail_->setTrailLength(this->maxTraillength_);238 this->ribbonTrail_->setMaterialName("Trail/backlighttrail");239 240 //this->setTimeFactor(Orxonox::getInstance().getTimeFactor());241 this->setTimeFactor(1.0f);242 243 this->ribbonTrail_->setMaxChainElements(this->maxTrailsegments_);244 this->ribbonTrail_->setTrailLength(this->traillength_ = 2 * this->maxTrailsegments_);245 this->ribbonTrail_->setInitialWidth(0, this->width_ * this->getScale());246 this->ribbonTrail_->setWidthChange(0, this->width_ * this->getScale() / this->maxLifeTime_ * Backlight::timeFactor_s);247 return true;248 }249 250 Backlight::~Backlight()251 {252 if (this->isInitialized())253 {254 this->detachObject(this->billboard_.getBillboardSet());255 GraphicsEngine::getInstance().getLevelSceneManager()->destroySceneNode(this->getName() + "RibbonTrailNode");256 GraphicsEngine::getInstance().getLevelSceneManager()->destroyRibbonTrail(this->ribbonTrail_);257 }258 }259 260 void Backlight::setConfigValues()261 {262 SetConfigValue(maxLifeTime_, 4.0).description("The maximal amount of seconds the trail behind a SpaceShip stays visible");263 SetConfigValue(trailSegmentLength_, 50).description("The length of one segment of the trail behind a SpaceShip (lower values make it more smooth)");264 SetConfigValue(width_, 7.0).description("The width of the trail");265 }266 267 void Backlight::setTimeFactor(float factor)268 {269 Backlight::timeFactor_s = factor;270 float change = Backlight::timeFactor_s / this->maxLifeTime_;271 this->ribbonTrail_->setWidthChange(0, this->width_ * change);272 this->updateColourChange();273 }274 275 void Backlight::updateColourChange()276 {277 this->ribbonTrail_->setColourChange(0, ColourValue(0, 0, 0, this->maxTraillength_ / this->traillength_ / this->maxLifeTime_ * Backlight::timeFactor_s));278 }279 280 void Backlight::tick(float dt)281 {282 SUPER(Backlight, tick, dt);283 284 if (this->isActive())285 {286 if (this->traillength_ < this->maxTraillength_)287 {288 this->traillength_ = min<float>(this->maxTraillength_, this->traillength_ + dt * this->maxTraillength_ / this->maxLifeTime_);289 this->updateColourChange();290 }291 }292 else293 {294 if (this->traillength_ > 1)295 {296 this->traillength_ = max<float>(1, this->traillength_ - this->brakefactor_ * dt * this->maxTraillength_ / this->maxLifeTime_);297 this->updateColourChange();298 }299 }300 301 this->ribbonTrail_->setTrailLength(this->traillength_);302 }303 304 void Backlight::configure(float maxspeed, float brakingtime, float scale)305 {306 this->maxTraillength_ = this->maxLifeTime_ * maxspeed;307 this->maxTrailsegments_ = (size_t)(this->maxTraillength_ / this->trailSegmentLength_);308 309 this->brakefactor_ = this->maxLifeTime_ / brakingtime;310 311 this->scale(scale);312 }313 314 void Backlight::changedVisibility()315 {316 SUPER(Backlight, changedVisibility);317 318 this->billboard_.setVisible(this->isVisible());319 this->ribbonTrail_->setVisible(this->isVisible());320 }321 */322 219 } -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Backlight.h
r2207 r2212 80 80 { return this->trailmaterial_; } 81 81 82 virtual void changedScale(); 83 82 84 private: 83 85 void stopturnoff(); … … 101 103 Timer<Backlight> turnofftimer_; 102 104 }; 103 104 105 /*106 public:107 Backlight(float maxspeed = 1.0, float brakingtime = 1.0, float scale = 1.0);108 virtual ~Backlight();109 110 void setConfigValues();111 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);112 virtual void tick(float dt);113 virtual void changedVisibility();114 virtual bool create();115 116 117 void setTimeFactor(float factor);118 119 private:120 void configure(float maxspeed, float brakingtime, float scale = 1);121 void updateColourChange();122 123 static float timeFactor_s;124 BillboardSet billboard_;125 Ogre::SceneNode* ribbonTrailNode_;126 Ogre::RibbonTrail* ribbonTrail_;127 128 129 float maxLifeTime_;130 float trailSegmentLength_;131 float width_;132 133 float brakefactor_;134 135 float maxTraillength_;136 float traillength_;137 138 size_t maxTrailsegments_;139 };140 */141 105 } 142 106 -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Billboard.cc
r2207 r2212 53 53 { 54 54 if (this->isInitialized() && this->billboard_.getBillboardSet()) 55 this->getNode()->detachObject(this->billboard_.get Name());55 this->getNode()->detachObject(this->billboard_.getBillboardSet()); 56 56 } 57 57 } -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/WorldEntity.h
r2207 r2212 107 107 108 108 inline void setScale3D(const Vector3& scale) 109 { this->node_->setScale(scale); }109 { this->node_->setScale(scale); this->changedScale(); } 110 110 inline void setScale3D(float x, float y, float z) 111 { this->node_->setScale(x, y, z); }112 inline const Vector3& getScale3D( void) const111 { this->node_->setScale(x, y, z); this->changedScale(); } 112 inline const Vector3& getScale3D() const 113 113 { return this->node_->getScale(); } 114 inline const Vector3& getWorldScale3D() const 115 { return this->node_->_getDerivedScale(); } 114 116 115 117 inline void setScale(float scale) 116 { this->node_->setScale(scale, scale, scale); }118 { this->node_->setScale(scale, scale, scale); this->changedScale(); } 117 119 inline float getScale() const 118 120 { Vector3 scale = this->getScale3D(); return (scale.x == scale.y && scale.x == scale.z) ? scale.x : 1; } 121 inline float getWorldScale() const 122 { Vector3 scale = this->getWorldScale3D(); return (scale.x == scale.y && scale.x == scale.z) ? scale.x : 1; } 119 123 120 124 inline void scale3D(const Vector3& scale) 121 { this->node_->scale(scale); }125 { this->node_->scale(scale); this->changedScale(); } 122 126 inline void scale3D(float x, float y, float z) 123 { this->node_->scale(x, y, z); }127 { this->node_->scale(x, y, z); this->changedScale(); } 124 128 inline void scale(float scale) 125 129 { this->node_->scale(scale, scale, scale); } 130 131 virtual void changedScale() {} 126 132 127 133 void attach(WorldEntity* object); … … 159 165 std::set<WorldEntity*> children_; 160 166 }; 167 168 SUPER_FUNCTION(5, WorldEntity, changedScale, false); 161 169 } 162 170
Note: See TracChangeset
for help on using the changeset viewer.