Cross-platform game development using C ++: irrlicht engine (3)

Source: Internet
Author: User

Vi. Particle System

The special effect described below is more interesting: a particle system. In the irrlicht engine, the particle system is both componentized and scalable, but still easy to use. You just need to put the particle transmitter in a particle system scene node, so that the particle seems to have no source. These transmitters can be flexibly configured as needed and often carry many parameters, such as particle direction, number of particles, and particle color.

Of course, there are differences in the transmitter type (for example, a point transmitter can enable particles to emit particles from a fixed point ). If the engine provides particle transmitters that do not meet your requirements, you can easily create your own transmitters. This simply derives a new class from the iparticleemitter interface and attaches it to the particle system using the setemitter () method.

The next instance will create a box of particle transmitters. You may have guessed that it randomly generates particles from a jumping box. The parameter defines the box, particle direction, minimum and maximum number of particles generated per second, color, and minimum and maximum lifecycle of particles.

A particle system completely composed of transmitters will be annoying because of lack of realism. Therefore, irrlicht supports particle influencers-which are responsible for trimming particles when they fly everywhere. Once added to the particle system, they can mimic other more realistic effects, such as gravity or wind. In this example, the particle influencer simply modifies the color of the particle to produce a fade-out effect.

You may have guessed that the particle influencer is implemented by deriving the iparticleaffector interface and then adding it to the particle system by using the addaffector () method. After you set a nice material for the particle system, you have a cool wild camping fire. By adjusting materials, textures, particle transmitters, and influencer parameters, you can easily create smoke, rain, explosion, snow, and other effects:

Scene: iparticlesystemscenenode * PS = 0;
PS = smgr-> addparticipant lesystemscenenode (false );
PS-> setposition (core: vector3df (-70, 60, 40 ));
PS-> setscale (core: vector3df (2, 2 ));
PS-> setparticle size (core: dimension2d (20366f, 10.0f ));
Scene: iparticleemitter * em = ps-> createboxemitter (
Core: aabbox3d ),
Core: vector3df (0.0f, 0.03f, 0.0f ),
80,100,
Video: scolor (0,255,255,255), video: scolor (0,255,255,255 ),
);
PS-> setemitter (EM );
Em-> drop ();
Scene: iparticleaffector * PAF = ps-> createfadeoutparticipant leaffector ();
PS-> addaffector (PAF );
PAF-> drop ();
PS-> setmaterialflag (Video: emf_lighting, false );
PS-> setmaterialtexture (0, driver-> gettexture, "maid "));
PS-> setmaterialtype (Video: emt_transparent_vertex_alpha );

VII. Shadow projection

Last but not least, you need to create a dynamic shadow for an animated role. Therefore, you can load a quake2.md2 model file and put it in your world. To create a shadow, you only need to call addshadowvolumescenenode (). You may call iscenemanager: setshadowcolor () to control the color of the Shadow. Note that this is only globally adjustable and affects all shadows. Well, the following figure shows your dynamic shadow effect.Code:

Mesh = smgr-> getmesh ("http://www.cnblogs.com/media/faerie.md2 ");
Scene: ianimatedmeshscenenode * anode = 0;
Anode = smgr-> addanimatedmeshscenenode (mesh );
Anode-> setposition (core: vector3df (-50, 45,-60 ));
Anode-> setmd2animation (Scene: emat_stand );
Anode-> setmaterialtexture (0, driver-> gettexture ("http://www.cnblogs.com/media/Faerie5.BMP "));
Anode-> addshadowvolumescenenode ();
Smgr-> setshadowcolor (Video: scolor ));

8. game loop

Finally, you can enter the game loop controlled by the device-> Run () method. This loop continues until you exit the device by getting a Close Window event, such as a ALT-F4 shortcut under a Windows operating system. You must draw everything between a beginscene () and an endscene () command pair. Beginscene () uses a specified color to clear the screen. If necessary, you can clear the depth buffer at the same time. Then you can let the scenario manager and GUI environment draw their content. With endscene () called, everything is drawn to the screen. In this example, you can dynamically display frames per second (FPS) on the title bar, which is very important for serious game developers:

Scene: icamerascenenode * camera = smgr-> addcamerascenenodefps ();
Camera-> setposition (core: vector3df (-50, 50,-150 ));
Int lastfps =-1;
While (device-> Run ())
{
Driver-> beginscene (true, true, 0 );
Smgr-> drawall ();
Driver-> endscene ();
Int FPS = driver-> getfps ();
If (lastfps! = FPS)
{
Core: stringw STR = l "campfire FX example [";
STR + = driver-> getname ();
STR + = "] FPS :";
STR + = FPS;
Device-> setwindowcaption (Str. c_str ());
Lastfps = FPS;
}
}
Device-> drop ();

After the loop ends, you must delete the irrlicht device that was previously created using the createdevice () method. By using the irrlicht engine, you should delete all the objects created by methods or functions starting with 'create. You can simply call device-> drop () to delete the device object.

9. The irrlicht plug-in you may like

As mentioned earlier, irrlicht has a group of diligent independent developers who have produced a large number of plug-ins and used it to develop a considerable number of games. Many of the improvements proposed by these developers are re-integrated into subsequent releases of irrlicht. I will list several examples below. I think this will attract many promising developers:

· Octtools is a set of tools used for irrlicht. It is created by Murphy McCauley and used to operate Oct files: outputers, loaders, and more.

· Ice (irrlicht General engine) is a development framework that provides an outline implementation of a project and accelerates the development of a new project.

· Mim, created by Murphy McCauley, is a very useful XML-based file format and can be used for irrlicht loaders, converters, and various tools.

· My3d is a development kit that enables you to directly output light Paster scenes from various 3D packages (3 dstudio Max, Giles, etc.) to irrlicht.

· Dusty engine allowsProgramMembers create "tasks"-these "tasks" can accomplish anything the programmer wants to do. Then, these tasks are added to a common task tree, and each task can have the desired number of child tasks. The task "group" allows game designers to perform common operations on a complete tree, such as pausing, continuing, or damaging the tree.

· Irrlicht RPG (Erring light) is a 3D walking game engine first developed for RPG games.

· 2D images and genie classes form a very useful library that extends irrlicht's 2d capabilities.

· The zenprogramming site provides the first informal External terrain Generator for irrlicht. Many related tutorials are also provided here.

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/huangchonghai/archive/2007/09/02/1768849.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.