History: NxOgre Creating a Bloody Mess
Preview of version: 2
Creating a Bloody Mess
<h1 style="font-weight:normal;font-size:14pt;color:#333;letter-spacing:0;border:0;">Preamble</h1>
<p>
This small guide is for the 1.5.x releases of NxOgre; also known as <span style="color:red">Bloody Mess</span>, it is more technical than the other NxOgre guides and does expect you to have previous knowledge with NxOgre, or previously used a Physics engine with Ogre before.</p> <p>
Ready? Let's go.</p> <h1 style="font-weight:normal;font-size:14pt;color:#333;letter-spacing:0;">World, Scenes and TimeControllers</h1> <p style="font-size: larger;">Classes: World, Scene and TimeController</p>
<h2>World</h2>
World is the main class it's like the Ogre Root class. Being a singleton it is created and destroyed like so;
World* mWorld = World::createWorld(); World::destroyWorld();
<h2>Scene</h2> <p>A Scene is a portion of the World. There can be up to 32 of them, and they are almost infinite in size. Actors, Materials, Shapes cannot be shared between scenes, but Meshes and HeightFields can.
SceneDescription description; description.mGravity.y = -9.81f; // -9.81 m/s Scene* mScene = mWorld->createScene(description);
The TimeController is in charge of time. Once time has been "injected" into NxOgre (in fractions of seconds), it will propagate to all EventListeners; Singletons, Scenes, Renderables, Actors and then finally to Shapes.
mTimeController = TimeController::getSingleton();
static const float sTime = 1.0f/60.0f; mTimeController->advance(sTime);
<h2>ResourceSystem</h2> <p>The Resource system allows you to read and write to things; such as files, zip files or even chunks of memory. The ResourceSystem singleton is created automatically by World when it is created, but if you need to use it before, then like all Singletons you can pre-create them.
World::precreateSingletons();
ResourceSystem::getSingleton();
NxOgre doesn't know or really care how an Resource is written or read to, all of that is handled by the ResourceProtocol. Which turns all of the functions and classes
involved in writing and reading to resources in a nice and neat interface provided by NxOgre.
There are two default ResourceProtocols in NxOgre by default they are file and memory. File uses the Operating System's function to write and read to files, where as memory reserve a resizeable block of memory to be used as you wish, but to NxOgre they are both the same.
</p> <h2>Archives</h2> <p>An archive represents a folder, zip folder, website or any collection of resources, again to NxOgre they all behave the same. A ResourceProtocol implements an archive such as FileArchive or MemoryArchive, but keep everything abstract you will never have to deal with them. Instead you work with UniformResourceIdentifiers and ArchiveResourceIdentifiers.
</p> <h2>UniformResourceIdentifier</h2> <p>A UniformResourceIdentifier or URI, is the protocol and location of an archive described as a string. The syntax is much like the URI syntax you use on the web; </p><table style="width:50%; margin:1em auto 1em auto;font-size: 115%;border:1px solid #ccc;"> <tr> <td style="text-align:right;width:4em;">-+file+-</td> <td style="width:0.25em;text-align:center;font-weight:bolder;">:</td> <td>-+c:/Program Files/myGame/myMediaFolder+-</td> </tr> <tr> <td style="border-top:1px solid gray;text-align:center;"> Protocol </td> <td></td> <td style="border-top:1px solid gray;text-align:center;"> Location </td> </tr>
</table><p>To create an archive, we tell the ResourceSystem to open an Archive by giving a URI and a common name to assign it with.</p>
ResourceSystem::getSingleton()->openArchive("media", "file:c:/Program Files/myGame/myMediaFolder");
The Resources are the final class in the ResourceSystem. They provide direct functions to reading and writing to a file, with tons of helper functions and anything else you want to manipulate or gather information from. We open our Resource using a ArchiveResourceIdentifier and the read/write permissions.
Resource* resource = ResourceSystem::getSingleton()->open("media:myFile.nxs", Enums::ResourceAccess_ReadOnly);
ResourceSystem::getSingleton()->close(resource);
ArchiveResourceIdentifiers or ''ARI'' are use to identifiy a Resource inside an Archive. They are much like URIs but do not specifiy what protocol is being used, instead it specificies what the archive name is, rather than the location of the archive or the protocol, names of the resources are always relative to the archive and in some cases Resource names are not used at all such as the MemoryResourceProtocol.</p>
<table style="width:50%; margin:1em auto 1em auto;font-size: 115%;border:1px solid #ccc;"> <tr> <td style="text-align:right;width:4em;">-+media+-</td> <td style="width:0.25em;text-align:center;font-weight:bolder;">:</td> <td>-+myFile.nxs+-</td> </tr> <tr> <td style="border-top:1px solid gray;text-align:center;">Archive Name</td> <td></td> <td style="border-top:1px solid gray;text-align:center;">Resource Name</td> </tr>
</table><h1 style="font-weight:normal;font-size:14pt;color:#333;letter-spacing:0;">Meshes and Heightfields</h1> <p style="font-size: larger;">Classes: Mesh, MeshManager, ManualMesh, HeightField, HeightFieldManager and ManualHeightField.</p>
<h2>Mesh</h2>
The Mesh class may represent a "convex point cloud", "triangle soup", CCD Skeleton, piece of cloth or a SoftBody that may be created within NxOgre, or saved previously then loaded. PhysX mesh files names usually end in ".nxs" but that is entirely optional. One note to point out; They aren't Ogre meshes and they can't be used with Ogre. NxOgre can't use Ogre meshes either - without converting them first using a conversion tool such as Flour.
A Mesh may be loaded in via the MeshManager or created via the ManualMesh classes. The MeshManager is a singleton, and like all NxOgre Singletons it may be created before or most definitely when World is created.
MeshManager::getSingleton();
</div>