コード例 #1
0
ファイル: CCullingSystem.cpp プロジェクト: zdementor/my-base
//! return true if this Scene Node is culled
bool CCullingSystem::isCull(ISceneNode* node) const
{
	if (!node)
		return true;

	E_CULLING_TESTS tests = node->getCullingFilter();

	if (tests == ECT_NO_CULL)
		return false;

	static core::aabbox3d<f32> tbox;

	if (node->getSceneNodeType() == ESNT_LIGHT_SCENE_NODE)
	{
		ILightSceneNode *light = static_cast<ILightSceneNode*>(node);

		vid::SLight lparams = light->getLightParameters();

		if (isCull(lparams.Position, lparams.Radius, tests))
			return true;

		tbox = lparams.LightedVolume;
	}
	else
	{
		tbox = node->getTransformedBoundingBox();	
	}

	return isCull(tbox, tests);
}
コード例 #2
0
ファイル: Celestial.cpp プロジェクト: atti92/StarCantata
Sun::Sun(u32 type, f32 scale, vector3df pos, vector3df rot, SColorf lightcolor, f32 lightrange):CelestialObject(scale, pos, rot, false)
{
  lightColor_ = lightcolor;
  lightRange_ = lightrange;
  texturePath_ = PATH_BASE_TEXTURE;
  texturePath_ += PATH_STAR_TEXTURE;
  io::path Obj_name = FILE_STAR_TEXTURE;
  Obj_name += type;

  sceneNode_->setMaterialTexture( 0, sIGfx->getDriver()->getTexture(texturePath_+Obj_name+_JPG) );
  sceneNode_->setMaterialFlag(video::EMF_LIGHTING, false);  //light will go through it
  sceneNode_->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true); //scaled object

  video::SLight light_data;
  light_data.DiffuseColor = video::SColorf(1.0f, 1.0f, 1.0f);
  light_data.SpecularColor = video::SColorf(0.8f, 0.8f, 0.6f);
  light_data.CastShadows = true;
  light_data.Type = video::ELT_POINT;
  light_data.Attenuation = vector3df(
        0.0f, 1.f/(lightrange*lightrange), 1.f/(lightrange*lightrange));

  ILightSceneNode* il = sIGfx->getSceneManager ()->addLightSceneNode(
        0, pos + vector3df(0, 0, 1.f * scale), lightcolor, lightrange);
  il->setLightData(light_data);
}
コード例 #3
0
ファイル: editor.cpp プロジェクト: CruzR/stk-editor
// ----------------------------------------------------------------------------
bool Editor::init()
{
    m_maps_path         = NULL;
    m_music_loc         = NULL;
    m_indicator         = NULL;
    m_valid_data_dir    = false;
    m_exe_loc           = "";
    m_toolbar           = NULL;
    m_toolbox           = NULL;
    m_rcs               = NULL;
    m_tex_sel           = NULL;
    m_indicator         = NULL;
    m_viewport          = NULL;
    m_rcs               = NULL;
    m_font              = NULL;
    m_new_dialog_wndw   = NULL;

    m_screen_size = dimension2du(10, 10);

    IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL);
    m_screen_size = nulldevice->getVideoModeList()->getDesktopResolution();
    readConfigFile(nulldevice->getFileSystem());
    nulldevice->drop();

    m_device = createDevice(EDT_OPENGL, m_screen_size, 16, false, false, true);
    if (!m_device) return false;

    m_device->setResizable(true);
    m_device->setWindowCaption(L"SuperTuxKart Track Editor Beta v0.03");

    if (m_screen_size.Width < 20 || m_screen_size.Height < 20)
        m_device->maximizeWindow();

    m_video_driver  = m_device->getVideoDriver();
    m_scene_manager = m_device->getSceneManager();
    m_gui_env       = m_device->getGUIEnvironment();

    m_screen_size   = m_video_driver->getScreenSize();
    m_def_wd        = m_device->getFileSystem()->getWorkingDirectory();

    // lights
    m_scene_manager->setAmbientLight(SColorf(0.3f, 0.3f, 0.3f, 1.0f));
    ILightSceneNode* l = m_scene_manager->addLightSceneNode(0, vector3df(0, 1, 0),
                                              SColorf(1.0f, 1.0f, 1.0f), 500, -1);
    l->setLightType(ELT_DIRECTIONAL);
    l->setPosition(vector3df(0,
        1, 0));

    m_device->setEventReceiver(this);

    if (!isValidDataLoc()) dataDirLocDlg();

    return true;
} // init
コード例 #4
0
void Editor::LoadScene()
{
	IVideoDriver *driver = device->getVideoDriver();
	ISceneManager *smgr = device->getSceneManager();

	// Calculate Projection Matrix
	matrix4 projMat;
	irr::f32 orth_w = (float)(driver->getScreenSize().Width - 256) / (float)driver->getScreenSize().Height;
	orth_w = 3 * orth_w;
	projMat.buildProjectionMatrixOrthoLH(orth_w, 3, 1, 100);

	// Create target
	target = smgr->addEmptySceneNode(0, 200);
	target->setPosition(vector3df(0, 0, 0));

	// Add rotational camera
	pivot = smgr->addEmptySceneNode(target, 199);
	camera[0] = smgr->addCameraSceneNode(NULL, vector3df(0, 0, -2), vector3df(0, 0, 0));
	camera[0]->setParent(pivot);
	pivot->setRotation(vector3df(25, -45, 0));

	// Add Topdown camera
	camera[1] = smgr->addCameraSceneNode(target, vector3df(0, 2, -0.01), vector3df(0, 0, 0));
	camera[1]->setProjectionMatrix(projMat, true);

	// Add front camera
	camera[2] = smgr->addCameraSceneNode(target, vector3df(0, 0, -5), vector3df(0, 0, 0));
	camera[2]->setProjectionMatrix(projMat, true);

	// Add side camera
	camera[3] = smgr->addCameraSceneNode(target, vector3df(5, 0, 0), vector3df(0, 0, 0));
	camera[3]->setProjectionMatrix(projMat, true);

	// Add Light
	ILightSceneNode* light = smgr->addLightSceneNode(target, vector3df(25, 50, 0));
	light->setLightType(ELT_POINT);
	light->setRadius(2000);

	// Add Plane
	IMeshSceneNode* plane = smgr->addCubeSceneNode(1, 0, -1,
			vector3df(0.5, -5.5, 0.5), vector3df(0, 0, 0),
			vector3df(10, 10, 10));
	plane->setMaterialTexture(0, driver->getTexture("media/texture_terrain.png"));
	plane->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
	plane->getMaterial(0).getTextureMatrix(0).setTextureScale(10, 10);

	// Add sky box
	scene::IMeshSceneNode* skybox = smgr->addCubeSceneNode(50);
	skybox->setMaterialTexture(0, driver->getTexture("media/sky.jpg"));
	skybox->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
	skybox->setMaterialFlag(video::EMF_LIGHTING, false);
	smgr->getMeshManipulator()->flipSurfaces(skybox->getMesh());
	state->plane_tri = smgr->createOctreeTriangleSelector(skybox->getMesh(), skybox);
}
コード例 #5
0
void PhysicsSim::makeLight(vector3df position, float intensity)
{
    ILightSceneNode* lsn = smgr->addLightSceneNode(0, position, video::SColorf(1.f, 1.f, 1.f), 1);
//    smgr->setAmbientLight(SColorf(0.2, 0.2, 0.2));

    SLight sl = lsn->getLightData();
    sl.Attenuation = Vector3D(0, 0.001, 0);
    sl.DiffuseColor = SColorf(1, 1, 1);
    sl.Direction = Vector3D(0, -1, 0);
    sl.AmbientColor = SColorf(0.4, 0.4, 0.4);

    lsn->setLightData(sl);
}
コード例 #6
0
ファイル: main2.cpp プロジェクト: pvmocbel/Lane3dViewer
int main()
{
    IrrlichtDevice *device =
            createDevice( video::EDT_BURNINGSVIDEO, dimension2d<u32>(640, 480), 16,
                    false, false, false, 0);
    if (!device)    return 1;

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

// Add Light to the Scene
    ILightSceneNode *light = smgr->addLightSceneNode( 0, vector3df() );
    light->getLightData().AmbientColor = SColorf( 0.2f, 0.2f, 0.2f );
    light->getLightData().SpecularColor = SColorf( 1.0f, 1.0f, 1.0f );
    light->getLightData().DiffuseColor = SColorf( 0.8f, 0.8f, 0.8f );
    light->setLightType( ELT_DIRECTIONAL );
    light->setRotation( vector3df( 45.0f, 45.0f, 0.0f ));
    smgr->setAmbientLight( SColorf( 0.2f, 0.2f, 0.2f ));

//    scene::IMeshSceneNode* node = smgr->addCubeSceneNode(20);
//    if (node){
//        node->setMaterialFlag(EMF_LIGHTING, false);
//        smgr->getMeshManipulator()->setVertexColors(node->getMesh(),SColor(250,250,0,0));
//        node->setPosition(core::vector3df(0,0,0) );
//        node->setVisible(false);
//    }

    smgr->addCameraSceneNode(0, vector3df(0,0,-50), vector3df(0,0,0));

    while(device->run())
    {
        core::aabbox3df box;
        box.MinEdge.set(vector3df(-100,-100,-100));
        box.MaxEdge.set(vector3df(100,100,100));

        driver->beginScene(true, true, SColor(250, 100, 150, 150));
        smgr->drawAll();
        guienv->drawAll();
        criaGizmosBicos(driver);

//        criaRegiaAnalise(box, driver);

        driver->endScene();
    }
    device->drop();
    return 0;
}
コード例 #7
0
ファイル: GraphicsEngine.cpp プロジェクト: brownman/may
void GraphicsEngine::init ( )
{

	// start up the engine
	device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(800,600), 32, 0, true, 0, &receiver);

	driver = device->getVideoDriver();
	scenemgr = device->getSceneManager();

	device->setWindowCaption(L"may");
	device->getCursorControl()->setVisible(false);
	
	ILightSceneNode * light = scenemgr->addLightSceneNode(0,core::vector3df(0,0,10),video::SColorf(1,0,0));
	light->enableCastShadow(true);
//	scenemgr->addCameraSceneNodeFPS();
}
コード例 #8
0
ファイル: irrqwidget.cpp プロジェクト: pvmocbel/Lane3dViewer
void IrrQWidget::buildIrrlichtScene(){
    if(idevice != 0){
        collMan = iscene->getSceneCollisionManager();
        geo = iscene->getGeometryCreator();

        ILightSceneNode *light = iscene->addLightSceneNode();
        light->setLightType( ELT_DIRECTIONAL );
        light->setRotation( vector3df( 45.0f, 45.0f, 0.0f ));
        light->getLightData().AmbientColor = SColorf( 0.2f, 0.2f, 0.2f, 1.0f );
        light->getLightData().DiffuseColor = SColorf( 0.8f, 0.8f, 0.8f, 1.0f );

        camera = iscene->addCameraSceneNodeFPS();
        camera->setPosition(vector3df(0,0,-90));
        camera->setTarget(vector3df(0,0,0));
    }
}
コード例 #9
0
void CIrrWindow::initScene()
{
	IVideoDriver* driver = m_driver;
	IrrlichtDevice* device = m_device;
	ISceneManager* smgr = m_smgr;

	// create texture manager
	CTextureManager::createGetInstance();

	// create design camera
	m_designCamera = new CGameCamera();
	m_designCamera->setName( L"Design camera" );
	m_designCamera->setTarget(core::vector3df(0,0,0));
	m_designCamera->setPosition( core::vector3df(-400, 200, -400) );


	// set active camera
	getIView()->setActiveCamera( m_designCamera );



	// add oxyz plane node
	CGameOxyzSceneNode *oxyPlane = new CGameOxyzSceneNode( smgr->getRootSceneNode(), smgr, 1 );	
	oxyPlane->drop();

	// add light
	ISceneNode* pNode = smgr->addEmptySceneNode();

	// default light	
	ILightSceneNode *light = smgr->addLightSceneNode( pNode, core::vector3df(0, 0, 0) );
	light->setLightType( video::ELT_DIRECTIONAL );


	// add demo particle
	m_particleObject = new CGameObject();
	CParticleComponent *particleComp = new CParticleComponent(m_particleObject);
	particleComp->initParticle();
	m_particleObject->m_components.push_back( particleComp );

}
コード例 #10
0
ファイル: Editor.cpp プロジェクト: asl97/NodeBoxEditor
void Editor::LoadScene()
{
	IVideoDriver *driver = device->getVideoDriver();
	ISceneManager *smgr = device->getSceneManager();

	// Create target
	target = smgr->addEmptySceneNode(0, 200);
	target->setPosition(vector3df(0, 0, 0));

	// Create cameras
	pivot = smgr->addEmptySceneNode(target, 199);
	pivot->setRotation(vector3df(25, -45, 0));
	recreateCameras();

	// Add Light
	ILightSceneNode* light = smgr->addLightSceneNode(target, vector3df(25, 50, 0));
	light->setLightType(ELT_POINT);
	light->setRadius(2000);

	// Add Plane
	plane = smgr->addCubeSceneNode(1, 0, -1,
			vector3df(0.5, -5.5, 0.5), vector3df(0, 0, 0),
			vector3df(10, 10, 10));
	plane->setMaterialTexture(0, driver->getTexture("media/texture_terrain.png"));
	plane->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
	plane->setMaterialFlag(video::EMF_LIGHTING, false);
	plane->setMaterialFlag(video::EMF_BACK_FACE_CULLING, true);
	plane->getMaterial(0).getTextureMatrix(0).setTextureScale(10, 10);

	// Add sky box
	scene::IMeshSceneNode* skybox = smgr->addCubeSceneNode(50);
	skybox->setMaterialTexture(0, driver->getTexture("media/sky.jpg"));
	skybox->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
	skybox->setMaterialFlag(video::EMF_LIGHTING, false);
	smgr->getMeshManipulator()->flipSurfaces(skybox->getMesh());
	state->plane_tri = smgr->createOctreeTriangleSelector(skybox->getMesh(), skybox);
}
コード例 #11
0
ファイル: main.cpp プロジェクト: OmniPlatGames/Seas-of-Gold
int main()
{
	Input input;
	IrrlichtDevice *device = createDevice(video::EDT_DIRECT3D9, dimension2d<u32>(800, 600), 16, false, true, false, &input);
	device->setWindowCaption(L"Seas of Gold");
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();
	E_DRIVER_TYPE driverType = driverChoiceConsole();
	EffectHandler *effect = new EffectHandler(device, driver->getScreenSize(), false, true);
	E_FILTER_TYPE filterType = (E_FILTER_TYPE)core::clamp<u32>((u32)3 - '1', 0, 4);
	MapID currentMap;
	int skyR = 30, skyG = 30, skyB = 70;
	int timer = 0;
	SColor sky = SColor(255, skyR, skyG, skyB);
	float plPos_x = 0.0f, plPos_y = 0.0f, plPos_z = 0.0f;
	bool updateCam = true;
	bool menu1 = false;
	int state = Main;
	int frameCount = 0;
	LoadMap loadMap;
	Player player;
	Interface playerInterface(driver);
	ITriangleSelector* selector = 0;
	ISceneNodeAnimator* anim = 0;
	Vendor southVendor;
	Vendor eastVendor;
	Vendor northVendor;
	//InitializeVendors(northVendor, southVendor, eastVendor, itemD);

	//ItemDatabase* itemD = new ItemDatabase;
	ItemDatabase itemD;
	itemD.Initialize();

	//initialize player's inventory
	player.AddGold(1000);
	player.getInventory()->addItem(itemD.getItem(bronzeOre), 50);
	player.getInventory()->addItem(itemD.getItem(ironOre), 50);
	player.getInventory()->addItem(itemD.getItem(goldOre), 50);

	//initialize south vendor's inventory
	southVendor.getInventory()->addItem(itemD.getItem(bronzeOre), 100);
	southVendor.getInventory()->addItem(itemD.getItem(coalOre), 100);
	southVendor.getInventory()->addItem(itemD.getItem(supplies), 1000);

	//initialize north vendor's inventory
	northVendor.getInventory()->addItem(itemD.getItem(obsidianOre), 50);
	northVendor.getInventory()->addItem(itemD.getItem(supplies), 1000);

	//initialize south vendor's inventory
	eastVendor.getInventory()->addItem(itemD.getItem(goldOre), 100);
	eastVendor.getInventory()->addItem(itemD.getItem(ironOre), 100);
	eastVendor.getInventory()->addItem(itemD.getItem(supplies), 1000);

	//Item item(0, "bronzeOre", "Sprites/ore_Bronze.png");
	//Item item2 = item;
	//Item* item2 = itemD.getItem(3);
	//inventory.addItem(&item, 2);
	//inventory.addItem(&item, 2);
	//inventory.addItem(item2, 2);

	//int test = 0;

	// Load the map scene
	//loadMap.Load(smgr, device, Map_Africa);
	//loadMap.Load(smgr, device, Map_India);
	//loadMap.Load(smgr, device, selector, plyrNode, anim, Map_England);

	IAnimatedMeshSceneNode* plyrNode = player.loadPlayerNode(device, smgr);
	//plyrNode->setDebugDataVisible((scene::E_DEBUG_SCENE_TYPE)(plyrNode->isDebugDataVisible() ^ scene::EDS_BBOX));

	ICameraSceneNode* camera = smgr->addCameraSceneNode(0, plyrNode->getPosition() + vector3df(0, 2, 2), vector3df(0, 0, 100));

	loadMap.Load(smgr, device, selector, plyrNode, anim, driver, Map_Africa);
	currentMap = Map_Africa;
	//loadMap.setCollisions(smgr, selector, plyrNode, anim);

	if (loadMap.CollNode)
	{
		selector = smgr->createOctreeTriangleSelector(loadMap.CollNode->getMesh(), loadMap.CollNode, 32);
		for (int i = 0; i < loadMap.CollNode->getMaterialCount(); i++)
		{
			loadMap.CollNode->getMaterial(i).NormalizeNormals = true;
		}
		loadMap.CollNode->setTriangleSelector(selector);
	}

	if (selector)
	{
		anim = smgr->createCollisionResponseAnimator(selector, plyrNode, vector3df(0.6f, 0.75f, 0.4f), core::vector3df(0.0f, -0.05f, 0.0f),
			core::vector3df(0.0f, -0.725f, 0.0f));

		plyrNode->addAnimator(anim);
	}

	ISceneCollisionManager* collMan = smgr->getSceneCollisionManager();

	////////////// The Sun ////////////
	ILightSceneNode *sun_node;
	SLight sun_data;
	ISceneNode *sun_billboard;
	float sun_angle = 0;
	video::SColorf Diffuse_Night = video::SColorf(0.0f, 0.0f, 0.0f, 1.0f);
	video::SColorf Diffuse_Day = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);

	sun_node = smgr->addLightSceneNode();
	sun_data.Direction = vector3df(0, 0, 0);
	sun_data.Type = video::ELT_DIRECTIONAL;
	sun_data.AmbientColor = video::SColorf(0.1f, 0.1f, 0.1f, 1);
	sun_data.SpecularColor = video::SColorf(0, 0, 0, 0);
	sun_data.DiffuseColor = Diffuse_Day;
	sun_data.CastShadows = true;
	sun_node->setLightData(sun_data);
	sun_node->setPosition(vector3df(0, 0, 0));
	sun_node->setRotation(vector3df(0, 0, 0));

	sun_billboard = smgr->addBillboardSceneNode(sun_node, core::dimension2d<f32>(60, 60));
	if (sun_billboard)
	{
		sun_billboard->setPosition(vector3df(0, 0, -100));
		sun_billboard->setMaterialFlag(video::EMF_LIGHTING, false);
		sun_billboard->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
		sun_billboard->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
		sun_billboard->setMaterialTexture(0, driver->getTexture("Assets/particlewhite.bmp"));
	}
	/////////// End ////////////

	//------- candleLight -----//
	ILightSceneNode *candleLight = smgr->addLightSceneNode();
	SLight candleLight_data;

	candleLight_data.Type = video::ELT_POINT;
	candleLight_data.DiffuseColor = SColorf(1.0f, 0.546f, 0.016f, 1.0f);
	candleLight_data.SpecularColor = video::SColorf(0, 0, 0, 0);
	candleLight->setPosition(vector3df(2.43467f, 1.55795f, -3.94657));
	candleLight_data.Radius = 1.5f;
	candleLight->setLightData(candleLight_data);
	//------- end -----//

	//// Make the player
	//player.AddGold(1000);
	//player.SetCurrentPort(eMapDest::South);
	//Item* itemCi = new Item("Iron Ore", 1);
	//player.getItems()->addItem(itemCi);
	//Item* itemCb = new Item("Bronze Ore", 1);
	//player.getItems()->addItem(itemCb);

	//Vendor vN;
	//Item* itemG = new Item("Gold Ore", 1000);
	//vN.getItems()->addItem(itemG);
	//Vendor vS;
	//Item* itemI = new Item("Iron Ore", 1000);
	//vS.getItems()->addItem(itemI);
	//Vendor vE;
	//Item* itemB = new Item("Bronze Ore", 1000);
	//vE.getItems()->addItem(itemB);
	//Vendor northVendor

	//delete &itemD;

	int test99 = 0;


	// Make the menus
	MainMenu mainMenu(device, driver);

	MapMenu mapMenu(device, driver);
	mapMenu.SetPlayer(&player);

	TradeMenu tradeMenu;
	tradeMenu.Initialize(device, driver, &player, &southVendor);
	//TradeMenu tradeMenu(device, driver);
	//tradeMenu.SetPlayer(&player);
	//tradeMenu.SetVendor(&vS);
	//
	CraftingMenu craftMenu(device, driver, &player, itemD);
	//craftMenu.SetPlayer(&player);

	//////////////////////////////////////////////////////////////////////////
	// Initialize timer to compute elapsed time between frames
	//////////////////////////////////////////////////////////////////////////
	__int64 cntsPerSec = 0;
	QueryPerformanceFrequency((LARGE_INTEGER*)&cntsPerSec);
	float secsPerCnt = 1.0f / (float)cntsPerSec;

	__int64 prevTimeStamp = 0;
	QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);

	while (device->run())
	{
		//for scaling animation by time, not by frame
		__int64 currTimeStamp = 0;
		QueryPerformanceCounter((LARGE_INTEGER*)&currTimeStamp);
		float dt = (currTimeStamp - prevTimeStamp) * secsPerCnt;

		sun_node->setRotation(vector3df(sun_angle, 0.0f, 0.0f));
		sun_angle += dt;
		frameCount += 1;
		if ((sun_angle > 0 && sun_angle < 109) || (sun_angle>350))
		{
			timer++;
			if (timer > 10)
			{
				if (skyR < 100) skyR += 1;
				if (skyG < 100) skyG += 1;
				if (skyB < 140) skyB += 1;
				timer = 0;
			}
		}
		if (sun_angle > 170 && sun_angle < 330)
		{
			timer++;
			if (timer > 10)
			{
				if (skyR > 0) skyR -= 1;
				if (skyG > 0) skyG -= 1;
				if (skyB > 40) skyB -= 1;
				timer = 0;
			}
		}

		player.updatePlayer(plyrNode, dt, collMan, selector);
		playerInterface.update(plyrNode, loadMap, driver, device, input, updateCam, state);

		switch (state)
		{
		case Map:
		{
			int out = mapMenu.Update(&input, frameCount);

			switch (out)
			{
			case eMapDest::Exit:
			{
				state = None;
				break;
			}
			case eMapDest::East:
			{
				state = None;
				//Item* itemB = new Item("Bronze Ore", 1000);
				//vE.getItems()->addItem(itemB);
				tradeMenu.SetVendor(&eastVendor);
				loadMap.Load(smgr, device, selector, plyrNode, anim, driver, Map_India);
				currentMap = Map_India;
				if (loadMap.CollNode)
				{
					selector = smgr->createOctreeTriangleSelector(loadMap.CollNode->getMesh(), loadMap.CollNode, 32);

					for (int i = 0; i < loadMap.CollNode->getMaterialCount(); i++)
					{
						loadMap.CollNode->getMaterial(i).NormalizeNormals = true;
					}
					loadMap.CollNode->setTriangleSelector(selector);
				}

				if (selector)
				{
					anim = smgr->createCollisionResponseAnimator(selector, plyrNode, vector3df(0.6f, 0.75f, 0.4f), core::vector3df(0.0f, -0.05f, 0.0f),
						core::vector3df(0.0f, -0.725f, 0.0f));
					plyrNode->addAnimator(anim);
				}
				collMan = smgr->getSceneCollisionManager();
				break;
			}
			case eMapDest::North:
			{
				state = None;
				//Item *itemG = new Item("Gold Ore", 1000);
				//vN.getItems()->addItem(itemG);
				//tradeMenu.SetVendor(&vN);
				tradeMenu.SetVendor(&northVendor);
				loadMap.Load(smgr, device, selector, plyrNode, anim, driver, Map_England);
				currentMap = Map_England;
				if (loadMap.CollNode)
				{
					selector = smgr->createOctreeTriangleSelector(loadMap.CollNode->getMesh(), loadMap.CollNode, 32);

					for (int i = 0; i < loadMap.CollNode->getMaterialCount(); i++)
					{
						loadMap.CollNode->getMaterial(i).NormalizeNormals = true;
					}
					loadMap.CollNode->setTriangleSelector(selector);
				}

				if (selector)
				{
					anim = smgr->createCollisionResponseAnimator(selector, plyrNode, vector3df(0.6f, 0.75f, 0.4f), core::vector3df(0.0f, -0.05f, 0.0f),
						core::vector3df(0.0f, -0.725f, 0.0f));
					plyrNode->addAnimator(anim);
				}
				collMan = smgr->getSceneCollisionManager();
				break;
			}
			case eMapDest::South:
			{
				state = None;
				//Item *itemI = new Item("Iron Ore", 1000);
				//vS.getItems()->addItem(itemI);
				//tradeMenu.SetVendor(&vS);
				tradeMenu.SetVendor(&southVendor);
				loadMap.Load(smgr, device, selector, plyrNode, anim, driver, Map_Africa);
				currentMap = Map_Africa;
				if (loadMap.CollNode)
				{
					selector = smgr->createOctreeTriangleSelector(loadMap.CollNode->getMesh(), loadMap.CollNode, 32);

					for (int i = 0; i < loadMap.CollNode->getMaterialCount(); i++)
					{
						loadMap.CollNode->getMaterial(i).NormalizeNormals = true;
					}
					loadMap.CollNode->setTriangleSelector(selector);
				}

				if (selector)
				{
					anim = smgr->createCollisionResponseAnimator(selector, plyrNode, vector3df(0.6f, 0.75f, 0.4f), core::vector3df(0.0f, -0.05f, 0.0f),
						core::vector3df(0.0f, -0.725f, 0.0f));
					plyrNode->addAnimator(anim);
				}
				collMan = smgr->getSceneCollisionManager();
				break;
			}
			default:
				break;
			}

			break;
		}
		case Trade:
		{

			bool out = false;
			out = tradeMenu.Update(&input, frameCount, device, currentMap);
			if (out)
				state = None;
			break;
		}
		case Main:
		{
			int out = mainMenu.Update(&input, frameCount);

			switch (out)
			{
			case MSstart:
			{
				state = None;
				break;
			}
			case MSexit:
			{
				device->closeDevice();
				//return 0;
				break;
			}
			default:
				break;
			}

			break;
		}
		case Craft:
		{
			bool out = craftMenu.Update(&input, frameCount, device);
			if (out)
				state = None;
			break;
		}
		default:
			// Do nothing
			break;
		}

		if (updateCam) moveCameraControl(plyrNode, device, camera);

		////////////////////////////////////////////////////////

		if (sun_angle > 360) sun_angle = 0;
		if (sun_angle < 180) sun_data.DiffuseColor = Diffuse_Day; else sun_data.DiffuseColor = Diffuse_Night;
		sun_node->setLightData(sun_data);

		sky.setRed(skyR);
		sky.setGreen(skyG);
		sky.setBlue(skyB);
		driver->beginScene(true, true, sky);

		smgr->drawAll();

		playerInterface.render(driver, state);

		// Draw the menu
		switch (state)
		{
		case Map:
		{
			mapMenu.Draw(driver, device);
			break;
		}
		case Trade:
		{
			tradeMenu.Render(driver, device);
			break;
		}
		case Main:
		{
			mainMenu.Draw(driver);
			break;
		}
		case Craft:
		{
			craftMenu.Draw(driver);
			break;
		}
		default:
			// Do nothing
			break;
		}

		driver->endScene();
		
		// Update the prev time stamp to current
		prevTimeStamp = currTimeStamp;

	}

	device->drop();

	return 0;
}
コード例 #12
0
ファイル: main.cpp プロジェクト: bacsmar/irrlicht
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;
}
コード例 #13
0
ファイル: SceneWorld.cpp プロジェクト: BThallid/pseuwow
SceneWorld::SceneWorld(PseuGUI *g) : Scene(g)
{
    DEBUG(logdebug("SceneWorld: Initializing..."));
    debugmode = false;
    _freeCameraMove = true;

    // store some pointers right now to prevent repeated ptr dereferencing later (speeds up code)
    gui = g;
    wsession = gui->GetInstance()->GetWSession();
    world = wsession->GetWorld();
    mapmgr = world->GetMapMgr();
    movemgr = world->GetMoveMgr();
    mychar = wsession->GetMyChar();
    ASSERT(mychar);
    _CalcXYMoveVect(mychar->GetO());
    old_char_o = mychar->GetO();

    if(soundengine)
    {
        soundengine->stopAllSounds();
    }

    ILightSceneNode* light = smgr->addLightSceneNode(0, core::vector3df(0,0,0), SColorf(255, 255, 255, 255), 1000.0f);
    SLight ldata = light->getLightData();
    ldata.AmbientColor = video::SColorf(0.2f,0.2f,0.2f);
    ldata.DiffuseColor = video::SColorf(1.0f,1.0f,1.0f);
    ldata.Type = video::ELT_DIRECTIONAL;
    ldata.Position = core::vector3df(-0.22f,-1,0);
    light->setLightData(ldata);

    eventrecv = new MyEventReceiver();
    device->setEventReceiver(eventrecv);
    eventrecv->mouse.wheel = MAX_CAM_DISTANCE;

    camera = new MCameraFPS(smgr);
    camera->setNearValue(0.1f);

    f32 farclip = instance->GetConf()->farclip;
    if(farclip < 50)
        farclip = TILESIZE;

    f32 fov = instance->GetConf()->fov;
    if(!iszero(fov))
    {
        logdetail("Camera: Field of view (FOV) = %.3f",fov);
        camera->setFOV(fov);
    }

    camera->setFarValue(farclip);

    debugText = guienv->addStaticText(L"< debug text >",rect<s32>(0,0,driver->getScreenSize().Width,30),true,true,0,-1,true);

    envBasicColor = video::SColor(0,100,101,190);

    smgr->setShadowColor(); // set shadow to default color

    sky = NULL;
    selectedNode = oldSelectedNode = NULL;
    //sky = smgr->addSkyDomeSceneNode(driver->getTexture("data/misc/sky.jpg"),64,64,1.0f,2.0f);
    /* // TODO: for now let irrlicht draw the skybox
    sky->grab(); // if the camera clip is set too short, the sky will not be rendered properly.
    sky->remove(); // thus we grab the sky node while removing it from rendering.
    */

    f32 fogfar = instance->GetConf()->fogfar;
    if(fogfar < 30)
        fogfar = farclip * 0.7f;

    f32 fognear = instance->GetConf()->fognear;
    if(fognear < 10)
        fognear = fogfar * 0.75f;

    logdetail("GUI: Using farclip=%.2f fogfar=%.2f fognear=%.2f", farclip, fogfar, fognear);

    driver->setFog(envBasicColor, true, fognear, fogfar, 0.02f);

    // setup cursor
    cursor->setOSCursorVisible(false);
    cursor->addMouseCursorTexture("data/misc/cursor.png", true);
    cursor->setVisible(true);

    InitTerrain();
    UpdateTerrain();
    RelocateCameraBehindChar();

    DEBUG(logdebug("SceneWorld: Init done!"));
}
コード例 #14
0
int main()
{
    const int nRobots = 2;
    //given robot numbers will be controlled by humans
    vector<int> humanBrainIds; 
    //humanBrainIds.push_back(1);
    //humanBrainIds.push_back(0);

//-- device ------------------------------------------------------------//

    IrrlichtDevice* device;

    device = createDevice(
        EDT_OPENGL, //driverType
        windowSize,
        16,  //bits
        false,
        false, //stencilbuffer
        false, //vsync
        NULL //receiver
    );
    //advanced device params
        //SIrrlichtCreationParameters params;
        //params.DeviceType = EIDT_CONSOLE;
        //params.DriverType = EDT_OPENGL;
        //params.WindowSize = windowSize;
        //device = createDeviceEx(params);

    if (device == 0)
        return EXIT_FAILURE; // could not create selected driver.

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

//-- lights ------------------------------------------------------------//

    //ambient light
    //smgr->setAmbientLight( SColorf(1.0f,1.0f,1.0f,1.0f) );
        //smgr->setAmbientLight( SColorf(.3f,.3f,.3f,1.0f) );

    //diffusive light
        SLight light_data;
        light_data.AmbientColor = SColorf(.3,.3,.3);
        //light_data.Attenuation = vector3df(.3,.3,.3); //Attenuation cte, linear quadratic TODO ??
        light_data.DiffuseColor = SColorf(.0,.0,.0);
        light_data.SpecularColor = SColorf(.0,.0,.0);
        light_data.CastShadows = true;
        light_data.Radius = 100.0f;
        light_data.Type = ELT_DIRECTIONAL;
            //ELT_POINT 	point light, it has a position in space and radiates light in all directions
            //ELT_SPOT    spot light, it has a position in space, a direction, and a limited cone of influence
            //ELT_DIRECTIONAL 	directional light, coming from a direction from an infinite distance 
            
        ILightSceneNode* light = smgr->addLightSceneNode(0, core::vector3df(.5f,.0f,.5f));
        light->setLightData(light_data);

//-- objects ------------------------------------------------------------//

    IMesh* mesh;
    ISceneNode * node;
    float HEIGHT=1000.f, WIDTH=1.f;
    //height between center/sky == height bottom/center
    //large so that scene looks 2d on interactive test mode.
    //on automatic mode, only middle pixel row is taken, so this does not matter

    //outter boundary
        
        //square
            node = smgr->addCubeSceneNode(
                2.f*WIDTH,  // width
                0,      // parent
                -1,     // id
                vector3df(0, 0, 0),               // center
                vector3df(0, 0, 0),               // rotation
                vector3df(1.0f, HEIGHT, 1.0f)*-1.f    // scale. *-1 turns it inside out. to use both faces make two cubes.
            );

        //circle
            //mesh = smgr->getGeometryCreator()->createCylinderMesh(
                //1.f,    //radius
                //1.,     //length
                //50,     //tesselation
                //SColor(0,0,0,255),     //color
                //false,                 //closeTop
                //0.f                    //oblique
            //);
            //node = smgr->addMeshSceneNode(
                //mesh,
                //0,     //ISceneNode * parent
                //-1,    //s32 id
                //vector3df(0, -HEIGHT, 0),            //const core::vector3df & position
                //vector3df(0, 0, 0),                     //const core::vector3df & rotation
                //vector3df(1.0f, 2.f*HEIGHT, 1.0f)      //const core::vector3df & scale
            //);

        node->getMaterial(0).AmbientColor.set(0,0,0,0);
        node->getMaterial(0).DiffuseColor.set(0,0,0,0);
        //node->getMaterial(0).SpecularColor.set(255,255,255,255);
        //node->getMaterial(0).Shininess = 20.0f;
        //node->getMaterial(0).EmissiveColor.set(0,0,0,0);
        //node->setMaterialFlag(EMF_WIREFRAME,true); //wireframe only

    //left cube
        node = smgr->addCubeSceneNode(
            0.2,    // width
            0,      // parent
            -1,     // id
            vector3df(-.3, 0, 0),       // center
            vector3df(0, 0, 0),           // rotation
            vector3df(1.0f, HEIGHT, 1.0f)   // scale
        );
        node->getMaterial(0).AmbientColor.set(0,255,0,0);
        node->getMaterial(0).DiffuseColor.set(0,255,0,0);

    //right cube
        node = smgr->addCubeSceneNode(
            .2f,    // width
            0,      // parent
            -1,     // id
            vector3df(.3, 0, 0),        // center
            vector3df(0, 0, 0),           // rotation
            vector3df(1.0f, HEIGHT, 1.0f)   // scale
        );
        node->getMaterial(0).AmbientColor.set(0,0,255,0);
        node->getMaterial(0).DiffuseColor.set(0,0,255,0);

    //cylinder
        //mesh = smgr->getGeometryCreator()->createCylinderMesh(
            //.1f,    //radius
            //1.,     //length
            //50,     //tesselation
            //SColor(),              //color
            //false,                 //closeTop
            //0.f                    //oblique
        //);
        //node = smgr->addMeshSceneNode(
            //mesh,
            //0,     //ISceneNode * parent
            //-1,    //s32 id
            //vector3df(0, -HEIGHT, 0),            //const core::vector3df & position
            //vector3df(0, 0, 0),                  //const core::vector3df & rotation
            //vector3df(1.0f, 2.*HEIGHT, 1.0f)     //const core::vector3df & scale
        //);
        //node->getMaterial(0).AmbientColor.set(0,0,0,255);
        //node->getMaterial(0).DiffuseColor.set(0,0,0,255);

    //sphere
        //node = smgr->addSphereSceneNode(
            //0.1,     // radius
            //50,     // poly count
            //0,      // parent
            //FruitID,     // id
            //vector3df(0, 0, 0),         // center
            //vector3df(0, 0, 0),           // rotation
            //vector3df(1.0f, 1.0f, 1.0f)   // scale
        //);
        //node->getMaterial(0).AmbientColor.set(0,0,0,255);
        //node->getMaterial(0).DiffuseColor.set(0,0,0,255);
        //node->getMaterial(0).Lighting = true;

//-- collision ------------------------------------------------------------//

    /* Put everything we want to do collision checking with inside the meta selector. */
    IMetaTriangleSelector * meta = smgr->createMetaTriangleSelector();
    array<ISceneNode *> nodes;
    smgr->getSceneNodesFromType(ESNT_ANY, nodes); // Find all nodes

    for (u32 i=0; i < nodes.size(); ++i)
    {
        ISceneNode * node = nodes[i];
        ITriangleSelector * selector = 0;

        switch(node->getType())
        {
            case ESNT_CUBE:
            case ESNT_ANIMATED_MESH:
            // Because the selector won't animate with the mesh,
            // and is only being used for camera collision, we'll just use an approximate
            // bounding box instead of ((IAnimatedMeshSceneNode*)node)->getMesh(0)
            selector = smgr->createTriangleSelectorFromBoundingBox(node);
            break;

            case ESNT_MESH:
            case ESNT_SPHERE: // Derived from IMeshSceneNode
            selector = smgr->createTriangleSelector(((IMeshSceneNode*)node)->getMesh(), node);
            break;

            case ESNT_TERRAIN:
            selector = smgr->createTerrainTriangleSelector((ITerrainSceneNode*)node);
            break;

            case ESNT_OCTREE:
            selector = smgr->createOctreeTriangleSelector(((IMeshSceneNode*)node)->getMesh(), node);
            break;

            default:
            // Don't create a selector for this node type
            break;
        }

        if(selector)
        {
            // Add it to the meta selector, which will take a reference to it
            meta->addTriangleSelector(selector);
            // And drop my reference to it, so that the meta selector owns it.
            selector->drop();
        }
    }

//-- robots ------------------------------------------------------------//

    //create robots
    Fly2D::Brain* brains[nRobots];


    //all to a default type
    //for ( int i=0; i<nRobots; i++ )
    //{
        //brains[i] = new Fly2D::BrainForward;
        ////brains[i] = new Fly2D::BrainCircle();
    //}

    brains[0] = new Fly2D::BrainForward;
    brains[1] = new Fly2D::BrainForward;

    //decide human control
        vector<Fly2D::BrainHuman*> hBrains;
        for (
            vector<int>::iterator i = humanBrainIds.begin();
            i != humanBrainIds.end();
            ++i
        )
        {
            if ( *i > nRobots )
            {
                cerr << "no such robot: " << *i << endl;
                exit(EXIT_FAILURE);
            }
            delete brains[*i];
            Fly2D::BrainHuman* hBrain = new Fly2D::BrainHuman;
            brains[*i] = hBrain;
            hBrains.push_back(hBrain);
        }
        Fly2D::ReceiverHuman hReceiver = Fly2D::ReceiverHuman( hBrains );
        device->setEventReceiver( &hReceiver );

    Robot* robots[nRobots];
    robots[0] = new Fly2D::Robot( *device, *meta, *brains[0], vector3df(0,0,-0.5f), vector3df(0,0, 0.5f),  0.01 );
    robots[1] = new Fly2D::Robot( *device, *meta, *brains[1], vector3df(0,0,0.5f),  vector3df(0,0, -0.5f), 0.01 );

    meta->drop(); // As soon as we're done with the selector, drop it.

//-- run ------------------------------------------------------------//
    //TEST
    vector3df oldpos, oldtarget;
    //END TEST
    
    int nFrames = 0;
    ITimer* timer = device->getTimer();
    int t0 = timer->getTime();
    int w = driver->getScreenSize().Width;
    int h = driver->getScreenSize().Height;
    int dh = h/nRobots;
    int observeRobot = 0;

	while(device->run())
	{
        //if (device->isWindowActive()) //only work if window has focus.

        //draw

        driver->setViewPort(rect<s32>(0,0,w,h));
        driver->beginScene(true,true,0);
        for(int i=0; i<nRobots; i++)
        {
            driver->setViewPort(rect<s32>(0,dh*i,w,dh*(i+1)));
            //only part of window gets drawn into

            smgr->setActiveCamera(robots[i]->camera);

            smgr->drawAll(); 
            //draws on window scene of active camera
 
            robots[i]->update();
        }
        driver->endScene();

        //TEST
        //if
        //(
            //robots[observeRobot].getPosition() != oldpos
            //|| robots[observeRobot].getTarget() != oldtarget
        //)
        //oldpos = robots[observeRobot].getPosition();
        //oldtarget = robots[observeRobot].getTarget();

        cout << robots[observeRobot]->str();

        //FPS info
            //cout << "frame no:" << endl << nFrames << endl;;
            //cout << "average fps:" << endl << 1000*nFrames/(float)(timer->getTime()-t0) << endl;
            //nFrames++;
            cout << "fps:" << endl << driver->getFPS() << endl;
        //END TEST
	}
	device->drop();
	return 0;
}
コード例 #15
0
int MultiBouncerGame::run()
{
	if( !m_Engine )
		return EXIT_FAILURE;

	ConfigStorage *input = m_Engine->getConfig()->getSubSection( "Input" );
	
	PulsarEventReceiver *evt = m_Engine->getToolKit<PulsarEventReceiver>();
	
	ScriptToolKit *scriptTK = m_Engine->getToolKit<ScriptToolKit>();
	lua_State *lua = scriptTK->getLuaState();

	bool useWiimotes = m_Engine->getConfig()->get<bool>( "UseWiimotes", false);
	
	EKEY_CODE **codes = 0;
	wiimote **wiimotes = 0;
	int connectedWiimotes = 0;

	int maxPlayers = 0;
	
	if( !useWiimotes )
	{
		codes = *loadControls( input, scriptTK );
		for( ; maxPlayers < 32; maxPlayers++ )
		{
			if( codes[maxPlayers][0] == KEY_KEY_CODES_COUNT )
				break;
		}
	}

	//Callbacks for the goals
	struct : public ICallback {
		void onTrigger( Value* entity ) {
			for( int x = 0; balls[x] != 0; x++ )
			{
				if( entity->getAs<Entity*>()->getID() ==
					balls[x]->getID() )
				{
					points++;
					balls[x]->reset();
				}
			}
		}
		int points;
		DynamicEntity **balls;
	} redGoalCallback;

	struct : public ICallback {
		void onTrigger( Value* entity ) {
			for( int x = 0; balls[x] != 0; x++ )
			{
				if( entity->getAs<Entity*>()->getID() ==
					balls[x]->getID() )
				{
					points++;
					balls[x]->reset();
				}
			}
		}
		int points;
		DynamicEntity **balls;
	} blueGoalCallback;

	struct : public ICallback {
		void onTrigger(Value* val){
			static_cast<DynamicEntity*>( val->getAs<Entity*>() )->reset();
		}
	} borderCallback;

	bool running = true;

	//Create a callback for the quit key
	struct : public ICallback {
		virtual void onTrigger( Value* val ){
			*running = false;
		}
		bool *running;
	} exitCallback;
	exitCallback.running = &running;

	EKEY_CODE exitKey = scriptTK->getPulsarKeyCode(
		input->get<String>( "Exit", "ESCAPE" ) );

	evt->addKeyPressedCallback( exitKey, &exitCallback );
	
	//Loop until the game is cancelled
	while( m_Engine->run() && running )
	{
		//Show menu
		m_MainMenu->setVisible( true );
		mScoreWindow->setVisible( false );

		//Reset points
		redGoalCallback.points = 0;
		blueGoalCallback.points = 0;
		
		//Store selected MapName
		int prevSelection = -1;
		
		//Standard loop
		while( m_Engine->run() && running )
		{
			m_Engine->beginDrawing();
			
			int selection = m_MapList->getSelected();
			
			//Exit loop if everything is selected
			if( m_OkButton->isPressed() && selection > -1 )
				break;
			
			//If a new Map gets selected, change the max player limit
			if( selection > -1 && prevSelection != selection && maxPlayers > 0 )
				m_PlayerCounter->setRange( 1.f, std::min( maxPlayers, 
					m_MapData.at( selection )->get<int>( "MaxPlayers" ) ) );

			if( mReconnectButton->isPressed() )
			{
				wiimotes = connectWiimotes( connectedWiimotes );
				maxPlayers = connectedWiimotes;
			}
			
			prevSelection = selection;
			
			m_Engine->endDrawing();
		}

		if( !running )
			break;
		
		//Hide menu
		m_MainMenu->setVisible( false );
		mScoreWindow->setVisible( true );
		
		//Get the selected file names
		String selectedMap = m_MapFiles.at( m_MapList->getSelected() ).string().c_str();
		
		//Load the map
		ConfigStorage map( true );
		map.parseXMLFile( selectedMap, "Map" );
		map.setAlwaysGetRecursive();

		std::vector<ILightSceneNode*> lights;

		//Add lights, complicated version...
		//TODO: Light management
		for( int x = 0; x < map.countVars( "Light" ); x++ )
		{
			ConfigStorage *light = map.getSubSection( "Data" )->getSubSectionN( x, "Light" );
			
			SColor lightColor( 128, light->get<int>( "ColorR", 255 ),
				light->get<int>( "ColorG", 255 ),
				light->get<int>( "ColorB", 255 ) );
			ILightSceneNode *node = m_Engine->getIrrlichtDevice()->getSceneManager()->
				addLightSceneNode( 0, light->get<Vector>( "Position" ),
					lightColor, light->get<float>( "Radius" ) );
			node->getLightData().SpecularColor.set( 0,0,0 );

			lights.push_back( node );
		}
		
		//Add a camera
		CameraToolKit *cam = m_Engine->getToolKit<CameraToolKit>();
		cam->addCamera( ID_CAMERA_PRIMARY );
		cam->setCameraPosition( ID_CAMERA_PRIMARY,
			map.getSubSection( "Data" )->getSubSection( "Camera" )->get<Vector>( "Position" ) );
		cam->setCameraTarget( ID_CAMERA_PRIMARY,
			map.getSubSection( "Data" )->getSubSection( "Camera" )->get<Vector>( "Target" ) );
		
		int numPlayers = (int)m_PlayerCounter->getValue();

		IBouncer *players[numPlayers];
		Value::createStandardGenerator<SmallFastTestBouncer>();

		for( int x = 0; x < numPlayers; x++ )
		{
			players[x] = new SmallFastTestBouncer( x + 1 );
			players[x]->setControls( codes[x][0], codes[x][1], codes[x][2],
				codes[x][3], codes[x][4], codes[x][5], codes[x][6] );

			Value *player = new Value( *(SmallFastTestBouncer*)players[x] );
			player->setAutoDestroy( true );
			map.setValue( "Player", player );

			if( x % 2 )
				players[x]->spawn( map.getN<Vector>( x / 2, "RedTeamSpawn" ), Vector() );
			else
				players[x]->spawn( map.getN<Vector>( x / 2, "BlueTeamSpawn" ), Vector() );
		}

		for( int x = 0; x < map.countVars( "RedGoal" ); x++ )
		{
			map.getN<GhostSensorEntity>( x, "RedGoal" ).
				setOnEnterCallback( &redGoalCallback );
		}

		for( int x = 0; x < map.countVars( "BlueGoal" ); x++ )
		{
			map.getN<GhostSensorEntity>( x, "BlueGoal" ).
				setOnEnterCallback( &blueGoalCallback );
		}

		//Create Balls
		int numBalls = map.countVars( "Ball" );
		DynamicEntity *ballEntity[numBalls + 1];
		
		for( int x = 0; x < numBalls; x++ )
		{
			ballEntity[x] = &map.getN<DynamicEntity>( x, "Ball" );
		}

		ballEntity[numBalls] = 0;

		redGoalCallback.balls = ballEntity;
		blueGoalCallback.balls = ballEntity;

		//Create borders
		for( int x = 0; x < map.countVars( "Border" ); x++ )
			map.getN<GhostSensorEntity>( x, "Border" ).setOnEnterCallback( &borderCallback );
		
		//Start simulation
		m_Engine->setSimulationState( true );

		bool toMenu = false;

		int sleeptime = 0;
		
		//Standard loop again
		while( m_Engine->run() && !toMenu && running )
		{
			m_Engine->beginDrawing();
			
			if( evt->keyState( KEY_F12 ) )
				toMenu = true;

			if( evt->keyState( KEY_F5 ) )
				sleeptime = 0;
			if( evt->keyState( KEY_F6 ) )
				sleeptime = 40000;

			usleep(sleeptime);
			
			String points( redGoalCallback.points );
			points += " : ";
			points += blueGoalCallback.points;
			points += " FPS: ";
			points += m_Engine->getIrrlichtDevice()->getVideoDriver()->getFPS();
			mScoreCounter->setText( irr::core::stringw( points ).c_str() );

			if( useWiimotes )
			{
				wiiuse_poll( wiimotes, 32 );
				for( int x = 0; x < numPlayers; x++ )
				{
					if( IS_PRESSED( wiimotes[x], WIIMOTE_BUTTON_B ) )
						players[x]->jump();
					if( IS_PRESSED( wiimotes[x], WIIMOTE_BUTTON_ONE ) )
						players[x]->startAction( 1 );
					if( IS_PRESSED( wiimotes[x], WIIMOTE_BUTTON_TWO ) )
						players[x]->startAction( 2 );
					if( IS_PRESSED( wiimotes[x], WIIMOTE_BUTTON_HOME ) )
						toMenu = true;
					if( IS_PRESSED( wiimotes[x], WIIMOTE_BUTTON_DOWN ) )
						players[x]->move( false, false, false, true );
					if( IS_PRESSED( wiimotes[x], WIIMOTE_BUTTON_UP ) )
						players[x]->move( false, false, true, false );
					if( IS_PRESSED( wiimotes[x], WIIMOTE_BUTTON_RIGHT ) )
						players[x]->move( true, false, false, false );
					if( IS_PRESSED( wiimotes[x], WIIMOTE_BUTTON_LEFT ) )
						players[x]->move( false, true, false, false );
				}
			}

			m_Engine->endDrawing();
		}
		
		//Stop simulation
		m_Engine->setSimulationState( false );

		for( std::vector<ILightSceneNode*>::iterator x = lights.begin(); x != lights.end(); x++ )
			( *x )->remove();
	}

	for( int x = 0; x < 32; x++ )
		delete[] codes[x];
	delete[] codes;
	
	wiiuse_cleanup( wiimotes, 32 );

	return EXIT_SUCCESS;
}
コード例 #16
0
void CLiquidbodyExample::runExample()
{
    debugDraw = true;
    drawProperties = true;
    drawWireFrame = false;

    int rows=2, columns=2;

    device =
        createDevice( video::EDT_OPENGL, dimension2d<u32>(640, 480), 16,
            false, false, false, this);

    printf("Please enter the number of rows and columns of floating objects to create: \n");

    cin >> rows;
    cin >> columns;


    device->setWindowCaption(L"irrBullet Liquidbody Example - Josiah Hartzell");

    device->getFileSystem()->addFolderFileArchive("../../media/");


    ILightSceneNode* light = device->getSceneManager()->addLightSceneNode(0, vector3df(20, 40, -50), SColorf(1.0f, 1.0f, 1.0f), 4000.0f);
    light->setLightType(ELT_DIRECTIONAL);
    light->setRotation(vector3df(0,200,30));

    device->getSceneManager()->setAmbientLight(SColor(100,100,100,100));

    camera = device->getSceneManager()->addCameraSceneNodeFPS();
	camera->setPosition(vector3df(50,15,4));
	camera->setTarget(vector3df(0,0,0));


    ////////////////////////////
    // Create irrBullet World //
    ////////////////////////////
    world = createIrrBulletWorld(device, true, debugDraw);

    world->setDebugMode(EPDM_DrawAabb |
            EPDM_DrawContactPoints);

    world->setGravity(vector3df(0,-10,0));

    ILiquidBody* water = world->addLiquidBody(vector3df(-5000,0,5000),irr::core::aabbox3df(0, -10000, 0, 10000, 0, 10000), 500.0f, 200.0f);
    water->setCurrentDirection(vector3df(0,0,0));
    water->setGlobalWaveChangeIncrement(0.01f);
    water->setGlobalWaveUpdateFrequency(1.0f);
    water->setMaxGlobalWaveHeight(4.0f);
    water->setMinGlobalWaveHeight(-1.0f);
    water->setLocalWaveValues(10,1,0.5f);
    water->setInfinite(true);
    water->setInfiniteDepth(true);
    water->setLiquidDensity(0.1f);
    //water->setDebugDrawEnabled(false);


    IAnimatedMesh* mesh = device->getSceneManager()->addHillPlaneMesh( "myHill",
		core::dimension2d<f32>(20,20),
		core::dimension2d<u32>(40,40), 0, 0,
		core::dimension2d<f32>(0,0),
		core::dimension2d<f32>(1000,1000));

	ISceneNode* node = device->getSceneManager()->addWaterSurfaceSceneNode(mesh->getMesh(0), 0.0f, 300.0f, 30.0f);
	node->setPosition(core::vector3df(0,5,0));

	node->setMaterialTexture(0, device->getVideoDriver()->getTexture("water.jpg"));
	node->setScale(vector3df(1000,1,1000));

	node->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);
	node->setMaterialFlag(EMF_BACK_FACE_CULLING, false);


	for(u32 i=0; i < rows; i++)
	{
	    for(u32 j=0; j < columns; j++)
        {
            IRigidBody* body = addCube(vector3df(i*15,0,j*15), vector3df(10,10,10), 1, "crate.jpg");

            irr::f32 t = 0.5f;
            irr::f32 buoyancy = 0.2f;

            irr::core::array<SBuoyancyPoint> points;
            //points.push_back(SBuoyancyPoint(irr::core::vector3df(0,0,0), 180.0f));
            points.push_back(SBuoyancyPoint(irr::core::vector3df(t,t,t), buoyancy));
            points.push_back(SBuoyancyPoint(irr::core::vector3df(-t,t,t), buoyancy));
            points.push_back(SBuoyancyPoint(irr::core::vector3df(-t,t,-t), buoyancy));
            points.push_back(SBuoyancyPoint(irr::core::vector3df(t,t,-t), buoyancy));

            points.push_back(SBuoyancyPoint(irr::core::vector3df(-t,-t,t), buoyancy));
            points.push_back(SBuoyancyPoint(irr::core::vector3df(t,-t,t), buoyancy));
            points.push_back(SBuoyancyPoint(irr::core::vector3df(-t,-t,-t), buoyancy));
            points.push_back(SBuoyancyPoint(irr::core::vector3df(t,-t,-t), buoyancy));


            /*ICollisionObjectAffectorBuoyancy* affector = new ICollisionObjectAffectorBuoyancy(points,
                irr::core::aabbox3df(0, -100, 0, 10000, 0, 10000), 1);
            affector->setDebugDrawing(true);
            body->addAffector(affector);*/
            body->setBuoyancyPoints(points);

            //body->setActivationState(EAS_DISABLE_DEACTIVATION);
        }
	}

    // Set our delta time and time stamp
    u32 TimeStamp = device->getTimer()->getTime();
    u32 DeltaTime = 0;
    while(device->run())
    {
        device->getVideoDriver()->beginScene(true, true, SColor(255,100,101,140));

        DeltaTime = device->getTimer()->getTime() - TimeStamp;
		TimeStamp = device->getTimer()->getTime();

		// Step the simulation with our delta time
        world->stepSimulation(DeltaTime*0.001f, 120);
        //static_cast<ISoftBody*>(world->getCollisionObjectByName("SOFTBODY1"))->addForce(vector3df(-2,0,0));


        //world->debugDrawWorld(debugDraw);
        // This call will draw the technical properties of the physics simulation
        // to the GUI environment.
        world->debugDrawProperties(drawProperties);


        device->getSceneManager()->drawAll();
        device->getGUIEnvironment()->drawAll();

        device->getVideoDriver()->endScene();
    }
    //delete Liquid;

    // We're done with the IrrBullet world, so we free the memory that it takes up.
    if(world)
        delete world;

    if(device)
        device->drop();
}