Ejemplo n.º 1
0
/** Support objects created, start application specific content. */
void UApp::Start() {
    // the mouse must be in cursor mode before setting the UI.
    auto input_ = GetSubsystem< Urho3D::Input >();
    input_->SetMouseVisible(true);

    // resources origin.
    cache_ = GetSubsystem< Urho3D::ResourceCache >();

    // use the default style from Urho3D.
    GetSubsystem< Urho3D::UI >()->GetRoot()->SetDefaultStyle(
                cache_->GetResource< Urho3D::XMLFile >("UI/DefaultStyle.xml"));

    // grab mouse
    input_->SetMouseGrabbed(true);

    // setup scene to render.
    scene_ = new Urho3D::Scene(context_);
    scene_->CreateComponent< Urho3D::Octree >();

    // Create the light
    {
        auto lightNode = scene_->CreateChild("Light");
        lightNode->SetPosition(Urho3D::Vector3(6, 6, -20));
        auto light = lightNode->CreateComponent< Urho3D::Light >();
        light->SetLightType(Urho3D::LIGHT_POINT);
        light->SetRange(1000);
    }

    // setup camera
    {
        auto cameraNode_ = scene_->CreateChild("Camera");
        cameraNode_->SetPosition(Urho3D::Vector3(6, 6, -20));
        auto camera_ = cameraNode_->CreateComponent< Urho3D::Camera >();
        camera_->SetFarClip(2000);
        auto renderer = GetSubsystem< Urho3D::Renderer >();
        Urho3D::SharedPtr< Urho3D::Viewport > viewport(new Urho3D::Viewport(context_, scene_, camera_));
        renderer->SetViewport(0, viewport);
    }

    // start the game
    game.start();

    // subscribe to events
    SubscribeToEvent(Urho3D::E_UPDATE,URHO3D_HANDLER(UApp,HandleUpdate));
    SubscribeToEvent(Urho3D::E_KEYDOWN,URHO3D_HANDLER(UApp,HandleKeyDown));
    SubscribeToEvent(Urho3D::E_KEYUP,URHO3D_HANDLER(UApp,HandleKeyUp));
}
Ejemplo n.º 2
0
        // Called when the state needs to load itself
        void GameState::Load()
        {
            auto cache = GetSubsystem<Urho3D::ResourceCache>();
            
            // Setup Scene
            _scene = new Urho3D::Scene(context_);
            
            // Add Scene components
            _scene->CreateComponent<Urho3D::Octree>();
			_scene->CreateComponent<Urho3D::DebugRenderer>();
			_scene->CreateComponent<Urho3D::PhysicsWorld>();
            
            // Add custom Scene components
            auto saveData = _scene->CreateComponent<SaveData>();
            auto dungeon = _scene->CreateComponent<Dungeon>();
            auto playerInterface = _scene->CreateComponent<PlayerInterface>();
            
            // Create Character
            auto characterNode = _scene->CreateChild("Character");
            characterNode->SetPosition(Urho3D::Vector3(0.f, 1.f, 0.f));
            characterNode->SetScale(Urho3D::Vector3(.45f, .85f, .45f));
            
            auto character = characterNode->CreateComponent<Character>();
            auto characterModel = characterNode->CreateComponent<Urho3D::StaticModel>();
            characterModel->SetModel(cache->GetResource<Urho3D::Model>("Models/Sphere.mdl"));
            characterModel->SetMaterial(cache->GetResource<Urho3D::Material>("Materials/Stone.xml"));
            
            // Attach spotlight node to Character
            auto lightNode = characterNode->CreateChild("Character");
            lightNode->SetPosition(Urho3D::Vector3(0.f, 10.f, -10.f));
            lightNode->LookAt(Urho3D::Vector3(0, 0, 0));
            
            // Create directional light
            auto light = lightNode->CreateComponent<Urho3D::Light>();
            light->SetLightType(Urho3D::LIGHT_DIRECTIONAL);
            
        }
Ejemplo n.º 3
0
void Light::SetLightTypeAttr(int type)
{
    if (type <= LIGHT_SPOT)
        SetLightType((LightType)type);
}