[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
`flarge' contains a number of sectors and various objects, and those are now all loaded in memory. However this is not enough. We also have to set the camera to some sector and position in that world. In the previous tutorials we simply used the sector that we just created and a fixed position in that sector (keep in mind that in Crystal Space a position in space is always defined as a sector in combination with a position). When loading a map we can't work that way because we don't know which sectors are in the map (unless we make an application that can only read one level, but that's not very flexible) and we also don't know where we can safely put our camera. In the map files it is possible to specify one or more starting positions. We will query the engine for such a starting position and initialize our view (camera) to that. This happens with the following code:
First add the following to the include section:
#include "iengine/campos.h" |
Then add the following somewhere before the creation of the view:
// Find the starting position in this level. csVector3 pos (0, 0, 0); if (engine->GetCameraPositions ()->GetCount () > 0) { // There is a valid starting position defined in the level file. iCameraPosition* campos = engine->GetCameraPositions ()->Get (0); room = engine->GetSectors ()->FindByName (campos->GetSector ()); pos = campos->GetPosition (); } else { // We didn't find a valid starting position. So we default // to going to room called 'room' at position (0,0,0). room = engine->GetSectors ()->FindByName ("room"); } if (!room) { csReport (object_reg, CS_REPORTER_SEVERITY_ERROR, "crystalspace.application.simple", "Can't find a valid starting position!"); return false; } |
First we see how many camera positions there were defined in the
map by using iEngine::GetCameraPositionCount()
. If this is 0
then the map didn't define a starting position. In that case we will
assume there is a sector called 'room' and we will start the camera
at (0,0,0) in that sector. But otherwise we will use the first
starting position defined in the map.
Then you also have to modify the call to SetOrigin()
so that
it reads:
view->GetCamera ()->GetTransform ().SetOrigin (pos); |
This is all. After adding this code this application will now load the 'flarge' map and display it so you can run around in this level.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |