glm::vec4 Grid::Box( Actor const& Obj, double Dt )const { Opt<IMoveComponent> moveC = Obj.Get<IMoveComponent>(); float const MvX = moveC.IsValid() ? Dt * moveC->GetSpeedX() : 0.0f; float const MvY = moveC.IsValid() ? Dt * moveC->GetSpeedY() : 0.0f; double const Radius = Obj.Get<ICollisionComponent>()->GetRadius(); Opt<IPositionComponent> const objPositionC = Obj.Get<IPositionComponent>(); double const Ox = objPositionC->GetX() - mMin.x; double const Oy = objPositionC->GetY() - mMin.y; glm::vec4 Ret( Ox - Radius, Oy - Radius, Ox + Radius, Oy + Radius ); if( MvX < 0.0 ) { Ret.x += MvX; } else { Ret.z += MvX; } if( MvY < 0.0 ) { Ret.y += MvY; } else { Ret.w += MvY; } return Ret; }
void ParticleSystem::Update( double DeltaTime ) { for( auto actor: mScene.GetActorsFromMap( GetType_static() ) ) { Opt<IEmitterComponent> emitterC = actor->Get<IEmitterComponent>(); if (!emitterC.IsValid()) { continue; } Opt<IPositionComponent> positionC = actor->Get<IPositionComponent>(); if( !positionC.IsValid() ) { continue; } Opt<IMoveComponent> moveC = actor->Get<IMoveComponent>(); glm::vec2 distance(0); if ( moveC.IsValid() && moveC->IsMoving() && !moveC->IsRooted() ) { distance = glm::vec2(moveC->GetSpeedX()*DeltaTime, moveC->GetSpeedY()*DeltaTime); } emitterC->Update( DeltaTime ); std::vector<int32_t> const& emitted = emitterC->GetEmitTypes(); for( std::vector<int32_t>::const_iterator ie = emitted.begin(), ee = emitted.end(); ie != ee; ++ie ) { static ParticleEngine& pe( ParticleEngine::Get() ); pe.AddParticle( *ie, glm::vec2( positionC->GetX(), positionC->GetY() ), distance, positionC->GetOrientation() ); } emitterC->Emitted( emitted ); } }