Preliminary analysis and research on irrlicht Game Engine

Source: Internet
Author: User

The irrlicht game engine is mainly designed by Nikolaus Gebhardt ordid. It is an open-source project on SourceForge and a famous open-source game 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 ". This project has been running since 2004. You can find it on this websiteSource codeFor more information, see http://irrlicht.sourceforge.net /.

 
<! -- [If! Supportlists] --> L <! -- [Endif] --> main technical features
Irrlicht is a 3D Game Engine written by C ++.CodeWell encapsulated, so this engine can be used on multiple platforms, such as Windows and Linux.

The engine uses the com-like middleware encapsulation technology, which ensures the cross-platform usage and scalability of the engine, that is, when the engine is modified internally, the original game logic code can be used normally without changing a line of code. When you need to add new technical features to the engine, you only need to comply with its specifications and interfaces to easily add new features.

All classes can implement serializing and dynamicly creating. This feature can save the running engine status as a file, and then restore the engine status from the file.

A common problem with the 3D engine is speed, while the IRR game engine is very fast.

 
 
<! -- [If! Supportlists] --> L <! -- [Endif] --> engine Basic Architecture Analysis
The engine base layer is composed of a series of virtual base classes, which provide basic interfaces for the upper class, and the basic architecture of the entire engine is built by the structure and virtual base class, the engine only needs to implement the virtual functions inherited from the virtual base class.

The entire engine architecture is very delicate. It is not only an example of object-oriented programming, but also a model for the use of C ++ language. Because the author still lacks a thorough understanding of the engine, he can only talk about the engine architecture in the general direction.

The engine can be divided into initialization and system modules, core modules, Gui modules, input and output modules (IO), and scene management modules (scene) and the video module ). The engine does not contain a sound system. The sound system of this engine is provided by an additional sound plug-in irrklang.

 
<! -- [If! Supportlists] --> U <! -- [Endif] --> initialization and system module:

<! -- [If! Supportlists] --> A) <! -- [Endif] --> the iunknown class is the base class of most classes. Its main function is to provide reference counting and class names in debug mode.

<! -- [If! Supportlists] --> B) <! -- [Endif] --> itimer provides time access and control for game timing. (Game timing is very important for games .)

<! -- [If! Supportlists] --> C) <! -- [Endif] --> the interface provided by ieventreceiver can be used to receive messages, such as mouse, keyboard, or custom messages.

<! -- [If! Supportlists] --> d) <! -- [Endif] --> the irrlichtdevice class is the engine manager. After calling the createdevice function, a pointer to this class is returned to obtain control of the engine. Ivideodriver, iguienvironment, iscenemanager, ifilesystem, and other important classes are created by ivideodriver.

 
<! -- [If! Supportlists] --> U <! -- [Endif] --> core ):

It mainly includes storage and operations of arrays, vectors, 2D coordinates, 3D coordinates, and strings.

 
<! -- [If! Supportlists] --> U <! -- [Endif] --> GUI module (GUI ):

The irrlicht engine provides a graphical interface, which eliminates the need to attach a GUI to the game. The GUI interface provided by the irrlicht engine is not related to the operating system and can be used across platforms. However, the GUI interface provides limited functions and is not highly appealing, A bug occurred during use, which caused the system to crash. I believe this bug is caused by lack of compatibility with Windows platforms.

 
<! -- [If! Supportlists] --> A) <! -- [Endif] --> first, it provides basic GUI elements and their operations, such as window, button, checkbox, editbox, ListBox, and scrollbar. These classes are derived from the iguielement class. iguielement provides general interface element operation interfaces, such as setvisible and move.

<! -- [If! Supportlists] --> B) <! -- [Endif] --> iguielementfactory provides the GUI with the dynamic creation function, which allows you to create a graphical interface based on the name and ID.

<! -- [If! Supportlists] --> C) <! -- [Endif] --> the iguienvironment class is the hub of the entire graphic interface module. It is used to add, manage, and draw various GUI elements. When the game needs to draw the interface, call the drawall method to draw all interfaces.

 
<! -- [If! Supportlists] --> U <! -- [Endif] --> input/output module (IO ):

This module provides the engine with the file read/write function and integrates the read/write of zip files. This module

It also provides a lightweight XML file analyzer that is fast and convenient for game development, such as recognition of RPG Game scripts and storage of game scenarios.

The ifilesystem class is responsible for coordinating and managing this class.

 
<! -- [If! Supportlists] --> U <! -- [Endif] --> Scenario Management Module (scene ):

Scenario management is the key to the entire engine. It manages all images as scene nodes, including the animation mesh, the bill board, the camera, and the mesh), particle system and shadow volume.

This module is also responsible for collision detection. It provides an easy-to-use programming interface.

It is mainly composed of three main types: iscenenode class family, which are all scene nodes inherited from the iscenenode class; grid model (mesh) class family, responsible for the regular operations of mesh models from File Import to memory and mesh; there is also an animation mesh, which can recognize mesh models with animated frames, the supported formats include b3d, md2, md3, X, ms3d, and BSP.

The icamerascenenode class can receive messages, so that you can control game screen switching through the mouse and keyboard.

The iscenemanager class is the manager of this module. It manages all scene nodes, grid model resources, viewfinder, and all other screen effects.

 
<! -- [If! Supportlists] --> U <! -- [Endif] --> display module (video ):

This module mainly provides the function of operating the graphics card driver.

The ivideodriver class is the core of this module. After the beginscene method is called, the image will be rendered and output to the display.

 
Previously I mentioned that this engine uses com-like encapsulation. It encapsulates everything in the engine and only sets aside interfaces. Call the global function creatdevice to obtain an instance pointer of the irrlichtdevice class. Then, this class creates instances of multiple important classes, such as ivideodriver, iguienvironment, iscenemanager, and ifilesystem. The irrlichtdevice class provides pointers for accessing these class instances. Then, you can use these pointers to access these instances. When you need to access other classes, you must use these classes to create other class instances and Their pointers to access them. In addition, instances of these classes cannot appear in the game logic, because the header files provided, that is, their interfaces, are declared as pure virtual functions, all classes must use the create ** function family to create instances and use the create ** function to create classes. when not in use, you must call the drop function to release the classes, if you do not call drop, the resources occupied by the instance will not be released. When you want to reference a class, you must call the grab function to add references to it. This is because the engine manages a large number of objects, and it does not know when resources can be released. once resources are released repeatedly or missing, the engine may crash. Each subclass inherited by the iunknown class has the grab and drop functions, and a reference count is maintained internally. When the grab function is called, this reference count is added, when the drop function is called, the reference count is reduced. When the count is 0, the object is released.

 
<! -- [If! Supportlists] --> L <! -- [Endif] --> use of basic Engine Features
 
<! -- [If! Supportlists] --> n <! -- [Endif] --> typical usage
This code is a typical use of IRR. Other usage methods are built on this basis, but more complex control logic is added.


# Include <irrlicht. h>
Using namespace IRR;

Int main ()
{
// Create an engine
Irrlichtdevice * Device = createdevice (Video: edt_direct3d8,
Core: dimension2d <s32> (640,480 ));

Video: ivideodriver * driver = device-> getvideodriver ();
Scene: iscenemanager * scenemgr = device-> getscenemanager ();
// Load the quake2. md2 Model
Scene: iscenenode * node = scenemgr-> addanimatedmeshscenenode (
Scenemgr-> getmesh ("quake2model. md2 "));

// Add materials and luminous Effects
If (node)
{
Node-> setmaterialtexture (0, driver-> gettexture ("texture.bmp "));
Node-> setmaterialflag (Video: emf_lighting, false );
}

// Add an FPS viewfinder.
Scenemgr-> addcamerascenenodefps ();

// Draw everything and start the game loop
While (device-> Run () & driver)
{
Driver-> beginscene (true, true, video: scolor (255, 0, 0,255 ));
Scenemgr-> drawall ();
Driver-> endscene ();
}

// Exit the engine
Device-> drop ();
Return 0;
}

<! -- [If! Supportlists] --> n <! -- [Endif] --> Collision Detection
The most common thing in the game is collision detection.


Scene: itriangleselector * selector = 0;
If (q3node)
{
Q3node-> setposition (core: vector3df (-1350,-130,-1400 ));
Selector = smgr-> createocttreetriangleselector (q3levelmesh-> getmesh (0), q3node, 128 );
Q3node-> settriangleselector (selector );
Selector-> drop ();
}
Scene: icamerascenenode * camera =
Smgr-> addcamerascenenodefps (0, 100366f, 300366f,-1, 0, 0, true );
Camera-> setposition (core: vector3df (-150, 50 ));

// This statement is important. It creates a detector and adds it to the camera node.
Scene: iscenenodeanimator * anim = smgr-> createcollisionresponseanimator (
Selector, camera, core: vector3df (30,50, 30 ),
Core: vector3df (0,-3, 0 ),
Core: vector3df (0, 20, 0 ));
Camera-> addanimator (anim );
Anim-> drop ();


<! -- [If! Supportlists] --> n <! -- [Endif] --> special effect usage
A game may require a lot of special effects. This code is used to create a luminous body for flying around.


// Create a surround flight light first
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 ();

// Then paste the billboard effect to the light. The billboard effect is to create a texture that uses the texture and looks the same in any direction. It is usually used to create a particle effect.
Node = smgr-> addbillboardscenenode (node, core: dimension2d <f32> (50, 50 ));
Node-> setmaterialflag (Video: emf_lighting, false );
Node-> setmaterialtype (Video: emt_transparent_add_color );
Node-> setmaterialtexture (0, driver-> gettexture ("http://www.cnblogs.com/media/particlewhite.bmp "));

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/hellphenix/archive/2008/03/19/2198226.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.