Ejemplo n.º 1
0
void QuakeShaderInitScene()
{
	if (!IrrlichtManager::GetIrrlichtManager()->GetDevice())
	{
		LogError("Error initializing Irrlicht");
		return;
	}
	IrrlichtManager::GetIrrlichtManager()->GetDevice()->getTimer()->setTime(0);
	
    scene::ISceneManager*   smgr   = IrrlichtManager::GetIrrlichtManager()->GetScene();
	IrrlichtDevice*         device = IrrlichtManager::GetIrrlichtManager()->GetDevice();
	
		   
	// Quake3 Shader controls Z-Writing
	smgr->getParameters()->setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true);
    
    //for Android
    FileSystemZip* pFileSystem = (FileSystemZip*) FileManager::GetFileManager()->GetFileSystem(0);
    
    //for Android
	if (pFileSystem)
        pFileSystem->SetRootDirectory("assets/game/quake");
	
	//hack so the textures can be found.  The quake map loader isn't all that smart
	device->getFileSystem()->changeWorkingDirectoryTo((GetBaseAppPath() + "game/quake").c_str());
    
	u32                     i;
    scene::IQ3LevelMesh*    mesh;
	scene::IMeshSceneNode*  node;
    scene::IMesh*           geometry;
    const scene::IMesh*     additional_mesh;
	
    mesh = (scene::IQ3LevelMesh*)smgr->getMesh("maps/20kdm2.bsp");
    
    if (mesh)
	{
		geometry = mesh->getMesh(quake3::E_Q3_MESH_GEOMETRY);
		node = smgr->addOctreeSceneNode(geometry, 0, -1, 4096);
	}
    
	if ( mesh )
	{
		// the additional mesh can be quite huge and is unoptimized
		additional_mesh = mesh->getMesh(quake3::E_Q3_MESH_ITEMS);
        
#ifdef SHOW_SHADER_NAME
		gui::IGUIFont *font = device->getGUIEnvironment()->getFont("media/fontlucida.png");
		u32 count = 0;
#endif
       
		for ( i = 0; i!= additional_mesh->getMeshBufferCount(); ++i )
		{
			const IMeshBuffer* meshBuffer = additional_mesh->getMeshBuffer(i);
			const video::SMaterial& material = meshBuffer->getMaterial();
            
			// The ShaderIndex is stored in the material parameter
			const s32 shaderIndex = (s32) material.MaterialTypeParam2;
            
			// the meshbuffer can be rendered without additional support, or it has no shader
			const quake3::IShader* shader = mesh->getShader(shaderIndex);
			if (0 == shader)
			{
				continue;
			}
            
			// we can dump the shader to the console in its
			// original but already parsed layout in a pretty
			// printers way.. commented out, because the console
			// would be full...
			// quake3::dumpShader ( Shader );
            
			node = smgr->addQuake3SceneNode(meshBuffer, shader);
            
#ifdef SHOW_SHADER_NAME
			count += 1;
			core::stringw name( node->getName() );
			node = smgr->addBillboardTextSceneNode(
                                                   font, name.c_str(), node,
                                                   core::dimension2d<f32>(80.0f, 8.0f),
                                                   core::vector3df(0, 10, 0));
#endif
		}
	}
  
    quake3::IEntity             search;
    s32                         index;
    s32                         notEndList;
    u32                         parsepos;
    f32                         angle;
    core::vector3df             pos;
    const quake3::SVarGroup*    group;
    scene::ICameraSceneNode*    camera;
	
    camera = smgr->addCameraSceneNodeFPS();
    	
	if ( mesh )
	{
		quake3::tQ3EntityList& entityList   = mesh->getEntityList();
		search.name                         = "info_player_deathmatch";
        index                               = entityList.binary_search(search);
        
		if (index >= 0)
		{
			do
			{
				group       = entityList[index].getGroup(1);
                
				parsepos    = 0;
				pos         = quake3::getAsVector3df(group->get("origin"), parsepos);
                
				parsepos    = 0;
				angle       = quake3::getAsFloat(group->get("angle"), parsepos);
                
				core::vector3df target(0.f, 0.f, 1.f);
				target.rotateXZBy(angle);
                
				camera->setPosition(pos);
				camera->setTarget(pos + target);
                
				++index;
                
				notEndList = index == 2;
			} while ( notEndList );
		}
	}
    

#ifdef _IRR_COMPILE_WITH_GUI_
    EventControlComponent* receiver = new EventControlComponent();
    receiver->AddGuiButton();
	device->setEventReceiver(receiver);
#endif

}
Ejemplo n.º 2
0
void Mesh3DInitScene()
{
	IAnimatedMesh*				mesh;
	IAnimatedMeshSceneNode*     node;
	scene::ISceneNodeAnimator*  anim;
	scene::ISceneManager*		smgr   = IrrlichtManager::GetIrrlichtManager()->GetScene();
	IrrlichtDevice*				device = IrrlichtManager::GetIrrlichtManager()->GetDevice();
	video::IVideoDriver*		driver = IrrlichtManager::GetIrrlichtManager()->GetDriver();
	
	std::string					load_zip;
	std::string					load_data;
	std::string					reload_path;
	FileSystemZip*				pfilesystem			= NULL;
	io::IReadFile*				memfile				= NULL;
	byte*						apk_buffer			= NULL;
	byte*						buff_extract		= NULL;
	int							size				= 0;
	int							apk_size			= 0;

	if (!IrrlichtManager::GetIrrlichtManager()->GetDevice())
	{
		LogError("Error initializing Irrlicht");
		return;
	}
	
	IrrlichtManager::GetIrrlichtManager()->GetDevice()->getTimer()->setTime(0);
		
    smgr->addLightSceneNode(0, core::vector3df(-100,10,0), video::SColorf(1.0f, 1.0f, 1.0f, 1.0f), 200.0f);
    smgr->addLightSceneNode(0, core::vector3df(+100,10,0), video::SColorf(1.0f, 1.0f, 1.0f, 1.0f), 200.0f);
	
		
//////////////////////////////mesh/////////////////////////////////////////////////
	load_zip	= (GetBaseAppPath() + "game/ninja.zip").c_str();
	load_data	= "ninja.b3d";
	reload_path	= (GetBaseAppPath() + "game/ninja.b3d").c_str();
	
#ifdef ANDROID_NDK
	apk_buffer	= FileManager::GetFileManager()->Get(load_zip.c_str(), &apk_size, false, false);
	
	if( apk_buffer )
	{
		pfilesystem	= new FileSystemZip();
		pfilesystem->Init_unzMemory(apk_buffer, apk_size);
		buff_extract = pfilesystem->Get_unz(load_data, &size);

		delete apk_buffer;
		apk_buffer = NULL;
	}
#else
	pfilesystem = new FileSystemZip();
	pfilesystem->Init_unz(load_zip.c_str());
	buff_extract = pfilesystem->Get_unz(load_data.c_str(), &size);
#endif
	
	memfile = device->getFileSystem()->createMemoryReadFile(buff_extract, size, reload_path.c_str(), true);
	//new buffer copy on file->read(Buffer, size) of CXMeshFileLoader::readFileIntoMemory
	mesh	= smgr->getMesh( memfile );
	node	= smgr->addAnimatedMeshSceneNode( mesh );

	//delete buff_extract in drop() then goto ~CMemoryReadFile
	memfile->drop();
						
	if( pfilesystem )
	{
		delete pfilesystem;
		pfilesystem = NULL;
	}

//////////////////////////////texture/////////////////////////////////////////////////
	node->setMaterialTexture( 0, driver->getTexture((GetBaseAppPath()+"game/nskinbl.jpg").c_str()) );
    node->setMaterialFlag(EMF_LIGHTING, true);
    node->setMaterialFlag(EMF_NORMALIZE_NORMALS, true);
    anim = smgr->createRotationAnimator(core::vector3df(0,0.3f,0));
    node->addAnimator(anim);
    anim->drop();

	u32 alpha_val		= 90;
	u32 MaterialCount	= node->getMaterialCount();
	
	for(u32 i=0; i<MaterialCount; i++)
	{
		video::SMaterial& tex_mat	= node->getMaterial(i);
		tex_mat.MaterialType		= video::EMT_TRANSPARENT_VERTEX_ALPHA;
		//tex_mat.MaterialTypeParam	= 0.1;
		//tex_mat.MaterialTypeParam2= 0.1;
		tex_mat.AmbientColor.setAlpha(alpha_val);
		tex_mat.DiffuseColor.setAlpha(alpha_val);
		tex_mat.SpecularColor.setAlpha(alpha_val);
		tex_mat.EmissiveColor.setAlpha(alpha_val);
	}

#if	defined(_IRR_COMPILE_WITH_OGLES2_)
	for(u32 i=0; i<mesh->getMeshBufferCount(); i++)
	{
		scene::IMeshBuffer* buffer = mesh->getMeshBuffer(i);
		video::S3DVertex* vertex = (video::S3DVertex*)buffer->getVertices();
		
		for(u32 j=0; j<buffer->getVertexCount(); j++)
		{
			vertex[j].Color.setAlpha(alpha_val);
		}
	}
#endif
	
	smgr->addSkyBoxSceneNode(IrrlichtManager::GetIrrlichtManager()->GetTexture("game/irrlicht2_up.jpg"),
                             IrrlichtManager::GetIrrlichtManager()->GetTexture("game/irrlicht2_dn.jpg"),
                             IrrlichtManager::GetIrrlichtManager()->GetTexture("game/irrlicht2_lf.jpg"),
                             IrrlichtManager::GetIrrlichtManager()->GetTexture("game/irrlicht2_rt.jpg"),
                             IrrlichtManager::GetIrrlichtManager()->GetTexture("game/irrlicht2_ft.jpg"),
                             IrrlichtManager::GetIrrlichtManager()->GetTexture("game/irrlicht2_bk.jpg"));
//////////////////////////////////cam/////////////////////////////////////////////    
   	ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 100.0f, .02f, 0, 0, 0, true, 1.0f);
	//camera->addCameraSceneNode(0, vector3df(0,2,-10));
	camera->setPosition(core::vector3df(0,5,-20));
	float fov = float(GetPrimaryGLX())/ float(GetPrimaryGLY());
	camera->setAspectRatio(fov);
	camera->setFOV((120 * (float)M_PI / 360.0f));

#ifdef _IRR_COMPILE_WITH_GUI_
	EventControlComponent* receiver = new EventControlComponent();
    receiver->AddGuiButton();
	device->setEventReceiver(receiver);
#endif
}
Ejemplo n.º 3
0
void TerrainInitScene()
{
	if (!IrrlichtManager::GetIrrlichtManager()->GetDevice())
	{
		LogError("Error initializing Irrlicht");
		return;
	}
	IrrlichtManager::GetIrrlichtManager()->GetDevice()->getTimer()->setTime(0);

	video::IVideoDriver*    driver  = IrrlichtManager::GetIrrlichtManager()->GetDriver();
	scene::ISceneManager*   smgr    = IrrlichtManager::GetIrrlichtManager()->GetScene();
    IrrlichtDevice*         device  = IrrlichtManager::GetIrrlichtManager()->GetDevice();
	
	driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
	scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0,100.0f,0.5f);
    
	camera->setAspectRatio(GetScreenSizeXf()/GetScreenSizeYf());
    
	camera->setPosition(core::vector3df(2700*2,255*2,2600*2));
	camera->setTarget(core::vector3df(2397*2,343*2,2700*2));
	camera->setFarValue(22000.0f);
    
	scene::ITerrainSceneNode* terrain =
    smgr->addTerrainSceneNode((GetBaseAppPath() + "game/terrain-heightmap.bmp").c_str(),
                              0,					// parent node
                              -1,					// node id
                              core::vector3df(0.f, 0.f, 0.f),		// position
                              core::vector3df(0.f, 130.f, 0.f),		// rotation
                              core::vector3df(40.f, 4.4f, 40.f),	// scale
                              video::SColor ( 255, 255, 255, 255 ),	// vertexColor
                              4,					// maxLOD
                              scene::ETPS_9,				// patchSize
                              4					// smoothFactor
                              );
    
	if (!terrain)
	{
		LogError("Looks like we couldn't find the heightmap.  Resources not built or copied?");
		return;
	}
	terrain->setMaterialFlag(video::EMF_LIGHTING, false);
    
	terrain->setMaterialTexture(0, IrrlichtManager::GetIrrlichtManager()->GetTexture("game/terrain-texture.jpg"));
	terrain->setMaterialTexture(1, IrrlichtManager::GetIrrlichtManager()->GetTexture("game/detailmap3.jpg"));
    
	terrain->setMaterialType(video::EMT_DETAIL_MAP);
    
	terrain->scaleTexture(1.0f, 20.0f);
    

	// create triangle selector for the terrain
	scene::ITriangleSelector* selector = smgr->createTerrainTriangleSelector(terrain, 0);
	terrain->setTriangleSelector(selector);
    
	// create collision response animator and attach it to the camera
	scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(selector, camera, core::vector3df(60,100,60),
                                                                            core::vector3df(0,0,0),
                                                                            core::vector3df(0,50,0));
	
	((ISceneNodeAnimatorCollisionResponse*)anim)->setGravity(vector3df(0,-10,0));
	selector->drop();
	
	camera->addAnimator(anim);
	anim->drop();
    
	driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
    
	scene::ISceneNode* skybox=smgr->addSkyBoxSceneNode(IrrlichtManager::GetIrrlichtManager()->GetTexture("game/irrlicht2_up.jpg"),
                                                       IrrlichtManager::GetIrrlichtManager()->GetTexture("game/irrlicht2_dn.jpg"),
                                                       IrrlichtManager::GetIrrlichtManager()->GetTexture("game/irrlicht2_lf.jpg"),
                                                       IrrlichtManager::GetIrrlichtManager()->GetTexture("game/irrlicht2_rt.jpg"),
                                                       IrrlichtManager::GetIrrlichtManager()->GetTexture("game/irrlicht2_ft.jpg"),
                                                       IrrlichtManager::GetIrrlichtManager()->GetTexture("game/irrlicht2_bk.jpg"));
    
	driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);

#ifdef _IRR_COMPILE_WITH_GUI_
    EventControlComponent* receiver = new EventControlComponent();
    receiver->AddGuiButton();
	device->setEventReceiver(receiver);
#endif
}
Ejemplo n.º 4
0
void Mesh3DInitScene()
{
	IAnimatedMesh*				mesh;
	IAnimatedMeshSceneNode*     node;
	scene::ISceneNodeAnimator*  anim;
	scene::ISceneManager*		smgr   = IrrlichtManager::GetIrrlichtManager()->GetScene();
	IrrlichtDevice*				device = IrrlichtManager::GetIrrlichtManager()->GetDevice();
	video::IVideoDriver*		driver = IrrlichtManager::GetIrrlichtManager()->GetDriver();
	
	std::string					load_zip;
	std::string					load_data;
	std::string					reload_path;
	FileSystemZip*				pfilesystem			= NULL;
	io::IReadFile*				memfile				= NULL;
	byte*						apk_buffer			= NULL;
	byte*						buff_extract		= NULL;
	int							size				= 0;
	int							apk_size			= 0;

	if (!IrrlichtManager::GetIrrlichtManager()->GetDevice())
	{
		LogError("Error initializing Irrlicht");
		return;
	}
	
	IrrlichtManager::GetIrrlichtManager()->GetDevice()->getTimer()->setTime(0);
		
    smgr->addLightSceneNode(0, core::vector3df(-100,10,0), video::SColorf(1.0f, 1.0f, 1.0f, 1.0f), 200.0f);
    smgr->addLightSceneNode(0, core::vector3df(+100,10,0), video::SColorf(1.0f, 1.0f, 1.0f, 1.0f), 200.0f);
	
		
//////////////////////////////mesh/////////////////////////////////////////////////
	load_zip	= (GetBaseAppPath() + "game/squirrel.zip").c_str();
	load_data	= "squirrel.x";
	reload_path	= (GetBaseAppPath() + "game/squirrel.x").c_str();
	
#ifdef ANDROID_NDK
	apk_buffer	= FileManager::GetFileManager()->Get(load_zip.c_str(), &apk_size, false, false);
	
	if( apk_buffer )
	{
		pfilesystem	= new FileSystemZip();
		pfilesystem->Init_unzMemory(apk_buffer, apk_size);
		buff_extract = pfilesystem->Get_unz(load_data, &size);

		delete apk_buffer;
		apk_buffer = NULL;
	}
#else
	pfilesystem = new FileSystemZip();
	pfilesystem->Init_unz(load_zip.c_str());
	buff_extract = pfilesystem->Get_unz(load_data.c_str(), &size);
#endif
	
	memfile = device->getFileSystem()->createMemoryReadFile(buff_extract, size, reload_path.c_str(), true);
	//new buffer copy on file->read(Buffer, size) of CXMeshFileLoader::readFileIntoMemory
	mesh	= smgr->getMesh( memfile );
	node	= smgr->addAnimatedMeshSceneNode( mesh );

	//delete buff_extract in drop() then goto ~CMemoryReadFile
	memfile->drop();
						
	if( pfilesystem )
	{
		delete pfilesystem;
		pfilesystem = NULL;
	}

//////////////////////////////texture/////////////////////////////////////////////////
	node->setMaterialTexture( 0, driver->getTexture((GetBaseAppPath()+"game/squirrel_skin.jpg").c_str()) );
    node->setMaterialFlag(EMF_LIGHTING, true);
    node->setMaterialFlag(EMF_NORMALIZE_NORMALS, true);
    anim = smgr->createRotationAnimator(core::vector3df(0,0.3f,0));
    node->addAnimator(anim);
    anim->drop();
	

//////////////////////////////////cam/////////////////////////////////////////////    
   	ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 100.0f, .02f, 0, 0, 0, true, 1.0f);
	//camera->addCameraSceneNode(0, vector3df(0,2,-10));
	camera->setPosition(core::vector3df(0,2,-10));
	float fov = float(GetPrimaryGLX())/ float(GetPrimaryGLY());
	camera->setAspectRatio(fov);
	camera->setFOV((120 * M_PI / 360.0f));

#ifdef _IRR_COMPILE_WITH_GUI_
	EventControlComponent* receiver = new EventControlComponent();
    receiver->AddGuiButton();
	device->setEventReceiver(receiver);
#endif
}