Ich habe das Einsteigertutorial etwas verdichtet und zeige in der Darstellungsschleife zwischen begin und end die 20 verschiedenen Darstellungsmöglichkeiten für das bekannte Quake2 Model.
Code:
/* VideoDriver, GUIEnvironment, SceneManager. */
#include <iostream>
#include <irrlicht.h>
#include <windows.h>
using namespace irr; using namespace core; using namespace scene;
using namespace video; using namespace io; using namespace gui;
/* http://irrlicht.sourceforge.net/docu/namespaces.html */
/* To use Irrlicht.DLL, link Irrlicht.lib in project settings or by pragma comment */
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif
int main()
{
IrrlichtDevice *device = createDevice(
video::EDT_DIRECT3D9, // EDT_SOFTWARE, EDT_BURNINGSVIDEO, EDT_NULL, EDT_DIRECT3D8, EDT_OPENGL
dimension2d<s32>(640,480), // windowSize
32, // bits per pixel when in fullscreen mode
false, // fullscreen mode: true, window mode: false
false, // stencilbuffer
false, // vsync
0); // eventReceiver
/* caption of the window, wchar strings used, not visible in fullscreen mode */
device->setWindowCaption( L"Irrlicht Engine 1.4.1 - Demo für VideoDriver, GUI-Environment, Scene-Manager" );
/* video driver, SceneManager, GUI environment */
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
/* label using the GUI environment */
guienv->addStaticText(
L"This is your first tutorial. Have fun!", // text
rect<s32>(10,10,100,50), // rectangle
true); // 3D-border
/* load and display Quake2 model "Sydney" (modelled by Brian Collins):
get the Mesh from the Scene Manager and add a SceneNode to display the mesh.
also possible: Maya object file (.obj), Quake3 map (.bsp), Milkshape file (.ms3d) */
IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
if(node)
{
node->setMaterialFlag ( EMF_LIGHTING, false ); //disable lighting (no dynamic light)
node->setMD2Animation ( scene::EMAT_CROUCH_WALK ); //animation frame loop: looped between the frames 0 and 310
node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") ); //texture for the mesh
}
/* camera at position (0, 30, -40). The camera looks from there to (0,5,0). */
smgr->addCameraSceneNode(0, vector3df(30,30,-30), vector3df(0,5,0));
/* draw: device runs in a while() loop, until window is closed (by X or Alt+F4) */
int alpha = 250;
int red = 10;
int green = 30;
int blue = 100;
driver->beginScene(true, true, SColor(alpha,red,green,blue));
while( device->run() )
{
/* draw between beginScene() and endScene().
beginScene clears the screen with a color and also the depth buffer if wanted.
Scene Manager and GUI Environment draw their content.
endScene() puts everything on the screen. */
int alpha = 200;
int red = 0;
int green = 30;
int blue = 200;
unsigned int t = (device->getTimer())->getTime();
static short int c=0;
if(t>3000)
{
++c;
node->setMD2Animation ( EMD2_ANIMATION_TYPE(c) );
std::cout << EMD2_ANIMATION_TYPE(c) << std::endl;
(device->getTimer())->setTime(0);
if (c>=20) c=0;
}
driver->beginScene(true, true, SColor(alpha,red,green,blue));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
/* delete the Irrlicht Device, because all objects created with 'create...' must be deleted.
The object is simply deleted by calling ->drop(). See the documentation at
http://irrlicht.sourceforge.net//docu/classirr_1_1IUnknown.html#a3 */
device->drop();
}