Esempio n. 1
0
void Pathfinding::unfoldRoute(Route& out, Space* unfoldee, Space* end, Entity* entity) {

    // NB: We're using a single-linked-list, so must retrace steps.
    Space* step = unfoldee;

    int timeout = 0;

    Vector3 halfSize = entity->getBoundingBox().size * 0.5;

    if(_showDebug) {
        cout << "Unfold: " << unfoldee->getArea().toString();
        cout << "End:    " << end->getArea().toString();
    }

    while(true) {
        if(step == step->astarParent) {
            if(_showDebug) cout << " breaking loop, recursion found. " << endl;
            break;
        }

        out.push_front(step->getCenter() - halfSize);

        if(++timeout > 10000) {
            if(_showDebug)
                cout << "Canceled unfolding. Iterations so far: " << timeout
                    << ". You probably have recursion? Or a too big map." << endl;
            break;
        }

        if(step->astarParent == 0) {
            if(_showDebug)
                cout << "Breaking, this space leads to NULL." << step->getArea().toString();
            break;
        }

        step = step->astarParent;
    }

    if(_showDebug)
        cout << "End of unfolding method." << endl;
}
void HelloParticlesApp::setup() {
	timer = new Timer();
	
	// init physics
	Space* space = new Space(getWindowWidth(), getWindowHeight(), 0);
	printf("init space %f %f %f\n", space->getWidth(), space->getHeight(), space->getDepth());
	
	physics = new Physics(space);
	
	Emitter* emitter = new Emitter(physics);
	physics->emitter = emitter;
	emitter->setPosition(space->getCenter());
	emitter->setInterval(0.01);
	emitter->setRate(1000);
	emitter->setMax(5000);
	
	emitter->addBehaviour(new RandomEmitter(space));
	physics->addBehaviour(new Gravity());
	
	// wrap
	BoxWrap* wrap = new BoxWrap(*space);
	wrap->preserveMomentum = false;
	physics->addBehaviour(wrap);
	
	// attractor 
	attractor = new AttractorPoint(space);
	attractor->setRange(0.25);
	attractor->setWeight(0);
	physics->addBehaviour(attractor);
	
	// init graphics
	gl::VboMesh::Layout layout;
	layout.setStaticIndices();
	layout.setDynamicPositions();
	layout.setStaticTexCoords2d();

	vboParticles = gl::VboMesh(emitter->getMax(), 0, layout, GL_POINTS);
}