From f9158592e1478b2013afc7041d9ed041cf2d2f4a Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Mon, 13 Jan 2014 19:47:58 +1000 Subject: Update Irrlicht to 1.8.1. Include actual change markers this time. lol --- .../irrlicht-1.8.1/examples/04.Movement/Makefile | 39 ++++ .../examples/04.Movement/Movement.cbp | 55 +++++ .../examples/04.Movement/Movement.dev | 59 +++++ .../examples/04.Movement/Movement.vcproj | 163 +++++++++++++ .../examples/04.Movement/Movement_vc10.vcxproj | 231 ++++++++++++++++++ .../examples/04.Movement/Movement_vc11.vcxproj | 235 +++++++++++++++++++ .../examples/04.Movement/Movement_vc8.vcproj | 231 ++++++++++++++++++ .../examples/04.Movement/Movement_vc9.vcproj | 230 ++++++++++++++++++ .../irrlicht-1.8.1/examples/04.Movement/main.cpp | 258 +++++++++++++++++++++ .../examples/04.Movement/tutorial.html | 188 +++++++++++++++ 10 files changed, 1689 insertions(+) create mode 100644 libraries/irrlicht-1.8.1/examples/04.Movement/Makefile create mode 100644 libraries/irrlicht-1.8.1/examples/04.Movement/Movement.cbp create mode 100644 libraries/irrlicht-1.8.1/examples/04.Movement/Movement.dev create mode 100644 libraries/irrlicht-1.8.1/examples/04.Movement/Movement.vcproj create mode 100644 libraries/irrlicht-1.8.1/examples/04.Movement/Movement_vc10.vcxproj create mode 100644 libraries/irrlicht-1.8.1/examples/04.Movement/Movement_vc11.vcxproj create mode 100644 libraries/irrlicht-1.8.1/examples/04.Movement/Movement_vc8.vcproj create mode 100644 libraries/irrlicht-1.8.1/examples/04.Movement/Movement_vc9.vcproj create mode 100644 libraries/irrlicht-1.8.1/examples/04.Movement/main.cpp create mode 100644 libraries/irrlicht-1.8.1/examples/04.Movement/tutorial.html (limited to 'libraries/irrlicht-1.8.1/examples/04.Movement') diff --git a/libraries/irrlicht-1.8.1/examples/04.Movement/Makefile b/libraries/irrlicht-1.8.1/examples/04.Movement/Makefile new file mode 100644 index 0000000..0dcd252 --- /dev/null +++ b/libraries/irrlicht-1.8.1/examples/04.Movement/Makefile @@ -0,0 +1,39 @@ +# Makefile for Irrlicht Examples +# It's usually sufficient to change just the target name and source file list +# and be sure that CXX is set to a valid compiler +Target = 04.Movement +Sources = main.cpp + +# general compiler settings +CPPFLAGS = -I../../include -I/usr/X11R6/include +CXXFLAGS = -O3 -ffast-math +#CXXFLAGS = -g -Wall + +#default target is Linux +all: all_linux + +ifeq ($(HOSTTYPE), x86_64) +LIBSELECT=64 +endif + +# target specific settings +all_linux: LDFLAGS = -L/usr/X11R6/lib$(LIBSELECT) -L../../lib/Linux -lIrrlicht -lGL -lXxf86vm -lXext -lX11 -lXcursor +all_linux clean_linux: SYSTEM=Linux +all_win32: LDFLAGS = -L../../lib/Win32-gcc -lIrrlicht -lopengl32 -lm +all_win32: CPPFLAGS += -D__GNUWIN32__ -D_WIN32 -DWIN32 -D_WINDOWS -D_MBCS -D_USRDLL +all_win32 clean_win32: SYSTEM=Win32-gcc +all_win32 clean_win32: SUF=.exe +# name of the binary - only valid for targets which set SYSTEM +DESTPATH = ../../bin/$(SYSTEM)/$(Target)$(SUF) + +all_linux all_win32: + $(warning Building...) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(Sources) -o $(DESTPATH) $(LDFLAGS) + +clean: clean_linux clean_win32 + $(warning Cleaning...) + +clean_linux clean_win32: + @$(RM) $(DESTPATH) + +.PHONY: all all_win32 clean clean_linux clean_win32 diff --git a/libraries/irrlicht-1.8.1/examples/04.Movement/Movement.cbp b/libraries/irrlicht-1.8.1/examples/04.Movement/Movement.cbp new file mode 100644 index 0000000..0fcc4d0 --- /dev/null +++ b/libraries/irrlicht-1.8.1/examples/04.Movement/Movement.cbp @@ -0,0 +1,55 @@ + + + + + + diff --git a/libraries/irrlicht-1.8.1/examples/04.Movement/Movement.dev b/libraries/irrlicht-1.8.1/examples/04.Movement/Movement.dev new file mode 100644 index 0000000..0753c10 --- /dev/null +++ b/libraries/irrlicht-1.8.1/examples/04.Movement/Movement.dev @@ -0,0 +1,59 @@ +[Project] +FileName=example.dev +Name=Irrlicht Example 04 Movement +UnitCount=1 +Type=1 +Ver=1 +ObjFiles= +Includes=..\..\include +Libs= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Compiler= +CppCompiler= +Linker=../../lib/Win32-gcc/libIrrlicht.a_@@_ +IsCpp=1 +Icon= +ExeOutput=../../bin/Win32-gcc +ObjectOutput=obj +OverrideOutput=1 +OverrideOutputName=04.Movement.exe +HostApplication= +Folders= +CommandLine= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=0000000000000000000000 +UseCustomMakefile=0 +CustomMakefile= + +[Unit1] +FileName=main.cpp +CompileCpp=1 +Folder=Projekt1 +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[VersionInfo] +Major=0 +Minor=1 +Release=1 +Build=1 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion= +FileDescription=Irrlicht Engine example compiled using DevCpp and gcc +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +AutoIncBuildNr=0 + diff --git a/libraries/irrlicht-1.8.1/examples/04.Movement/Movement.vcproj b/libraries/irrlicht-1.8.1/examples/04.Movement/Movement.vcproj new file mode 100644 index 0000000..105c625 --- /dev/null +++ b/libraries/irrlicht-1.8.1/examples/04.Movement/Movement.vcproj @@ -0,0 +1,163 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libraries/irrlicht-1.8.1/examples/04.Movement/Movement_vc10.vcxproj b/libraries/irrlicht-1.8.1/examples/04.Movement/Movement_vc10.vcxproj new file mode 100644 index 0000000..7e59058 --- /dev/null +++ b/libraries/irrlicht-1.8.1/examples/04.Movement/Movement_vc10.vcxproj @@ -0,0 +1,231 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + 04.Movement + {7BDBB7E8-E0C9-4A0D-83C1-D389D6140FEF} + Movement + + + + Application + false + MultiByte + + + Application + false + MultiByte + + + Application + false + MultiByte + + + Application + false + MultiByte + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + ..\..\bin\Win32-VisualStudio\ + ..\..\bin\Win64-VisualStudio\ + + + ..\..\bin\Win32-VisualStudio\ + ..\..\bin\Win64-VisualStudio\ + + + AllRules.ruleset + AllRules.ruleset + + + + + AllRules.ruleset + AllRules.ruleset + + + + + + + + .\Debug/Movement.tlb + + + + + Disabled + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + + + Level3 + EditAndContinue + + + _DEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + ..\..\bin\Win32-VisualStudio\04.Movement.exe + ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) + true + Console + + + + + + + .\Debug/Movement.tlb + + + + + Disabled + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + + + Level3 + ProgramDatabase + + + _DEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + ..\..\bin\Win64-VisualStudio\04.Movement.exe + ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) + true + Console + + + + + + + .\Release/Movement.tlb + + + + + MaxSpeed + OnlyExplicitInline + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreaded + true + + + Level3 + + + NDEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + ..\..\bin\Win32-VisualStudio\04.Movement.exe + ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) + Console + + + + + + + .\Release/Movement.tlb + + + + + MaxSpeed + OnlyExplicitInline + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreaded + true + + + Level3 + + + NDEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + ..\..\bin\Win64-VisualStudio\04.Movement.exe + ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) + Console + + + + + + + Disabled + Disabled + %(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + EnableFastChecks + EnableFastChecks + MaxSpeed + MaxSpeed + %(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + + + + \ No newline at end of file diff --git a/libraries/irrlicht-1.8.1/examples/04.Movement/Movement_vc11.vcxproj b/libraries/irrlicht-1.8.1/examples/04.Movement/Movement_vc11.vcxproj new file mode 100644 index 0000000..7fe0339 --- /dev/null +++ b/libraries/irrlicht-1.8.1/examples/04.Movement/Movement_vc11.vcxproj @@ -0,0 +1,235 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + 04.Movement + {7BDBB7E8-E0C9-4A0D-83C1-D389D6140FEF} + Movement + + + + Application + false + MultiByte + v110 + + + Application + false + MultiByte + v110 + + + Application + false + MultiByte + v110 + + + Application + false + MultiByte + v110 + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + ..\..\bin\Win32-VisualStudio\ + ..\..\bin\Win64-VisualStudio\ + + + ..\..\bin\Win32-VisualStudio\ + ..\..\bin\Win64-VisualStudio\ + + + AllRules.ruleset + AllRules.ruleset + + + + + AllRules.ruleset + AllRules.ruleset + + + + + + + + .\Debug/Movement.tlb + + + + + Disabled + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + + + Level3 + EditAndContinue + + + _DEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + ..\..\bin\Win32-VisualStudio\04.Movement.exe + ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) + true + Console + + + + + + + .\Debug/Movement.tlb + + + + + Disabled + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + + + Level3 + ProgramDatabase + + + _DEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + ..\..\bin\Win64-VisualStudio\04.Movement.exe + ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) + true + Console + + + + + + + .\Release/Movement.tlb + + + + + MaxSpeed + OnlyExplicitInline + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreaded + true + + + Level3 + + + NDEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + ..\..\bin\Win32-VisualStudio\04.Movement.exe + ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) + Console + + + + + + + .\Release/Movement.tlb + + + + + MaxSpeed + OnlyExplicitInline + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreaded + true + + + Level3 + + + NDEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + ..\..\bin\Win64-VisualStudio\04.Movement.exe + ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) + Console + + + + + + + Disabled + Disabled + %(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + EnableFastChecks + EnableFastChecks + MaxSpeed + MaxSpeed + %(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + + + + \ No newline at end of file diff --git a/libraries/irrlicht-1.8.1/examples/04.Movement/Movement_vc8.vcproj b/libraries/irrlicht-1.8.1/examples/04.Movement/Movement_vc8.vcproj new file mode 100644 index 0000000..8f56add --- /dev/null +++ b/libraries/irrlicht-1.8.1/examples/04.Movement/Movement_vc8.vcproj @@ -0,0 +1,231 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libraries/irrlicht-1.8.1/examples/04.Movement/Movement_vc9.vcproj b/libraries/irrlicht-1.8.1/examples/04.Movement/Movement_vc9.vcproj new file mode 100644 index 0000000..074fe40 --- /dev/null +++ b/libraries/irrlicht-1.8.1/examples/04.Movement/Movement_vc9.vcproj @@ -0,0 +1,230 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libraries/irrlicht-1.8.1/examples/04.Movement/main.cpp b/libraries/irrlicht-1.8.1/examples/04.Movement/main.cpp new file mode 100644 index 0000000..7bacda3 --- /dev/null +++ b/libraries/irrlicht-1.8.1/examples/04.Movement/main.cpp @@ -0,0 +1,258 @@ +/** Example 004 Movement + +This Tutorial shows how to move and animate SceneNodes. The +basic concept of SceneNodeAnimators is shown as well as manual +movement of nodes using the keyboard. We'll demonstrate framerate +independent movement, which means moving by an amount dependent +on the duration of the last run of the Irrlicht loop. + +Example 19.MouseAndJoystick shows how to handle those kinds of input. + +As always, I include the header files, use the irr namespace, +and tell the linker to link with the .lib file. +*/ +#ifdef _MSC_VER +// We'll also define this to stop MSVC complaining about sprintf(). +#define _CRT_SECURE_NO_WARNINGS +#pragma comment(lib, "Irrlicht.lib") +#endif + +#include +#include "driverChoice.h" + +using namespace irr; + +/* +To receive events like mouse and keyboard input, or GUI events like "the OK +button has been clicked", we need an object which is derived from the +irr::IEventReceiver object. There is only one method to override: +irr::IEventReceiver::OnEvent(). This method will be called by the engine once +when an event happens. What we really want to know is whether a key is being +held down, and so we will remember the current state of each key. +*/ +class MyEventReceiver : public IEventReceiver +{ +public: + // This is the one method that we have to implement + virtual bool OnEvent(const SEvent& event) + { + // Remember whether each key is down or up + if (event.EventType == irr::EET_KEY_INPUT_EVENT) + KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown; + + return false; + } + + // This is used to check whether a key is being held down + virtual bool IsKeyDown(EKEY_CODE keyCode) const + { + return KeyIsDown[keyCode]; + } + + MyEventReceiver() + { + for (u32 i=0; i(640, 480), 16, false, false, false, &receiver); + + if (device == 0) + return 1; // could not create selected driver. + + video::IVideoDriver* driver = device->getVideoDriver(); + scene::ISceneManager* smgr = device->getSceneManager(); + + /* + Create the node which will be moved with the WSAD keys. We create a + sphere node, which is a built-in geometry primitive. We place the node + at (0,0,30) and assign a texture to it to let it look a little bit more + interesting. Because we have no dynamic lights in this scene we disable + lighting for each model (otherwise the models would be black). + */ + scene::ISceneNode * node = smgr->addSphereSceneNode(); + if (node) + { + node->setPosition(core::vector3df(0,0,30)); + node->setMaterialTexture(0, driver->getTexture("../../media/wall.bmp")); + node->setMaterialFlag(video::EMF_LIGHTING, false); + } + + /* + Now we create another node, movable using a scene node animator. Scene + node animators modify scene nodes and can be attached to any scene node + like mesh scene nodes, billboards, lights and even camera scene nodes. + Scene node animators are not only able to modify the position of a + scene node, they can also animate the textures of an object for + example. We create a cube scene node and attach a 'fly circle' scene + node animator to it, letting this node fly around our sphere scene node. + */ + scene::ISceneNode* n = smgr->addCubeSceneNode(); + + if (n) + { + n->setMaterialTexture(0, driver->getTexture("../../media/t351sml.jpg")); + n->setMaterialFlag(video::EMF_LIGHTING, false); + scene::ISceneNodeAnimator* anim = + smgr->createFlyCircleAnimator(core::vector3df(0,0,30), 20.0f); + if (anim) + { + n->addAnimator(anim); + anim->drop(); + } + } + + /* + The last scene node we add to show possibilities of scene node animators is + a b3d model, which uses a 'fly straight' animator to run between to points. + */ + scene::IAnimatedMeshSceneNode* anms = + smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/ninja.b3d")); + + if (anms) + { + scene::ISceneNodeAnimator* anim = + smgr->createFlyStraightAnimator(core::vector3df(100,0,60), + core::vector3df(-100,0,60), 3500, true); + if (anim) + { + anms->addAnimator(anim); + anim->drop(); + } + + /* + To make the model look right we disable lighting, set the + frames between which the animation should loop, rotate the + model around 180 degrees, and adjust the animation speed and + the texture. To set the right animation (frames and speed), we + would also be able to just call + "anms->setMD2Animation(scene::EMAT_RUN)" for the 'run' + animation instead of "setFrameLoop" and "setAnimationSpeed", + but this only works with MD2 animations, and so you know how to + start other animations. But a good advice is to not use + hardcoded frame-numbers... + */ + anms->setMaterialFlag(video::EMF_LIGHTING, false); + + anms->setFrameLoop(0, 13); + anms->setAnimationSpeed(15); +// anms->setMD2Animation(scene::EMAT_RUN); + + anms->setScale(core::vector3df(2.f,2.f,2.f)); + anms->setRotation(core::vector3df(0,-90,0)); +// anms->setMaterialTexture(0, driver->getTexture("../../media/sydney.bmp")); + + } + + + /* + To be able to look at and move around in this scene, we create a first + person shooter style camera and make the mouse cursor invisible. + */ + smgr->addCameraSceneNodeFPS(); + device->getCursorControl()->setVisible(false); + + /* + Add a colorful irrlicht logo + */ + device->getGUIEnvironment()->addImage( + driver->getTexture("../../media/irrlichtlogoalpha2.tga"), + core::position2d(10,20)); + + gui::IGUIStaticText* diagnostics = device->getGUIEnvironment()->addStaticText( + L"", core::rect(10, 10, 400, 20)); + diagnostics->setOverrideColor(video::SColor(255, 255, 255, 0)); + + /* + We have done everything, so lets draw it. We also write the current + frames per second and the name of the driver to the caption of the + window. + */ + int lastFPS = -1; + + // In order to do framerate independent movement, we have to know + // how long it was since the last frame + u32 then = device->getTimer()->getTime(); + + // This is the movemen speed in units per second. + const f32 MOVEMENT_SPEED = 5.f; + + while(device->run()) + { + // Work out a frame delta time. + const u32 now = device->getTimer()->getTime(); + const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds + then = now; + + /* Check if keys W, S, A or D are being held down, and move the + sphere node around respectively. */ + core::vector3df nodePosition = node->getPosition(); + + if(receiver.IsKeyDown(irr::KEY_KEY_W)) + nodePosition.Y += MOVEMENT_SPEED * frameDeltaTime; + else if(receiver.IsKeyDown(irr::KEY_KEY_S)) + nodePosition.Y -= MOVEMENT_SPEED * frameDeltaTime; + + if(receiver.IsKeyDown(irr::KEY_KEY_A)) + nodePosition.X -= MOVEMENT_SPEED * frameDeltaTime; + else if(receiver.IsKeyDown(irr::KEY_KEY_D)) + nodePosition.X += MOVEMENT_SPEED * frameDeltaTime; + + node->setPosition(nodePosition); + + driver->beginScene(true, true, video::SColor(255,113,113,133)); + + smgr->drawAll(); // draw the 3d scene + device->getGUIEnvironment()->drawAll(); // draw the gui environment (the logo) + + driver->endScene(); + + int fps = driver->getFPS(); + + if (lastFPS != fps) + { + core::stringw tmp(L"Movement Example - Irrlicht Engine ["); + tmp += driver->getName(); + tmp += L"] fps: "; + tmp += fps; + + device->setWindowCaption(tmp.c_str()); + lastFPS = fps; + } + } + + /* + In the end, delete the Irrlicht device. + */ + device->drop(); + + return 0; +} + +/* +That's it. Compile and play around with the program. +**/ diff --git a/libraries/irrlicht-1.8.1/examples/04.Movement/tutorial.html b/libraries/irrlicht-1.8.1/examples/04.Movement/tutorial.html new file mode 100644 index 0000000..28b207d --- /dev/null +++ b/libraries/irrlicht-1.8.1/examples/04.Movement/tutorial.html @@ -0,0 +1,188 @@ + + +Irrlicht Engine Tutorial + + + + +
+ + + + + + + + +
+
+
+
Tutorial 4.Movement
+
+
+
+

This Tutorial shows how to move and animate SceneNodes. The basic concept + of SceneNodeAnimators is shown as well as manual movement of nodes using + the keyboard.

+

The program which is described here will look like this:

+


+

+
+
+
+ + + + + + + +
+ Lets start!
+

As always, I include the header files, use the irr namespace, and tell + the linker to link with the .lib file.

+ + + + +
#include <stdio.h>
#include <wchar.h>
#include <irrlicht.h>
+
using namespace irr;
+
#pragma comment(lib, "Irrlicht.lib")
+

In this tutorial, one of our goals is to move a scene node using some + keys on the keyboard. We store a pointer to the scene node we want to + move with the keys here.
+ The other pointer is a pointer to the Irrlicht Device, which we need + int the EventReceiver to manipulate the scene node and to get the active + camera.

+ + + + +
scene::ISceneNode* node = 0;
IrrlichtDevice* device = 0;
+

To get events like mouse and keyboard input, or GUI events like "the + OK button has been clicked", we need an object wich is derived + from the IEventReceiver object. There is only one method to override: + OnEvent. This method will be called by the engine when an event happened. + We will use this input to move the scene node with the keys W and S.

+ + + + +
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(const SEvent& event)
{
+

If the key 'W' or 'S' was left up, we get the position of the scene + node, and modify the Y coordinate a little bit. So if you press 'W', + the node moves up, and if you press 'S' it moves down.

+ + + + +
if (node != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT&&
!event.KeyInput.PressedDown)
{
switch(event.KeyInput.Key)
{
case KEY_KEY_W:
case KEY_KEY_S:
{
core::vector3df v = node->getPosition();
v.Y += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;
node->setPosition(v);
}
return true;
}
} return false;
}
};
+ +
+

The event receiver for moving a scene node is ready. So lets just create + an Irrlicht Device and the scene node we want to move. We also create + some other additional scene nodes, to show that there are also some different + possibilities to move and animate scene nodes.

+ + + + +
int main()
{
MyEventReceiver receiver; + + device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480), + 16, false, false, false, &receiver);
+
   video::IVideoDriver* driver = device->getVideoDriver();
+   scene::ISceneManager* smgr = device->getSceneManager();
+
+

Create the node for moving it with the 'W' and 'S' key. We create a + sphere node, which is a built in geometric primitive scene node. + We place the node at (0,0,30) and assign a texture to it to let it look + a little bit more interesting.

+ + + + +
node = smgr->addSphereSceneNode();
+node->setPosition(core::vector3df(0,0,30));
+node->setMaterialFlag(video::EMF_LIGHTING, false);
+node->setMaterialTexture(0, driver->getTexture("../../media/wall.bmp"));
+

Now we create another node, moving using a scene node animator. Scene + node animators modify scene nodes and can be attached to any scene node + like
+ mesh scene nodes, billboards, lights and even camera scene nodes. Scene + node animators are not only able to modify the position of a scene node, + they can
+ also animate the textures of an object for example. We create a test scene + node again an attach a 'fly circle' scene node to it, letting this node + fly around our first test scene node.

+ + + + +
scene::ISceneNode* n = smgr->addCubeSceneNode();
+n->setMaterialTexture(0, driver->getTexture("../../media/t351sml.jpg"));
+n->setMaterialFlag(video::EMF_LIGHTING, false);
+scene::ISceneNodeAnimator* anim = 
+	smgr->createFlyCircleAnimator(core::vector3df(0,0,30), 20.0f);
+n->addAnimator(anim);
+anim->drop();
+

The last scene node we add to show possibilities of scene node animators + is a md2 model, which uses a 'fly straight' animator to run between to + points.

+ + + + +
scene::IAnimatedMeshSceneNode* anms = smgr->addAnimatedMeshSceneNode(
smgr->getMesh("../../media/sydney.md2")); + +if (n)
{
anim = smgr->createFlyStraightAnimator(core::vector3df(100,0,60),
core::vector3df(-100,0,60), 10000, true);
anms->addAnimator(anim);
anim->drop();
+
+

To make to model look right we set the frames between which + the animation should loop, rotate the model around 180 degrees, and adjust + the animation speed and the texture.
+ To set the right animation (frames and speed), we would also be able to + just call "anms->setMD2Animation(scene::EMAT_RUN)" for the + 'run' animation instead of "setFrameLoop" and "setAnimationSpeed", + but this only works with MD2 animations, and so you know how to start + other animations.

+ + + + +
   anms->setMaterialFlag(video::EMF_LIGHTING, false);
anms->setFrameLoop(320, 360); + anms->setAnimationSpeed(30);
anms->setRotation(core::vector3df(0,180.0f,0));
anms->setMaterialTexture(0, driver->getTexture("../../media/sydney.bmp"));
}
+

To be able to look at and move around in this scene, we create a first + person shooter style camera and make the mouse cursor invisible.

+ + + + +
smgr->addCameraSceneNodeFPS(0, 100.0f, 100.0f);
device->getCursorControl()->setVisible(false);
+

We have done everything, so lets draw it. We also write the current frames + per second and the name of the driver to the caption of the window.

+ + + + +
int lastFPS = -1;
+
while(device->run())
+{
+     driver->beginScene(true, true, video::SColor(255,90,90,156));
+     smgr->drawAll();
+     driver->endScene();
+
     int fps = driver->getFPS();
+
     if (lastFPS != fps)
+     {
+        wchar_t tmp[1024];
+        swprintf(tmp, 1024, L"Movement Example - Irrlicht Engine (%ls)(fps:%d)",
driver->getName(), fps);
+
       device->setWindowCaption(tmp);
+       lastFPS = fps;
+     }
+}
+
+device->drop();
return 0;
}
+

That's it. Compile and play around with the program.

+

 

+

 

+ + -- cgit v1.1