Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //engine
- #include <Urho3D/Engine/Application.h>
- #include <Urho3D/Engine/Engine.h>
- #include <Urho3D/Input/Input.h>
- #include <Urho3D/Input/InputEvents.h>
- #include <Urho3D/Graphics/Graphics.h>
- #include <Urho3D/Resource/ResourceCache.h>
- #include <Urho3D/Scene/Scene.h>
- #include <Urho3D/Scene/SceneEvents.h>
- #include <Urho3D/Graphics/Octree.h>
- #include <Urho3D/Graphics/DebugRenderer.h>
- #include <Urho3D/Graphics/Camera.h>
- #include <Urho3D/Graphics/Viewport.h>
- #include <Urho3D/Graphics/Renderer.h>
- #include <Urho3D/Graphics/Model.h>
- #include <Urho3D/Graphics/StaticModel.h>
- #include <Urho3D/Graphics/AnimatedModel.h>
- #include <Urho3D/Graphics/Material.h>
- #include <Urho3D/Graphics/Light.h>
- #include <Urho3D/Core/CoreEvents.h>
- #include <Urho3D/Math/Vector3.h>
- #include <Urho3D/UI/Window.h>
- #include <Urho3D/UI/Text.h>
- #include <Urho3D/UI/Font.h>
- #include <Urho3D/UI/UI.h>
- //include
- #include <string>
- #include <iostream>
- #include <sstream>
- using namespace Urho3D;
- class projet : public Application
- {
- URHO3D_OBJECT(projet, Application)
- public:
- ////______________________
- //// DEFINITION
- SharedPtr<Scene> my_scene;
- //about camera
- SharedPtr<Node> camNode;
- //about text
- Window* window;
- Text* text;
- projet(Context* context) : Application(context)
- {
- }
- virtual void Setup()
- {
- engineParameters_["FullScreen"]=false;
- engineParameters_["WindowWidth"]=1280;
- engineParameters_["WindowHeight"]=720;
- engineParameters_["WindowResizable"]=true;
- }
- virtual void Start()
- {
- ResourceCache* cache=GetSubsystem<ResourceCache>();
- my_scene=new Scene(context_);
- my_scene->CreateComponent<Octree>();
- my_scene->CreateComponent<DebugRenderer>();
- ////__________________
- //// CAMERA
- camNode=my_scene->CreateChild("camNode");
- Camera* camObject=camNode->CreateComponent<Camera>();
- camObject->SetFarClip(2000);
- camNode->SetWorldPosition(Vector3(20,20,20));
- camNode->LookAt(Vector3::ZERO);
- //camera light
- {
- Light* light=camNode->CreateComponent<Light>();
- light->SetLightType(LIGHT_POINT);
- light->SetRange(25);
- light->SetBrightness(2.0);
- light->SetColor(Color(.8,1,.8,1.0));
- }
- ////________________
- //// TEXT
- std::string str = (" ");
- {
- std::ostringstream ss;
- ss<<"test";
- std::string s(ss.str());
- str.append(s/*.substr(0,60)*/);
- }
- String s(str.c_str(),str.size());
- window=new Window(context_);
- GetSubsystem<UI>()->GetRoot()->AddChild(window);
- window->SetStyle("Window");
- window->SetSize(600,300);
- window->SetColor(Color(.0,.15,.3,.5));
- window->SetAlignment(HA_LEFT,VA_TOP);
- text=new Text(context_);
- text->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"),14);
- text->SetColor(Color(.8,.85,.9));
- text->SetAlignment(HA_LEFT,VA_TOP);
- text->SetText(s); //s
- window->AddChild(text);
- ////__________________
- //// RENDER
- Renderer* renderer=GetSubsystem<Renderer>();
- SharedPtr<Viewport> viewport(new Viewport(context_,my_scene,camNode->GetComponent<Camera>()));
- renderer->SetViewport(0,viewport);
- ////__________________
- //// EVENTS
- //SubscribeToEvent(E_BEGINFRAME,URHO3D_HANDLER(projet,HandleBeginFrame));
- //SubscribeToEvent(E_KEYDOWN,URHO3D_HANDLER(projet,HandleKeyDown));
- //SubscribeToEvent(E_UIMOUSECLICK,URHO3D_HANDLER(projet,HandleControlClicked));
- SubscribeToEvent(E_UPDATE, URHO3D_HANDLER(projet, HandleUpdate));
- //SubscribeToEvent(E_POSTUPDATE,URHO3D_HANDLER(projet,HandlePostUpdate));
- //SubscribeToEvent(E_RENDERUPDATE,URHO3D_HANDLER(projet,HandleRenderUpdate));
- //SubscribeToEvent(E_POSTRENDERUPDATE,URHO3D_HANDLER(projet,HandlePostRenderUpdate));
- //SubscribeToEvent(E_ENDFRAME,URHO3D_HANDLER(projet,HandleEndFrame));
- SubscribeToEvent(E_KEYDOWN, URHO3D_HANDLER(projet, HandleKeyDown));
- }
- virtual void Stop()
- {
- }
- ////________
- void HandleUpdate(StringHash eventType,VariantMap& eventData)
- {
- float timeStep=eventData[Update::P_TIMESTEP].GetFloat();
- float MOVE_SPEED=50.0f;
- Input* input=GetSubsystem<Input>();
- if(input->GetQualifierDown(1)) // 1 is shift, 2 is ctrl, 4 is alt
- MOVE_SPEED*=4;
- if(input->GetKeyDown('D')) //rotate sens inverse horizontal
- camNode->Translate(Vector3(1,0, 0)*MOVE_SPEED*timeStep);
- if(input->GetKeyDown('Q')) //sens montre horizontal
- camNode->Translate(Vector3(-1,0,0)*MOVE_SPEED*timeStep);
- if(input->GetKeyDown('Z')) //zoom avant
- camNode->Translate(Vector3(0,0,1)*MOVE_SPEED*timeStep);
- if(input->GetKeyDown('S')) //zoom arriere
- camNode->Translate(Vector3(0,0,-1)*MOVE_SPEED*timeStep);
- if(input->GetKeyDown('E')) //rotate sens inverse vertical
- camNode->Translate(Vector3(0,1,0)*MOVE_SPEED*timeStep);
- if(input->GetKeyDown('A')) //sens montre vertical
- camNode->Translate(Vector3(0,-1,0)*MOVE_SPEED*timeStep);
- if(!GetSubsystem<Input>()->IsMouseGrabbed())
- {
- IntVector2 mouseMove=input->GetMouseMove();
- if(mouseMove.x_>-2000000000&&mouseMove.y_>-2000000000)
- {
- camNode->LookAt(Vector3::ZERO); //look at 0,0,0
- }
- }
- }
- ////________
- void HandleKeyDown(StringHash eventType, VariantMap& eventData)
- {
- using namespace KeyDown;
- Graphics* graphics=GetSubsystem<Graphics>();
- int key = eventData[P_KEY].GetInt();
- if (key == KEY_ESC) //ESC to quit
- {
- engine_->Exit();
- }
- else if(key == KEY_TAB) //TAB to toggle mouse cursor
- {
- GetSubsystem<Input>()->SetMouseVisible(!GetSubsystem<Input>()->IsMouseVisible());
- GetSubsystem<Input>()->SetMouseGrabbed(!GetSubsystem<Input>()->IsMouseGrabbed());
- }
- else if(key == 'W') //W for fullscreen
- {
- graphics->ToggleFullscreen();
- }
- else if(key == 'I')
- {
- //GetSubsystem<UI>()->menu->ShowPopup ();
- }
- }
- ////________
- };
- URHO3D_DEFINE_APPLICATION_MAIN(projet)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement