Esempio n. 1
0
	bool frameStarted(const Ogre::FrameEvent& evt)
	{
		if (mExit)
			return false;
		if (mWindow->isClosed())
			return false;

		mKeyboard->capture();
		mMouse->capture();

		if (mKeyboard->isKeyDown(OIS::KC_A) || mKeyboard->isKeyDown(OIS::KC_LEFT))
			mCamera->moveRelative(Ogre::Vector3(-evt.timeSinceLastFrame*20, 0, 0));

		if (mKeyboard->isKeyDown(OIS::KC_D) || mKeyboard->isKeyDown(OIS::KC_RIGHT))
			mCamera->moveRelative(Ogre::Vector3(evt.timeSinceLastFrame*20, 0, 0));

		if (mKeyboard->isKeyDown(OIS::KC_W) || mKeyboard->isKeyDown(OIS::KC_UP))
			mCamera->moveRelative(Ogre::Vector3(0, 0, -evt.timeSinceLastFrame*20));

		if (mKeyboard->isKeyDown(OIS::KC_S) || mKeyboard->isKeyDown(OIS::KC_DOWN))
			mCamera->moveRelative(Ogre::Vector3(0, 0, evt.timeSinceLastFrame*20));

		mGUI->injectFrameEntered(evt.timeSinceLastFrame);

		return true;
	}
OgreAppFrameListener::~OgreAppFrameListener()
{
	Ogre::RenderWindow *window = mApplication->getRenderWindow();

	WindowEventUtilities::removeWindowEventListener(window, this);
	if(!window->isClosed())
		windowClosed(window);
}
Esempio n. 3
0
int main(int argc, char* argv[]){
    cout << "Test Ogre Program blaha" << endl;

    //Relative to where its executed from, not binary location
    Ogre::Root *mRoot = new Ogre::Root("configs/plugins.cfg","configs/config.cfg","logs/main.log");
    if(!(mRoot->restoreConfig() || mRoot->showConfigDialog())){
        delete mRoot;
        return -1;
    }

    // setup resources
    // Only add the minimally required resource locations to load up the Ogre head mesh
    Ogre::ResourceGroupManager::getSingleton().addResourceLocation("/Users/jgrey/OgreSDK/Media/materials/programs", "FileSystem", "General");
    Ogre::ResourceGroupManager::getSingleton().addResourceLocation("/Users/jgrey/OgreSDK/Media/materials/programs/GLSL", "FileSystem", "General");
    Ogre::ResourceGroupManager::getSingleton().addResourceLocation("/Users/jgrey/OgreSDK/Media/materials/scripts", "FileSystem", "General");
    Ogre::ResourceGroupManager::getSingleton().addResourceLocation("/Users/jgrey/OgreSDK/Media/materials/textures", "FileSystem", "General");
    Ogre::ResourceGroupManager::getSingleton().addResourceLocation("/Users/jgrey/OgreSDK/Media/models", "FileSystem", "General");

    
    //Create the window
    Ogre::RenderWindow *mWindow = mRoot->initialise(true, "initial Render Window");
    Ogre::SceneManager *sceneManager = mRoot->createSceneManager(Ogre::ST_GENERIC);

    Ogre::Camera *camera = sceneManager->createCamera("PlayerCam");

    camera->setPosition(Ogre::Vector3(0,0,80));
    camera->lookAt(Ogre::Vector3(0,0,-300));
    camera->setNearClipDistance(5);
    
    Ogre::Viewport* vp = mWindow->addViewport(camera);
    vp->setBackgroundColour(Ogre::ColourValue(0,0,0,0));
    camera->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));

    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    
    Ogre::Entity* ogreHead = sceneManager->createEntity("Head","ogreHead.mesh");
    Ogre::SceneNode* headNode = sceneManager->getRootSceneNode()->createChildSceneNode();
    headNode->attachObject(ogreHead);

    sceneManager->setAmbientLight(Ogre::ColourValue(0.5,0.5,0.5));
    
    
    
    
    //Run the system
    bool continueRunning = true;
    while(continueRunning){
        mRoot->renderOneFrame();
        headNode->rotate(Ogre::Vector3(0,1,0),Ogre::Radian(0.005));
        if(mWindow->isClosed()){
            continueRunning = false;
        }

    }
    
    
    delete mRoot;
}
bool application::frameRenderingQueued (Ogre::FrameEvent const& e)
{
    if (wnd->isClosed()) return false;
    if (shutdown)        return false;

    kbd   -> capture();
    mouse -> capture();

    tray_mgr->frameRenderingQueued(e);

    if (!tray_mgr->isDialogVisible())
        cameraman->frameRenderingQueued(e);

    return true;
}
Esempio n. 5
0
		//-----------------------------------------------------------------------------
		bool Engine::Update()
		{
				bool bContinue = !(m_pRenderWnd->isClosed());

				Ogre::WindowEventUtilities::messagePump();
		
				if(m_pRenderWnd->isActive())
				{
						float timeDelta = 0.033f;
						if(!m_pRoot->renderOneFrame(timeDelta))
								bContinue = false;
				}
				else
				{
						Sleep(1000);
				}

				return bContinue;
		}
Esempio n. 6
0
void Client::Play() {
    OgreEasy::SimpleOgreInit lOgreInit;
    if(!lOgreInit.initOgre()) {
        std::cout<<"Could not init ogre"<<std::endl;
        return;
    }
    Ogre::Root* lRoot = lOgreInit.mRoot.get();
    Ogre::RenderWindow* lWindow = lOgreInit.mWindow;
    World* w = new World();
    w->SetDebugMode(false);
    GameObject camObject = w->AddObject("camera");
    camObject.AddCameraComponent("camera");
    camObject.SetPosition(Ogre::Vector3(0,0,0));
    camObject.LookAt(Ogre::Vector3(0,0,0));

    GameObject& light2 = w->AddObject("point_light");
    light2.AddLightComponent(Ogre::Light::LT_DIRECTIONAL);
    light2.SetPosition(Ogre::Vector3(0,0,40));
    light2.LookAt(Ogre::Vector3(0,100,0));

    GameObject& c = w->AddPhysicsObject("esine", "cube/Cube.mesh");
    c.SetPosition(Ogre::Vector3(0,0,0));
    c.AddBoxCollider(1,1,1);
    PhysicsComponent phys = c.GetPhysicsComponent();
    phys.SetMass(1.0);
    c.SetMaterial("tex");

    GameObject& c2 = w->AddPhysicsObject("esine2", "cube/Cube.mesh");
    c2.SetPosition(Ogre::Vector3(1,2,1));
    c2.AddBoxCollider(1,1,1);
    PhysicsComponent phys2 = c2.GetPhysicsComponent();
    phys2.SetMass(1.0);
    c2.SetMaterial("tex");

    GameObject& taso = w->AddPhysicsObject("taso", "cube/other/Cube.mesh");
    taso.SetPosition(Ogre::Vector3(0, -10, 0));
    taso.AddBoxCollider(10,0.1,10);
    taso.SetMaterial("plane");
    PhysicsComponent phys3 = taso.GetPhysicsComponent();
    phys3.SetMass(0.0);

    GameObject& anim = w->AddObject("anim"  , "second_anim/Cube.mesh");
    anim.SetPosition(Ogre::Vector3(0, -5, 0));
    anim.SetMaterial("tex");

    lRoot->clearEventTimes();
    float f=0.0;
    unsigned long t=0;
    double d;
    Ogre::Timer* a = new Ogre::Timer();
    while(!lWindow->isClosed()) {
        t=a->getMicroseconds();

        camObject.SetPosition(Ogre::Vector3(cos(f)*15.0, -5, sin(f)*15.0));
        camObject.LookAt(Ogre::Vector3(-0,-10,-0), Ogre::Vector3::UNIT_Y);
        w->Update(d);

        f+=d*.5;
        d = (double)(a->getMicroseconds()-t)/1000000;
    }
    delete w;
}
Esempio n. 7
0
int main() {
    Ogre::Root* root = new Ogre::Root();
    root->addResourceLocation("/home/soulmerge/projects/Diplomarbeit/Prototype/resources/Ogre/", "FileSystem");
    if (!root->restoreConfig() && !root->showConfigDialog()) {
        throw 1;
    }
    root->initialise(false);
    Ogre::SceneManager* sceneMgr = root->createSceneManager(Ogre::ST_GENERIC);
    sceneMgr->setAmbientLight(Ogre::ColourValue::White * 10);
    Ogre::RenderWindow* window = root->createRenderWindow("Ogre RenderWindow", 800, 600, false, NULL);
    Ogre::Camera* cam1 = sceneMgr->createCamera("cam1");
    Ogre::Camera* cam2 = sceneMgr->createCamera("cam2");
    Ogre::Camera* cam3 = sceneMgr->createCamera("cam3");
    Ogre::Camera* cam4 = sceneMgr->createCamera("cam4");
	Ogre::Viewport* vp1 = window->addViewport(cam1, 1, 0  , 0  , 0.5, 0.5);
	Ogre::Viewport* vp2 = window->addViewport(cam2, 2, 0.5, 0  , 0.5, 0.5);
	Ogre::Viewport* vp3 = window->addViewport(cam3, 3, 0  , 0.5, 0.5, 0.5);
	Ogre::Viewport* vp4 = window->addViewport(cam4, 4, 0.5, 0.5, 0.5, 0.5);
    vp1->setBackgroundColour(Ogre::ColourValue(1, 1, 1));
    vp2->setBackgroundColour(Ogre::ColourValue(1, 1, 1) * 0.95);
    vp3->setBackgroundColour(Ogre::ColourValue(1, 1, 1) * 0.95);
    vp4->setBackgroundColour(Ogre::ColourValue(1, 1, 1));
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    Ogre::Entity* model = sceneMgr->createEntity("model", "alexandria.mesh");
    Ogre::SceneNode* modelNode1 = sceneMgr->getRootSceneNode()->createChildSceneNode("modelnode1");
    modelNode1->attachObject(model);
    cam1->setNearClipDistance(5);
    cam2->setNearClipDistance(5);
    cam3->setNearClipDistance(5);
    cam4->setNearClipDistance(5);
	/*
    cam1->setPolygonMode(Ogre::PM_WIREFRAME);
    cam2->setPolygonMode(Ogre::PM_WIREFRAME);
    cam3->setPolygonMode(Ogre::PM_WIREFRAME);
    cam4->setPolygonMode(Ogre::PM_WIREFRAME);
	*/
    Ogre::SceneNode* camNode1 = sceneMgr->getRootSceneNode()->createChildSceneNode("camnode1");
    Ogre::SceneNode* camNode2 = sceneMgr->getRootSceneNode()->createChildSceneNode("camnode2");
    Ogre::SceneNode* camNode3 = sceneMgr->getRootSceneNode()->createChildSceneNode("camnode3");
    Ogre::SceneNode* camNode4 = sceneMgr->getRootSceneNode()->createChildSceneNode("camnode4");
    camNode1->attachObject(cam1);
    camNode2->attachObject(cam2);
    camNode3->attachObject(cam3);
    camNode4->attachObject(cam4);
	Ogre::Quaternion q;
	q.FromAngleAxis(Ogre::Degree(90), Ogre::Vector3::UNIT_Y);
	camNode1->lookAt(Ogre::Vector3(-1, -1, -1), Ogre::Node::TS_LOCAL);
	camNode2->setOrientation(q * camNode1->getOrientation());
	camNode3->setOrientation(q * camNode2->getOrientation());
	camNode4->setOrientation(q * camNode3->getOrientation());
    camNode1->setPosition(100, 100, 100);
    camNode2->setPosition(100, 100, -100);
    camNode3->setPosition(-100, 100, -100);
    camNode4->setPosition(-100, 100, 100);
    while(true) {
        Ogre::WindowEventUtilities::messagePump();
        if (window->isClosed()) {
            return 0;
        }
        if (!root->renderOneFrame()) {
            return 0;
        }
    }
    return 0;
}
Esempio n. 8
0
void Main::EnterMainLoop()
{
	/* Setup 3D engine */
	OgreSubsystem* ror_ogre_subsystem = RoR::Application::GetOgreSubsystem();
	assert(ror_ogre_subsystem != nullptr);
	m_viewport = ror_ogre_subsystem->GetRenderWindow()->addViewport(nullptr);
	int viewport_width = m_viewport->getActualWidth();
	m_viewport->setBackgroundColour(m_config->viewport_background_color);
	m_camera->setAspectRatio(m_viewport->getActualHeight() / viewport_width);
	m_viewport->setCamera(m_camera);

	InitializeOrRestoreGui();

	/* Setup input */
	RoR::Application::GetInputEngine()->SetKeyboardListener(m_input_handler);
	RoR::Application::GetInputEngine()->SetMouseListener(m_input_handler);

	/* Show debug box */
	m_debug_box->setVisible(true);

	while (! m_exit_loop_requested)
	{
		UpdateMainLoop();

		Ogre::RenderWindow* rw = RoR::Application::GetOgreSubsystem()->GetRenderWindow();
		if (rw->isClosed())
		{
			RoR::Application::GetMainThreadLogic()->RequestShutdown();
			break;
		}

		/* Render */
		RoR::Application::GetOgreSubsystem()->GetOgreRoot()->renderOneFrame();

		if (!rw->isActive() && rw->isVisible())
		{
			rw->update(); // update even when in background !
		}
	}

	/* Hide GUI */
	m_gui_menubar->Hide();
	if (m_gui_open_save_file_dialog->isModal())
	{
		m_gui_open_save_file_dialog->endModal(); // Hides the dialog
	}
	m_gui_delete_menu->Hide();
	// Supress node/beam panels (if visible)
	m_nodes_panel    ->HideTemporarily();
	m_beams_panel    ->HideTemporarily();
	m_hydros_panel   ->HideTemporarily();
	m_commands2_panel->HideTemporarily();
	m_shocks_panel   ->HideTemporarily();
	m_shocks2_panel  ->HideTemporarily();
    m_meshwheels2_panel     ->HideTemporarily();
    m_flexbodywheels_panel  ->HideTemporarily();

	/* Hide debug box */
	m_debug_box->setVisible(false);

	m_exit_loop_requested = false;
}
Esempio n. 9
0
int main(int argc, char* argv[])
{
	std::unique_ptr<ExecutionArgs> exArgs(new ExecutionArgs());
	if (!processCommandLineArgs(argc, argv, *exArgs)) {
		return -1;
	} else if (exArgs->helpPrompt) {
		std::cout << "Usage: sts [--help] || [--config]" << std::endl;
		std::cout << "Options:" << std::endl;
		std::cout << "\t --help - print this message;" << std::endl;
		std::cout << "\t --config - show config dialog." << std::endl;
		std::cout << std::endl;
		return 0;
	}

	try {
		Ogre::String lConfigFileName = "ogre.cfg";
		Ogre::String lPluginsFileName = "plugins.cfg";
		Ogre::String lLogFileName = "Ogre_STS.log";

		std::unique_ptr<Ogre::Root> lRoot(new Ogre::Root(lPluginsFileName, lConfigFileName, lLogFileName));

		if (exArgs->showConfigDialog) {
			if (!lRoot->showConfigDialog()) {
				return 0;
			}
		}

		Ogre::String lWindowTitle = "STS";
		Ogre::String lCustomCapacities = "";

		/* Check for the valid ogre.cfg */
		bool lCreateAWindowAutomatically = lRoot->restoreConfig();
		if (!lCreateAWindowAutomatically) {
			initSomeRenderSystem(lRoot);
		}
		Ogre::RenderWindow* lWindow = lRoot->initialise(lCreateAWindowAutomatically, lWindowTitle, lCustomCapacities);

		if (!lWindow) {
			/* ogre.cfg is not available - start with hardcoded parameters */
			unsigned int lSizeX = 800;
			unsigned int lSizeY = 600;
			bool lFullscreen = false;

			Ogre::NameValuePairList lParams;
			lParams["FSAA"] = "0";
			lParams["vsync"] = "true";
			lWindow = lRoot->createRenderWindow(lWindowTitle, lSizeX, lSizeY, lFullscreen, &lParams);
		}

		/* Create a scene manager */
		Ogre::SceneManager* lScene = lRoot->createSceneManager(Ogre::ST_GENERIC, "SceneManager");

		Ogre::SceneNode* lRootSceneNode = lScene->getRootSceneNode();

		/* Create camera */
		Ogre::Camera* lCamera = lScene->createCamera("MyCamera");

		/* Create viewport (camera <-> window) */
		Ogre::Viewport* vp = lWindow->addViewport(lCamera);

		vp->setAutoUpdated(true);
		vp->setBackgroundColour(Ogre::ColourValue(1, 0, 1));

		lCamera->setAspectRatio(float(vp->getActualWidth()) / vp->getActualHeight());
		lCamera->setPosition(Ogre::Vector3(0, 100, -1));
		lCamera->lookAt(Ogre::Vector3(0, 0, 0));

		/* Set clipping*/
		lCamera->setNearClipDistance(1.5f);
		lCamera->setFarClipDistance(3000.0f);

		/* Lighting */
		Ogre::Light* lLight = lScene->createLight("MainLight");
		lLight->setPosition(Ogre::Vector3(0, 100, 0));

		/* Resource manager */
		Ogre::String lRcGroupName = "Main group";
		initResourceMainGroup(lRcGroupName);

		/* Load model */
		Ogre::Entity* lShipEntity = lScene->createEntity("airship.mesh");
		lShipEntity->setCastShadows(false);

		Ogre::SceneNode* lShipNode = lRootSceneNode->createChildSceneNode();
		lShipNode->attachObject(lShipEntity);
		lShipNode->setScale(Ogre::Vector3(3.15f, 3.15f, 3.15f));

		/* Starship start point */
		Ogre::Vector3 razorSP(0, -200, -100);
		lShipNode->setPosition(razorSP);

		/* Sprite billboard */
		Ogre::SceneNode* lSpriteNode = lRootSceneNode->createChildSceneNode();
		Ogre::BillboardSet* lBillboardSet = lScene->createBillboardSet();
		lBillboardSet->setMaterialName("enemy_01", lRcGroupName);
		lBillboardSet->setTextureStacksAndSlices(1, 4);
		Ogre::Billboard* lSpriteBillboard = lBillboardSet->createBillboard(Ogre::Vector3(0, 0, 0));
		lSpriteBillboard->setDimensions(48.0f / 2.0f, 58.0f / 2.0f);
		lSpriteBillboard->setTexcoordIndex(1);
		lSpriteNode->attachObject(lBillboardSet);
		lSpriteNode->setPosition(Ogre::Vector3(0, -200, 100));

		/* Obtain the timer pointer */
		Ogre::Timer* lTimer = lRoot->getTimer();

		/* Skip all the messages */
		lWindow->setAutoUpdated(false);
		lRoot->clearEventTimes();

		while (!lWindow->isClosed()) {
			float angle = Ogre::Math::Sin(float(lTimer->getMilliseconds()) * Ogre::Math::PI / 2000.0f) * Ogre::Math::PI / 4.0f;
			float diplacement = Ogre::Math::Cos(float(lTimer->getMilliseconds()) * Ogre::Math::PI / 2000.0f) * 100.0f;
			lShipNode->setOrientation(Ogre::Quaternion(Ogre::Radian(angle), Ogre::Vector3(0, 0, 1)));
			lShipNode->setPosition(razorSP + Ogre::Vector3(diplacement, 0.0f, 0.0f));

			unsigned int spriteFrame = (lTimer->getMilliseconds() / 125) % 2;
			lSpriteBillboard->setTexcoordIndex(spriteFrame);

			lWindow->update(false);
			lWindow->swapBuffers();
			lRoot->renderOneFrame();

			Ogre::WindowEventUtilities::messagePump();
		}
		Ogre::LogManager::getSingleton().logMessage("Render window closed.");
	}
	catch (Ogre::Exception &e) {
		std::cerr << "Ogre::Exception: " << e.what() << std::endl;
	}
	catch (std::exception &e) {
		std::cerr << "std::exception: " << e.what() << std::endl;
	}

	return 0;
}