Exemplo n.º 1
0
// ----------------------------------------------------------------------------
void Editor::initAfterDataDirKnown()
{
    m_rcs = RoadCrossSectionWndw::get();

    // fonts
    IGUISkin* skin = m_gui_env->getSkin();
    m_font = m_gui_env->getFont(m_data_loc + L"editor/font/font.xml");
    skin->setFont(m_font);

    // removing gui transparency
    for (s32 i = 0; i < EGDC_COUNT; ++i)
    {
        video::SColor col = skin->getColor((EGUI_DEFAULT_COLOR)i);
        col.setAlpha(255);
        skin->setColor((EGUI_DEFAULT_COLOR)i, col);
    }

    // free camera
    ICameraSceneNode* cam;
    cam = m_scene_manager->addCameraSceneNodeMaya();
    cam->setID(1);
    cam->setFarValue(20000.f);
    cam->setTarget(vector3df(0, 0, 0));
    cam->setInputReceiverEnabled(false);

    // viewport init
    ICameraSceneNode* norm_cam;
    norm_cam = m_scene_manager->addCameraSceneNode(0, vector3df(25, 50, 30),
        vector3df(5, 10, 6));
    norm_cam->setID(2);
    m_viewport = Viewport::get(norm_cam, &m_mouse, &m_keys);
    m_viewport->setFreeCamera(cam);
    m_indicator = m_viewport->getIndicator();
    m_scene_manager->setActiveCamera(norm_cam);

    m_msg_wndw = MsgWndw::get();

    m_toolbar = ToolBar::getToolBar();
    m_new_dialog_wndw = NewDialogWndw::get();
    m_new_dialog_wndw->hide();
    m_welcome_screen = WelcomeScreen::get();
} // initAfterDataDirKnown
Exemplo n.º 2
0
int main(int argc, char* argv[])
{
	// ask user for driver
	video::E_DRIVER_TYPE driverType=driverChoiceConsole();
	if (driverType==video::EDT_COUNT)
		return 1;

	MyEventReceiver receiver;
	IrrlichtDevice* device = createDevice(driverType,
			core::dimension2du(800, 600), 32, false, false, false,
			&receiver);

	if(device == 0)
		return 1;

	IVideoDriver *driver = device->getVideoDriver();
	ISceneManager *smgr = device->getSceneManager();
	device->setWindowCaption(L"Irrlicht Example for SMesh usage.");

	/*
	Create the custom mesh and initialize with a heightmap
	*/
	TMesh mesh;
	HeightMap hm = HeightMap(255, 255);
	hm.generate(eggbox);
	mesh.init(hm, 50.f, grey, driver);

	// Add the mesh to the scene graph
	IMeshSceneNode* meshnode = smgr -> addMeshSceneNode(mesh.Mesh);
	meshnode->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);

	// light is just for nice effects
	ILightSceneNode *node = smgr->addLightSceneNode(0, vector3df(0,100,0),
		SColorf(1.0f, 0.6f, 0.7f, 1.0f), 500.0f);
	if (node)
	{
		node->getLightData().Attenuation.set(0.f, 1.f/500.f, 0.f);
		ISceneNodeAnimator* anim = smgr->createFlyCircleAnimator(vector3df(0,150,0),250.0f);
		if (anim)
		{
			node->addAnimator(anim);
			anim->drop();
		}
	}

	ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
	if (camera)
	{
		camera->setPosition(vector3df(-20.f, 150.f, -20.f));
		camera->setTarget(vector3df(200.f, -80.f, 150.f));
		camera->setFarValue(20000.0f);
	}

	/*
	Just a usual render loop with event handling. The custom mesh is
	a usual part of the scene graph which gets rendered by drawAll.
	*/
	while(device->run())
	{
		if(!device->isWindowActive())
		{
			device->sleep(100);
			continue;
		}

		if(receiver.IsKeyDown(irr::KEY_KEY_W))
		{
			meshnode->setMaterialFlag(video::EMF_WIREFRAME, !meshnode->getMaterial(0).Wireframe);
		}
		else if(receiver.IsKeyDown(irr::KEY_KEY_1))
		{
			hm.generate(eggbox);
			mesh.init(hm, 50.f, grey, driver);
		}
		else if(receiver.IsKeyDown(irr::KEY_KEY_2))
		{
			hm.generate(moresine);
			mesh.init(hm, 50.f, yellow, driver);
		}
		else if(receiver.IsKeyDown(irr::KEY_KEY_3))
		{
			hm.generate(justexp);
			mesh.init(hm, 50.f, yellow, driver);
		}

		driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, SColor(0xff000000));
		smgr->drawAll();
		driver->endScene();
	}

	device->drop();

	return 0;
}
Exemplo n.º 3
0
bool terrainSceneNode(void)
{
    IrrlichtDevice *device =
        createDevice(video::EDT_OPENGL, dimension2di(160, 120), 32);

    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();

    ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
        "../media/terrain-heightmap.bmp");
    terrain->setScale(core::vector3df(40.f, .1f, 40.f));

    terrain->setMaterialFlag(video::EMF_LIGHTING, false);
    terrain->setMaterialTexture(0, driver->getTexture("../media/terrain-texture.jpg"));
    terrain->setDebugDataVisible(scene::EDS_FULL);

    ICameraSceneNode* camera = smgr->addCameraSceneNode();

    const core::vector3df center (terrain->getBoundingBox().getCenter());
    camera->setTarget (center);

    // yes, Y is intentionally being set to X here
    const core::vector3df above (center.X, center.X, center.Z);
    camera->setPosition (above);
	camera->setUpVector(vector3df(1.f, 0.f, 0.f));
    camera->setFarValue(above.Y);

    device->run();
    smgr->drawAll();


	// This shouldn't cause a recalc
	camera->setUpVector(vector3df(1.f, 0.f, .01f).normalize());
    device->run();
	driver->beginScene(true, true, video::SColor(255,100,101,140));
	smgr->drawAll();
	driver->endScene();

	// Note that this has to be a slightly fuzzier than usual compare to satisfy multiple OpenGL environments
	bool result = takeScreenshotAndCompareAgainstReference(driver, "-terrainSceneNode-1.png", 98.3f);
	if(!result)
	{
		logTestString("Small camera up rotation caused bad recalc.\n");
		assert(false);
	}


	// This is big enough to cause a recalc
	camera->setUpVector(vector3df(1.f, 0.f, .1f).normalize());
    device->run();
	driver->beginScene(true, true, video::SColor(255,100,101,140));
	smgr->drawAll();
	driver->endScene();

	result &= takeScreenshotAndCompareAgainstReference(driver, "-terrainSceneNode-2.png", 98.9f);
	if(!result)
	{
		logTestString("Large camera up rotation caused bad recalc.\n");
		assert(false);
	}

    device->drop();
    return result;
}
WxIrrMainWindow::WxIrrMainWindow(const wxString& title, void (*draw)(WxIrrViewportManager*), void (*update)(void),
                                 bool (*irrlichtLeftMouseDown)(bool controlDown, bool shiftDown, int x, int y),
                                 bool (*irrlichtLeftMouseUp)(bool controlDown, bool shiftDown, int x, int y),
                                 bool (*irrlichtLeftMouseDoubleClick)(bool controlDown, bool shiftDown, int x, int y),
                                 bool (*irrlichtMouseMove)(bool controlDown, bool shiftDown, int x, int y, int moveX, int moveY),
                                 void (*irrlichtCameraMouseMove)(int moveX, int moveY, WxIrrViewport* selectedViewport),
                                 void (*irrlichtCameraKeyDown)(int id, WxIrrViewport* selectedViewport),	void (*irrlichtCameraKeyUp)(int id), void (*irrlichtCameraKeyboardReset)(void),
                                 void (*simulationMouseMove)(wxPoint mousePos, bool isShiftDown, WxIrrViewport* mouseOverViewport),
                                 bool (*simulationMouseClick)(bool isShiftDown, bool isControlDown), bool (*simulationMouseDoubleClick)(void), void (*SimulationStartMouseChecking)(void),
                                 void (*onSimulationShowAxesFunctionPointer)(bool), void (*onSimulationShowObjectNameFunctionPointer)(bool),
                                 SColor (*onSimulationXAxisGetColorFunctionPointer)(void), SColor (*onSimulationYAxisGetColorFunctionPointer)(void), SColor (*onSimulationZAxisGetColorFunctionPointer)(void),
                                 void (*onSimulationXAxisChangeColorFunctionPointer)(wxColour& color), void (*onSimulationYAxisChangeColorFunctionPointer)(wxColour& color), void (*onSimulationZAxisChangeColorFunctionPointer)(wxColour& color),
                                 void (*onSimulationShowXYGridFunctionPointer)(bool), void (*onSimulationShowXZGridFunctionPointer)(bool), void (*onSimulationShowYZGridFunctionPointer)(bool))
    : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(800, 600))
{
    OnSimulationShowAxesFunctionPointer = onSimulationShowAxesFunctionPointer;
    OnSimulationShowObjectNameFunctionPointer = onSimulationShowObjectNameFunctionPointer;

    OnSimulationXAxisGetColorFunctionPointer = onSimulationXAxisGetColorFunctionPointer;
    OnSimulationYAxisGetColorFunctionPointer = onSimulationYAxisGetColorFunctionPointer;
    OnSimulationZAxisGetColorFunctionPointer = onSimulationZAxisGetColorFunctionPointer;
    OnSimulationXAxisChangeColorFunctionPointer = onSimulationXAxisChangeColorFunctionPointer;
    OnSimulationYAxisChangeColorFunctionPointer = onSimulationYAxisChangeColorFunctionPointer;
    OnSimulationZAxisChangeColorFunctionPointer = onSimulationZAxisChangeColorFunctionPointer;

    OnSimulationShowXYGridFunctionPointer = onSimulationShowXYGridFunctionPointer;
    OnSimulationShowXZGridFunctionPointer = onSimulationShowXZGridFunctionPointer;
    OnSimulationShowYZGridFunctionPointer = onSimulationShowYZGridFunctionPointer;

    leftPanel = new WxIrrViewportWindow(this, 1000);
    leftPanel->SetBackgroundColour(wxColour(wxT("Black")));

    irr::SIrrlichtCreationParameters param;
#if defined _WX_IRR_WINDOWS

    param.DriverType = EDT_DIRECT3D9;
    param.AntiAlias = false;
    param.WindowId = reinterpret_cast<void*>(GetLeftPanelHandle());

#elif defined _WX_IRR_LINUX

    param.DriverType = EDT_OPENGL;
    param.AntiAlias = false;
    GtkWidget* handle = (GtkWidget*)GetLeftPanelHandle();
    gtk_widget_realize(handle);
    Window xHandle = GDK_WINDOW_XWINDOW(handle->window);
    param.WindowId = (void*)(xHandle);

#elif defined _WX_IRR_MACOS

    //param.DriverType = EDT_OPENGL;

#else

    //return false;
    Close();

#endif

    leftPanel->InitalizeViewportManager();
    SetupDevice(param, draw, update, irrlichtLeftMouseDown, irrlichtLeftMouseUp, irrlichtLeftMouseDoubleClick, irrlichtMouseMove, irrlichtCameraMouseMove, irrlichtCameraKeyDown, irrlichtCameraKeyUp, irrlichtCameraKeyboardReset,
                simulationMouseMove, simulationMouseClick, simulationMouseDoubleClick, SimulationStartMouseChecking);

    //Main camera
    ICameraSceneNode* camera = GetDevice()->getSceneManager()->addCameraSceneNode();
    camera->setPosition(Vector3(30,-10,30));
    //camera->bindTargetAndRotation(true);
    //camera->setTarget(Vector3(0,0,0));
    Vector3 currentCameraRot = camera->getRotation();
    Vector3 rot = currentCameraRot.rotationToDirection();
    Vector3 pos = camera->getPosition();
    camera->setTarget(rot + pos);
    camera->setFarValue(100000);
    SetCamera(camera);

    rightPanel = new SimulationPanel(this, 1001, wxDefaultPosition, wxDefaultSize);
    rightPanel->SetBackgroundColour(wxColour(wxT("Black")));

    m_mgr.SetManagedWindow(this);

    //Create Main Menu
    menuBar = new wxMenuBar();
    menuBarManager = new PhysicsHelperMenuBar(menuBar);

    SetMenuBar( menuBar );
    //Status bar
    CreateStatusBar();
    SetStatusText( wxT("PhysicsHelper") );
    statusBarText = wxT("PhysicsHelper");

    toolBarsManager = new PhysicsHelperToolbars(this, m_mgr);

    //add the normal panes
    m_mgr.AddPane(leftPanel, wxAuiPaneInfo().CenterPane().Name(wxT("leftPanel")));
    m_mgr.AddPane(rightPanel, wxAuiPaneInfo().CloseButton(false).Right().PinButton(true).MinimizeButton(true).Name(wxT("rightPanel")));

    m_mgr.Update();

    //Centre();
}
Exemplo n.º 5
0
int main(int argc, const char** argv)
{
/*	- deviceType: Type of the device. This can currently be the Null-device,
	   one of the two software renderers, D3D8, D3D9, or OpenGL. In this
	   example we use EDT_SOFTWARE, but to try out, you might want to
	   change it to EDT_BURNINGSVIDEO, EDT_NULL, EDT_DIRECT3D8,
	   EDT_DIRECT3D9, or EDT_OPENGL.
	*/
	MyEventReceiver receiver;
	ISoundEngine* music = createIrrKlangDevice();
	IrrlichtDevice *device =
		createDevice( EDT_DIRECT3D9, dimension2d<u32>(640, 480), 32,
			false, false, false, &receiver);

	music->play2D("../media/MUSIC/Dark Impetus.mp3",true,false,true);

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();
	ICameraSceneNode *camera = smgr->addCameraSceneNode();
	IGUIFont* font = device->getGUIEnvironment()->getFont("../media/fonthaettenschweiler.bmp");
	camera->setFarValue(900);

	IAnimatedMesh* map = smgr->getMesh(DC_01);
	IAnimatedMeshSceneNode* mapnode = smgr->addAnimatedMeshSceneNode(map);
	mapnode->setMaterialFlag(EMF_LIGHTING,false);

	IAnimatedMesh* player1 = smgr->getMesh(SORA);
	IAnimatedMeshSceneNode* p1node = smgr->addAnimatedMeshSceneNode(player1);
	p1node->setMaterialFlag(EMF_LIGHTING, false);
	p1node->setScale(SORA_VECTOR3D);

	IAnimatedMesh* player2 = smgr->getMesh(AQUA);
	IAnimatedMeshSceneNode* p2node = smgr->addAnimatedMeshSceneNode(player2);
	p2node->setMaterialFlag(EMF_LIGHTING, false);
	p2node->setScale(NORMAL_VECTOR3D);

	vector3df Position = p1node->getPosition();
	vector3df P2Pos = p2node->getPosition();
	vector3df PosCam = p1node->getPosition();
	vector3df Rotate = p1node->getPosition();

	int CurrentHP = 300;
	int MaxHP = 400;
	int HeartP = 10;
	bool LockOn = false;
	bool LockCheck = false;
	stringw CoorCheck;

	while(device->run())
	{
		CoorCheck +=L"Your position\nX:";
		CoorCheck +=Position.X;
		CoorCheck +=L"\nY:";
		CoorCheck +=Position.Y;
		CoorCheck +=L"\nZ:";
		CoorCheck +=Position.Z;
		CoorCheck +=L"\n\nTarget Position:";
		CoorCheck +=P2Pos.X;
		if(LockCheck != true){
			if(receiver.IsKeyDown(KEY_KEY_J)){LockOn = true; LockCheck = true;}}
		else{
			if(receiver.IsKeyDown(KEY_KEY_J)){LockOn = false;LockCheck = false;}}

		//3D Rendering.
		MaximizeKey(receiver,device);
		GetCaption(driver,device);
		driver->beginScene(true, true, SColor(255,100,101,140));
		p1node->setPosition(Position);
		camera->setPosition(vector3df(PosCam.X,PosCam.Y+2,PosCam.Z+3));
		if(LockOn != false){camera->setTarget(P2Pos);}
		else{camera->setTarget(Position);}
		smgr->drawAll();

		//2D Rendering.
		if(CurrentHP<=0){font->draw(L"You are dead!!!",rect<s32>(120,140,250,210),SColor(255,255,255,255));}
		else{if(receiver.IsKeyDown(KEY_KEY_L)){--CurrentHP;}}
		if(CurrentHP>=MaxHP){}else{if(receiver.IsKeyDown(KEY_KEY_K)){++CurrentHP;}}

		if(receiver.IsKeyDown(KEY_KEY_N)){++MaxHP;}
		if(receiver.IsKeyDown(KEY_KEY_M) && CurrentHP<MaxHP){--MaxHP;}
		if(HeartP>=86){}else{
			if(receiver.IsKeyDown(KEY_KEY_F)){++HeartP;}}

		font->draw
		(L"Press O for full screen.\nPress Up-Down-Left-right to move.\nPress L to hurt the character.\nPress K to heal the character.\nPress N to increase Max HP.\nPress M to decrease Max HP.\nPress F to fill the Heart gauge.",rect<s32>(20,40,150,110),SColor(255,0,0,0));
		font->draw(CoorCheck,rect<s32>(20,140,150,110),SColor(255,0,0,0));

		//Button detection.
		if(receiver.IsKeyDown(KEY_UP)){
			Position.Z -= 0.1f;
			PosCam.Z = Position.Z;
			p1node->setRotation(vector3df(Rotate.X,Rotate.Y = 0,Rotate.Z));
			p1node->setPosition(Position);}
		if(receiver.IsKeyDown(KEY_DOWN)){
			Position.Z += 0.1f;
			PosCam.Z = Position.Z;
			p1node->setRotation(vector3df(Rotate.X,Rotate.Y -180,Rotate.Z));
			p1node->setPosition(Position);}
		if(receiver.IsKeyDown(KEY_LEFT)){
			Position.X += 0.1f;
			PosCam.X = Position.X;
			p1node->setRotation(vector3df(Rotate.X,Rotate.Y -90,Rotate.Z));
			p1node->setPosition(Position);}
		if(receiver.IsKeyDown(KEY_RIGHT)){
			Position.X -= 0.1f;
			PosCam.X = Position.X;
			p1node->setRotation(vector3df(Rotate.X,Rotate.Y +90,Rotate.Z));
			p1node->setPosition(Position);}

		HUD_Display(device,driver,receiver,font,CurrentHP,MaxHP,HeartP);

		guienv->drawAll();
		CoorCheck = L"";
		driver->endScene();
	}
	music->drop();
	device->drop();
	return 0;
}