Example #1
0
void CScene::UpdateScene(vector<vector3df> otherClientPosition, ICameraSceneNode* camera)
{
	ISceneManager* smgr=device->getSceneManager();
	IVideoDriver* driver=device->getVideoDriver();

	// 测试用
	IAnimatedMesh* personMeshTest=smgr->getMesh("../../media/sydney.md2");
	IAnimatedMeshSceneNode* personNode = smgr->addAnimatedMeshSceneNode( personMeshTest );
	if (!personMeshTest)
	{
		device->drop();
		return ;
	}
	if (personNode)
	{
		personNode->setScale(vector3df(0.4f,0.4f,0.4f));
		personNode->setPosition(vector3df(0.0f,10.0f,0.0f));
		personNode->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
		personNode->setMaterialFlag(EMF_LIGHTING, false);
		personNode->getMaterial(0).Shininess=28.0f;
		personNode->getMaterial(0).NormalizeNormals=true;
		personNode->setMD2Animation ( scene::EMAT_STAND );

	}
	personMeshTest->setMaterialFlag(EMF_LIGHTING,false);

	// 显示其他客户端
	for (int i=0;i!=otherClientPosition.size();i++)
	{
		IAnimatedMesh* personMesh=smgr->getMesh("../../media/sydney.md2");
		IAnimatedMeshSceneNode* personNode = smgr->addAnimatedMeshSceneNode( personMesh );
		if (!personMesh)
		{
			device->drop();
			return ;
		}
		if (personNode && personNode->getPosition()!=camera->getPosition())
		{
//			personNode->setPosition(vector3df(10,20,0));
//			personNode->setScale(vector3df(0.5,0.5,0.5));
			personNode->setPosition(otherClientPosition[i]);
			personNode->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
			personNode->setMaterialFlag(EMF_LIGHTING, false);
			personNode->getMaterial(0).Shininess=28.0f;
			personNode->getMaterial(0).NormalizeNormals=true;
			personNode->setMD2Animation ( scene::EMAT_STAND );

		}
		personMesh->setMaterialFlag(EMF_LIGHTING,false);
	}
}
Example #2
0
ISceneNode* Render::createNode(bool isMD2, IAnimatedMesh* mesh, ITexture* texture, bool light,core::vector3df scale, core::vector3df pos, core::vector3df rotation)
{
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh, NULL, IDFlag_IsPickable);
	
	if(node)
	{
		pos.Y += -node->getBoundingBox().MinEdge.Y * scale.Y;
		node->setPosition(pos);
		node->setRotation(rotation);
		node->setScale(scale);
		node->setAnimationSpeed(20.f);
		scene::ITriangleSelector* selector = 0;
		selector = smgr->createTriangleSelector(node);
		node->setTriangleSelector(selector);
		selector->drop();
		
		//Autoscale
		//f32 scale = 0.25f;
		node->setScale(scale);
		
		if (texture)
		{
			//node->setMaterialFlag(EMF_LIGHTING, false);
			node->setMaterialTexture(0, texture);
		}

		node->setMD2Animation(EMAT_STAND);
	}

	return node;
}
Example #3
0
void TestLevel::init() {

	IAnimatedMesh* mesh = smgr->getMesh("img/sydney.md2");

	IAnimatedMeshSceneNode * tmpnode = smgr->addAnimatedMeshSceneNode(mesh);

	if (tmpnode) {
		tmpnode->setMaterialFlag(EMF_LIGHTING, false);
		tmpnode->setMD2Animation(scene::EMAT_STAND);
		tmpnode->setMaterialTexture(0, driver->getTexture("img/sydney.bmp"));
	}

	tmpnode->setPosition(vector3df(-222,0,0));




	vector3df wsp(0,5,-10);

	ship = new TestPlayerShip(TestPlayerShip::createTestPlayerShipNode(context));
	ship->attachNewCamera(new StaticCamera(context,ship));




//	ship.attachCamera(cam);

	this->node = new NonPlayerShip(tmpnode);
	testPlanet = Planet::createTestPlanet(context);

}
Example #4
0
int main( ) {
	// Boring stuff: set up the scene, object & camera as usual
	IrrlichtDevice* device = createDevice( DRIVER, dimension2d<s32>( 640, 480 ), 16, false, false, false, 0 );
	IVideoDriver* driver = device->getVideoDriver( );
	ISceneManager* smgr = device->getSceneManager( );
	IGUIEnvironment* guienv = device->getGUIEnvironment( );
	device->getFileSystem( )->changeWorkingDirectoryTo( MEDIA_DIRECTORY );
	guienv->addStaticText( L"Lens Flare", rect<s32>( 10, 10, 260, 22 ), true );
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( smgr->getMesh( "sydney.md2" ) );
	node->setMaterialFlag( EMF_LIGHTING, false );
	node->setMD2Animation( scene::EMAT_STAND );
	node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
	IAnimatedMeshSceneNode* node2 = smgr->addAnimatedMeshSceneNode( smgr->getMesh( "sydney.md2" ) );
	node2->setMaterialFlag( EMF_LIGHTING, false );
	node2->setMD2Animation( scene::EMAT_STAND );
	node2->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
	node2->setPosition( vector3df( 20.0f, 0.0f, 0.0f ) );
	ICameraSceneNode* cam = smgr->addCameraSceneNode( 0, vector3df( 40.0f, 30.0f, -40.0f ), vector3df( 0.0f, 5.0f, 0.0f ) );

	ISceneNode* sun = smgr->addSphereSceneNode( 50.0f, 16 );
	sun->setPosition( vector3df( 0.0f, 50.0f, 1000.0f ) );
	sun->setMaterialFlag( EMF_LIGHTING, false );
	sun->setMaterialTexture( 0, driver->getTexture("sun.png") );
	// Interesting stuff

	// As before, we make a renderer
	IPostProc* ppRenderer = new CRendererPostProc( smgr, dimension2di( 1024, 512 ), true, true, SColor( 255u, 100u, 101u, 140u ) );
	// Now make a flare effect:
	// (render from, output size, sun scene node)
	// can also use a vector instead of a scene node - when using a scene node the position will follow node automatically
	CLensFlarePostProc* ppFlare1 = new CLensFlarePostProc( ppRenderer, dimension2di( 1024, 512 ), driver->getTexture("flare.png"), sun, 50.0f );
	CLensFlarePostProc* ppFlare2 = new CLensFlarePostProc( ppFlare1, dimension2di( 1024, 512 ), driver->getTexture("flare.png"), vector3df( -2000.0f, 50.0f, 1000.0f ) );
	ppFlare2->setQuality( PPQ_CRUDE ); // Setting the quality to crude avoids pixel checking, which is slow (expecially when more than one lens flare), so if you use >1 flare, set most of them to crude.

	// These variables aren't important - they are just for showing the FPS
	wchar_t tmp[255]; u8 t = 0u;

	while( device->run( ) ) {
		cam->setPosition( vector3df( -(device->getCursorControl( )->getPosition( ).X - 320.0f) * 0.1f, (device->getCursorControl( )->getPosition( ).Y - 240.0f) * 0.2f, -70.0f ) );
		driver->beginScene( false, driver->getDriverType( ) == video::EDT_DIRECT3D9 );
		ppFlare2->render( NULL );
		guienv->drawAll( );
		driver->endScene( );

		// Show the current FPS
		if( ++ t == 30u ) { t = 0u; swprintf(tmp, 255, L"%ls fps:%3d", driver->getName(), driver->getFPS() ); device->setWindowCaption( tmp ); }
	}

	delete ppFlare1;
	delete ppFlare2;
	delete ppRenderer;

	// Back to boring stuff
	device->drop();
	return 0;
}
Example #5
0
int main( ) {
	// Boring stuff: set up the scene, object & camera as usual
	IrrlichtDevice* device = createDevice( DRIVER, dimension2d<s32>( 640, 480 ), 16, false, false, false, 0 );
	IVideoDriver* driver = device->getVideoDriver( );
	ISceneManager* smgr = device->getSceneManager( );
	IGUIEnvironment* guienv = device->getGUIEnvironment( );
	device->getFileSystem( )->changeWorkingDirectoryTo( MEDIA_DIRECTORY );
	guienv->addStaticText( L"Multiple Renders", rect<s32>( 10, 10, 260, 22 ), true );
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( smgr->getMesh( "sydney.md2" ) );
	node->setMaterialFlag( EMF_LIGHTING, false );
	node->setMD2Animation( scene::EMAT_STAND );
	node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
	smgr->addCameraSceneNode( 0, vector3df( 40.0f, 30.0f, -40.0f ), vector3df( 0.0f, 5.0f, 0.0f ) );

	// Interesting stuff
	// This time, we make 2 renderers for the same scene
	IPostProc* ppRenderer1 = new CRendererPostProc( smgr, dimension2di( 1024, 512 ), true, true, SColor( 255u, 100u, 101u, 140u ) );
	IPostProc* ppRenderer2 = new CRendererPostProc( smgr, dimension2di( 1024, 512 ), true, true, SColor( 255u, 100u, 101u, 140u ) );
	CEffectPostProc* ppBlur = new CEffectPostProc( ppRenderer2, dimension2di( 1024, 512 ), PP_BLUR, 0.005f );
	CEffectPostProc* ppOverlay = new CEffectPostProc( ppRenderer1, dimension2di( 1024, 512 ), PP_OVERLAY, 1.0f );
	ppOverlay->setInput( 1, ppBlur );

	// These variables aren't important - they are just for showing the FPS
	wchar_t tmp[255]; u8 t = 0u;

	while( device->run( ) ) {
		driver->beginScene( false, driver->getDriverType( ) == video::EDT_DIRECT3D9 );

		// Because we want to have each scene render differently, we need to render them manually between changes:
		node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
		ppRenderer1->preRender( ); // Note: preRender not render, and no NULL

		node->setMaterialTexture( 0, driver->getTexture("fireball.bmp") );
		// We could call ppRender2->preRender() here, but it isn't necessary since the overlay will do that for us anyway
		ppOverlay->render( NULL );

		guienv->drawAll( );
		driver->endScene( );

		// Show the current FPS
		if( ++ t == 30u ) { t = 0u; swprintf(tmp, 255, L"%ls fps:%3d", driver->getName(), driver->getFPS() ); device->setWindowCaption( tmp ); }
	}

	delete ppOverlay;
	delete ppBlur;
	delete ppRenderer1;
	delete ppRenderer2;

	// Back to boring stuff
	device->drop();
	return 0;
}
Example #6
0
int main( ) {
	// Boring stuff: set up the scene, object & camera as usual
	IrrlichtDevice* device = createDevice( DRIVER, dimension2d<s32>( 640, 480 ), 16, false, false, false, 0 );
	IVideoDriver* driver = device->getVideoDriver( );
	ISceneManager* smgr = device->getSceneManager( );
	IGUIEnvironment* guienv = device->getGUIEnvironment( );
	device->getFileSystem( )->changeWorkingDirectoryTo( MEDIA_DIRECTORY );
	guienv->addStaticText( L"Custom Effect (Old Monitor)", rect<s32>( 10, 10, 260, 22 ), true );
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( smgr->getMesh( "sydney.md2" ) );
	node->setMaterialFlag( EMF_LIGHTING, false );
	node->setMD2Animation( scene::EMAT_STAND );
	node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
	smgr->addCameraSceneNode( 0, vector3df( 40.0f, 30.0f, -40.0f ), vector3df( 0.0f, 5.0f, 0.0f ) );

	// Interesting stuff

	IPostProc* ppRenderer = new CRendererPostProc( smgr, dimension2di( 1024, 512 ), true, true, SColor( 255u, 100u, 101u, 140u ) );
	CEffectPostProc* ppMine = new CEffectPostProc( ppRenderer, dimension2di( 1024, 512 ), GL_OLDMONITOR, DX_OLDMONITOR, EPST_PS_1_2, EPST_PS_2_0, EMT_SOLID, PPF_FROMCODE, 1.0f );
	// Notes:
	//	EPST_PS_1_2	shows the minimum version required to run your shader - usually EPST_PS_1_1 for simple things
	//	EMT_SOLID	can be changed to EMT_TRANSPARENT_ALPHA_CHANNEL, EMT_TRANSPARENT_ALPHA_CHANNEL_REF, etc. If this is done, the first texture is copied to the screen, then the second drawn on top using your shader. This is much faster than using 2 dynamic textures in one shader (not sure why) so use it when you can if you have 2 inputs
	//	1.0f		is where your parameters go
	// Remember to use setTimer if your effect uses the time variable:
	ppMine->setTimer( device->getTimer( ) );
	// I hate this next line, but it needs to be set correctly to prevent MAJOR slowdown in Irrlicht when running in Direct3D mode.
	// (if not called, your shader will have all parameters set to 0. If called with values too high, your app will slow significantly)
	// Note: this is ONLY needed with custom shaders
	ppMine->setRequiredVariables( 1, true, true ); // (number of input parameters, uses time?, uses randNum?)

	// These variables aren't important - they are just for showing the FPS
	wchar_t tmp[255]; u8 t = 0u;

	while( device->run( ) ) {
		// The monitor effect needs to know how strong it should be
		ppMine->setParameters( min_( 1.0f, device->getTimer( )->getTime( ) * 0.0002f ) );

		driver->beginScene( false, driver->getDriverType( ) == video::EDT_DIRECT3D9 );
		ppMine->render( NULL );
		guienv->drawAll( );
		driver->endScene( );

		// Show the current FPS
		if( ++ t == 30u ) { t = 0u; swprintf(tmp, 255, L"%ls fps:%3d", driver->getName(), driver->getFPS() ); device->setWindowCaption( tmp ); }
	}

	delete ppMine;
	delete ppRenderer;

	// Back to boring stuff
	device->drop();
	return 0;
}
Example #7
0
int main( ) {
	// Boring stuff: set up the scene, object & camera as usual
	IrrlichtDevice* device = createDevice( DRIVER, dimension2d<s32>( 640, 480 ), 16, false, false, false, 0 );
	IVideoDriver* driver = device->getVideoDriver( );
	ISceneManager* smgr = device->getSceneManager( );
	IGUIEnvironment* guienv = device->getGUIEnvironment( );
	device->getFileSystem( )->changeWorkingDirectoryTo( MEDIA_DIRECTORY );
	guienv->addStaticText( L"Mixing Scenes", rect<s32>( 10, 10, 260, 22 ), true );
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( smgr->getMesh( "sydney.md2" ) );
	node->setMaterialFlag( EMF_LIGHTING, false );
	node->setMD2Animation( scene::EMAT_STAND );
	node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
	smgr->addCameraSceneNode( 0, vector3df( 40.0f, 30.0f, -40.0f ), vector3df( 0.0f, 5.0f, 0.0f ) );
	// Set up the second scene, object & camera - this time, use a different texture and camera angle to show some change
	ISceneManager* smgr2 = smgr->createNewSceneManager( false );
	ISceneNode* rootnode2 = smgr2->getRootSceneNode( );
	IAnimatedMeshSceneNode* node2 = smgr2->addAnimatedMeshSceneNode( smgr2->getMesh( "sydney.md2" ), rootnode2 );
	node2->setMaterialFlag( EMF_LIGHTING, false );
	node2->setMD2Animation( scene::EMAT_STAND );
	node2->setMaterialTexture( 0, driver->getTexture("fireball.bmp") );
	smgr2->addCameraSceneNode( 0, vector3df( 40.0f, 30.0f, -40.0f ), vector3df( 10.0f, 5.0f, 0.0f ) );

	// Interesting stuff (see previous example for full details)
	IPostProc* ppRenderer1 = new CRendererPostProc( smgr, dimension2di( 1024, 512 ), true, true, SColor( 255u, 100u, 101u, 140u ) );
	IPostProc* ppRenderer2 = new CRendererPostProc( smgr2, dimension2di( 1024, 512 ), true, true, SColor( 255u, 0u, 0u, 0u ) );
	// PP_OVERLAY takes a multiplication parameter - setting this to 1.0 does a simple add, 2.0 doubles the second texture's luminosity, etc.
	CEffectPostProc* ppOverlay = new CEffectPostProc( ppRenderer1, dimension2di( 1024, 512 ), PP_OVERLAY, 2.0f );
	// The constructor can only take 1 input, but PP_OVERLAY needs 2, so set the other one now;
	ppOverlay->setInput( 1, ppRenderer2 );

	// These variables aren't important - they are just for showing the FPS
	wchar_t tmp[255]; u8 t = 0u;

	while( device->run( ) ) {
		driver->beginScene( false, driver->getDriverType( ) == video::EDT_DIRECT3D9 );
		// We only need to tell the final node to render - it will automatically render both scenes
		ppOverlay->render( NULL );
		guienv->drawAll( );
		driver->endScene( );

		// Show the current FPS
		if( ++ t == 30u ) { t = 0u; swprintf(tmp, 255, L"%ls fps:%3d", driver->getName(), driver->getFPS() ); device->setWindowCaption( tmp ); }
	}

	delete ppRenderer1;
	delete ppRenderer2;
	delete ppOverlay;

	// Back to boring stuff
	device->drop();
	return 0;
}
Example #8
0
int main( ) {
	// Boring stuff: set up the scene, object & camera as usual
	IrrlichtDevice* device = createDevice( DRIVER, dimension2d<s32>( 640, 480 ), 16, false, false, false, 0 );
	IVideoDriver* driver = device->getVideoDriver( );
	ISceneManager* smgr = device->getSceneManager( );
	IGUIEnvironment* guienv = device->getGUIEnvironment( );
	device->getFileSystem( )->changeWorkingDirectoryTo( MEDIA_DIRECTORY );
	guienv->addStaticText( L"Transitions", rect<s32>( 10, 10, 260, 22 ), true );
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( smgr->getMesh( "sydney.md2" ) );
	node->setMaterialFlag( EMF_LIGHTING, false );
	node->setMD2Animation( scene::EMAT_STAND );
	node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
	smgr->addCameraSceneNode( 0, vector3df( 40.0f, 30.0f, -40.0f ), vector3df( 0.0f, 5.0f, 0.0f ) );
	// Set up the second scene, object & camera - this time, use a different texture and camera angle to show some change
	ISceneManager* smgr2 = smgr->createNewSceneManager( false );
	ISceneNode* rootnode2 = smgr2->getRootSceneNode( );
	IAnimatedMeshSceneNode* node2 = smgr2->addAnimatedMeshSceneNode( smgr2->getMesh( "sydney.md2" ), rootnode2 );
	node2->setMaterialFlag( EMF_LIGHTING, false );
	node2->setMD2Animation( scene::EMAT_STAND );
	node2->setMaterialTexture( 0, driver->getTexture("fireball.bmp") );
	smgr2->addCameraSceneNode( 0, vector3df( 40.0f, 30.0f, -40.0f ), vector3df( 10.0f, 5.0f, 0.0f ) );

	// Interesting stuff
	IPostProc* ppRenderer1 = new CRendererPostProc( smgr, dimension2di( 1024, 512 ), true, true, SColor( 255u, 100u, 101u, 140u ) );
	IPostProc* ppRenderer2 = new CRendererPostProc( smgr2, dimension2di( 1024, 512 ), true, true, SColor( 255u, 0u, 0u, 0u ) );
	CTransitionPostProc* ppTransition = new CTransitionPostProc( ppRenderer1, ppRenderer2, dimension2di( 1024, 512 ), driver->getTexture("terrain-heightmap.bmp") );
//	ppTransition->setQuality( PPQ_CRUDE );

	// These variables aren't important - they are just for showing the FPS
	wchar_t tmp[255]; u8 t = 0u;

	while( device->run( ) ) {
		ppTransition->setBlend( sinf( device->getTimer( )->getTime( ) * 0.0005f - 2.0f ) * 2.0f + 0.5f );

		driver->beginScene( false, driver->getDriverType( ) == video::EDT_DIRECT3D9 );
		ppTransition->render( NULL );
		guienv->drawAll( );
		driver->endScene( );

		// Show the current FPS
		if( ++ t == 30u ) { t = 0u; swprintf(tmp, 255, L"%ls fps:%3d", driver->getName(), driver->getFPS() ); device->setWindowCaption( tmp ); }
	}

	delete ppTransition;
	delete ppRenderer1;
	delete ppRenderer2;

	// Back to boring stuff
	device->drop();
	return 0;
}
Example #9
0
int main( ) {
	// Boring stuff: set up the scene, object & camera as usual
	IrrlichtDevice* device = createDevice( DRIVER, dimension2d<s32>( 640, 480 ), 16, false, false, false, 0 );
	IVideoDriver* driver = device->getVideoDriver( );
	ISceneManager* smgr = device->getSceneManager( );
	IGUIEnvironment* guienv = device->getGUIEnvironment( );
	device->getFileSystem( )->changeWorkingDirectoryTo( MEDIA_DIRECTORY );
	guienv->addStaticText( L"Single Effect", rect<s32>( 10, 10, 260, 22 ), true );
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( smgr->getMesh( "sydney.md2" ) );
	node->setMaterialFlag( EMF_LIGHTING, false );
	node->setMD2Animation( scene::EMAT_STAND );
	node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
	smgr->addCameraSceneNode( 0, vector3df( 40.0f, 30.0f, -40.0f ), vector3df( 0.0f, 5.0f, 0.0f ) );

	// Interesting stuff

	// We make 2 objects - a scene renderer, and a blur. both render to textures with size 1024x512 (always use powers of 2)
	// When setting up the renderer, the parameters are:
	// SceneManager to render, size of output, clearBackBuffer?, clearZBuffer?, background colour
	IPostProc* ppRenderer = new CRendererPostProc( smgr, dimension2di( 1024, 512 ), true, true, SColor( 255u, 100u, 101u, 140u ) );
	// When setting up the effect, the parameters are:
	// Input, size of output, effect ID (see CEffectPostProc.h for full list), effect parameters (in this case, blur size)
	CEffectPostProc* ppBlur = new CEffectPostProc( ppRenderer, dimension2di( 1024, 512 ), PP_BLUR, 0.01f );
	// Change to a better quality - not all shaders will respect these, but they can be used to hint the rendering standard required.
	ppBlur->setQuality( PPQ_GOOD );
	// Options (worst to best): PPQ_CRUDE, PPQ_FAST, PPQ_DEFAULT, PPQ_GOOD, PPQ_BEST
	// You can also call setOverallQuality( PPQ_WHATEVER ) to change the quality of all effects which are in the chain.

	// These variables aren't important - they are just for showing the FPS
	wchar_t tmp[255]; u8 t = 0u;

	while( device->run( ) ) {
		// What's happened to beginScene? well we want to use beginScene( false, false ) for speed, but this makes Irrlicht complain (wrongly) when using Direct3D9, so use ( false, true ) in that case.
		driver->beginScene( false, driver->getDriverType( ) == video::EDT_DIRECT3D9 );
		// The rendering is as normal, except smgr->drawAll(); is replaced with this line:
		ppBlur->render( NULL ); // NULL = render to screen. Can also take a texture to render to, or no parameter (renders to an internal texture)
		guienv->drawAll( );
		driver->endScene( );

		// Show the current FPS
		if( ++ t == 30u ) { t = 0u; swprintf(tmp, 255, L"%ls fps:%3d", driver->getName(), driver->getFPS() ); device->setWindowCaption( tmp ); }
	}

	delete ppBlur;
	delete ppRenderer;

	// Back to boring stuff
	device->drop();
	return 0;
}
Example #10
0
int main( ) {
	// Boring stuff: set up the scene, object & camera as usual
	IrrlichtDevice* device = createDevice( DRIVER, dimension2d<s32>( 640, 480 ), 16, false, false, false, 0 );
	IVideoDriver* driver = device->getVideoDriver( );
	ISceneManager* smgr = device->getSceneManager( );
	IGUIEnvironment* guienv = device->getGUIEnvironment( );
	device->getFileSystem( )->changeWorkingDirectoryTo( MEDIA_DIRECTORY );
	guienv->addStaticText( L"Splitscreen", rect<s32>( 10, 10, 260, 22 ), true );
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( smgr->getMesh( "sydney.md2" ) );
	node->setMaterialFlag( EMF_LIGHTING, false );
	node->setMD2Animation( scene::EMAT_STAND );
	node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
	smgr->addCameraSceneNode( 0, vector3df( 40.0f, 30.0f, -40.0f ), vector3df( 0.0f, 5.0f, 0.0f ) );
	// Set up the second scene, object & camera - this time, use a different texture and camera angle to show some change
	ISceneManager* smgr2 = smgr->createNewSceneManager( false );
	ISceneNode* rootnode2 = smgr2->getRootSceneNode( );
	IAnimatedMeshSceneNode* node2 = smgr2->addAnimatedMeshSceneNode( smgr2->getMesh( "sydney.md2" ), rootnode2 );
	node2->setMaterialFlag( EMF_LIGHTING, false );
	node2->setMD2Animation( scene::EMAT_STAND );
	node2->setMaterialTexture( 0, driver->getTexture("fireball.bmp") );
	smgr2->addCameraSceneNode( 0, vector3df( 40.0f, 30.0f, -40.0f ), vector3df( 10.0f, 5.0f, 0.0f ) );

	// Interesting stuff
	IPostProc* ppRenderer1 = new CRendererPostProc( smgr, dimension2di( 1024, 512 ), true, true, SColor( 255u, 100u, 101u, 140u ) );
	IPostProc* ppRenderer2 = new CRendererPostProc( smgr2, dimension2di( 1024, 512 ), true, true, SColor( 255u, 0u, 0u, 0u ) );
	// Splitscreen objects can be given up to 4 views. The rects at the end are optional - if not given, an arrangement will be created to fit the given number of views
	CSplitPostProc* ppSplit = new CSplitPostProc( ppRenderer1, ppRenderer2, dimension2di( 1024, 512 ), rect<f32>( -0.5f, -1.0f, 0.5f, 0.0f ), rect<f32>( -0.7f, 0.0f, 0.3f, 1.0f ) );
	ppSplit->setVoidColor( SColor( 255u, 128u, 128u, 128u ) ); // Change the colour shown where there are no views. Call setVoidColor() to use no color (slightly faster, but should only be used if the views entirely cover the screen)

	// These variables aren't important - they are just for showing the FPS
	wchar_t tmp[255]; u8 t = 0u;

	while( device->run( ) ) {
		driver->beginScene( false, driver->getDriverType( ) == video::EDT_DIRECT3D9 );
		ppSplit->render( NULL );
		guienv->drawAll( );
		driver->endScene( );

		// Show the current FPS
		if( ++ t == 30u ) { t = 0u; swprintf(tmp, 255, L"%ls fps:%3d", driver->getName(), driver->getFPS() ); device->setWindowCaption( tmp ); }
	}

	delete ppRenderer1;
	delete ppSplit;
	delete ppRenderer2;

	// Back to boring stuff
	device->drop();
	return 0;
}
Example #11
0
int main()
{
    IrrlichtDevice *device =
        createDevice( video::EDT_SOFTWARE, dimension2d<u32>(640, 480), 16,
            false, false, false, 0);

    if (!device)
        return 1;

    device->setWindowCaption(L"Have a go here: Chapter 3");

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

    IAnimatedMesh* mesh = smgr->getMesh("/home/fuyajun/Documents/irrlicht-1.7.2/media/sydney.md2");
    if (!mesh)
    {
        device->drop();
        return 1;
    }
    IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );

    MyAnimationEndCallback animEndCallback;

    //连续动画
    if (node)
    {
        node->setMaterialFlag(EMF_LIGHTING, false);
        node->setMD2Animation(scene::EMAT_STAND);
        node->setMaterialTexture( 0, driver->getTexture("/home/fuyajun/Documents/irrlicht-1.7.2/media/sydney.bmp") );

        node->setLoopMode(false);
        node->setAnimationEndCallback(&animEndCallback);
    }

    smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));

    while(device->run())
    {
        driver->beginScene(true, true, SColor(255,100,101,140));

        smgr->drawAll();

        driver->endScene();
    }

    device->drop();
    return 0;
}
IAnimatedMeshSceneNode* MyIrrlichtComposition::mLoadMesh(vector3df pos,vector3df rot,vector3df scale, std::string name1, std::string name2)
{
	IAnimatedMeshSceneNode* obj = smgr->addAnimatedMeshSceneNode(smgr->getMesh(name1.c_str()));
	if(obj)
	{
		obj->setPosition(pos);
		obj->setMD2Animation(scene::EMAT_RUN);
		obj->setRotation(rot); 
		obj->setScale(scale);
		obj->setMaterialTexture(0, driver->getTexture(name2.c_str()));
		obj->addShadowVolumeSceneNode();
		return obj;
	}
	else 
		exit(2);
}
Example #13
0
int example_helloworld()
{
	// create device
	IrrlichtDevice *device = startup();
	if (device == 0)
		return 1; // could not create selected driver.

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

	IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
	if (!mesh)
	{
		device->drop();
		return 1;
	}
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );

	/*
	To let the mesh look a little bit nicer, we change its material. We
	disable lighting because we do not have a dynamic light in here, and
	the mesh would be totally black otherwise. Then we set the frame loop,
	such that the predefined STAND animation is used. And last, we apply a
	texture to the mesh. Without it the mesh would be drawn using only a
	color.
	*/
	if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setMD2Animation(scene::EMAT_STAND);
		node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
	}

	/*
	To look at the mesh, we place a camera into 3d space at the position
	(0, 30, -40). The camera looks from there to (0,5,0), which is
	approximately the place where our md2 model is.
	*/
	smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));

	EventReceiver_basic receiver(device);
	device->setEventReceiver(&receiver);

	return run ( device );

}
Example #14
0
int main()
{
	eventReceiver receiver;
	IrrlichtDevice *device = createDevice( video::EDT_OPENGL, dimension2d<u32>(1366, 768), 16,true, false, false,&receiver);
	device->setWindowCaption(L"(WhizGeek || Mclightning).com");
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();

	scene::ICameraSceneNode* kam= smgr->addCameraSceneNode(NULL,vector3df(0,0,200),vector3df(0,0,0));
	
	//kam->setPosition(vector3df(0,0,200));

	ISceneNode* kutu=smgr->addCubeSceneNode(50,0,2,vector3df(50,0,0));
	ISceneNode* kutu2=smgr->addCubeSceneNode(50,0,2,vector3df(-50,0,0));
	ITexture *duvar=driver->getTexture("wall.jpg");
	kutu->setMaterialTexture(0,duvar);
	kutu->setMaterialFlag(video::EMF_LIGHTING, false);
	kutu2->setMaterialTexture(0,duvar);
	kutu2->setMaterialFlag(video::EMF_LIGHTING, false);

		IAnimatedMesh* mesh = smgr->getMesh("sydney.md2");
		IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setMD2Animation(scene::EMAT_STAND);
		node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
		node->setRotation(vector3df(0,270,0));
		
	irFinder ir("test",true,230,255);
	CvPoint in;
	while(device->run())
	{		
		if(receiver.IsKeyDown(KEY_ESCAPE))
		{
			device->drop();
			return 0;
		}
		driver->beginScene(true, true, SColor(255,0,0,255));
		in=ir.yenile();
		//node->setPosition(vector3df(30*in.x/320,30*(240-in.y)/240,0));
		kam->setPosition(vector3df(in.x-160,(240-in.y),200));
		smgr->drawAll();
		driver->endScene();
	}
	device->drop();
}
Example #15
0
/** At the moment, this just verifies that the last frame of the animation produces the expected bitmap. */
bool md2Animation(void)
{
	// Use EDT_BURNINGSVIDEO since it is not dependent on (e.g.) OpenGL driver versions.
	IrrlichtDevice *device = createDevice( EDT_BURNINGSVIDEO, dimension2d<u32>(160, 120), 32);
	assert(device);
	if (!device)
		return false;

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

	IAnimatedMesh* mesh = smgr->getMesh("../media/sydney.md2");
	IAnimatedMeshSceneNode* node;
	assert(mesh);

	if(mesh)
	{
		node = smgr->addAnimatedMeshSceneNode(mesh);
		assert(node);

		if(node)
		{
			node->setPosition(vector3df(20, 0, 30));
			node->setMaterialFlag(EMF_LIGHTING, false);
			node->setMaterialTexture(0, driver->getTexture("../media/sydney.bmp"));
			node->setLoopMode(false);

			(void)smgr->addCameraSceneNode();

			// Just jump to the last frame since that's all we're interested in.
			node->setMD2Animation(EMAT_DEATH_FALLBACK);
			node->setCurrentFrame((f32)(node->getEndFrame()));
			device->run();
			driver->beginScene(true, true, SColor(255, 255, 255, 0));
			smgr->drawAll();
			driver->endScene();
		}
	}

	bool result = takeScreenshotAndCompareAgainstReference(driver, "-md2Animation.png");
	device->drop();

	return result;
}
Example #16
0
int main()
{
	IrrlichtDevice *device =
	                createDevice( video::EDT_OPENGL, dimension2d<u32>(640, 480), 16,
	                        false, false, false, 0);

	if (!device)
		cout<<"error";
	else
	{
		device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
		IVideoDriver* driver = device->getVideoDriver();
		ISceneManager* smgr = device->getSceneManager();
		IGUIEnvironment* guienv = device->getGUIEnvironment();
		guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
		                rect<s32>(10,10,260,22), true);
        IAnimatedMesh* mesh = smgr->getMesh("sydney.md2");
        if (!mesh)
        {
                device->drop();
                return 1;
        }
        IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
        if (node)
        {
                node->setMaterialFlag(EMF_LIGHTING, false);
                node->setMD2Animation(scene::EMAT_STAND);
                node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
        }
        smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
        while(device->run())
        {
            driver->beginScene(true, true, SColor(255,100,101,140));

            smgr->drawAll();
            guienv->drawAll();

            driver->endScene();
        }
        device->drop();

	}
	cout<<"hello world2";
}
Example #17
0
int main( ) {
	// Boring stuff: set up the scene, object & camera as usual
	IrrlichtDevice* device = createDevice( DRIVER, dimension2d<s32>( 640, 480 ), 16, false, false, false, 0 );
	IVideoDriver* driver = device->getVideoDriver( );
	ISceneManager* smgr = device->getSceneManager( );
	IGUIEnvironment* guienv = device->getGUIEnvironment( );
	device->getFileSystem( )->changeWorkingDirectoryTo( MEDIA_DIRECTORY );
	guienv->addStaticText( L"Combined Effects", rect<s32>( 10, 10, 260, 22 ), true );
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( smgr->getMesh( "sydney.md2" ) );
	node->setMaterialFlag( EMF_LIGHTING, false );
	node->setMD2Animation( scene::EMAT_STAND );
	node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
	smgr->addCameraSceneNode( 0, vector3df( 40.0f, 30.0f, -40.0f ), vector3df( 0.0f, 5.0f, 0.0f ) );

	// Interesting stuff (see previous example for full details)
	IPostProc* ppRenderer = new CRendererPostProc( smgr, dimension2di( 1024, 512 ), true, true, SColor( 255u, 100u, 101u, 140u ) );
	CEffectPostProc* ppInvert = new CEffectPostProc( ppRenderer, dimension2di( 1024, 512 ), PP_INVERT );
	// The second effect is made exactly the same way, but takes ppInvert as the input instead of ppRenderer
	CEffectPostProc* ppBlur = new CEffectPostProc( ppInvert, dimension2di( 1024, 512 ), PP_BLUR, 0.01f );

//	delete ppInvert;

	// These variables aren't important - they are just for showing the FPS
	wchar_t tmp[255]; u8 t = 0u;

	while( device->run( ) ) {
		driver->beginScene( false, driver->getDriverType( ) == video::EDT_DIRECT3D9 );
		ppBlur->render( NULL );
		guienv->drawAll( );
		driver->endScene( );

		// Show the current FPS
		if( ++ t == 30u ) { t = 0u; swprintf(tmp, 255, L"%ls fps:%3d", driver->getName(), driver->getFPS() ); device->setWindowCaption( tmp ); }
	}

	// The effects can be deleted in any order
	delete ppBlur;
	delete ppInvert;
	delete ppRenderer;

	// Back to boring stuff
	device->drop();
	return 0;
}
Example #18
0
void AnnyFactory::produce(int x,int y,int z){
	std::string sydneyMesh = "monkey.obj";
	std::string sydneyMaterial = "unwrappedPainted.png";//"monkey.bmp";
	IAnimatedMesh* mesh = sceneManager->getMesh((RESOURCES+sydneyMesh).c_str());
	if (!mesh)
	{
		exit(1);
	}
	IAnimatedMeshSceneNode* node = sceneManager->addAnimatedMeshSceneNode( mesh );

	const wchar_t* name = L"Monkey head";
	objectList->addObject(name);

	if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setMD2Animation(scene::EMAT_RUN);
		node->setMaterialTexture( 0, driver->getTexture((RESOURCES+sydneyMaterial).c_str()) );
		node->setName(name);
		node->setPosition(core::vector3df(x,y,z));
		node->setScale(core::vector3df(10,10,10));
		node->setRotation(core::vector3df(0,200,0));
	}
}
Example #19
0
int main(int argc, char** argv)
{
    SIrrlichtCreationParameters params;
    params.DriverType = video::EDT_OPENGL;
    params.WindowSize = core::dimension2d<u32>(800, 600);
    params.Bits = 32;
    params.Fullscreen = false;
    params.Stencilbuffer = false;
    params.Vsync = false;
    params.AntiAlias = false;

    for(int i = 0; i < argc; i++) {
        if(strcmp(argv[i], "-wid") == 0)
            params.WindowId = (void*)strtol(argv[i+1], NULL, 16);
        if(strcmp(argv[i], "-fullscreen") == 0)
            params.Fullscreen = true;
        if(strcmp(argv[i], "-width") == 0)
            params.WindowSize.Width = strtol(argv[i+1], NULL, 10);
        if(strcmp(argv[i], "-height") == 0)
            params.WindowSize.Height = strtol(argv[i+1], NULL, 10);
    }
    IrrlichtDevice *device = createDeviceEx(params);

	if (!device)
		return 1;

	device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");

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

	guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
		rect<s32>(10,10,260,22), true);

	IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
	if (!mesh)
	{
		device->drop();
		return 1;
	}
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );

	if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setMD2Animation(scene::EMAT_STAND);
		node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
	}

	smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));

	while(device->run())
	{
		driver->beginScene(true, true, SColor(255,100,101,140));

		smgr->drawAll();
		guienv->drawAll();

		driver->endScene();
	}

	device->drop();

	return 0;
}
void CCharacterExample::runExample()
{
    for(s32 i=0; i<KEY_KEY_CODES_COUNT; i++)
        KeyIsDown[i] = false;

    debugDraw = true;
    drawProperties = true;
    drawWireFrame = false;

    rows = 10;
	columns = 10;

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


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

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


    device->getSceneManager()->addLightSceneNode(0, vector3df(20, 40, -50), SColorf(1.0f, 1.0f, 1.0f), 4000.0f);


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

    world->setDebugMode(EPDM_DrawAabb |
            EPDM_DrawContactPoints);

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


    camera = device->getSceneManager()->addCameraSceneNodeMaya();
	camera->setPosition(vector3df(50,15,200));
	camera->bindTargetAndRotation(true);


	createGround();
	createBoxes();

	IKinematicCharacterController* character = new IKinematicCharacterController(world);

	IAnimatedMeshSceneNode* sydney = device->getSceneManager()->addAnimatedMeshSceneNode(device->getSceneManager()->getMesh("sydney.md2"));
	sydney->setScale(vector3df(0.14,0.14,0.14));
	sydney->getMaterial(0).setTexture(0, device->getVideoDriver()->getTexture("sydney.bmp"));
	sydney->setMD2Animation(scene::EMAT_STAND);


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

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


		/*sydney->setPosition(character->getWorldTransform().getTranslation()+vector3df(0,-((sydney->getBoundingBox().MaxEdge.Y-sydney->getBoundingBox().MinEdge.Y)*0.1*0.5f),0));
        vector3df dir = camera->getAbsolutePosition()-sydney->getAbsolutePosition();
        dir.normalize();
        dir.Y = 0;
        dir *= -1;

        character->setWalkDirection(dir*0.3f);*/

        if(IsKeyDown(KEY_KEY_W))
        {
            DirZ = -1.0f;
        }

        else if(IsKeyDown(KEY_KEY_S))
        {
            DirZ = 1.0f;
        }

        else
        {
            DirZ = 0.0f;
        }

        if(IsKeyDown(KEY_KEY_A))
        {
            DirX = 1.0f;
        }

        else if(IsKeyDown(KEY_KEY_D))
        {
            DirX = -1.0f;
        }

        else
        {
            DirX = 0.0f;
        }

        if(IsKeyDown(KEY_SPACE))
        {
            character->jump();
            jump = true;
        }

        if(DirZ != 0 || DirX != 0)
            newAnimation = EMAT_RUN;

        else
            newAnimation = EMAT_STAND;

        if(!character->isOnGround())
        {
            newAnimation = jump ? EMAT_JUMP:EMAT_CROUCH_STAND;
        }

        else
            jump = false;


        if(animation != newAnimation)
        {
            animation = newAnimation;
            sydney->setMD2Animation(animation);
        }


        sydney->setPosition(character->getWorldTransform().getTranslation());

        vector3df rot(0, camera->getRotation().Y-90.0f, 0);
        sydney->setRotation(rot);


        vector3df direction(DirX, 0.0f, DirZ);

        irr::core::matrix4 m;

        m.setRotationDegrees(vector3df(0, camera->getRotation().Y-180.0f, 0));

        m.transformVect(direction);

        character->setPositionIncrementPerSimulatorStep(direction*0.3f);

        camera->setTarget(sydney->getPosition());

		// Step the simulation with our delta time
        world->stepSimulation(DeltaTime*0.001f, 120);


        world->debugDrawWorld(debugDraw);

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


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

        device->getVideoDriver()->endScene();
    }

    delete character;

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

    if(device)
        device->drop();
}
Example #21
0
int main( ) {
	// Boring stuff: set up the scene, object & camera as usual
	// To make things more interesting, we add many Sydneys and a textured floor this time
	IrrlichtDevice* device = createDevice( DRIVER, dimension2d<s32>( 640, 480 ), 16, false, false, false, 0 );
	IVideoDriver* driver = device->getVideoDriver( );
	ISceneManager* smgr = device->getSceneManager( );
	IGUIEnvironment* guienv = device->getGUIEnvironment( );
	device->getFileSystem( )->changeWorkingDirectoryTo( MEDIA_DIRECTORY );
	guienv->addStaticText( L"Sandbox", rect<s32>( 10, 10, 260, 22 ), true );
	IAnimatedMesh* mesh = smgr->getMesh("sydney.md2");
	IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices( );
	u32 matid;
	switch( driver->getDriverType( ) ) {
		case EDT_OPENGL:
			matid = gpu->addHighLevelShaderMaterial( GL_V_MAT, "main", EVST_VS_1_1, GL_PLAIN, "main", EPST_PS_1_1, new CTexturesShaderCallback( ), EMT_SOLID, 1 );
			break;
		case EDT_DIRECT3D8:
		case EDT_DIRECT3D9:
		default:
			matid = gpu->addHighLevelShaderMaterial( DX_V_MAT, "main", EVST_VS_1_1, DX_PLAIN, "main", EPST_PS_2_0, new CTexturesShaderCallback( ), EMT_SOLID, 0 );
	}
	for( u8 x = 0u; x != 2u; ++ x )
		for( u8 i = 0u; i != 5u; ++ i ) {
			IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
			node->setMaterialFlag(EMF_LIGHTING, false);
			node->setMD2Animation(scene::EMAT_STAND);
			node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
			node->setMaterialType( (E_MATERIAL_TYPE) matid );
			node->setPosition( vector3df( -x * 20.0f, 0.0f, i * 40.0f ) );
		}
	ISceneNode* nodeF = smgr->addTerrainSceneNode( "terrain-heightmap.bmp" );
	nodeF->setMaterialFlag(EMF_LIGHTING, false);
	nodeF->setMaterialTexture( 0, driver->getTexture("terrain-heightmap.bmp") );
	nodeF->setPosition( vector3df( -512.0f, -50.0f, -512.0f ) );
	nodeF->setScale( vector3df( 4.0f, 0.2f, 4.0f ) );
	nodeF->setMaterialType( (E_MATERIAL_TYPE) matid );
	ICameraSceneNode* cam1 = smgr->addCameraSceneNode( 0, vector3df( 0.0f, 0.0f, -40.0f ), vector3df( 0.0f, 5.0f, 50.0f ) );

	IPostProc* ppRenderer1 = new CRendererPostProc( smgr, dimension2di( 1024, 512 ), true, true, SColor( 255, 130u, 180u, 230u ) );
	CWaterPostProc* ppWater = new CWaterPostProc( ppRenderer1, dimension2di( 1024, 512 ), -22.0f );
	ppWater->setTimer( device->getTimer( ) );
	wchar_t tmp[255];
	u8 t = 0u;
	while( device->run( ) ) {
//		cam1->setPosition( vector3df( 40.0f, 60.0f - (device->getCursorControl( )->getPosition( ).Y - 240.0f) * 0.1f, -40.0f ) );
		cam1->setPosition( vector3df( (device->getCursorControl( )->getPosition( ).X - 320.0f) * 0.1f, (device->getCursorControl( )->getPosition( ).Y - 240.0f) * 0.1f, -40.0f ) );
//		cam1->setTarget( vector3df( (device->getCursorControl( )->getPosition( ).X - 320.0f) * 0.1f, (device->getCursorControl( )->getPosition( ).Y - 240.0f) * 0.1f, 0.0f ) );
//		cam1->setTarget( cam1->getPosition( ) + vector3df( 0.0f, 0.0f, 10.0f ) );
//		cam1->setTarget( vector3df( -(device->getCursorControl( )->getPosition( ).X - 320.0f) * 0.1f, (device->getCursorControl( )->getPosition( ).Y - 240.0f) * 0.2f, 50.0f ) );

		driver->beginScene( false, driver->getDriverType( ) == video::EDT_DIRECT3D9 );
		ppWater->render( NULL );
		guienv->drawAll( );
		driver->endScene( );

		if( ++ t == 30u ) {
			t = 0u;
			swprintf(tmp, 255, L"%ls fps:%3d", driver->getName(), driver->getFPS() );
			device->setWindowCaption( tmp );
		}
	}

	delete ppWater;
	delete ppRenderer1;

	// Back to boring stuff
	device->drop();
	return 0;
}
Example #22
0
/*
This is the main method. We can use int main() on every platform.
On Windows platforms, we could also use the WinMain method
if we would want to get rid of the console window, which pops up when
starting a program with main(), but to keep this example simple,
we use main().
*/
int main()
{
	/*
	The most important function of the engine is the 'createDevice'
	function. The Irrlicht Device can be created with it, which is the
	root object for doing everything with the engine.
	createDevice() has 7 paramters:
	deviceType: Type of the device. This can currently be the Null-device,
	   the Software device, the second software renderer, 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. 
	windowSize: Size of the Window or FullscreenMode to be created. In this 
	   example we use 640x480.
	bits: Amount of bits per pixel when in fullscreen mode. This should 
	   be 16 or 32. This parameter is ignored when running in windowed mode.
	fullscreen: Specifies if we want the device to run in fullscreen mode
	   or not.
	stencilbuffer: Specifies if we want to use the stencil buffer for drawing shadows.
	vsync: Specifies if we want to have vsync enabled, this is only useful in fullscreen
	  mode.
	eventReceiver: An object to receive events. We do not want to use this
	   parameter here, and set it to 0.
	*/

	IrrlichtDevice *device =
		createDevice( video::EDT_SOFTWARE, dimension2d<s32>(640, 480), 16,
			false, false, false, 0);

	/*
	Set the caption of the window to some nice text. Note that there is 
	a 'L' in front of the string. The Irrlicht Engine uses wide character
	strings when displaying text.
	*/
	device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");

	/*
	Get a pointer to the video driver, the SceneManager and the
	graphical user interface environment, so that
	we do not always have to write device->getVideoDriver(),
	device->getSceneManager() and device->getGUIEnvironment().
	*/
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();

	/*
	We add a hello world label to the window, using the GUI environment.
	*/
	guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
		rect<int>(10,10,260,22), true);

	/*
	To display something interesting, we load a Quake 2 model 
	and display it. We only have to get the Mesh from the Scene 
	Manager (getMesh()) and add a SceneNode to display the mesh.
	(addAnimatedMeshSceneNode()). Instead of writing the filename
	sydney.md2, it would also be possible to load a Maya object file
	(.obj), a complete Quake3 map (.bsp) or a Milshape file (.ms3d).
	By the way, that cool Quake 2 model called sydney was modelled
	by Brian Collins.
	*/
	IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );

	/*
	To let the mesh look a little bit nicer, we change its material a
	little bit: We disable lighting because we do not have a dynamic light
	in here, and the mesh would be totally black. Then we set the frame
	loop, so that the animation is looped between the frames 0 and 310.
	And at last, we apply a texture to the mesh. Without it the mesh
	would be drawn using only a color.
	*/
	if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setMD2Animation ( scene::EMAT_STAND );
		node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
	}

	/*
	To look at the mesh, we place a camera into 3d space at the position
	(0, 30, -40). The camera looks from there to (0,5,0).
	*/
	smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));

	/*
	Ok, now we have set up the scene, lets draw everything:
	We run the device in a while() loop, until the device does not
	want to run any more. This would be when the user closed the window
	or pressed ALT+F4 in windows.
	*/
	while(device->run())
	{
		/*
		Anything can be drawn between a beginScene() and an endScene()
		call. The beginScene clears the screen with a color and also the
		depth buffer if wanted. Then we let the Scene Manager and the
		GUI Environment draw their content. With the endScene() call
		everything is presented on the screen.
		*/
		driver->beginScene(true, true, SColor(255,100,101,140));

		smgr->drawAll();
		guienv->drawAll();

		driver->endScene();
	}

	/*
	After we are finished, we have to delete the Irrlicht Device
	created before with createDevice(). In the Irrlicht Engine, 
	you will have to delete all objects you created with a method or 
	function which starts with 'create'. The object is simply deleted
	by calling ->drop().
	See the documentation at 
	http://irrlicht.sourceforge.net//docu/classirr_1_1IUnknown.html#a3
	for more information.
	*/
	device->drop();

	return 0;
}
Example #23
0
int main( ) {
	// Boring stuff: set up the scene, object & camera as usual
	// To make things more interesting, we add many Sydneys and a textured floor this time
	IrrlichtDevice* device = createDevice( DRIVER, dimension2d<s32>( 640, 480 ), 16, false, false, false, 0 );
	IVideoDriver* driver = device->getVideoDriver( );
	ISceneManager* smgr = device->getSceneManager( );
	IGUIEnvironment* guienv = device->getGUIEnvironment( );
	device->getFileSystem( )->changeWorkingDirectoryTo( MEDIA_DIRECTORY );
	guienv->addStaticText( L"Heat Haze (with Depth dependence)", rect<s32>( 10, 10, 260, 22 ), true );
	IAnimatedMesh* mesh = smgr->getMesh("sydney.md2");
	ISceneManager* smgr2 = smgr->createNewSceneManager( false );
	ISceneNode* rootnode2 = smgr2->getRootSceneNode( );
	IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices( );
	u32 matid, matid2;
	switch( driver->getDriverType( ) ) {
		case EDT_OPENGL:
			matid = gpu->addHighLevelShaderMaterial( GL_V_MAT, "main", EVST_VS_1_1, GL_PLAIN, "main", EPST_PS_1_1, new CTexturesShaderCallback( ), EMT_SOLID, 1 );
			matid2 = gpu->addHighLevelShaderMaterial( GL_V_MAT, "main", EVST_VS_1_1, GL_HEATSOURCE, "main", EPST_PS_1_1, new CTexturesShaderCallback( ), EMT_TRANSPARENT_ALPHA_CHANNEL, 1 );
			break;
		case EDT_DIRECT3D8:
		case EDT_DIRECT3D9:
		default:
			matid = gpu->addHighLevelShaderMaterial( DX_V_MAT, "main", EVST_VS_1_1, DX_PLAIN, "main", EPST_PS_2_0, new CTexturesShaderCallback( ), EMT_SOLID, 0 );
			matid2 = gpu->addHighLevelShaderMaterial( DX_V_MAT, "main", EVST_VS_1_1, DX_HEATSOURCE, "main", EPST_PS_2_0, new CTexturesShaderCallback( ), EMT_TRANSPARENT_ALPHA_CHANNEL, 0 );
	}
	for( u8 x = 0u; x != 2u; ++ x )
		for( u8 i = 0u; i != 5u; ++ i ) {
			IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
			node->setMaterialFlag(EMF_LIGHTING, false);
			node->setMD2Animation(scene::EMAT_STAND);
			node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
			node->setMaterialType( (E_MATERIAL_TYPE) matid );
			node->setPosition( vector3df( -x * 20.0f, 0.0f, i * 40.0f ) );
			ISceneNode* node2 = smgr2->addBillboardSceneNode( rootnode2, dimension2df( 30.0f, 80.0f ), vector3df( -x * 20.0f, 30.0f, i * 40.0f ) );
			node2->setMaterialFlag(EMF_LIGHTING, false);
			node2->setMaterialType( EMT_TRANSPARENT_ADD_COLOR );
			node2->setMaterialTexture( 0, driver->getTexture("fireball.bmp") );
			node2->setMaterialType( (E_MATERIAL_TYPE) matid2 );
		}
	ISceneNode* nodeF = smgr->addMeshSceneNode( smgr->addHillPlaneMesh( "", dimension2df( 200.0f, 200.0f ), dimension2d<u32>( 10, 10 ), NULL, 0.0f, dimension2df( 0.0f, 0.0f ), dimension2df( 100.0f, 100.0f ) ) );
	nodeF->setMaterialFlag(EMF_LIGHTING, false);
	nodeF->setMaterialTexture( 0, driver->getTexture("terrain-heightmap.bmp") );
	nodeF->setPosition( vector3df( 0.0f, -22.0f, 0.0f ) );
	nodeF->setMaterialType( (E_MATERIAL_TYPE) matid );
	ICameraSceneNode* cam1 = smgr->addCameraSceneNode( 0, vector3df( 40.0f, 60.0f, -40.0f ), vector3df( 0.0f, 5.0f, 50.0f ) );
	ICameraSceneNode* cam2 = smgr2->addCameraSceneNode( rootnode2, vector3df( 40.0f, 60.0f, -40.0f ), vector3df( 0.0f, 5.0f, 50.0f ) );

	IPostProc* ppRenderer1 = new CRendererPostProc( smgr, dimension2di( 1024, 512 ), true, true, SColor( 255u, 100u, 101u, 140u ) );
	IPostProc* ppRenderer2 = new CRendererPostProc( smgr2, dimension2di( 1024, 512 ), true, true, SColor( 255u, 0u, 0u, 0u ) );
	CEffectPostProc* ppHaze = new CEffectPostProc( ppRenderer1, dimension2di( 1024, 512 ), PP_HAZEDEPTH );
	ppHaze->setInput( 1, ppRenderer2 );
	ppHaze->setTimer( device->getTimer( ) );

	// These variables aren't important - they are just for showing the FPS
	wchar_t tmp[255]; u8 t = 0u;

	while( device->run( ) ) {
		cam1->setPosition( vector3df( 40.0f, 60.0f - (device->getCursorControl( )->getPosition( ).Y - 240.0f) * 0.1f, -40.0f ) );
		cam1->setTarget( vector3df( -(device->getCursorControl( )->getPosition( ).X - 320.0f) * 0.1f, (device->getCursorControl( )->getPosition( ).Y - 240.0f) * 0.2f, 50.0f ) );
		cam2->setPosition( cam1->getPosition( ) );
		cam2->setTarget( cam1->getTarget( ) );
		cam2->setUpVector( cam1->getUpVector( ) );

		driver->beginScene( false, driver->getDriverType( ) == video::EDT_DIRECT3D9 );
		ppHaze->render( NULL );
		guienv->drawAll( );
		driver->endScene( );

		// Show the current FPS
		if( ++ t == 30u ) { t = 0u; swprintf(tmp, 255, L"%ls fps:%3d", driver->getName(), driver->getFPS() ); device->setWindowCaption( tmp ); }
	}

	delete ppHaze;
	delete ppRenderer1;
	delete ppRenderer2;

	// Back to boring stuff
	device->drop();
	return 0;
}
Example #24
0
/*
This is the main method. We can now use main() on every platform.
*/
int main()
{
	/*
	The most important function of the engine is the createDevice()
	function. The IrrlichtDevice is created by it, which is the root
	object for doing anything with the engine. createDevice() has 7
	parameters:

	- deviceType: Type of the device. This can currently be the Null-device,
	   one of the two software renderers, 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_DIRECT3D9, or EDT_OPENGL.

	- windowSize: Size of the Window or screen in FullScreenMode to be
	   created. In this example we use 640x480.

	- bits: Amount of color bits per pixel. This should be 16 or 32. The
	   parameter is often ignored when running in windowed mode.

	- fullscreen: Specifies if we want the device to run in fullscreen mode
	   or not.

	- stencilbuffer: Specifies if we want to use the stencil buffer (for
	   drawing shadows).

	- vsync: Specifies if we want to have vsync enabled, this is only useful
	   in fullscreen mode.

	- eventReceiver: An object to receive events. We do not want to use this
	   parameter here, and set it to 0.

	Always check the return value to cope with unsupported drivers,
	dimensions, etc.
	*/
	IrrlichtDevice *device =
		createDevice( video::EDT_OGLES1, dimension2d<u32>(640, 480), 16,
			false, false, false, 0);

	if (!device)
		return 1;

	/*
	Set the caption of the window to some nice text. Note that there is an
	'L' in front of the string. The Irrlicht Engine uses wide character
	strings when displaying text.
	*/
	device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");

	/*
	Get a pointer to the VideoDriver, the SceneManager and the graphical
	user interface environment, so that we do not always have to write
	device->getVideoDriver(), device->getSceneManager(), or
	device->getGUIEnvironment().
	*/
	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();

	/*
	We add a hello world label to the window, using the GUI environment.
	The text is placed at the position (10,10) as top left corner and
	(260,22) as lower right corner.
	*/
	guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
		rect<s32>(10,10,260,22), true);

	/*
	Get a media path dedicated for your platform.
	*/
	const io::path mediaPath = getExampleMediaPath();

	/*
	To show something interesting, we load a Quake 2 model and display it.
	We only have to get the Mesh from the Scene Manager with getMesh() and add
	a SceneNode to display the mesh with addAnimatedMeshSceneNode(). We
	check the return value of getMesh() to become aware of loading problems
	and other errors.

	Instead of writing the filename sydney.md2, it would also be possible
	to load a Maya object file (.obj), a complete Quake3 map (.bsp) or any
	other supported file format. By the way, that cool Quake 2 model
	called sydney was modelled by Brian Collins.
	*/
	IAnimatedMesh* mesh = smgr->getMesh(mediaPath + "sydney.md2");
	if (!mesh)
	{
		device->drop();
		return 1;
	}
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );

	/*
	To let the mesh look a little bit nicer, we change its material. We
	disable lighting because we do not have a dynamic light in here, and
	the mesh would be totally black otherwise. Then we set the frame loop,
	such that the predefined STAND animation is used. And last, we apply a
	texture to the mesh. Without it the mesh would be drawn using only a
	color.
	*/
	if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setMD2Animation(scene::EMAT_STAND);
		node->setMaterialTexture( 0, driver->getTexture(mediaPath + "sydney.bmp") );
	}

	/*
	To look at the mesh, we place a camera into 3d space at the position
	(0, 30, -40). The camera looks from there to (0,5,0), which is
	approximately the place where our md2 model is.
	*/
	smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));

	/*
	Ok, now we have set up the scene, lets draw everything: We run the
	device in a while() loop, until the device does not want to run any
	more. This would be when the user closes the window or presses ALT+F4
	(or whatever keycode closes a window).
	*/
	while(device->run())
	{
		/*
		Anything can be drawn between a beginScene() and an endScene()
		call. The beginScene() call clears the screen with a color and
		the depth buffer, if desired. Then we let the Scene Manager and
		the GUI Environment draw their content. With the endScene()
		call everything is presented on the screen.
		*/
		driver->beginScene(ECBF_COLOR | ECBF_DEPTH, SColor(255,100,101,140));

		smgr->drawAll();
		guienv->drawAll();

		driver->endScene();
	}

	/*
	After we are done with the render loop, we have to delete the Irrlicht
	Device created before with createDevice(). In the Irrlicht Engine, you
	have to delete all objects you created with a method or function which
	starts with 'create'. The object is simply deleted by calling ->drop().
	See the documentation at irr::IReferenceCounted::drop() for more
	information.
	*/
	device->drop();

	return 0;
}
Example #25
0
bool 
ProcTitle::OnInit(irr::IrrlichtDevice& device)
{	
	device.setWindowCaption(L"Pair - title");
	//device.getCursorControl()->setVisible(false);

	u32 width = IrrDvc.GetDriver()->getScreenSize().Width;
	u32 height = IrrDvc.GetDriver()->getScreenSize().Height;

	scene::ISceneManager* pSmgr = IrrDvc.GetSmgr();
	IVideoDriver* pDriver = IrrDvc.GetDriver();

	// camera setting 
	{		
		irr::scene::ICameraSceneNode* pCamera = pSmgr->addCameraSceneNode(0, core::vector3df(0,0,-100), core::vector3df(0,0,0));		
		//f32 zNear = 1;
		//f32 zFar = 3000;
		//f32 zNear = pCamera->getNearValue();
		//f32 zFar = pCamera->getFarValue();
#if 0
		CMatrix4<f32> matOrtho;				
		matOrtho.buildProjectionMatrixOrthoLH(width, height, zNear, zFar);
		pCamera->setProjectionMatrix(matOrtho, true);
#else
		//CMatrix4<f32> matPerspective;
		//matPerspective.buildProjectionMatrixPerspectiveLH((f32)width, (f32)height, zNear, zFar);
		//pCamera->setProjectionMatrix(matPerspective, false);
#endif
	}

	// title
	{		
		m_p2DSprite = pSmgr->addBillboardSceneNode();
		video::ITexture* pTexture = pDriver->getTexture("Rsrc/title.png");		
		m_p2DSprite->setMaterialTexture(0, pTexture);
		m_p2DSprite->setMaterialFlag(video::EMF_LIGHTING, false);
		m_p2DSprite->setMaterialFlag(video::EMF_ZBUFFER, true);
		m_p2DSprite->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
		m_p2DSprite->setMaterialFlag(video::EMF_ANTI_ALIASING, true);
		m_p2DSprite->setMaterialFlag(video::EMF_BILINEAR_FILTER, true);
		m_p2DSprite->setSize(dimension2df((f32)width, (f32)height));
		m_p2DSprite->setPosition(vector3df(0.f, 0.f, 300.f));
		m_p2DSprite->setID(1004);
		m_p2DSprite->getMaterial(0).getTextureMatrix(0).setTextureScale(1.0f, 1.0f);

		// animation test
		//scene::ISceneNodeAnimator* pAni = pSmgr->createFlyCircleAnimator(core::vector3df(0,0,200), 20.0f);
		//m_p2DSprite->addAnimator(pAni);
	}

	// card
	{
		for (int i = 0; i < 3; i++)
		{
			IMeshSceneNode* pCard = pSmgr->addCubeSceneNode();
			char buff[20];
			sprintf_s(buff, 20, "Rsrc/card%d.png", i);
			video::ITexture* pTexture = pDriver->getTexture(buff);			
			pCard->setMaterialTexture(0, pTexture);
			pCard->setScale(vector3df(4.f, 4.f * 1.618f, 0.1f));
			pCard->setPosition(vector3df(-60.f + 60.f * i, 0.f, 0.f));
			pCard->setMaterialFlag(video::EMF_LIGHTING, false);

			// animation test
			scene::ISceneNodeAnimator* pAni = pSmgr->createRotationAnimator(vector3df(0.f, 1.f, 0.f));
			pCard->addAnimator(pAni);
			pAni->drop();
		}
	}

	// mesh
	{
		IAnimatedMesh* mesh = pSmgr->getMesh("Rsrc/sydney.md2");
		IAnimatedMeshSceneNode* pNode = pSmgr->addAnimatedMeshSceneNode(mesh);
		if (pNode)
		{
			//pNode->setScale(vector3df(10.f, 10.f, 10.f));
			pNode->setMaterialFlag(EMF_LIGHTING, false);
			//pNode->setMaterialFlag(EMF_ZBUFFER, false);
			pNode->setMD2Animation(scene::EMAT_STAND);
			pNode->setMaterialTexture( 0, pDriver->getTexture("Rsrc/sydney.bmp") );
			pNode->setPosition(vector3df(0.0f, -5.f, -55.f));
		}
	}

	// button 
	{
		IGUIEnvironment* env = device.getGUIEnvironment();
		
		video::ITexture* pTexture = pDriver->getTexture("Rsrc/new_game_btn_normal.PNG");	// refcount = 1
		dimension2d<u32> dim = pTexture->getOriginalSize();
		s32 offsetX = width / 2 - dim.Width / 2;
		s32 offsetY = height - dim.Height * 3;
		IGUIButton* pButton = env->addButton(rect<s32>(offsetX, offsetY, offsetX + dim.Width, offsetY + dim.Height), 0, GUI_ID_START_BUTTON);
		pButton->setDrawBorder(false);		
		pButton->setImage(pTexture);										// refcount += 2, means when button released refcount will be 1	
		pButton->setUseAlphaChannel(true);									// 1 will be decreased pDriver->removeAllTextures();

		{
			ITexture* pTexture = pDriver->getTexture("Rsrc/new_game_btn_pressed.PNG");
			pButton->setPressedImage(pTexture);
		}
	}

	// sound test
	IrrSnd.GetSndEngine()->play2D("Rsrc/getout.ogg", true);

	return true;
}
Example #26
0
int main( ) {
	// Boring stuff: set up the scene, object & camera as usual
	// To make things more interesting, we add many Sydneys and a textured floor this time
	IrrlichtDevice* device = createDevice( DRIVER, dimension2d<s32>( 640, 480 ), 16, false, false, false, 0 );
	IVideoDriver* driver = device->getVideoDriver( );
	ISceneManager* smgr = device->getSceneManager( );
	IGUIEnvironment* guienv = device->getGUIEnvironment( );
	device->getFileSystem( )->changeWorkingDirectoryTo( MEDIA_DIRECTORY );
	guienv->addStaticText( L"Depth of Field", rect<s32>( 10, 10, 260, 22 ), true );
	IAnimatedMesh* mesh = smgr->getMesh("sydney.md2");

	// Create the required material. This is a simple shader which draws the texture with no lights.
	// Use GL_PLAIN1 / DX_PLANE1 or GL_PLAIN2 / DX_PLANE2 to support 1 or 2 basic point-lights
	u32 matid;
	IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices( );
	switch( driver->getDriverType( ) ) {
		case EDT_OPENGL:
			matid = gpu->addHighLevelShaderMaterial( GL_V_MAT, "main", EVST_VS_1_1, GL_PLAIN, "main", EPST_PS_1_1, new CTexturesShaderCallback( ), EMT_SOLID, 1 );
			break;
		case EDT_DIRECT3D8:
		case EDT_DIRECT3D9:
		default:
			matid = gpu->addHighLevelShaderMaterial( DX_V_MAT, "main", EVST_VS_1_1, DX_PLAIN, "main", EPST_PS_2_0, new CTexturesShaderCallback( ), EMT_SOLID, 0 );
	}

	for( u8 x = 0u; x != 2u; ++ x )
		for( u8 i = 0u; i != 5u; ++ i ) {
			IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
			node->setMaterialFlag(EMF_LIGHTING, false);
			node->setMD2Animation(scene::EMAT_STAND);
			node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );
			node->setMaterialType( (E_MATERIAL_TYPE) matid );
			node->setPosition( vector3df( -x * 20.0f, 0.0f, i * 40.0f ) );
		}
	ISceneNode* node2 = smgr->addMeshSceneNode( smgr->addHillPlaneMesh( "", dimension2df( 200.0f, 200.0f ), dimension2d<u32>( 10, 10 ), NULL, 0.0f, dimension2df( 0.0f, 0.0f ), dimension2df( 100.0f, 100.0f ) ) );
	node2->setMaterialFlag(EMF_LIGHTING, false);
	node2->setMaterialTexture( 0, driver->getTexture("terrain-heightmap.bmp") );
	node2->setMaterialType( (E_MATERIAL_TYPE) matid );
	node2->setPosition( vector3df( 0.0f, -22.0f, 0.0f ) );
	ICameraSceneNode* cam = smgr->addCameraSceneNode( 0, vector3df( 40.0f, 60.0f, -40.0f ), vector3df( 0.0f, 5.0f, 50.0f ) );

	IPostProc* ppRenderer = new CRendererPostProc( smgr, dimension2di( 1024, 512 ), true, true, SColor( 255u, 100u, 101u, 140u ) );
	CEffectPostProc* ppBlurDOF = new CEffectPostProc( ppRenderer, dimension2di( 1024, 512 ), PP_BLURDOF );
	// We could set parameters on creation, but no need since we will animate it anyway.
	// Parameters are: near blur, near focus, far focus, far blur, blur level
	// You can also use PP_BLURDOFNEAR or PP_BLURDOFFAR to have only near or far blurring

	// These variables aren't important - they are just for showing the FPS
	wchar_t tmp[255]; u8 t = 0u;

	while( device->run( ) ) {
		// Change the camera angle
		cam->setTarget( vector3df( -(device->getCursorControl( )->getPosition( ).X - 320.0f) * 0.1f, (device->getCursorControl( )->getPosition( ).Y - 240.0f) * 0.2f, 0.0f ) );

		// Animate the depth of field:
		f32 p = sinf( device->getTimer( )->getTime( ) * 0.0005f ) * 0.5f - 0.2f;
		ppBlurDOF->setParameters( p * 100.0f + 80.0f, p * 100.0f + 110.0f, p * 100.0f + 160.0f, p * 100.0f + 240.0f, 0.01f );

		driver->beginScene( false, driver->getDriverType( ) == video::EDT_DIRECT3D9 );
		ppBlurDOF->render( NULL );
		guienv->drawAll( );
		driver->endScene( );

		// Show the current FPS
		if( ++ t == 30u ) { t = 0u; swprintf(tmp, 255, L"%ls fps:%3d", driver->getName(), driver->getFPS() ); device->setWindowCaption( tmp ); }
	}

	delete ppBlurDOF;
	delete ppRenderer;

	// Back to boring stuff
	device->drop();
	return 0;
}
Example #27
0
int main()
{
	// create device
    EventHandler receiver;
	Init();
	Output();
	ISceneNode* objects [MAX_OBJECTS];



	 IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<u32>(ResX, ResY), 32, fullscreen, false, vsync, &receiver); 
	 
	 receiver.device = device; 

    if (!device)
        return 1;

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

	HMDDescriptor HMD;
	// Parameters from the Oculus Rift DK1
	HMD.hResolution = ResX;
	HMD.vResolution = ResY;
	HMD.hScreenSize = 0.14976;
	HMD.vScreenSize = 0.0936;
	HMD.interpupillaryDistance = 0.064;
	HMD.lensSeparationDistance = 0.064;
	HMD.eyeToScreenDistance = 0.041;
	HMD.distortionK[0] = 1.0;
	HMD.distortionK[1] = 0.22;
	HMD.distortionK[2] = 0.24;
	HMD.distortionK[3] = 0.0;

	HMDStereoRender renderer(device, HMD, 10); 


	#ifdef OCCULUS
		ICameraSceneNode* camera = smgr->addCameraSceneNode();
		camera->bindTargetAndRotation(false);
		camera->setTarget(vector3df(1,0,0));
	#else	
		ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
	#endif	

	
    device->getCursorControl()->setVisible(false); 


	// load a faerie 
	IAnimatedMesh* faerie = smgr->getMesh("media/faerie.md2");
	IAnimatedMeshSceneNode* faerieNode = smgr->addAnimatedMeshSceneNode(faerie);
	faerieNode->setMaterialTexture(0, driver->getTexture("media/faerie2.bmp"));
	faerieNode->setMaterialFlag(EMF_LIGHTING, false);
	faerieNode->setPosition(vector3df(40,190,-1030));
	faerieNode->setRotation(vector3df(0,-90,0));
	faerieNode->setMD2Animation(EMAT_SALUTE);

	// load a dwarf
	IAnimatedMesh* dwarf = smgr->getMesh("media/dwarf.x");
	IAnimatedMeshSceneNode* dwarfNode = smgr->addAnimatedMeshSceneNode(dwarf);
	dwarfNode->setPosition(vector3df(40,-25,20));
	  
	
	Level currentLevel(device);
	currentLevel.makeLevel(0);

	smgr->setAmbientLight(video::SColorf(0.1,0.1,0.1,1));
	ILightSceneNode* light1 = smgr->addLightSceneNode( camera , vector3df(0,0,0), video::SColorf(0.3f,0.4f,0.4f), 80.0f, 1 );


	vector3df pos = vector3df(0,0,0);

	//naplníme tunel pøekážkama

	 srand (time(NULL));
	/* generate secret number between 1 and 10: */
	
	for(int i = 0; i < MAX_OBJECTS; i++){
		objects[i] = smgr->addCubeSceneNode(2);
		objects[i]->setMaterialFlag(EMF_LIGHTING, false);
		objects[i]->setPosition( vector3df( (rand() % 30) - 5, (rand() % 30) - 5, rand() % 80) );
	}

	//device->setInputReceivingSceneManager(smgr);
	
	//použivane pro 
	vector3df tempRot; 
	irr::core::quaternion tempQ;
	irr::core::matrix4 tempM;

	float round = 0;

    while(device->run())
    {
		round += 0.01;
        driver->beginScene(true, true, SColor(255,100,101,140));
		
		for(int i = 0; i < MAX_OBJECTS; i++){
			vector3df tmpPos = objects[i]->getPosition();
			if(tmpPos.Z > pos.Z) continue;
			
			objects[i]->setPosition( vector3df( (rand() % 30) - 15, (rand() % 30) - 15, rand() % 80 + pos.Z) );
		}
		
	#ifndef OCCULUS
			tempM.setRotationDegrees(vector3df(sin(round*0.5)*360-180, sin(round)*360-180, cos(round*0.8)*360-180));
			
			// transform forward vector of camera
			irr::core::vector3df frv = irr::core::vector3df (0.0f, 0.0f, 1.0f);
			tempM.transformVect(frv);
    
			// transform upvector of camera
		    irr::core::vector3df upv = irr::core::vector3df (0.0f, 1.0f, 0.0f);
			tempM.transformVect(upv);

		    camera->setUpVector(upv); //set up vector of camera
			camera->setTarget(frv); //set target of camera (look at point) (thx Zeuss for correcting it)

	#endif

		
		if(pSensor){
			Quatf quaternion = FusionResult.GetOrientation();

		   ICameraSceneNode* camera = smgr->getActiveCamera();
   
		   tempQ.set(-quaternion.z,quaternion.y,-quaternion.x, quaternion.w);
		   tempQ.normalize();
		   tempQ.toEuler(tempRot);
    
		   
			tempM.setRotationDegrees(tempRot);

			// transform forward vector of camera
			irr::core::vector3df frv = irr::core::vector3df (0.0f, 0.0f, 1.0f);
			tempM.transformVect(frv);
    
			// transform upvector of camera
		    irr::core::vector3df upv = irr::core::vector3df (0.0f, 1.0f, 0.0f);
			tempM.transformVect(upv);

		    camera->setUpVector(upv); //set up vector of camera
			camera->setTarget(frv); //set target of camera (look at point) (thx Zeuss for correcting it)

			// update absolute position
			camera->updateAbsolutePosition();



			float yaw, pitch, roll;
			quaternion.GetEulerAngles<Axis_Y, Axis_X, Axis_Z>(&yaw, &pitch, &roll);
			camera->getParent()->setRotation( vector3df(RadToDegree(pitch),RadToDegree(yaw),RadToDegree(roll)));
			//camera->setRotation( vector3df(RadToDegree(-pitch),RadToDegree(-yaw),RadToDegree(roll)));
			//camera->setProjectionMatrix(ToMatrix(quaternion));
			cout << " Yaw: " << RadToDegree(yaw) << 
				", Pitch: " << RadToDegree(pitch) << 
				", Roll: " << RadToDegree(roll) << endl;
		
			if (_kbhit()) exit(0);
		}

		#ifdef OCCULUS
			renderer.drawAll(smgr); 
		#else
			smgr->drawAll();
		#endif

        guienv->drawAll();

        driver->endScene();
    }


    device->drop();
	Clear();
    return 0;
}