<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://c4engine.com/wiki/index.php?action=history&amp;feed=atom&amp;title=SimpleChar_Source_Code</id>
	<title>SimpleChar Source Code - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://c4engine.com/wiki/index.php?action=history&amp;feed=atom&amp;title=SimpleChar_Source_Code"/>
	<link rel="alternate" type="text/html" href="https://c4engine.com/wiki/index.php?title=SimpleChar_Source_Code&amp;action=history"/>
	<updated>2026-04-15T16:56:39Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://c4engine.com/wiki/index.php?title=SimpleChar_Source_Code&amp;diff=535&amp;oldid=prev</id>
		<title>Eric Lengyel: Created page with &quot;This page contains the complete source code for the &lt;code&gt;SimpleChar&lt;/code&gt; example game module. See the Simple Games page for more information about the basic examples.  == SimpleChar.h ==  &lt;syntaxhighlight lang=&quot;c++&quot;&gt; #ifndef SimpleChar_h #define SimpleChar_h   #include &quot;C4Application.h&quot; #include &quot;C4World.h&quot; #include &quot;C4Input.h&quot; #include &quot;C4Cameras.h&quot; #include &quot;C4Interface.h&quot; #include &quot;C4Character.h&quot;   // Every application/game module needs to declare a function ca...&quot;</title>
		<link rel="alternate" type="text/html" href="https://c4engine.com/wiki/index.php?title=SimpleChar_Source_Code&amp;diff=535&amp;oldid=prev"/>
		<updated>2023-09-12T21:43:45Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;This page contains the complete source code for the &amp;lt;code&amp;gt;SimpleChar&amp;lt;/code&amp;gt; example game module. See the &lt;a href=&quot;/wiki/index.php?title=Simple_Games&quot; title=&quot;Simple Games&quot;&gt;Simple Games&lt;/a&gt; page for more information about the basic examples.  == SimpleChar.h ==  &amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt; #ifndef SimpleChar_h #define SimpleChar_h   #include &amp;quot;C4Application.h&amp;quot; #include &amp;quot;C4World.h&amp;quot; #include &amp;quot;C4Input.h&amp;quot; #include &amp;quot;C4Cameras.h&amp;quot; #include &amp;quot;C4Interface.h&amp;quot; #include &amp;quot;C4Character.h&amp;quot;   // Every application/game module needs to declare a function ca...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This page contains the complete source code for the &amp;lt;code&amp;gt;SimpleChar&amp;lt;/code&amp;gt; example game module. See the [[Simple Games]] page for more information about the basic examples.&lt;br /&gt;
&lt;br /&gt;
== SimpleChar.h ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
#ifndef SimpleChar_h&lt;br /&gt;
#define SimpleChar_h&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;quot;C4Application.h&amp;quot;&lt;br /&gt;
#include &amp;quot;C4World.h&amp;quot;&lt;br /&gt;
#include &amp;quot;C4Input.h&amp;quot;&lt;br /&gt;
#include &amp;quot;C4Cameras.h&amp;quot;&lt;br /&gt;
#include &amp;quot;C4Interface.h&amp;quot;&lt;br /&gt;
#include &amp;quot;C4Character.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Every application/game module needs to declare a function called CreateApplication()&lt;br /&gt;
// exactly as follows. (It must be declared extern &amp;quot;C&amp;quot;, and it must include the tag&lt;br /&gt;
// C4_MODULE_EXPORT.) The engine looks for this function in the DLL and calls&lt;br /&gt;
// it to create an instance of the subclass of the Application class that the&lt;br /&gt;
// application/game module defines.&lt;br /&gt;
&lt;br /&gt;
extern &amp;quot;C&amp;quot;&lt;br /&gt;
{&lt;br /&gt;
	C4_MODULE_EXPORT C4::Application *CreateApplication(void);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
namespace SimpleChar&lt;br /&gt;
{&lt;br /&gt;
	using namespace C4;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	// These are action types used to define action bindings in the&lt;br /&gt;
	// Input Manager. If the four-character code for an action is&lt;br /&gt;
	// 'abcd', then any input control (there can be more than one)&lt;br /&gt;
	// bound to %abcd triggers the associated action.&lt;br /&gt;
&lt;br /&gt;
	enum : ActionType&lt;br /&gt;
	{&lt;br /&gt;
		kActionForward			= 'frwd',&lt;br /&gt;
		kActionBackward			= 'bkwd',&lt;br /&gt;
		kActionLeft				= 'left',&lt;br /&gt;
		kActionRight			= 'rght',&lt;br /&gt;
		kActionUp				= 'jump',&lt;br /&gt;
		kActionDown				= 'down',&lt;br /&gt;
		kActionUse				= 'fire'&lt;br /&gt;
	};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	// These are movement flags used by the soldier controller. They are set or cleared&lt;br /&gt;
	// by the Engage() and Disengage() functions in the MovementAction class.&lt;br /&gt;
&lt;br /&gt;
	enum : uint32&lt;br /&gt;
	{&lt;br /&gt;
		kMovementForward		= 1 &amp;lt;&amp;lt; 0,&lt;br /&gt;
		kMovementBackward		= 1 &amp;lt;&amp;lt; 1,&lt;br /&gt;
		kMovementLeft			= 1 &amp;lt;&amp;lt; 2,&lt;br /&gt;
		kMovementRight			= 1 &amp;lt;&amp;lt; 3,&lt;br /&gt;
		kMovementUp				= 1 &amp;lt;&amp;lt; 4,&lt;br /&gt;
		kMovementDown			= 1 &amp;lt;&amp;lt; 5,&lt;br /&gt;
		kMovementPlanarMask		= 15&lt;br /&gt;
	};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	// Model types are associated with a model resource using the ModelRegistration&lt;br /&gt;
	// class. Models are registered with the engine in the Game constructor.&lt;br /&gt;
&lt;br /&gt;
	enum : ModelType&lt;br /&gt;
	{&lt;br /&gt;
		kModelSoldier			= 'sold'&lt;br /&gt;
	};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	// New controller types are registered with the engine in the Game constructor.&lt;br /&gt;
&lt;br /&gt;
	enum : ControllerType&lt;br /&gt;
	{&lt;br /&gt;
		kControllerSoldier		= 'sold'&lt;br /&gt;
	};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	// New locator types are registered with the engine in the Game constructor.&lt;br /&gt;
	// The 'spwn' locator is used to specify where the player should be positioned&lt;br /&gt;
	// when a world is loaded.&lt;br /&gt;
&lt;br /&gt;
	enum : LocatorType&lt;br /&gt;
	{&lt;br /&gt;
		kLocatorSpawn			= 'spwn'&lt;br /&gt;
	};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	class SoldierController;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	// An Action object represents an input action that can be triggered by some&lt;br /&gt;
	// input control, such as a key on the keyboard or a button on a gamepad.&lt;br /&gt;
	// The HandleEngage() and HandleDisengage() methods are called when the button&lt;br /&gt;
	// is pressed and released, respectively. Actions are registered with the Input&lt;br /&gt;
	// Manager when the Game class is constructed.&lt;br /&gt;
&lt;br /&gt;
	class MovementAction : public Action&lt;br /&gt;
	{&lt;br /&gt;
		private:&lt;br /&gt;
&lt;br /&gt;
			uint32		movementFlag;&lt;br /&gt;
&lt;br /&gt;
		public:&lt;br /&gt;
&lt;br /&gt;
			MovementAction(ActionType type, uint32 flag);&lt;br /&gt;
			~MovementAction();&lt;br /&gt;
&lt;br /&gt;
			void HandleEngage(void) override;&lt;br /&gt;
			void HandleDisengage(void) override;&lt;br /&gt;
	};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	class UseAction : public Action&lt;br /&gt;
	{&lt;br /&gt;
		public:&lt;br /&gt;
&lt;br /&gt;
			UseAction();&lt;br /&gt;
			~UseAction();&lt;br /&gt;
&lt;br /&gt;
			void HandleEngage(void) override;&lt;br /&gt;
			void HandleDisengage(void) override;&lt;br /&gt;
	};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	// The Interactor class is used to track player interactions with objects in the scene.&lt;br /&gt;
&lt;br /&gt;
	class SoldierInteractor : public Interactor&lt;br /&gt;
	{&lt;br /&gt;
		private:&lt;br /&gt;
&lt;br /&gt;
			SoldierController	*soldierController;&lt;br /&gt;
&lt;br /&gt;
		public:&lt;br /&gt;
&lt;br /&gt;
			SoldierInteractor(SoldierController *controller);&lt;br /&gt;
			~SoldierInteractor();&lt;br /&gt;
&lt;br /&gt;
			void HandleInteractionEvent(EventType type, Node *node, const InteractionProperty *property, const Point3D *position) override;&lt;br /&gt;
	};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	// Controllers are used to control anything that moves in the world.&lt;br /&gt;
	// New types of controllers defined by the application/game module are&lt;br /&gt;
	// registered with the engine when the Game class is constructed.&lt;br /&gt;
	//&lt;br /&gt;
	// The SoldierController is used to animate the soldier. It uses the&lt;br /&gt;
	// built-in character controller as a base class so that the engine's&lt;br /&gt;
	// native physics can be used to move the character.&lt;br /&gt;
&lt;br /&gt;
	class SoldierController final : public CharacterController&lt;br /&gt;
	{&lt;br /&gt;
		private:&lt;br /&gt;
&lt;br /&gt;
			// These are motion states that are used to keep track&lt;br /&gt;
			// of which animation should be played.&lt;br /&gt;
&lt;br /&gt;
			enum&lt;br /&gt;
			{&lt;br /&gt;
				kMotionNone,&lt;br /&gt;
				kMotionStand,&lt;br /&gt;
				kMotionForward,&lt;br /&gt;
				kMotionBackward&lt;br /&gt;
			};&lt;br /&gt;
&lt;br /&gt;
			// The movement flags tell how the user is trying to move the player.&lt;br /&gt;
&lt;br /&gt;
			uint32				movementFlags;&lt;br /&gt;
&lt;br /&gt;
			// The soldier motion keeps track of what animation is currently playing.&lt;br /&gt;
&lt;br /&gt;
			int32				soldierMotion;&lt;br /&gt;
&lt;br /&gt;
			// The azimuth and altitude represent the direction the player is looking&lt;br /&gt;
			// by using the mouse.&lt;br /&gt;
&lt;br /&gt;
			float				modelAzimuth;&lt;br /&gt;
			float				modelAltitude;&lt;br /&gt;
&lt;br /&gt;
			// The frame animator controls playback of an animation resource.&lt;br /&gt;
&lt;br /&gt;
			FrameAnimator		frameAnimator;&lt;br /&gt;
&lt;br /&gt;
			// The previous center of mass stores the center point of the character on the&lt;br /&gt;
			// previous frame. This is used with the new center point to activate triggers.&lt;br /&gt;
&lt;br /&gt;
			Point3D				previousCenterOfMass;&lt;br /&gt;
&lt;br /&gt;
			// We keep an interactor object here in the controller.&lt;br /&gt;
&lt;br /&gt;
			SoldierInteractor	soldierInteractor;&lt;br /&gt;
&lt;br /&gt;
			SoldierController(const SoldierController&amp;amp; soldierController);&lt;br /&gt;
&lt;br /&gt;
			Controller *Replicate(void) const override;&lt;br /&gt;
&lt;br /&gt;
			void SetSoldierMotion(int32 motion);&lt;br /&gt;
&lt;br /&gt;
		public:&lt;br /&gt;
&lt;br /&gt;
			SoldierController(float azimuth);&lt;br /&gt;
			~SoldierController();&lt;br /&gt;
&lt;br /&gt;
			Model *GetTargetNode(void) const&lt;br /&gt;
			{&lt;br /&gt;
				return (static_cast&amp;lt;Model *&amp;gt;(Controller::GetTargetNode()));&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
			uint32 GetMovementFlags(void) const&lt;br /&gt;
			{&lt;br /&gt;
				return (movementFlags);&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
			void SetMovementFlags(uint32 flags)&lt;br /&gt;
			{&lt;br /&gt;
				movementFlags = flags;&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
			float GetModelAzimuth(void) const&lt;br /&gt;
			{&lt;br /&gt;
				return (modelAzimuth);&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
			float GetModelAltitude(void) const&lt;br /&gt;
			{&lt;br /&gt;
				return (modelAltitude);&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
			SoldierInteractor *GetSoldierInteractor(void)&lt;br /&gt;
			{&lt;br /&gt;
				return (&amp;amp;soldierInteractor);&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
			void PreprocessController(void) override;&lt;br /&gt;
			void MoveController(void) override;&lt;br /&gt;
	};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	// The ChaseCamera class represents a camera that will track the player's movement.&lt;br /&gt;
&lt;br /&gt;
	class ChaseCamera : public FrustumCamera&lt;br /&gt;
	{&lt;br /&gt;
		private:&lt;br /&gt;
&lt;br /&gt;
			Model		*targetModel;&lt;br /&gt;
&lt;br /&gt;
		public:&lt;br /&gt;
&lt;br /&gt;
			ChaseCamera();&lt;br /&gt;
			~ChaseCamera();&lt;br /&gt;
&lt;br /&gt;
			Model *GetTargetModel(void) const&lt;br /&gt;
			{&lt;br /&gt;
				return (targetModel);&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
			void SetTargetModel(Model *model)&lt;br /&gt;
			{&lt;br /&gt;
				targetModel = model;&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
			void MoveCamera(void) override;&lt;br /&gt;
	};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	// The application/game module will usually define a subclass of the World&lt;br /&gt;
	// class so that extra information can be associated with the current world.&lt;br /&gt;
	// In this case, a pointer to a spawn locator and an instance of the ChaseCamera&lt;br /&gt;
	// class is included with the world. A new instance of this World subclass should&lt;br /&gt;
	// be returned when the Game::CreateWorld() function is called (see below).&lt;br /&gt;
&lt;br /&gt;
	class GameWorld : public World&lt;br /&gt;
	{&lt;br /&gt;
		private:&lt;br /&gt;
&lt;br /&gt;
			const LocatorMarker		*spawnLocator;&lt;br /&gt;
&lt;br /&gt;
			ChaseCamera				chaseCamera;&lt;br /&gt;
&lt;br /&gt;
			static const LocatorMarker *FindSpawnLocator(const Zone *zone);&lt;br /&gt;
&lt;br /&gt;
		public:&lt;br /&gt;
&lt;br /&gt;
			GameWorld(const char *name);&lt;br /&gt;
			~GameWorld();&lt;br /&gt;
&lt;br /&gt;
			const LocatorMarker *GetSpawnLocator(void) const&lt;br /&gt;
			{&lt;br /&gt;
				return (spawnLocator);&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
			ChaseCamera *GetChaseCamera(void)&lt;br /&gt;
			{&lt;br /&gt;
				return (&amp;amp;chaseCamera);&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
			ResourceResult PreprocessWorld(void) override;&lt;br /&gt;
&lt;br /&gt;
			void HandlePhysicsSpaceExit(RigidBodyController *rigidBody) override;&lt;br /&gt;
&lt;br /&gt;
			void DetectInteractions(void) override;&lt;br /&gt;
			void RenderWorld(void) override;&lt;br /&gt;
	};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	// Every application/game module needs to define a subclass of the Application&lt;br /&gt;
	// class to serve as the primary interface with the engine. This subclass is&lt;br /&gt;
	// created and returned to the engine in the CreateApplication() function.&lt;br /&gt;
	// There should be only one instance of this class, and a pointer to it is&lt;br /&gt;
	// declared below.&lt;br /&gt;
&lt;br /&gt;
	class Game : public Application, public Global&amp;lt;Game&amp;gt;&lt;br /&gt;
	{&lt;br /&gt;
		private:&lt;br /&gt;
&lt;br /&gt;
			ModelRegistration				soldierModelReg;&lt;br /&gt;
			LocatorRegistration				locatorReg;&lt;br /&gt;
&lt;br /&gt;
			InputMgr::KeyCallback			*prevEscapeCallback;&lt;br /&gt;
			void							*prevEscapeCookie;&lt;br /&gt;
&lt;br /&gt;
			MovementAction					*forwardAction;&lt;br /&gt;
			MovementAction					*backwardAction;&lt;br /&gt;
			MovementAction					*leftAction;&lt;br /&gt;
			MovementAction					*rightAction;&lt;br /&gt;
			MovementAction					*upAction;&lt;br /&gt;
			MovementAction					*downAction;&lt;br /&gt;
			UseAction						*useAction;&lt;br /&gt;
&lt;br /&gt;
			SoldierController				*soldierController;&lt;br /&gt;
&lt;br /&gt;
			static World *CreateWorld(const char *name, void *cookie);&lt;br /&gt;
&lt;br /&gt;
			static void EscapeCallback(void *cookie);&lt;br /&gt;
&lt;br /&gt;
		public:&lt;br /&gt;
&lt;br /&gt;
			Game();&lt;br /&gt;
			~Game();&lt;br /&gt;
&lt;br /&gt;
			SoldierController *GetSoldierController(void) const&lt;br /&gt;
			{&lt;br /&gt;
				return (soldierController);&lt;br /&gt;
			}&lt;br /&gt;
&lt;br /&gt;
			EngineResult LoadWorld(const char *name) override;&lt;br /&gt;
			void UnloadWorld(void) override;&lt;br /&gt;
	};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	// This is a pointer to the one instance of the Game class through which&lt;br /&gt;
	// any other part of the application/game module can access it.&lt;br /&gt;
&lt;br /&gt;
	extern Game *TheGame;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== SimpleChar.cpp ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c++&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;quot;SimpleChar.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
using namespace SimpleChar;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// This is the definition of the pointer to the Game class global.&lt;br /&gt;
// It should be initialized to nullptr, and its value will be set by&lt;br /&gt;
// the Game class constructor.&lt;br /&gt;
&lt;br /&gt;
Game *SimpleChar::TheGame = nullptr;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
C4::Application *CreateApplication(void)&lt;br /&gt;
{&lt;br /&gt;
	// This function should simply return a pointer to a new instance of&lt;br /&gt;
	// the Application class. Normally, the application/game module will&lt;br /&gt;
	// define a subclass of the Application class (in this case, the&lt;br /&gt;
	// Game class) and return a pointer to a new instance of that type.&lt;br /&gt;
&lt;br /&gt;
	// This function is called exactly one time right after the&lt;br /&gt;
	// application/game module DLL is loaded by the engine. The returned&lt;br /&gt;
	// class is destroyed via the virtual destructor of the Application&lt;br /&gt;
	// class right before the application/game module DLL is unloaded.&lt;br /&gt;
&lt;br /&gt;
	return (new Game);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
MovementAction::MovementAction(ActionType type, uint32 flag) : Action(type)&lt;br /&gt;
{&lt;br /&gt;
	// Each instance of the MovementAction class represents a movement&lt;br /&gt;
	// in a single direction, as indicated by the flag parameter.&lt;br /&gt;
	// All of the MovementAction instances are constructed in the&lt;br /&gt;
	// Game class constructor.&lt;br /&gt;
&lt;br /&gt;
	movementFlag = flag;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
MovementAction::~MovementAction()&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void MovementAction::HandleEngage(void)&lt;br /&gt;
{&lt;br /&gt;
	// This function is called when the input control associated with this&lt;br /&gt;
	// particular action is engaged (e.g., a key was pressed). We respond to&lt;br /&gt;
	// such an event by setting a movement flag in the soldier controller.&lt;br /&gt;
&lt;br /&gt;
	SoldierController *controller = TheGame-&amp;gt;GetSoldierController();&lt;br /&gt;
	if (controller)&lt;br /&gt;
	{&lt;br /&gt;
		controller-&amp;gt;SetMovementFlags(controller-&amp;gt;GetMovementFlags() | movementFlag);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void MovementAction::HandleDisengage(void)&lt;br /&gt;
{&lt;br /&gt;
	// This function is called when the input control associated with this&lt;br /&gt;
	// particular action is disengaged (e.g., a key was released). We respond to&lt;br /&gt;
	// such an event by clearing a movement flag in the soldier controller.&lt;br /&gt;
&lt;br /&gt;
	SoldierController *controller = TheGame-&amp;gt;GetSoldierController();&lt;br /&gt;
	if (controller)&lt;br /&gt;
	{&lt;br /&gt;
		controller-&amp;gt;SetMovementFlags(controller-&amp;gt;GetMovementFlags() &amp;amp; ~movementFlag);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
UseAction::UseAction() : Action(kActionUse)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
UseAction::~UseAction()&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void UseAction::HandleEngage(void)&lt;br /&gt;
{&lt;br /&gt;
	// The player has pressed the fire/use button. If we are currently interacting with&lt;br /&gt;
	// a node in the scene and that node has a controller, then we send an activate event&lt;br /&gt;
	// to that controller to let it know that the player is doing something with it.&lt;br /&gt;
&lt;br /&gt;
	SoldierController *controller = TheGame-&amp;gt;GetSoldierController();&lt;br /&gt;
	if (controller)&lt;br /&gt;
	{&lt;br /&gt;
		const SoldierInteractor *interactor = controller-&amp;gt;GetSoldierInteractor();&lt;br /&gt;
		const Node *interactionNode = interactor-&amp;gt;GetInteractionNode();&lt;br /&gt;
		if (interactionNode)&lt;br /&gt;
		{&lt;br /&gt;
			Controller *interactionController = interactionNode-&amp;gt;GetController();&lt;br /&gt;
			if (interactionController)&lt;br /&gt;
			{&lt;br /&gt;
				interactionController-&amp;gt;HandleInteractionEvent(kEventInteractionActivate, &amp;amp;interactor-&amp;gt;GetInteractionPosition(), controller-&amp;gt;GetTargetNode());&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void UseAction::HandleDisengage(void)&lt;br /&gt;
{&lt;br /&gt;
	// The player has released the fire/use button. Let the node with which we are interacting&lt;br /&gt;
	// know that we are done with it by sending its controller a deactivate event.&lt;br /&gt;
&lt;br /&gt;
	SoldierController *controller = TheGame-&amp;gt;GetSoldierController();&lt;br /&gt;
	if (controller)&lt;br /&gt;
	{&lt;br /&gt;
		const SoldierInteractor *interactor = controller-&amp;gt;GetSoldierInteractor();&lt;br /&gt;
		const Node *interactionNode = interactor-&amp;gt;GetInteractionNode();&lt;br /&gt;
		if (interactionNode)&lt;br /&gt;
		{&lt;br /&gt;
			Controller *interactionController = interactionNode-&amp;gt;GetController();&lt;br /&gt;
			if (interactionController)&lt;br /&gt;
			{&lt;br /&gt;
				interactionController-&amp;gt;HandleInteractionEvent(kEventInteractionDeactivate, &amp;amp;interactor-&amp;gt;GetInteractionPosition(), controller-&amp;gt;GetTargetNode());&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SoldierInteractor::SoldierInteractor(SoldierController *controller)&lt;br /&gt;
{&lt;br /&gt;
	soldierController = controller;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
SoldierInteractor::~SoldierInteractor()&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void SoldierInteractor::HandleInteractionEvent(EventType type, Node *node, const InteractionProperty *property, const Point3D *position)&lt;br /&gt;
{&lt;br /&gt;
	// Always call the base class counterpart.&lt;br /&gt;
&lt;br /&gt;
	Interactor::HandleInteractionEvent(type, node, property, position);&lt;br /&gt;
&lt;br /&gt;
	// If the node with which we are interacting has a controller,&lt;br /&gt;
	// then pass the event through to that controller.&lt;br /&gt;
&lt;br /&gt;
	Controller *controller = node-&amp;gt;GetController();&lt;br /&gt;
	if (controller)&lt;br /&gt;
	{&lt;br /&gt;
		controller-&amp;gt;HandleInteractionEvent(type, position);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SoldierController::SoldierController(float azimuth) :&lt;br /&gt;
		CharacterController(kControllerSoldier),&lt;br /&gt;
		soldierInteractor(this)&lt;br /&gt;
{&lt;br /&gt;
	soldierMotion = kMotionNone;&lt;br /&gt;
	movementFlags = 0;&lt;br /&gt;
&lt;br /&gt;
	modelAzimuth = azimuth;&lt;br /&gt;
	modelAltitude = 0.0F;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
SoldierController::SoldierController(const SoldierController&amp;amp; soldierController) :&lt;br /&gt;
		CharacterController(soldierController),&lt;br /&gt;
		soldierInteractor(this)&lt;br /&gt;
{&lt;br /&gt;
	soldierMotion = kMotionNone;&lt;br /&gt;
	movementFlags = 0;&lt;br /&gt;
&lt;br /&gt;
	modelAzimuth = 0.0F;&lt;br /&gt;
	modelAltitude = 0.0F;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
SoldierController::~SoldierController()&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Controller *SoldierController::Replicate(void) const&lt;br /&gt;
{&lt;br /&gt;
	return (new SoldierController(*this));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void SoldierController::PreprocessController(void)&lt;br /&gt;
{&lt;br /&gt;
	// This function is called once before the target node is ever&lt;br /&gt;
	// rendered or moved. The base class PreprocessController() function&lt;br /&gt;
	// should always be called first, and then the subclass can do whatever&lt;br /&gt;
	// preprocessing it needs to do.&lt;br /&gt;
&lt;br /&gt;
	CharacterController::PreprocessController();&lt;br /&gt;
&lt;br /&gt;
	SetRigidBodyFlags(kRigidBodyKeepAwake | kRigidBodyFixedOrientation);&lt;br /&gt;
	SetFrictionCoefficient(0.0F);&lt;br /&gt;
&lt;br /&gt;
	// We use a frame animator to play animation resources&lt;br /&gt;
	// for the soldier model.&lt;br /&gt;
&lt;br /&gt;
	Model *soldier = GetTargetNode();&lt;br /&gt;
	frameAnimator.SetTargetModel(soldier);&lt;br /&gt;
	soldier-&amp;gt;SetRootAnimator(&amp;amp;frameAnimator);&lt;br /&gt;
&lt;br /&gt;
	// Initialize the previous center of mass to the current center of mass&lt;br /&gt;
	// so that this doesn't contain garbage the first time we call ActivateTriggers().&lt;br /&gt;
&lt;br /&gt;
	previousCenterOfMass = GetWorldCenterOfMass();&lt;br /&gt;
&lt;br /&gt;
	// Register our interactor with the world.&lt;br /&gt;
&lt;br /&gt;
	soldier-&amp;gt;GetWorld()-&amp;gt;AddInteractor(&amp;amp;soldierInteractor);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void SoldierController::MoveController(void)&lt;br /&gt;
{&lt;br /&gt;
	// This function is called once per frame to allow the controller to&lt;br /&gt;
	// move its target node.&lt;br /&gt;
&lt;br /&gt;
	// The movementIndexTable is a 16-entry table that maps all combinations of&lt;br /&gt;
	// the forward, backward, left, and right movement flags to one of eight directions.&lt;br /&gt;
	// The direction codes are as follows:&lt;br /&gt;
	//&lt;br /&gt;
	// 0 - forward&lt;br /&gt;
	// 1 - backward&lt;br /&gt;
	// 2 - left&lt;br /&gt;
	// 3 - right&lt;br /&gt;
	// 4 - forward and left&lt;br /&gt;
	// 5 - forward and right&lt;br /&gt;
	// 6 - backward and left&lt;br /&gt;
	// 7 - backward and right&lt;br /&gt;
	//&lt;br /&gt;
	// The number 8 in the table means no movement, and it appears where either no&lt;br /&gt;
	// movement buttons are being pressed or two opposing buttons are the only ones pressed&lt;br /&gt;
	// (e.g., left and right pressed simultaneously cancel each other out).&lt;br /&gt;
&lt;br /&gt;
	static const uint8 movementIndexTable[16] =&lt;br /&gt;
	{&lt;br /&gt;
		8, 0, 1, 8,&lt;br /&gt;
		2, 4, 6, 2,&lt;br /&gt;
		3, 5, 7, 3,&lt;br /&gt;
		8, 0, 1, 8&lt;br /&gt;
	};&lt;br /&gt;
&lt;br /&gt;
	// First, we grab the mouse deltas from the Input Manager.&lt;br /&gt;
	// We use these to change the angles representing the direction in&lt;br /&gt;
	// which the player is looking/moving.&lt;br /&gt;
&lt;br /&gt;
	float azm = modelAzimuth + TheInputMgr-&amp;gt;GetMouseDeltaX();&lt;br /&gt;
	if (azm &amp;lt; -Math::tau_over_2)&lt;br /&gt;
	{&lt;br /&gt;
		azm += Math::tau;&lt;br /&gt;
	}&lt;br /&gt;
	else if (azm &amp;gt; Math::tau_over_2)&lt;br /&gt;
	{&lt;br /&gt;
		azm -= Math::tau;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	float alt = Clamp(modelAltitude + TheInputMgr-&amp;gt;GetMouseDeltaY(), -1.45F, 1.45F);&lt;br /&gt;
&lt;br /&gt;
	modelAzimuth = azm;&lt;br /&gt;
	modelAltitude = alt;&lt;br /&gt;
&lt;br /&gt;
	// Now, we determine whether the player is attempting to move, and&lt;br /&gt;
	// we play the appropriate animation on the soldier model.&lt;br /&gt;
&lt;br /&gt;
	int32 motion = kMotionStand;&lt;br /&gt;
	Vector2D propel(0.0F, 0.0F);&lt;br /&gt;
&lt;br /&gt;
	int32 index = movementIndexTable[movementFlags &amp;amp; kMovementPlanarMask];&lt;br /&gt;
	if (index &amp;lt; 8)&lt;br /&gt;
	{&lt;br /&gt;
		// The movementDirectionTable maps each direction code looked up in the&lt;br /&gt;
		// movementIndexTable to an angle measured counterclockwise from the straight&lt;br /&gt;
		// ahead direction in units of tau/8.&lt;br /&gt;
&lt;br /&gt;
		static const float movementDirectionTable[8] =&lt;br /&gt;
		{&lt;br /&gt;
			0.0F, 4.0F, 2.0F, -2.0F, 1.0F, -1.0F, 3.0F, -3.0F&lt;br /&gt;
		};&lt;br /&gt;
&lt;br /&gt;
		float direction = movementDirectionTable[index] * Math::tau_over_8 + modelAzimuth;&lt;br /&gt;
&lt;br /&gt;
		// Set the propulsive force based on the direction of movement.&lt;br /&gt;
&lt;br /&gt;
		Vector2D cs = CosSin(direction);&lt;br /&gt;
		propel.Set(cs.x * 100.0F, cs.y * 100.0F);&lt;br /&gt;
&lt;br /&gt;
		// Determine whether we should play the forward or backward running animation.&lt;br /&gt;
&lt;br /&gt;
		motion = ((index == 1) || (index &amp;gt;= 6)) ? kMotionBackward : kMotionForward;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	// Update the external force for the rigid body representing the character.&lt;br /&gt;
	// The GetGroundContact() function is a member of the CharacterController base class.&lt;br /&gt;
&lt;br /&gt;
	if (GetGroundContact())&lt;br /&gt;
	{&lt;br /&gt;
		SetExternalLinearResistance(Vector2D(10.0F, 10.0F));&lt;br /&gt;
		SetExternalForce(propel);&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		// If the soldier is not on the ground, reduce the propulsive force down to 2%.&lt;br /&gt;
		// This controls how well the player is able to control his movement while&lt;br /&gt;
		// falling through the air.&lt;br /&gt;
&lt;br /&gt;
		SetExternalLinearResistance(Vector2D::zero);&lt;br /&gt;
		SetExternalForce(propel * 0.02F);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	// Change the soldier's orientation based on horizontal mouse movement.&lt;br /&gt;
	// The SetCharacterOrientation() function is a member of the CharacterController base class.&lt;br /&gt;
&lt;br /&gt;
	SetCharacterOrientation(modelAzimuth);&lt;br /&gt;
&lt;br /&gt;
	// If the animation needs to be changed, do it.&lt;br /&gt;
&lt;br /&gt;
	if (motion != soldierMotion)&lt;br /&gt;
	{&lt;br /&gt;
		SetSoldierMotion(motion);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	// Activate triggers along the line connecting to the current center of mass&lt;br /&gt;
	// from the center of mass in the previous frame.&lt;br /&gt;
&lt;br /&gt;
	Model *model = GetTargetNode();&lt;br /&gt;
	model-&amp;gt;GetWorld()-&amp;gt;ActivateTriggers(previousCenterOfMass, GetWorldCenterOfMass(), 0.25F, model);&lt;br /&gt;
	previousCenterOfMass = GetWorldCenterOfMass();&lt;br /&gt;
&lt;br /&gt;
	// Call the Model::AnimateModel() function to update the animation playing for the model.&lt;br /&gt;
&lt;br /&gt;
	GetTargetNode()-&amp;gt;AnimateModel();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void SoldierController::SetSoldierMotion(int32 motion)&lt;br /&gt;
{&lt;br /&gt;
	// This function sets the animation resource corresponding to&lt;br /&gt;
	// the current type of motion assigned to the soldier.&lt;br /&gt;
&lt;br /&gt;
	Interpolator *interpolator = frameAnimator.GetFrameInterpolator();&lt;br /&gt;
&lt;br /&gt;
	if (motion == kMotionStand)&lt;br /&gt;
	{&lt;br /&gt;
		frameAnimator.SetAnimation(&amp;quot;soldier/Stand&amp;quot;);&lt;br /&gt;
		interpolator-&amp;gt;SetMode(kInterpolatorForward | kInterpolatorLoop);&lt;br /&gt;
	}&lt;br /&gt;
	else if (motion == kMotionForward)&lt;br /&gt;
	{&lt;br /&gt;
		frameAnimator.SetAnimation(&amp;quot;soldier/Run&amp;quot;);&lt;br /&gt;
		interpolator-&amp;gt;SetMode(kInterpolatorForward | kInterpolatorLoop);&lt;br /&gt;
	}&lt;br /&gt;
	else if (motion == kMotionBackward)&lt;br /&gt;
	{&lt;br /&gt;
		frameAnimator.SetAnimation(&amp;quot;soldier/Backward&amp;quot;);&lt;br /&gt;
		interpolator-&amp;gt;SetMode(kInterpolatorForward | kInterpolatorLoop);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	soldierMotion = motion;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ChaseCamera::ChaseCamera() : FrustumCamera(2.67F, 1.0F)&lt;br /&gt;
{&lt;br /&gt;
	targetModel = nullptr;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
ChaseCamera::~ChaseCamera()&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void ChaseCamera::MoveCamera(void)&lt;br /&gt;
{&lt;br /&gt;
	Model *model = GetTargetModel();&lt;br /&gt;
	if (model)&lt;br /&gt;
	{&lt;br /&gt;
		CollisionData	data;&lt;br /&gt;
&lt;br /&gt;
		SoldierController *controller = static_cast&amp;lt;SoldierController *&amp;gt;(model-&amp;gt;GetController());&lt;br /&gt;
&lt;br /&gt;
		// Here, we calculate the local coordinate frame for the chase camera&lt;br /&gt;
		// based on the direction that the player is looking.&lt;br /&gt;
&lt;br /&gt;
		Vector2D t = CosSin(controller-&amp;gt;GetModelAzimuth());&lt;br /&gt;
		Vector2D u = CosSin(controller-&amp;gt;GetModelAltitude());&lt;br /&gt;
&lt;br /&gt;
		Vector3D view(t.x * u.x, t.y * u.x, u.y);&lt;br /&gt;
		Vector3D right(t.y, -t.x, 0.0F);&lt;br /&gt;
		Vector3D down = Cross(view, right);&lt;br /&gt;
&lt;br /&gt;
		// We are going to place the camera behind the player, but we don't&lt;br /&gt;
		// want the camera to go through any geometry, so we'll do a quick&lt;br /&gt;
		// check for a collision.&lt;br /&gt;
&lt;br /&gt;
		const Point3D&amp;amp; position = model-&amp;gt;GetWorldPosition();&lt;br /&gt;
		Point3D p1(position.x, position.y, position.z + 1.5F);&lt;br /&gt;
		Point3D p2 = p1 - view * 4.0F;&lt;br /&gt;
&lt;br /&gt;
		if (GetWorld()-&amp;gt;DetectCollision(p1, p2, 0.3F, kCollisionCamera, &amp;amp;data))&lt;br /&gt;
		{&lt;br /&gt;
			// There's something in the way, so move the camera in closer&lt;br /&gt;
			// to the player.&lt;br /&gt;
&lt;br /&gt;
			float s = data.param;&lt;br /&gt;
			p2 = p1 * (1.0F - s) + p2 * s;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Set the camera's position and orientation.&lt;br /&gt;
&lt;br /&gt;
		SetNodeTransform(right, down, view, p2);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
GameWorld::GameWorld(const char *name) : World(name)&lt;br /&gt;
{&lt;br /&gt;
	// This constructor is called when the Game::CreateWorld() function is&lt;br /&gt;
	// called to create a new world class. The world hasn't actually been loaded&lt;br /&gt;
	// from disk yet when we get here.&lt;br /&gt;
&lt;br /&gt;
	spawnLocator = nullptr;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
GameWorld::~GameWorld()&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
const LocatorMarker *GameWorld::FindSpawnLocator(const Zone *zone)&lt;br /&gt;
{&lt;br /&gt;
	// Iterate through all of the markers in the zone.&lt;br /&gt;
&lt;br /&gt;
	const Marker *marker = zone-&amp;gt;GetFirstMarker();&lt;br /&gt;
	while (marker)&lt;br /&gt;
	{&lt;br /&gt;
		if (marker-&amp;gt;NodeEnabled())&lt;br /&gt;
		{&lt;br /&gt;
			MarkerType type = marker-&amp;gt;GetMarkerType();&lt;br /&gt;
			if (type == kMarkerLocator)&lt;br /&gt;
			{&lt;br /&gt;
				const LocatorMarker *locator = static_cast&amp;lt;const LocatorMarker *&amp;gt;(marker);&lt;br /&gt;
				if (locator-&amp;gt;GetLocatorType() == kLocatorSpawn)&lt;br /&gt;
				{&lt;br /&gt;
					return (locator);&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Get the next marker in the list.&lt;br /&gt;
&lt;br /&gt;
		marker = marker-&amp;gt;GetNextListElement();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	// Look in all of the subzones.&lt;br /&gt;
&lt;br /&gt;
	const Zone *subzone = zone-&amp;gt;GetFirstSubzone();&lt;br /&gt;
	while (subzone)&lt;br /&gt;
	{&lt;br /&gt;
		const LocatorMarker *locator = FindSpawnLocator(subzone);&lt;br /&gt;
		if (locator)&lt;br /&gt;
		{&lt;br /&gt;
			return (locator);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		subzone = subzone-&amp;gt;ListElement&amp;lt;Zone&amp;gt;::GetNextListElement();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	return (nullptr);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
WorldResult GameWorld::PreprocessWorld(void)&lt;br /&gt;
{&lt;br /&gt;
	// The PreprocessWorld() function is called after the world has been constructed.&lt;br /&gt;
	// We must always call the base class PreprocessWorld() function first. If it&lt;br /&gt;
	// returns an error, then we just return the same result code.&lt;br /&gt;
&lt;br /&gt;
	WorldResult result = World::PreprocessWorld();&lt;br /&gt;
	if (result != kWorldOkay)&lt;br /&gt;
	{&lt;br /&gt;
		return (result);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	// The world is now completely loaded. We search for a locator node that represents the&lt;br /&gt;
	// player's spawn position. It has a locator type of kLocatorSpawn.&lt;br /&gt;
&lt;br /&gt;
	spawnLocator = FindSpawnLocator(GetRootNode());&lt;br /&gt;
	return (kWorldOkay);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void GameWorld::HandlePhysicsSpaceExit(RigidBodyController *rigidBody)&lt;br /&gt;
{&lt;br /&gt;
	// Do nothing because this code can't handle it.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void GameWorld::DetectInteractions(void)&lt;br /&gt;
{&lt;br /&gt;
	// The DetectInteractions() function is called once per frame. Before calling the base&lt;br /&gt;
	// class's DetectInteractions() function, we set up the interaction probe to be a line&lt;br /&gt;
	// segment extending two meters from the players head in the direction that the&lt;br /&gt;
	// camera is looking.&lt;br /&gt;
&lt;br /&gt;
	SoldierController *controller = TheGame-&amp;gt;GetSoldierController();&lt;br /&gt;
	if (controller)&lt;br /&gt;
	{&lt;br /&gt;
		const Point3D&amp;amp; p = controller-&amp;gt;GetTargetNode()-&amp;gt;GetWorldPosition();&lt;br /&gt;
		Point3D position(p.x, p.y, p.z + 1.5F);&lt;br /&gt;
&lt;br /&gt;
		const Vector3D&amp;amp; direction = chaseCamera.GetWorldTransform()[2];&lt;br /&gt;
		controller-&amp;gt;GetSoldierInteractor()-&amp;gt;SetInteractionProbe(position, position + direction * 2.0F);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	// Always call the base class counterpart.&lt;br /&gt;
&lt;br /&gt;
	World::DetectInteractions();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void GameWorld::RenderWorld(void)&lt;br /&gt;
{&lt;br /&gt;
	// This function is called once per frame to render the world.&lt;br /&gt;
	// The subclass may do whatever it needs to before or after rendering,&lt;br /&gt;
	// but at some point must call World::RenderWorld().&lt;br /&gt;
&lt;br /&gt;
	World::RenderWorld();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Game::Game() :&lt;br /&gt;
&lt;br /&gt;
		// This is the constructor for the main application/game module class.&lt;br /&gt;
		// This class is created by the CreateApplication() function, which is&lt;br /&gt;
		// called right after the application/game DLL is loaded by the engine.&lt;br /&gt;
		// We initialize the global pointer to the current game instance first.&lt;br /&gt;
&lt;br /&gt;
		Global&amp;lt;Game&amp;gt;(TheGame),&lt;br /&gt;
&lt;br /&gt;
		// A model registration represents a model that can be instanced.&lt;br /&gt;
		// This particular declaration associates the kModelSoldier type with the&lt;br /&gt;
		// model named &amp;quot;soldier/Soldier.mdl&amp;quot;. The fourth parameter tells the engine&lt;br /&gt;
		// to precache the model resource and not to display the model in the&lt;br /&gt;
		// World Editor. The last parameter specifies the default controller&lt;br /&gt;
		// type to assign to models of type kModelSoldier.&lt;br /&gt;
&lt;br /&gt;
		soldierModelReg(kModelSoldier, nullptr, &amp;quot;soldier/Soldier&amp;quot;, kModelPrecache | kModelPrivate, kControllerSoldier),&lt;br /&gt;
&lt;br /&gt;
		// Locator markers are registered so that the World Editor&lt;br /&gt;
		// can display their names in the Markers page.&lt;br /&gt;
&lt;br /&gt;
		locatorReg(kLocatorSpawn, &amp;quot;Spawn Location&amp;quot;)&lt;br /&gt;
{&lt;br /&gt;
	// This sets the function that is called when the user hits the&lt;br /&gt;
	// escape key during gameplay. We save the old function so that&lt;br /&gt;
	// it can be restored when the game DLL is unloaded.&lt;br /&gt;
&lt;br /&gt;
	prevEscapeCallback = TheInputMgr-&amp;gt;GetEscapeCallback();&lt;br /&gt;
	prevEscapeCookie = TheInputMgr-&amp;gt;GetEscapeCookie();&lt;br /&gt;
	TheInputMgr-&amp;gt;SetEscapeCallback(&amp;amp;EscapeCallback, this);&lt;br /&gt;
&lt;br /&gt;
	// This registers our world class constructor with the World Manager.&lt;br /&gt;
	// We only need to do this if we have defined a subclass of the World&lt;br /&gt;
	// class that holds extra information.&lt;br /&gt;
&lt;br /&gt;
	TheWorldMgr-&amp;gt;SetWorldCreator(&amp;amp;CreateWorld);&lt;br /&gt;
&lt;br /&gt;
	// These create the movement actions that are used to&lt;br /&gt;
	// move the player around and interact with objects.&lt;br /&gt;
&lt;br /&gt;
	forwardAction = new MovementAction(kActionForward, kMovementForward);&lt;br /&gt;
	backwardAction = new MovementAction(kActionBackward, kMovementBackward);&lt;br /&gt;
	leftAction = new MovementAction(kActionLeft, kMovementLeft);&lt;br /&gt;
	rightAction = new MovementAction(kActionRight, kMovementRight);&lt;br /&gt;
	upAction = new MovementAction(kActionUp, kMovementUp);&lt;br /&gt;
	downAction = new MovementAction(kActionDown, kMovementDown);&lt;br /&gt;
	useAction = new UseAction;&lt;br /&gt;
&lt;br /&gt;
	// These register our new actions with the Input Manager.&lt;br /&gt;
&lt;br /&gt;
	TheInputMgr-&amp;gt;AddAction(forwardAction);&lt;br /&gt;
	TheInputMgr-&amp;gt;AddAction(backwardAction);&lt;br /&gt;
	TheInputMgr-&amp;gt;AddAction(leftAction);&lt;br /&gt;
	TheInputMgr-&amp;gt;AddAction(rightAction);&lt;br /&gt;
	TheInputMgr-&amp;gt;AddAction(upAction);&lt;br /&gt;
	TheInputMgr-&amp;gt;AddAction(downAction);&lt;br /&gt;
	TheInputMgr-&amp;gt;AddAction(useAction);&lt;br /&gt;
&lt;br /&gt;
	// Let the Interface Manager determine when to change input devices to gameplay mode.&lt;br /&gt;
&lt;br /&gt;
	TheInterfaceMgr-&amp;gt;SetInputManagementMode(kInputManagementAutomatic);&lt;br /&gt;
&lt;br /&gt;
	soldierController = nullptr;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Game::~Game()&lt;br /&gt;
{&lt;br /&gt;
	// When the game DLL is about to be unloaded, this destructor is called.&lt;br /&gt;
&lt;br /&gt;
	TheWorldMgr-&amp;gt;UnloadWorld();&lt;br /&gt;
	TheWorldMgr-&amp;gt;SetWorldCreator(nullptr);&lt;br /&gt;
&lt;br /&gt;
	delete useAction;&lt;br /&gt;
	delete downAction;&lt;br /&gt;
	delete upAction;&lt;br /&gt;
	delete rightAction;&lt;br /&gt;
	delete leftAction;&lt;br /&gt;
	delete backwardAction;&lt;br /&gt;
	delete forwardAction;&lt;br /&gt;
&lt;br /&gt;
	// Restore the previous escape key handling function.&lt;br /&gt;
&lt;br /&gt;
	TheInputMgr-&amp;gt;SetEscapeCallback(prevEscapeCallback, prevEscapeCookie);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
World *Game::CreateWorld(const char *name, void *cookie)&lt;br /&gt;
{&lt;br /&gt;
	// This function is called when a new world is being loaded. It should&lt;br /&gt;
	// return a pointer to a newly constructed subclass of the World class.&lt;br /&gt;
&lt;br /&gt;
	return (new GameWorld(name));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void Game::EscapeCallback(void *cookie)&lt;br /&gt;
{&lt;br /&gt;
	// This function is called when the user hits the escape key in gameplay&lt;br /&gt;
	// mode because we registered it using the InputMgr::SetEscapeCallback() function.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
EngineResult Game::LoadWorld(const char *name)&lt;br /&gt;
{&lt;br /&gt;
	// Attempt to load the world.&lt;br /&gt;
&lt;br /&gt;
	WorldResult result = TheWorldMgr-&amp;gt;LoadWorld(name);&lt;br /&gt;
	if (result == kWorldOkay)&lt;br /&gt;
	{&lt;br /&gt;
		GameWorld *world = static_cast&amp;lt;GameWorld *&amp;gt;(TheWorldMgr-&amp;gt;GetWorld());&lt;br /&gt;
		const LocatorMarker *locator = world-&amp;gt;GetSpawnLocator();&lt;br /&gt;
		if (locator)&lt;br /&gt;
		{&lt;br /&gt;
			// If a spawn locator was found in the world, put a soldier character there.&lt;br /&gt;
&lt;br /&gt;
			// The BeginSinglePlayerGame() function puts the Message Manager in single player mode.&lt;br /&gt;
&lt;br /&gt;
			TheMessageMgr-&amp;gt;BeginSinglePlayerGame();&lt;br /&gt;
&lt;br /&gt;
			// Calculate the angle corresponding to the direction the character is initially facing.&lt;br /&gt;
&lt;br /&gt;
			const Vector3D direction = locator-&amp;gt;GetWorldTransform()[0];&lt;br /&gt;
			float azimuth = Arctan(direction.y, direction.x);&lt;br /&gt;
&lt;br /&gt;
			// Load a soldier model and attach a controller to it.&lt;br /&gt;
&lt;br /&gt;
			Model *model = Model::GetModel(kModelSoldier);&lt;br /&gt;
			SoldierController *controller = new SoldierController(azimuth);&lt;br /&gt;
			model-&amp;gt;SetController(controller);&lt;br /&gt;
			TheGame-&amp;gt;soldierController = controller;&lt;br /&gt;
&lt;br /&gt;
			// Put the model in the world at the locator's position.&lt;br /&gt;
&lt;br /&gt;
			model-&amp;gt;SetNodePosition(locator-&amp;gt;GetWorldPosition());&lt;br /&gt;
			locator-&amp;gt;GetWorld()-&amp;gt;AddNewNode(model);&lt;br /&gt;
&lt;br /&gt;
			// Set the world's current camera to be our chase camera.&lt;br /&gt;
			// The world will not render without a camera being set.&lt;br /&gt;
&lt;br /&gt;
			ChaseCamera *camera = world-&amp;gt;GetChaseCamera();&lt;br /&gt;
			camera-&amp;gt;SetTargetModel(model);&lt;br /&gt;
			world-&amp;gt;SetWorldCamera(camera);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	return (result);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void Game::UnloadWorld(void)&lt;br /&gt;
{&lt;br /&gt;
	TheWorldMgr-&amp;gt;UnloadWorld();&lt;br /&gt;
&lt;br /&gt;
	TheMessageMgr-&amp;gt;EndGame();&lt;br /&gt;
&lt;br /&gt;
	TheGame-&amp;gt;soldierController = nullptr;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[Simple Games]]&lt;br /&gt;
* [[SimpleBall Source Code]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Eric Lengyel</name></author>
	</entry>
</feed>