From 393b5cd1dc438872af89d334ef6e5fcc59f27d47 Mon Sep 17 00:00:00 2001
From: David Walter Seikel
Date: Sun, 13 Jan 2013 17:24:39 +1000
Subject: Added Irrlicht 1.8, but without all the Windows binaries.
---
.../examples/19.MouseAndJoystick/Makefile | 39 +++
.../19.MouseAndJoystick/MouseAndJoystick.cbp | 56 ++++
.../19.MouseAndJoystick/MouseAndJoystick.dev | 59 +++++
.../19.MouseAndJoystick/MouseAndJoystick.vcproj | 162 ++++++++++++
.../MouseAndJoystick_vc10.vcxproj | 227 ++++++++++++++++
.../MouseAndJoystick_vc11.vcxproj | 231 +++++++++++++++++
.../MouseAndJoystick_vc8.vcproj | 231 +++++++++++++++++
.../MouseAndJoystick_vc9.vcproj | 230 +++++++++++++++++
.../examples/19.MouseAndJoystick/main.cpp | 285 +++++++++++++++++++++
9 files changed, 1520 insertions(+)
create mode 100644 libraries/irrlicht-1.8/examples/19.MouseAndJoystick/Makefile
create mode 100644 libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick.cbp
create mode 100644 libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick.dev
create mode 100644 libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick.vcproj
create mode 100644 libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick_vc10.vcxproj
create mode 100644 libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick_vc11.vcxproj
create mode 100644 libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick_vc8.vcproj
create mode 100644 libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick_vc9.vcproj
create mode 100644 libraries/irrlicht-1.8/examples/19.MouseAndJoystick/main.cpp
(limited to 'libraries/irrlicht-1.8/examples/19.MouseAndJoystick')
diff --git a/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/Makefile b/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/Makefile
new file mode 100644
index 0000000..2462ea8
--- /dev/null
+++ b/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/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 = 19.MouseAndJoystick
+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/examples/19.MouseAndJoystick/MouseAndJoystick.cbp b/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick.cbp
new file mode 100644
index 0000000..808c0a7
--- /dev/null
+++ b/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick.cbp
@@ -0,0 +1,56 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick.dev b/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick.dev
new file mode 100644
index 0000000..cac8418
--- /dev/null
+++ b/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick.dev
@@ -0,0 +1,59 @@
+[Project]
+FileName=example.dev
+Name=Irrlicht Example 04 MouseAndJoystick
+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=19.MouseAndJoystick.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/examples/19.MouseAndJoystick/MouseAndJoystick.vcproj b/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick.vcproj
new file mode 100644
index 0000000..84d8396
--- /dev/null
+++ b/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick.vcproj
@@ -0,0 +1,162 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick_vc10.vcxproj b/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick_vc10.vcxproj
new file mode 100644
index 0000000..aaa8027
--- /dev/null
+++ b/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick_vc10.vcxproj
@@ -0,0 +1,227 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ Win32
+
+
+ Release
+ x64
+
+
+
+ 19.MouseAndJoystick
+ {FE853A36-E0D1-4AC5-A792-B643E70D2953}
+ MouseAndJoystick
+
+
+
+ Application
+ MultiByte
+
+
+ Application
+ MultiByte
+
+
+ Application
+ MultiByte
+
+
+ Application
+ 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/MouseAndJoystick.tlb
+
+
+
+
+ Disabled
+ ..\..\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ EnableFastChecks
+ MultiThreadedDebug
+
+
+ Level3
+ EditAndContinue
+
+
+ _DEBUG;%(PreprocessorDefinitions)
+ 0x0c07
+
+
+ ..\..\bin\Win32-VisualStudio\19.MouseAndJoystick.exe
+ ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories)
+ true
+ Console
+
+
+
+
+
+
+ .\Debug/MouseAndJoystick.tlb
+
+
+
+
+ Disabled
+ ..\..\include;%(AdditionalIncludeDirectories)
+ WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ EnableFastChecks
+ MultiThreadedDebug
+
+
+ Level3
+ ProgramDatabase
+
+
+ _DEBUG;%(PreprocessorDefinitions)
+ 0x0c07
+
+
+ ..\..\bin\Win64-VisualStudio\19.MouseAndJoystick.exe
+ ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories)
+ true
+ Console
+
+
+
+
+
+
+ .\Release/MouseAndJoystick.tlb
+
+
+
+
+ MaxSpeed
+ OnlyExplicitInline
+ ..\..\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ MultiThreaded
+ true
+
+
+ Level3
+
+
+ NDEBUG;%(PreprocessorDefinitions)
+ 0x0c07
+
+
+ ..\..\bin\Win32-VisualStudio\19.MouseAndJoystick.exe
+ ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories)
+ Console
+
+
+
+
+
+
+ .\Release/MouseAndJoystick.tlb
+
+
+
+
+ MaxSpeed
+ OnlyExplicitInline
+ ..\..\include;%(AdditionalIncludeDirectories)
+ WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ MultiThreaded
+ true
+
+
+ Level3
+
+
+ NDEBUG;%(PreprocessorDefinitions)
+ 0x0c07
+
+
+ ..\..\bin\Win64-VisualStudio\19.MouseAndJoystick.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/examples/19.MouseAndJoystick/MouseAndJoystick_vc11.vcxproj b/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick_vc11.vcxproj
new file mode 100644
index 0000000..44c2b07
--- /dev/null
+++ b/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick_vc11.vcxproj
@@ -0,0 +1,231 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ Win32
+
+
+ Release
+ x64
+
+
+
+ 19.MouseAndJoystick
+ {FE853A36-E0D1-4AC5-A792-B643E70D2953}
+ MouseAndJoystick
+
+
+
+ Application
+ MultiByte
+ v110
+
+
+ Application
+ MultiByte
+ v110
+
+
+ Application
+ MultiByte
+ v110
+
+
+ Application
+ 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/MouseAndJoystick.tlb
+
+
+
+
+ Disabled
+ ..\..\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ EnableFastChecks
+ MultiThreadedDebug
+
+
+ Level3
+ EditAndContinue
+
+
+ _DEBUG;%(PreprocessorDefinitions)
+ 0x0c07
+
+
+ ..\..\bin\Win32-VisualStudio\19.MouseAndJoystick.exe
+ ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories)
+ true
+ Console
+
+
+
+
+
+
+ .\Debug/MouseAndJoystick.tlb
+
+
+
+
+ Disabled
+ ..\..\include;%(AdditionalIncludeDirectories)
+ WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ EnableFastChecks
+ MultiThreadedDebug
+
+
+ Level3
+ ProgramDatabase
+
+
+ _DEBUG;%(PreprocessorDefinitions)
+ 0x0c07
+
+
+ ..\..\bin\Win64-VisualStudio\19.MouseAndJoystick.exe
+ ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories)
+ true
+ Console
+
+
+
+
+
+
+ .\Release/MouseAndJoystick.tlb
+
+
+
+
+ MaxSpeed
+ OnlyExplicitInline
+ ..\..\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ MultiThreaded
+ true
+
+
+ Level3
+
+
+ NDEBUG;%(PreprocessorDefinitions)
+ 0x0c07
+
+
+ ..\..\bin\Win32-VisualStudio\19.MouseAndJoystick.exe
+ ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories)
+ Console
+
+
+
+
+
+
+ .\Release/MouseAndJoystick.tlb
+
+
+
+
+ MaxSpeed
+ OnlyExplicitInline
+ ..\..\include;%(AdditionalIncludeDirectories)
+ WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ MultiThreaded
+ true
+
+
+ Level3
+
+
+ NDEBUG;%(PreprocessorDefinitions)
+ 0x0c07
+
+
+ ..\..\bin\Win64-VisualStudio\19.MouseAndJoystick.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/examples/19.MouseAndJoystick/MouseAndJoystick_vc8.vcproj b/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick_vc8.vcproj
new file mode 100644
index 0000000..51b7fac
--- /dev/null
+++ b/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick_vc8.vcproj
@@ -0,0 +1,231 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick_vc9.vcproj b/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick_vc9.vcproj
new file mode 100644
index 0000000..e121452
--- /dev/null
+++ b/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/MouseAndJoystick_vc9.vcproj
@@ -0,0 +1,230 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/main.cpp b/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/main.cpp
new file mode 100644
index 0000000..4563278
--- /dev/null
+++ b/libraries/irrlicht-1.8/examples/19.MouseAndJoystick/main.cpp
@@ -0,0 +1,285 @@
+/** Example 019 Mouse and Joystick
+
+This tutorial builds on example 04.Movement which showed how to
+handle keyboard events in Irrlicht. Here we'll handle mouse events
+and joystick events, if you have a joystick connected and a device
+that supports joysticks. These are currently Windows, Linux and SDL
+devices.
+*/
+
+#ifdef _MSC_VER
+// We'll 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;
+
+/*
+Just as we did in example 04.Movement, we'll store the latest state of the
+mouse and the first joystick, updating them as we receive events.
+*/
+class MyEventReceiver : public IEventReceiver
+{
+public:
+ // We'll create a struct to record info on the mouse state
+ struct SMouseState
+ {
+ core::position2di Position;
+ bool LeftButtonDown;
+ SMouseState() : LeftButtonDown(false) { }
+ } MouseState;
+
+ // This is the one method that we have to implement
+ virtual bool OnEvent(const SEvent& event)
+ {
+ // Remember the mouse state
+ if (event.EventType == irr::EET_MOUSE_INPUT_EVENT)
+ {
+ switch(event.MouseInput.Event)
+ {
+ case EMIE_LMOUSE_PRESSED_DOWN:
+ MouseState.LeftButtonDown = true;
+ break;
+
+ case EMIE_LMOUSE_LEFT_UP:
+ MouseState.LeftButtonDown = false;
+ break;
+
+ case EMIE_MOUSE_MOVED:
+ MouseState.Position.X = event.MouseInput.X;
+ MouseState.Position.Y = event.MouseInput.Y;
+ break;
+
+ default:
+ // We won't use the wheel
+ break;
+ }
+ }
+
+ // The state of each connected joystick is sent to us
+ // once every run() of the Irrlicht device. Store the
+ // state of the first joystick, ignoring other joysticks.
+ // This is currently only supported on Windows and Linux.
+ if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT
+ && event.JoystickEvent.Joystick == 0)
+ {
+ JoystickState = event.JoystickEvent;
+ }
+
+ return false;
+ }
+
+ const SEvent::SJoystickEvent & GetJoystickState(void) const
+ {
+ return JoystickState;
+ }
+
+ const SMouseState & GetMouseState(void) const
+ {
+ return MouseState;
+ }
+
+
+ MyEventReceiver()
+ {
+ }
+
+private:
+ SEvent::SJoystickEvent JoystickState;
+};
+
+
+/*
+The event receiver for keeping the pressed keys is ready, the actual responses
+will be made inside the render loop, right before drawing the scene. So lets
+just create an irr::IrrlichtDevice 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()
+{
+ // ask user for driver
+ video::E_DRIVER_TYPE driverType=driverChoiceConsole();
+ if (driverType==video::EDT_COUNT)
+ return 1;
+
+ // create device
+ MyEventReceiver receiver;
+
+ IrrlichtDevice* device = createDevice(driverType,
+ core::dimension2d(640, 480), 16, false, false, false, &receiver);
+
+ if (device == 0)
+ return 1; // could not create selected driver.
+
+
+ core::array joystickInfo;
+ if(device->activateJoysticks(joystickInfo))
+ {
+ std::cout << "Joystick support is enabled and " << joystickInfo.size() << " joystick(s) are present." << std::endl;
+
+ for(u32 joystick = 0; joystick < joystickInfo.size(); ++joystick)
+ {
+ std::cout << "Joystick " << joystick << ":" << std::endl;
+ std::cout << "\tName: '" << joystickInfo[joystick].Name.c_str() << "'" << std::endl;
+ std::cout << "\tAxes: " << joystickInfo[joystick].Axes << std::endl;
+ std::cout << "\tButtons: " << joystickInfo[joystick].Buttons << std::endl;
+
+ std::cout << "\tHat is: ";
+
+ switch(joystickInfo[joystick].PovHat)
+ {
+ case SJoystickInfo::POV_HAT_PRESENT:
+ std::cout << "present" << std::endl;
+ break;
+
+ case SJoystickInfo::POV_HAT_ABSENT:
+ std::cout << "absent" << std::endl;
+ break;
+
+ case SJoystickInfo::POV_HAT_UNKNOWN:
+ default:
+ std::cout << "unknown" << std::endl;
+ break;
+ }
+ }
+ }
+ else
+ {
+ std::cout << "Joystick support is not enabled." << std::endl;
+ }
+
+ core::stringw tmp = L"Irrlicht Joystick Example (";
+ tmp += joystickInfo.size();
+ tmp += " joysticks)";
+ device->setWindowCaption(tmp.c_str());
+
+ video::IVideoDriver* driver = device->getVideoDriver();
+ scene::ISceneManager* smgr = device->getSceneManager();
+
+ /*
+ We'll create an arrow mesh and move it around either with the joystick axis/hat,
+ or make it follow the mouse pointer. */
+ scene::ISceneNode * node = smgr->addMeshSceneNode(
+ smgr->addArrowMesh( "Arrow",
+ video::SColor(255, 255, 0, 0),
+ video::SColor(255, 0, 255, 0),
+ 16,16,
+ 2.f, 1.3f,
+ 0.1f, 0.6f
+ )
+ );
+ node->setMaterialFlag(video::EMF_LIGHTING, false);
+
+ scene::ICameraSceneNode * camera = smgr->addCameraSceneNode();
+ camera->setPosition(core::vector3df(0, 0, -10));
+
+ // As in example 04, we'll use framerate independent movement.
+ u32 then = device->getTimer()->getTime();
+ 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;
+
+ bool movedWithJoystick = false;
+ core::vector3df nodePosition = node->getPosition();
+
+ if(joystickInfo.size() > 0)
+ {
+ f32 moveHorizontal = 0.f; // Range is -1.f for full left to +1.f for full right
+ f32 moveVertical = 0.f; // -1.f for full down to +1.f for full up.
+
+ const SEvent::SJoystickEvent & joystickData = receiver.GetJoystickState();
+
+ // We receive the full analog range of the axes, and so have to implement our
+ // own dead zone. This is an empirical value, since some joysticks have more
+ // jitter or creep around the center point than others. We'll use 5% of the
+ // range as the dead zone, but generally you would want to give the user the
+ // option to change this.
+ const f32 DEAD_ZONE = 0.05f;
+
+ moveHorizontal =
+ (f32)joystickData.Axis[SEvent::SJoystickEvent::AXIS_X] / 32767.f;
+ if(fabs(moveHorizontal) < DEAD_ZONE)
+ moveHorizontal = 0.f;
+
+ moveVertical =
+ (f32)joystickData.Axis[SEvent::SJoystickEvent::AXIS_Y] / -32767.f;
+ if(fabs(moveVertical) < DEAD_ZONE)
+ moveVertical = 0.f;
+
+ // POV hat info is only currently supported on Windows, but the value is
+ // guaranteed to be 65535 if it's not supported, so we can check its range.
+ const u16 povDegrees = joystickData.POV / 100;
+ if(povDegrees < 360)
+ {
+ if(povDegrees > 0 && povDegrees < 180)
+ moveHorizontal = 1.f;
+ else if(povDegrees > 180)
+ moveHorizontal = -1.f;
+
+ if(povDegrees > 90 && povDegrees < 270)
+ moveVertical = -1.f;
+ else if(povDegrees > 270 || povDegrees < 90)
+ moveVertical = +1.f;
+ }
+
+ if(!core::equals(moveHorizontal, 0.f) || !core::equals(moveVertical, 0.f))
+ {
+ nodePosition.X += MOVEMENT_SPEED * frameDeltaTime * moveHorizontal;
+ nodePosition.Y += MOVEMENT_SPEED * frameDeltaTime * moveVertical;
+ movedWithJoystick = true;
+ }
+ }
+
+ // If the arrow node isn't being moved with the joystick, then have it follow the mouse cursor.
+ if(!movedWithJoystick)
+ {
+ // Create a ray through the mouse cursor.
+ core::line3df ray = smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(
+ receiver.GetMouseState().Position, camera);
+
+ // And intersect the ray with a plane around the node facing towards the camera.
+ core::plane3df plane(nodePosition, core::vector3df(0, 0, -1));
+ core::vector3df mousePosition;
+ if(plane.getIntersectionWithLine(ray.start, ray.getVector(), mousePosition))
+ {
+ // We now have a mouse position in 3d space; move towards it.
+ core::vector3df toMousePosition(mousePosition - nodePosition);
+ const f32 availableMovement = MOVEMENT_SPEED * frameDeltaTime;
+
+ if(toMousePosition.getLength() <= availableMovement)
+ nodePosition = mousePosition; // Jump to the final position
+ else
+ nodePosition += toMousePosition.normalize() * availableMovement; // Move towards it
+ }
+ }
+
+ node->setPosition(nodePosition);
+
+ // Turn lighting on and off depending on whether the left mouse button is down.
+ node->setMaterialFlag(video::EMF_LIGHTING, receiver.GetMouseState().LeftButtonDown);
+
+ driver->beginScene(true, true, video::SColor(255,113,113,133));
+ smgr->drawAll(); // draw the 3d scene
+ driver->endScene();
+ }
+
+ /*
+ In the end, delete the Irrlicht device.
+ */
+ device->drop();
+
+ return 0;
+}
+
+/*
+**/
--
cgit v1.1