Quick hand with ofxBox2d collisions

Im using ofxBox2D for a small particle system, it’s super simple, but I’m running into sloowwwwnesss because of how I’m testing collisions.

So… I have 5 planets that are big and static (not ofxBox2d objects), these get collided into by the circles (ofxBox2DCircles), so this is how i check:

void ofApp::update() {
    
    ofVec2f gravity;
    gravity.x = ofxAccelerometer.getForce().y*-5;
    gravity.y = ofxAccelerometer.getForce().x*-5;
    box2d.setGravity(gravity);
    
    for(int i=0; i<circles.size(); i++) {
        for (int j=0; j<numPlanets; j++) {
            
            if(planets[j].checkOn(circles[i].get()->getPosition())) circles[i].get()->addRepulsionForce(planets[j].pos, 4);
            else circles[i].get()->addAttractionPoint(planets[j].pos, 0.01);
        }
    }

    box2d.update();
}

How should i be doing it so it doesn’t run like a potato?
Thanks!

hello,

any reason you are using non ofxBox2d objects for the planets ?

It should work fine if you convert your planets into ofxBox2DEdges so ofxBox2D can automatically handle collisions

hi gallo,
thanks for the response, is there a way for the particles to get affected by the “gravity” of the planets?

hi,

i have never used box2D for that purpose but it should be possible. Or maybe at least you can create a point of attraction which resides inside the planet to simulate it ?

ah yeah, that sounds cunning. ill give it a go

otherwise, edges are ofxBaseShapes so you should be able to use physics on them like

addImpulseForce()

or

enableGravity()