void ad_grav_wall::setup( ofImage * img, ofCamera *cam ){ if( !bInitPhysics ){ world.setup(); world.setCamera( cam ); world.setGravity( ofVec3f(0, 0, 0) ); // world.enableCollisionEvents(); // ofAddListener(world.COLLISION_EVENT, this, &ad_grav_wall::onCollision); for( int i=1; i<=30; i++ ){ float size = 13 + i; sphereShapes.push_back( ofBtGetSphereCollisionShape( size ) ); cout << ofToString(size,2) << " "; } cout << endl; bInitPhysics = true; pid = -1; } points.setUsage( GL_DYNAMIC_DRAW ); points.setMode( OF_PRIMITIVE_POINTS ); lines.setUsage( GL_DYNAMIC_DRAW ); lines.setMode( OF_PRIMITIVE_LINES ); prep_lines.setUsage( GL_DYNAMIC_DRAW ); prep_lines.setMode( OF_PRIMITIVE_LINES ); colref = img; wall_thickness = 80; }
void ofApp::setup(){ ofSetFrameRate( 60 ); ofSetVerticalSync( true ); cam.setDistance( 150 ); bDraw_info = true; rot_angle = 0; points.setUsage( GL_DYNAMIC_DRAW ); points.setMode( OF_PRIMITIVE_POINTS ); lines.setUsage( GL_DYNAMIC_DRAW ); lines.setMode( OF_PRIMITIVE_LINES ); world.setup(); // world.enableCollisionEvents(); // ofAddListener( world.COLLISION_EVENT, this, &ofApp::onCollision ); world.setCamera( &cam ); world.setGravity( ofVec3f(0, 0, 0) ); sphereShape = ofBtGetSphereCollisionShape( 1.0 ); for( int i=0; i<100; i++){ add_dust( 100 ); } }
//-------------------------------------------------------------- void testApp::setup() { ofSetFrameRate(60); ofSetVerticalSync(true); ofBackground( 10, 10, 10); camera.setPosition(ofVec3f(0, -4.f, -40.f)); camera.lookAt(ofVec3f(0, 0, 0), ofVec3f(0, -1, 0)); camera.cacheMatrices(true); world.setup(); // enables mouse Pick events // world.enableGrabbing(); ofAddListener(world.MOUSE_PICK_EVENT, this, &testApp::mousePickEvent); world.enableCollisionEvents(); ofAddListener(world.COLLISION_EVENT, this, &testApp::onCollision); world.setCamera(&camera); world.setGravity( ofVec3f(0, 25., 0) ); int ii = 0; // let's make a shape that all of the rigid bodies use, since it is faster // // though all of the spheres will be the same radius // sphereShape = ofBtGetSphereCollisionShape(2.5); for (int i = 0; i < 4; i++) { shapes.push_back( new ofxBulletSphere() ); ii = shapes.size()-1; ((ofxBulletSphere*)shapes[ii])->init(sphereShape); // no need to pass radius, since we already created it in the sphereShape // ((ofxBulletSphere*)shapes[ii])->create(world.world, ofVec3f(ofRandom(-3, 3), ofRandom(-2, 2), ofRandom(-1, 1)), 0.1); shapes[ii]->setActivationState( DISABLE_DEACTIVATION ); shapes[ii]->add(); bColliding.push_back( false ); } // now lets add some boxes // boxShape = ofBtGetBoxCollisionShape(2.65, 2.65, 2.65); for (int i = 0; i < 4; i++) { shapes.push_back( new ofxBulletBox() ); ii = shapes.size()-1; ((ofxBulletBox*)shapes[ii])->init(boxShape); ((ofxBulletBox*)shapes[ii])->create(world.world, ofVec3f(ofRandom(-3, 3), ofRandom(-2, 2), ofRandom(-1, 1)), 0.2); shapes[ii]->setActivationState( DISABLE_DEACTIVATION ); shapes[ii]->add(); bColliding.push_back( false ); } ofVec3f startLoc; ofPoint dimens; boundsWidth = 30.; float hwidth = boundsWidth*.5; float depth = 2.; float hdepth = depth*.5; for(int i = 0; i < 6; i++) { bounds.push_back( new ofxBulletBox() ); if(i == 0) { // ground // startLoc.set( 0., hwidth+hdepth, 0. ); dimens.set(boundsWidth, depth, boundsWidth); } else if (i == 1) { // back wall // startLoc.set(0, 0, hwidth+hdepth); dimens.set(boundsWidth, boundsWidth, depth); } else if (i == 2) { // right wall // startLoc.set(hwidth+hdepth, 0, 0.); dimens.set(depth, boundsWidth, boundsWidth); } else if (i == 3) { // left wall // startLoc.set(-hwidth-hdepth, 0, 0.); dimens.set(depth, boundsWidth, boundsWidth); } else if (i == 4) { // ceiling // startLoc.set(0, -hwidth-hdepth, 0.); dimens.set(boundsWidth, depth, boundsWidth); } else if (i == 5) { // front wall // startLoc.set(0, 0, -hwidth-hdepth); dimens.set(boundsWidth, boundsWidth, depth); } bounds[i]->create( world.world, startLoc, 0., dimens.x, dimens.y, dimens.z ); bounds[i]->setProperties(.25, .95); bounds[i]->add(); } mousePickIndex = -1; bDrawDebug = false; bRenderShapes = true; bAddCenterAttract = true; bSpacebar = false; }
void ofApp::setup(){ ofSetFrameRate( 60 ); ofSetVerticalSync( true ); cam.setDistance( 400 ); bDraw_info = true; points.setUsage( GL_DYNAMIC_DRAW ); points.setMode( OF_PRIMITIVE_POINTS ); p2p.setUsage( GL_DYNAMIC_DRAW ); p2p.setMode( OF_PRIMITIVE_LINES ); attrs.setUsage( GL_DYNAMIC_DRAW ); attrs.setMode( OF_PRIMITIVE_POINTS ); lines.setUsage( GL_DYNAMIC_DRAW ); lines.setMode( OF_PRIMITIVE_LINES ); world.setup(); world.setCamera( &cam ); world.setGravity( ofVec3f(0, 0, 0) ); sphereShape = ofBtGetSphereCollisionShape( 1.0 ); float w = ofGetWidth(); // for( int i=0; i<10; i++){ // add_dust( 10 ); // } int num = w/2; for(int i=0; i<num; i++){ float x = ((float)i/(num)-0.5) * 700.0; { ofVec3f pos( x, 10, 0); float mass = 3.0 - abs(x)/600.0*2; ofxBulletSphere * s= new ofxBulletSphere(); s->init( sphereShape ); s->create( world.world, pos, mass ); s->setActivationState( DISABLE_DEACTIVATION ); s->add(); shapes.push_back( s ); points.addVertex( pos ); } } for(int i=0; i<num; i++){ float x = ((float)i/(num)-0.5) * 700.0; { ofVec3f pos( x, -10, 0); float mass = 10.0 - abs(x)/500.0*9.8; ofxBulletSphere * s= new ofxBulletSphere(); s->init( sphereShape ); s->create( world.world, pos, mass ); s->setActivationState( DISABLE_DEACTIVATION ); s->add(); shapes.push_back( s ); points.addVertex( pos ); } } w *= 1.1; int step = 50; float adder = w/step; for( int i=0; i<step; i++ ){ float x = i * adder - w/2; attrs.addVertex( ofVec3f(x, ofNoise(i, x)*50, 0) ); attrs.addColor( ofFloatColor(1,0,0) ); } }