Esempio n. 1
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;
}
Esempio n. 2
0
pAnimatedSceneObject AnimatedSceneObject::init(pObject const& parent)
{
    setupSceneAndManager(parent);

    std::ostringstream oss;
    oss << Conf::i().expand("rc/model/") << name_ << ".x";
    IAnimatedMesh* mesh = smgr_->getMesh( oss.str().c_str() );
    IAnimatedMeshSceneNode* temp = smgr_->addAnimatedMeshSceneNode( mesh, parent->body() );
    temp->setAnimationSpeed(0);
    body_ = temp;
    body_->grab(); //added so its d'tor order is consistent with view::Object.
    body_->getMaterial(0).Shininess = 0;
    for( size_t i = 0; i < body_->getMaterialCount(); ++i ) {
        body_->getMaterial(i).MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
        body_->getMaterial(i).MaterialTypeParam = 0.01f;
        body_->getMaterial(i).DiffuseColor.set(255, 255, 255, 255);
    }

    //test
    body_->grab();

    pAnimatedSceneObject self = static_pointer_cast<AnimatedSceneObject>( shared_from_this() );
    scene()->addPickMapping( body_, self );
    return self;
}
Esempio n. 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);

}
Esempio n. 4
0
bool testTransparentVertexAlphaMore(E_DRIVER_TYPE driverType)
{
	IrrlichtDevice *device = createDevice(driverType, dimension2d<u32>(160, 120));
	if (!device)
		return true;

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

	if (driver->getColorFormat() != video::ECF_A8R8G8B8)
	{
		device->closeDevice();
		device->run();
		device->drop();
		return true;
	}

	logTestString("Testing driver %ls\n", driver->getName());

	IAnimatedMesh* mesh = smgr->getMesh("../media/sydney.md2");
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
	IMeshSceneNode* cube = smgr->addCubeSceneNode(10.0f,0,-1,vector3df(-5,3,-15));

	if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setFrameLoop(0, 310);
		node->setMaterialTexture( 0, driver->getTexture("../media/sydney.bmp") );
	}
	if (cube)
	{
		cube->getMaterial(0).MaterialType = EMT_TRANSPARENT_VERTEX_ALPHA;
		cube->setMaterialTexture(0, driver->getTexture("../media/wall.bmp"));
		cube->setMaterialFlag(EMF_LIGHTING, false);
		smgr->getMeshManipulator()->setVertexColorAlpha(cube->getMesh(),128);
	}
	// second cube without texture
	cube = smgr->addCubeSceneNode(10.0f,0,-1,vector3df(5,3,-15));
	if (cube)
	{
		cube->getMaterial(0).MaterialType = EMT_TRANSPARENT_VERTEX_ALPHA;
		cube->setMaterialFlag(EMF_LIGHTING, false);
		smgr->getMeshManipulator()->setVertexColorAlpha(cube->getMesh(),128);
	}

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

	driver->beginScene(true, true, SColor(0,200,200,200));
	smgr->drawAll();
	driver->endScene();

	bool result = takeScreenshotAndCompareAgainstReference(driver, "-transparentVertexAlphaChannelMore.png", 99.18f);

	device->closeDevice();
	device->run();
	device->drop();

	return result;
}
Esempio n. 5
0
IAnimatedMeshSceneNode* Level::createNode(
    const LevelConfig::Model& model, u32 position)
{
    IAnimatedMeshSceneNode* node = _game->getDevice()->getSceneManager(
                                   )->addAnimatedMeshSceneNode(model.Mesh, _rootNode,
                                           -1, _board->getPosition(position));
    node->setAnimationSpeed(model.AnimationSpeed);
    return node;
}
Esempio n. 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"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;
}
Esempio n. 7
0
static ISceneNode* addNinja(ISceneManager* smgr, core::vector3df pos)
{
	IAnimatedMeshSceneNode* ninja = smgr->addAnimatedMeshSceneNode(
		smgr->getMesh("Assets/model/ninja/ninja.b3d"));
	ninja->setFrameLoop(182, 204);
	ninja->setMaterialFlag(video::EMF_LIGHTING, false);
	ninja->setAnimationSpeed(12);
	ninja->setPosition(pos);

	return ninja;
}
Esempio n. 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"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;
}
Esempio n. 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"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;
}
Esempio n. 10
0
//loads the player and sets initial position
IAnimatedMeshSceneNode* Player::loadPlayerNode(IrrlichtDevice* device, ISceneManager* smgr) 
{
	IAnimatedMesh* player = smgr->getMesh("Assets/player.x");
	if (!player) { device->drop(); return NULL; }
	IAnimatedMeshSceneNode *plyrNode = smgr->addAnimatedMeshSceneNode(player);
	for (int i = 0; i < plyrNode->getMaterialCount(); i++)
	{
		plyrNode->getMaterial(i).NormalizeNormals = true;
	}
	plyrNode->setPosition(vector3df(5.0f, 0.1f, 5.0f));

	return plyrNode;
}
Esempio n. 11
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;
}
bool CRaycastTankExample::OnEvent(const SEvent& event)
{
	if (!device)
		return false;

    switch(event.EventType)
    {
        case EET_MOUSE_INPUT_EVENT:
        {
            if(event.MouseInput.Event==EMIE_RMOUSE_PRESSED_DOWN)
            {
                shootSphere(vector3df(0.2,0.2,0.2), 0.2);
            }
        }
        break;

        case EET_KEY_INPUT_EVENT:
        {
            KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
            if(event.KeyInput.Key == KEY_KEY_P && event.KeyInput.PressedDown == false)
            {
                world->pauseSimulation(!world->simulationPaused());
            }

            else
            if(event.KeyInput.Key == KEY_KEY_R && event.KeyInput.PressedDown == false)
            {
                // Re-Spawn our tank at the original location.
                irr::core::matrix4 mat;
                mat.setTranslation(spawnPoint);
                tank->setWorldTransform(mat);
                tank->setAngularVelocity(vector3df(0,0,0));
                tank->setLinearVelocity(vector3df(0,0,0));
            }

            if(event.KeyInput.Key == KEY_SPACE && event.KeyInput.PressedDown == false)
            {
                IAnimatedMeshSceneNode *node = static_cast<IAnimatedMeshSceneNode*>(tank->getCollisionShape()->getSceneNode());
                vehicle->getRigidBody()->applyImpulse(vector3df(0,0,-500), node->getJointNode("Muzzle")->getPosition(), ERBTS_LOCAL);
                createMuzzleFlash(node->getJointNode("Muzzle"));
            }

        }
        break;
        default:
            break;
    }
    return false;


}
Esempio n. 13
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;
}
Esempio n. 14
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;
}
Esempio n. 15
0
int main()
{
	MyIrrlichtComposition mDevice(video::EDT_SOFTWARE,dimension2d<u32>(800,600 ));

	mDevice.AddBackground("background.png");

	IAnimatedMeshSceneNode* node = mDevice.mLoadMesh(vector3df(0,10,0),vector3df(0,-90,0),vector3df(0.2,0.2,0.2),"raven.md2","raven.jpg");
	const int count=5;
	IAnimatedMeshSceneNode* plat[count+1];
	for(int i(0);i<count;++i)
		plat[i] = mDevice.mLoadMesh(vector3df(-41+i*20, -20+i*10, 0),vector3df(30,0,0),vector3df(2.5,2.5,2.5),"platform02.obj","platform00.tga");
	
	mDevice.AddCamera();
	//u32 then = mDevice()->getTimer()->getTime();
	f32 g=-0.2;

	while(mDevice()->run())
	{
		g-=0.002;
 
		// двигаем ее текущую позицию вправо или влево
		if(mDevice.receiver.IsKeyDown(irr::KEY_KEY_A)) 
			mDevice.ObjMoving(node, vector3df(0,0,-0.25));
		else if(mDevice.receiver.IsKeyDown(irr::KEY_KEY_D))
			mDevice.ObjMoving(node, vector3df(0,0,0.25));

		//считываем для выхода
		if(mDevice.receiver.IsKeyDown(irr::KEY_ESCAPE))
			return 0;
		
		//"гравитация"
		mDevice.ObjMoving(node, vector3df(0,g,0));
		//движение камеры
		mDevice.SetCamera(vector3df(0, node->getPosition().Y, 0));
		mDevice.MoveCamera(vector3df(0 , node->getPosition().Y, node->getPosition().Z + 50));

		//перенос игрока на другую сторону при вылете за пределы поля
		if(node->getPosition().X == -45)
			mDevice.ObjMoving(node, vector3df(0, 0, -90));
		else if(node->getPosition().X == 45)
			mDevice.ObjMoving(node, vector3df(0, 0, 90));

		//обработка столкновения и "прыжок"
		for(int i(0);i<count;++i)
			if(mDevice.mCollision(node,plat[i]))
				g=0.2;
		
		//выход, если слишком сильно упал
		f32 fall=-150;
		if (node->getPosition().Y>fall - 5 && node->getPosition().Y<fall + 5)
			return 0;

		//обработка сцены
		mDevice.ShowScene();
	}

	mDevice()->drop();
	
	return 0;
}
Esempio n. 16
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 );

}
Esempio n. 17
0
bool    PlayerObject::initWithLevel(int level)
{
    //    IMesh* mesh = _assets->getMesh(PLAYER, MESH, 0);
    //    if (!mesh)
    //	return false;
    //
    //    IMeshSceneNode* node = _smgr->addMeshSceneNode(mesh);
    //    _node = node;
    //    if (node)
    //    {
    //	node->setMaterialFlag(EMF_LIGHTING, true);
    ////	node->setMaterialFlag(EMF_FOG_ENABLE, true);
    //	    node->setMaterialTexture(0, _assets->getTexture(PLAYER, TEXTURE, 0));
    ////	for (int i = 0; i < 9; i++)//TODO : comment faire pour ne pas mettre le nombre de textures en dur
    ////	{
    ////	    node->setMaterialTexture(0, _ressources->getTexture(PLAYER, TEXTURE, 0));
    ////	}
    //
    //	this->scaleOnCase();
    //	this->updateNodePosition();
    //	return true;
    //    }    
    
    _level = level;
    
    IAnimatedMesh* mesh = static_cast<IAnimatedMesh*>(_assets->getMesh(PLAYER, MESH, _level));
    if (!mesh)
	return false;
    
    IAnimatedMeshSceneNode* node = _smgr->addAnimatedMeshSceneNode(mesh, getParentNode(), NODE_ID_PLAYER);
    _node = node;
    if (node)
    {
	node->setMaterialFlag(EMF_LIGHTING, false);
	//	node->setMaterialFlag(EMF_FOG_ENABLE, true);
	startNewAnim(EMAT_STAND, REPEAT);
	startNewAnim(EMAT_SALUTE, ONCE);
	//	node->setMD2Animation(EMAT_STAND);
	
	this->scaleOnCase();
	this->updateNodePosition();
	node->setMaterialTexture(0, _assets->getTexture(PLAYER, TEXTURE, _level));
	return true;
    }    
    return false;
}
SceneObject* PhysicsSim::loadSceneObject(stringw mesh_file, stringw texture_file)
{
	IAnimatedMesh *mesh = smgr->getMesh(mediaDirectory + mesh_file);

	IAnimatedMeshSceneNode* Node = smgr->addAnimatedMeshSceneNode(mesh, smgr->getRootSceneNode());
	stringw tex_file = texture_file;
	if(tex_file == L"")
	{
		tex_file = mesh_file;
		if(tex_file.find(".dae") > -1)
			tex_file.remove(".dae");
		if(tex_file.find(".3ds") > -1)
			tex_file.remove(".3ds");
		tex_file.append(".jpg");
	}
	tex_file = mediaDirectory + tex_file;
	if(smgr->getFileSystem()->existFile(tex_file))
		Node->setMaterialTexture(0, driver->getTexture(tex_file));
	Node->setMaterialFlag(EMF_LIGHTING, true);
	Node->setMaterialFlag(EMF_TEXTURE_WRAP, false);
	Node->setMaterialFlag(EMF_BACK_FACE_CULLING, true);
	Node->addShadowVolumeSceneNode(0,-1,false);
	Node->getMaterial(0).AmbientColor.set(255,255,255,255);

	updateObjects();
	return Node;
}
Esempio n. 19
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();
}
Esempio n. 20
0
void Game::addCheckPoint(const vector3df& position, const vector3df& rotation)
{
	string<char> str = "checkpoint" + checkpoint->size();
	IAnimatedMesh *cp1 = smgr->addHillPlaneMesh(str.c_str(), dimension2d<f32>(1000,1000), dimension2d<u32>(1,1));
	IAnimatedMeshSceneNode *c = smgr->addAnimatedMeshSceneNode(cp1);
	c->setRotation(rotation);
	c->setPosition(position);
	//c->setDebugDataVisible(EDS_BBOX);
	checkpoint->push_back(c);
	
	if (checkpoint->size() == 1)
	{
		first_checkpoint = c;
	}
	
	c->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);
	//c->setMaterialFlag(EMF_BACK_FACE_CULLING, false);
}
Esempio n. 21
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;
}
Esempio n. 22
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";
}
Esempio n. 23
0
IAnimatedMeshSceneNode* getModel(ISceneManager* smgr, IVideoDriver* drv) {
	//load mesh
	IAnimatedMesh* mesh = smgr->getMesh("../model/box.obj");
	
	//set mesh to new node
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
	
	//if node is created, add some texture on it
	if(node) {
		node->setMaterialFlag(EMF_LIGHTING, false);
		//node->setMaterialTexture(0,drv->getTexture("../model/kuva2.bmp"));
		//node->setMaterialType( EMT_SOLID );
		node->setMaterialFlag(EMF_BACK_FACE_CULLING, false);
		node->setMaterialFlag(EMF_FRONT_FACE_CULLING, false);
		std::cout << "node ok\n";
	}
	
	return node;
}
Esempio n. 24
0
int main()
{

   IrrlichtDevice *device =
      createDevice( video::EDT_OPENGL, dimension2d<u32>(800, 600));


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

        smgr->addCameraSceneNode(0, vector3df(0,10,-10), vector3df(0,5,0));

        IAnimatedMesh* mesh = smgr->getMesh("ninja.b3d");
   IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
   node->setMaterialFlag(EMF_LIGHTING, false);
   node->setMaterialTexture( 0, driver->getTexture("nskinrd.jpg") );
        node->setRotation(vector3df(0,180,0)); // let ninja be in front to us

        node->setJointMode(EJUOR_CONTROL); // tell irrlicht that you want to control joint positions

        IBoneSceneNode* bone = node->getJointNode("Joint10"); // create IBoneSceneNode and select the desired bone

   while(device->run()) {
            bone->setRotation(bone->getRotation() + vector3df(1,0,0)); // rotate bone

            driver->beginScene();
            smgr->drawAll();
            driver->endScene();
   }


   device->drop();

   return 0;
}
Esempio n. 25
0
void Game::setupHud(){
  IAnimatedMesh* gunmesh = smgr->getMesh("resources/models/weapons/test.obj");
  IAnimatedMeshSceneNode* gunnode;
  if(gunmesh)
  {
             gunnode = smgr->addAnimatedMeshSceneNode(gunmesh, gunnode);
             gunnode->setParent(camera);
             gunnode->setPosition(vector3df(50, 0, 1000));
             gunnode->setRotation(vector3df(0, 0, 1000));
             gunnode->updateAbsolutePosition();
             std::cout << gunnode->getAbsolutePosition().X << ", " << gunnode->getAbsolutePosition().Y << ", "
            << gunnode->getAbsolutePosition().Z;
             //gunnode->setScale(vector3df(1, 1, 1));
  }
}
void PhysicsSim::drawVector(Vector3D init, Vector3D end, Color c)
{
	Vector3D vec = end-init;
	float length = vec.getLength();

	stringw meshname("ArrowMesh");
	meshname += (int)arrows.size();
	IAnimatedMesh* arrow = smgr->addArrowMesh (meshname, c, c, 4, 8, length, (length - 0.4 < 0.0) ? length*0.4 : (length-0.4));
	IAnimatedMeshSceneNode *arrownode =	smgr->addAnimatedMeshSceneNode(arrow);

	arrownode->setPosition(init);

	//arrownode->setScale(vector3df(1.0, length, 1.0));

	vec.normalize();
	quaternion q;
	q.rotationFromTo(vector3df(0,1,0), vec);
	vector3df rot;
	q.toEuler(rot);

	arrownode->setRotation(vector3df(rot.X*180.0/M_PI, rot.Y*180.0/M_PI, rot.Z*180.0/M_PI));

	arrows.push_back(arrownode);
}
Esempio n. 27
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;
}
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);
}
Esempio n. 29
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;
}
Esempio n. 30
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;
}