O --- O
libpedsim Documentation
[HOME] [EXAMPLES] [DEMO APP] [DOCUMENTATION] [DOWNLOAD]
O --- O

libpedsim Documentation

General Usage Notes

In short for now:
More to follow. See the Code Example further down, and Demo Application as well, once the source code is available.

Detailed Class Documentation

There is a complete documentation of the classes in the library. It is automatically generated out of the source code. You can access this documentation online here. This same documentation is delivered as PDF file with the library for offline use.

Code Example

This example shows the very basic usage of the library. No fancy graphics, of course, only text output to the console. Additional code around it might be required in order to compile it. If you are using Windows and, for example, MS Visual C++ 2010 Express, you can create a new console application using the wizard. Create a file called example.cpp and copy-paste the code into it. In the project's Properties, under Linker/Input, add libpedsim.lib in front of the Additional Dependencies list. Click run. On a typical linux system, use this to compile, link and run:

g++ example.cpp -o example -lpedsim -L./libpedsim/ -I./libpedsim/
export LD_LIBRARY_PATH=./libpedsim
./example

It will create 100 agents, which are placed somewhat randomly distributed around -50/0. They should walk between -100/0 and 100/0. An obstacle (wall) is placed from 0/-50 to 0/50. The agents must walk around that obstacle. That's it, as simple as that: the agents will walk with that little code.

If you want to display some graphics, write a file, or send data over the network, you will get the agent's positions with a->getx() and a->gety(). Of course, you can inherit your own classes from Tagent, Tobctacle etc, if you want to have more control. See the Demo App Source for an example.


// file: example.cpp

#include "ped_includes.h"

#include <iostream>
#include <stdlib.h>

using namespace std;

int main(int argc, char *argv[]) {

  vector<Ped::Tagent*> myagents;
  Ped::Tscene *pedscene = new Ped::Tscene();

  Ped::Twaypoint w1(-100, 0, 24);
  Ped::Twaypoint w2(+100, 0, 12);

  pedscene->addObstacle(new Ped::Tobstacle(0, -50,  0, +50));

  for (int i = 0; i<100; i++) { 
    Ped::Tagent *a = new Ped::Tagent();
    
    a->addWaypoint(&w1);
    a->addWaypoint(&w2);

    a->setPosition(-50 + rand()/(RAND_MAX/80)-40, 0 + rand()/(RAND_MAX/20)-10, 0);

    pedscene->addAgent(a);
    myagents.push_back(a);
  }
  
  while (true) {
    for (vector<Ped::Tagent*>::iterator iter = myagents.begin(); iter != myagents.end(); ++iter) {
      Ped::Tagent *a = (*iter);
      a->move(0.2);
      a->print();
    }
  }

}

O --- O

(c) 2002-2012 by Christian Gloor [contact]