I. Introduction
The irrlicht engine is a high-performance real-time 3D engine written in C ++. It can be used in C ++ProgramOr. NET language. By using direct3d (Windows Platform), OpenGL 1.2 or its own software coloring program, the engine can be fully cross-platform. Despite being open-source, the irrlicht Library provides artistic features that can be used on commercial 3D engines, such as dynamic shadows, particle systems, role animation, indoor and Outdoor technologies and collision detection (see figure 1 ).
|
Figure 1. irrlicht 3D Engine |
Irrlicht is the name of an animal in a German mythical story. It can shine and fly and be found near most of the swamp. The word "irrlicht" is a combination of two German words ("IRR" means crazy, and "Licht" means light. In English, it is translated as "Ghost fire ".
Irrlicht is fortunate to be supported by a large number of projects for an active development team. However, irrlicht is designed primarily by the game guru Nikolaus Gebhardt, so the game is very coherent in design. You can find irrlicht enhancement programs everywhere on the Internet, such as optional terrain generators, entry generators, output generators, world layer generators, related tutorials and editors. Moreover, it independently creates bindings to Java, Perl, Ruby, basic, Python, Lua, and even more languages. The most important thing is that it is completely free.
Ii. irrlicht features
Before in-depth analysis of the API, let me introduce more specifically what functions irrlicht provides to 3D Game Developers:
· An engine that can run on Linux, Windows 98, me, NT, 2000, XP (MACOs is under planning), and other operating systems
· Provides anti-aliasing support for direct3d 8 generator or direct3d 9 generator (optional)
· Skin-changing GUI environment (including a cool metallic shadow skin), with beautiful appearances for some vintage dialogs
· Scenario Management System, which allows seamless indoor/outdoor transition
· Role animation system with skeleton and deformation target animation Functions
· A special effect system, including particle effects (rain, smoke, fire, snow, etc.), notice boards, light maps, environments, maps, template buffer shadows, fog, texture animations, parallax texture, concave & convex texture, and more
· Built-in material support, including support for pixel and vertex shaders versions 1.1 to 3.0, ARB fragment and vertex programs, and HLSL (glsl is under Planning)
·. NET language binding, which enables the engine to be used in all. NET languages such as C #, Visual Basic. net, and Delphi. net.
· A built-in platform-independent software generator with features: Z-buffering, Gouraud shadow, Alpha mixing and transparency, and fast 2D plotting (see figure 2)
· Your long-awaited 2D drawing functions, such as alpha mixing, key-color-based bitmap copying, font painting, and hybrid 3D and 2D graphics
· Direct import of common modeling file formats: Maya, 3 dstudio Max, Collada, deled, milkshape, quake 3 levels, quake2 models, DirectX, Pulsar, my3dtools, fsrad, and cartography shop
· Imports textures directly from BMP, PNG, Photoshop, JPEG, Targa, and PCX
· Fast and easy-to-use collision detection and response
· Optimized the Rapid 3D operations and container Template Library
· Directly read the file (which can be compressed, for example, A. ZIP file)
· Integrated quick XML Analyzer
· Unicode support for easy local development
Figure 2: irrlicht-based game yet another space shooter (yass), which shows the surprising coloring effect in a static game Frame
Iii. Special Effects in irrlicht
In the example in this article, I will show you how to use the template buffer Shadow technology, as well as particle systems, billboards, dynamic light, and water surface scene nodes. See figure 3.
|
Figure 3. Scene coloring with dynamic light and water |
The irrlicht engine automatically checks whether your hardware supports template buffering. If not, the shadow is not enabled. In this demo, The 'shaddones' flag in method createdevice () is set to generate a dynamic shadow cast from an animated role. If this instance program runs too slowly on your PC, you can set this flag to false or simply buy a better Graphics Accelerator card.
To use the irrlicht. dll file, you need to link to the irrlicht. Lib library file. You can set this option in the Project Settings dialog box. However, to facilitate implementation, you can use a pragma pre-compile annotation command. The createdevice () method is used to instantiate the root object-it uses the engine to complete everything. The parameters are as follows:
· Devicetype: device type. You can select a null device and a soft device, such as directx8, directx9, or OpenGL.
· Windowsize: the size or full screen mode of the window to be created. In this example, 512x384 is used.
· Bits: the number of bits per pixel (when the screen is full ). Only 16 or 32 values are allowed.
· Fullscreen: Specifies whether you want the device to run in full screen mode.
· Stencilbuffer: Specifies whether you want to use the template buffer to draw shadows.
· Vsync: Specifies whether you want to start vsync (only on the full screen). Optional.
· Eventreceiver: an object that receives events. Optional.
To suit the environment of this instance, you will load a 3D Studio Max file (a house ). The house looks nothing special, but the irrlicht engine can create a cool texture map for you. You only need to use the shape control tool and create a planar texture map for it:
# Include <irrlicht. h> # Include <iostream> Using namespace IRR; # Pragma comment (Lib, "irrlicht. lib ") Int main () { // Let's assume that the user uses OpenGL in this example. // Of course, you can also specify DirectX 8, 9, and so on. Video: e_driver_type drivertype = video: edt_opengl; // Create a device. If the device fails to be created, exit immediately. Irrlichtdevice * Device = createdevice (drivertype, Core: dimension2d (640,480), 16, false, true ); If (device = 0) Return 1; Video: ivideodriver * driver = device-> getvideodriver (); Scene: iscenemanager * smgr = device-> getscenemanager (); |
I am not satisfied with the effect of the light emitting color produced from this import file. BelowCodeShow how to implement these steps:
Scene: ianimatedmesh * mesh = smgr-> getmesh ("room.3ds "); Smgr-> getmeshmanipulator ()-> makeplanartexturemapping ( Mesh-> getmesh (0), 0.008f ); Scene: iscenenode * node = 0; Node = smgr-> addanimatedmeshscenenode (mesh ); Node-> setmaterialtexture (0, driver-> gettexture ("wall.jpg ")); Node-> getmaterial (0). emissivecolor. Set (0, 0, 0 ); |
4. Water Animation
The first special effect you add is a water animation. To this end, watersurfacescenenode imports a styling file and changes it as if it were a water meter. If you want the scene node to use a very good material such as mt_reflection_2_layer, it looks cool:
Mesh = smgr-> addhillplanemesh ("Myhill ", Core: dimension2d (20, 20 ), Core: dimension2d (40, 40), 0, 0, Core: dimension2d (0, 0 ), Core: dimension2d (10, 10 )); Node = smgr-> addwatersurfacescenenode (mesh-> getmesh (0), 3,300, 30 ); Node-> setposition (core: vector3df (0, 7, 0 )); Node-> setmaterialtexture (0, driver-> gettexture ("water.jpg ")); Node-> setmaterialtexture (1, driver-> gettexture ("stones.jpg ")); Node-> setmaterialtype (Video: emt_reflection_2_layer ); |
As an input shape, you can create a steep plane shape, but you can also use any other shape for this. You can even reuse the room.3ds input file (it looks strange ). This example also uses a General Stone texture model to draw all other surfaces.
5. Transparent billboards and lights
The second special effect is very basic but very useful: a transparent notice board with a dynamic light. To achieve this effect, you only need to generate a scene node and let it fly around. In addition, to make it look cooler, you can attach a notice board scene node to it:
// Create a light Node = smgr-> addlightscenenode (0, core: vector3df (0, 0 ), Video: scolgrading (1.0f, 0.6f, 0.7f, 1.0f), 600366f ); Scene: iscenenodeanimator * anim = 0; Anim = smgr-> createflycircleanimator (core: vector3df (0,150, 0), 250366f ); Node-> addanimator (anim ); Anim-> drop (); // Attach the notice board to the light Node = smgr-> addbillboardscenenode (node, core: dimension2d (50, 50 )); Node-> setmaterialflag (Video: emf_lighting, false ); Node-> setmaterialtype (Video: emt_transparent_add_color ); Node-> setmaterialtexture (0, driver-> gettexture ("maid ")); |
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. Okay. Here is your code that produces the dynamic shadow effect:
Mesh = smgr-> getmesh (".../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 (".../../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 the number of frames per second (FPS) on the title bar. This 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.
· The dusty engine allows programmers to create "tasks"-these "tasks" can do whatever they want. 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.