Created
January 21, 2021 17:49
-
-
Save vanderlin/cb905bafc6e9aa5b84eca050e65d06b7 to your computer and use it in GitHub Desktop.
vector of ofxBox2d Circles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
//-------------------------------------------------------------- | |
void ofApp::setup() { | |
// first init box2d | |
box2d.init(); | |
// set the gravity | |
box2d.setGravity(0, 10); | |
// create bounds x,y,w,h | |
box2d.createBounds(); | |
// enable mouse grabbing | |
box2d.registerGrabbing(); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::update() { | |
if (ofGetFrameNum() % 30) { | |
// make a shared circle | |
auto circle = make_shared<ofxBox2dCircle>(); | |
// set the physics of the circle | |
circle->setPhysics(1, 0.7, 0.7); | |
// set the position and size of circle then add to the world | |
circle->setup(box2d.getWorld(), ofGetWidth()/2 + ofRandom(-10, 10), ofGetHeight()/2 + ofRandom(-10, 10), 10); | |
// add to the vector | |
circles.push_back(circle); | |
} | |
// update every frame | |
box2d.update(); | |
} | |
//-------------------------------------------------------------- | |
void ofApp::draw() { | |
for(auto &circle : circles) { | |
circle->draw(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment