示例#1
0
void EC_WaterPlane::DetachEntity()
{
    if (!attached_ || entity_ == 0)
        return;

    EC_Placeable* placeable = dynamic_cast<EC_Placeable*>(FindPlaceable().get());
    if (placeable != 0 && !attachedToRoot_)
    {
        Ogre::SceneNode* node = placeable->GetSceneNode();
        node_->detachObject(entity_);
        node->removeChild(node_); 
    }
    else
    {
        // Attached to root.
        // Sanity check..
        if (entity_->isAttached() )
        {
            Ogre::SceneManager* sceneMgr = world_.lock()->GetSceneManager();
            node_->detachObject(entity_);
            sceneMgr->getRootSceneNode()->removeChild(node_);
            attachedToRoot_ = false;
        }
    }

    attached_ = false;
}
示例#2
0
void EC_WaterPlane::SetParent()
{
    if (!ViewEnabled())
        return;
    
    CreateWaterPlane();
    
    // Parent entity has set.
    // Has parent a placeable?
    EC_Placeable* placeable = dynamic_cast<EC_Placeable*>(FindPlaceable().get());
    if (placeable != 0)
    {
        // Are we currently attached?
        if (attached_ )
        {
            // Now there might be that we are attached to OgreRoot not to placeable node.
            DetachEntity();
            AttachEntity();
        }
    }

    connect(parentEntity,SIGNAL(ComponentAdded(IComponent*, AttributeChange::Type)),
        SLOT(ComponentAdded(IComponent*, AttributeChange::Type)));
    connect(parentEntity,SIGNAL(ComponentRemoved(IComponent*, AttributeChange::Type)),
        SLOT(ComponentRemoved(IComponent*, AttributeChange::Type)));
}
示例#3
0
void EC_WaterPlane::AttachEntity()
{
    if (attached_ || entity_ == 0)
        return;

    EC_Placeable* placeable = dynamic_cast<EC_Placeable* >(FindPlaceable().get());
    
    // If there exist placeable attach node and entity to it
    if (placeable != 0 )
    {
        Ogre::SceneNode* node = placeable->GetSceneNode();
        node->addChild(node_);
        node_->attachObject(entity_);
        node_->setVisible(true);
    }
    else
    {
        // There is no placeable attacht entity to OgreSceneRoot 
        Ogre::SceneManager* sceneMgr = world_.lock()->GetSceneManager();
        node_->attachObject(entity_);
        sceneMgr->getRootSceneNode()->addChild(node_);
        node_->setVisible(true);
        attachedToRoot_ = true;
    }

    attached_ = true;
}
示例#4
0
文件: EC_Sound.cpp 项目: Chiru/naali
void EC_Sound::PlaySound()
{
    triggerSound_.Set(false, AttributeChange::LocalOnly);
    ComponentChanged(AttributeChange::LocalOnly);

    Foundation::SoundServiceInterface *soundService = framework_->GetService<Foundation::SoundServiceInterface>();
    if(!soundService)
        return;

    if(sound_id_)
        StopSound();

    OgreRenderer::EC_OgrePlaceable *placeable = dynamic_cast<OgreRenderer::EC_OgrePlaceable *>(FindPlaceable().get());
    if(placeable)
    {
        sound_id_ = soundService->PlaySound3D(soundId_.Get().toStdString(), Foundation::SoundServiceInterface::Triggered, false, placeable->GetPosition());
        soundService->SetGain(sound_id_, soundGain_.Get());
        soundService->SetLooped(sound_id_, loopSound_.Get());
        soundService->SetRange(sound_id_, soundInnerRadius_.Get(), soundOuterRadius_.Get(), 2.0f);
    }
    else // If entity isn't holding placeable component treat sound as ambient sound.
    {
        sound_id_ = soundService->PlaySound(soundId_.Get().toStdString(), Foundation::SoundServiceInterface::Ambient);
        soundService->SetGain(sound_id_, soundGain_.Get());
    }
}