//--------------------------------- void GeneratedMesh::setup(ofxBulletWorldRigid &world, ofVec3f position, string url, ofVec3f ModelScale){ type = ShapeTypeAnimatedMesh; collisionTime = -120; ModelPath = url; this->position = position; this->world = &world; //rotation = btQuaternion(btVector3(0,1,0), ofDegToRad(-90)); //TODO to try with ofBtGetCylinderCollisionShape, for improve collision detection anisotropy = 4.; float fboDiv = 4.f; // ofSetMinMagFilters( GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR ); fbo.allocate( (float)ofGetWidth() / fboDiv, (float)ofGetWidth() / fboDiv, GL_RGB, 4 ); fbo.begin(); { ofClear(0, 0, 0, 255 ); ofSetColor( 11,90,121, 255); ofRect(0, 0, ofGetWidth(), ofGetHeight() ); ofSetColor(120, 140, 150, 255); int numIterations = 4; float inc = (float)fbo.getWidth() / ((float)numIterations); for( int i = 0; i < numIterations; i++ ) { float tx = (float)i*inc + inc; float ty = (float)i*inc + inc; ofSetColor(152,197,190, 255); ofSetLineWidth( 1.5 ); if( i % 2 == 0 ) ofSetLineWidth( 0.5 ); ofLine( tx, 0, tx, fbo.getHeight() ); ofLine( 0, ty, fbo.getWidth(), ty ); } } fbo.end(); ofSetLineWidth( 1 ); fbo.getTextureReference().bind(); glGenerateMipmap( fbo.getTextureReference().texData.textureTarget); ofSetMinMagFilters( GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR ); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy); // glSamplerParameterf( fbo.getTextureReference().texData.textureTarget, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2 ); fbo.getTextureReference().unbind(); omesh = ofMesh::plane( 70, 70, 14, 14, OF_PRIMITIVE_TRIANGLES ); ofQuaternion rquat; rquat.makeRotate( 90, 1, 0, 0); ofSeedRandom(); float rseed = ofRandom(0, 10000); vector< ofVec3f >& verts = omesh.getVertices(); for( int i = 0; i < verts.size(); i++ ) { verts[i] = rquat * verts[i]; verts[i].y = ofSignedNoise( verts[i].x*0.02, verts[i].y*0.02 + verts[i].z*0.02, ofGetElapsedTimef() * 0.1 + rseed ) * 3; } vector< ofVec2f >& tcoords = omesh.getTexCoords(); for( int i = 0; i < tcoords.size(); i++ ) { tcoords[i].x *= 4.f; tcoords[i].y *= 4.f; } mesh = omesh; //ofEnableSeparateSpecularLight(); //save init values initScale = scale; // create ofxBullet shape //body.create(world.world, position, 0); // we set m=0 for kinematic body body.create( world.world, mesh, position, 0.f, ofVec3f(-10000, -10000, -10000), ofVec3f(10000,10000,10000) ); body.add(); body.enableKinematic(); body.setActivationState( DISABLE_DEACTIVATION ); bAnimate = true; body.add(); //body.setProperties(1., 0.); // .25 (more restituition means more energy) , .95 ( friction ) // to add force to the ball on collision set restitution to > 1 body.setProperties(3, .95); // restitution, friction body.setDamping( .25 ); //Set Rotation Objects setupRot(); body.activate(); setDefaultZ(); }
//--------------------------------- void AnimatedMotionPath::setup(ofxBulletWorldRigid &world, ofVec3f position, string url, string pathMotionModel, ofVec3f ModelScale){ // position.z = -0.511; type = ShapeTypeAnimatedMotionPath; collisionTime = -120; ModelPath = url; m_pathMotionModel = pathMotionModel; this->position = position; m_fixedZ = position.z; m_AnimationMeshNo = 1; //rotation = btQuaternion(btVector3(0,1,0), ofDegToRad(-90)); //TODO to try with ofBtGetCylinderCollisionShape, for improve collision detection // create ofxBullet shape body.create(world.world, position, 0); // we set m=0 for kinematic body // load 3D model scale = ModelScale; assimpModel.loadModel(url, true); assimpModel.setScale(scale.x, scale.y, scale.z); assimpModel.setPosition(0, 0, 0); assimpModel.update(); //ofEnableSeparateSpecularLight(); //save init values initScale = scale; // add 3D meshes to ofxBullet shape // for(int i = 0; i < assimpModel.getNumMeshes(); i++) // { body.addMesh(assimpModel.getCurrentAnimatedMesh(0), scale, true); // } bAnimate = true; assimpModel.setLoopStateForAllAnimations(OF_LOOP_NORMAL); assimpModel.playAllAnimations(); body.add(); body.enableKinematic(); //body.setProperties(1., 0.); // .25 (more restituition means more energy) , .95 ( friction ) // to add force to the ball on collision set restitution to > 1 body.setProperties(3, .95); // restitution, friction body.setDamping( .25 ); //Set Rotation Objects setupRot(); body.activate(); setDefaultZ(); assimpPath.loadModel(m_pathMotionModel); assimpPath.setPosition(0, 0, 0); assimpPath.setScale(scale.x, scale.y, scale.z); assimpPath.setLoopStateForAllAnimations(OF_LOOP_NORMAL); assimpPath.playAllAnimations(); m_motionPathCurPos = assimpPath.getAnimation(m_AnimationMeshNo).getPosition(); m_eMotionControl = MOTION_CONTROL_LOOP; ofRegisterKeyEvents(this); }
//--------------------------------- void AnimatedObject::setup(ofxBulletWorldRigid &world, ofVec3f position, string url, ofVec3f ModelScale){ //position.z = -0.511; type = ShapeTypeAnimatedObject; collisionTime = -120; ModelPath = url; this->position = position; //rotation = btQuaternion(btVector3(0,1,0), ofDegToRad(-90)); //TODO to try with ofBtGetCylinderCollisionShape, for improve collision detection // create ofxBullet shape body.create(world.world, position, 0); // we set m=0 for kinematic body // load 3D model scale = ModelScale; assimpModel.loadModel(url, true); assimpModel.setScale(scale.x, scale.y, scale.z); assimpModel.setPosition(0, 0, 0); //ofEnableSeparateSpecularLight(); //save init values initScale = scale; // add 3D meshes to ofxBullet shape // for(int i = 0; i < assimpModel.getNumMeshes(); i++) // { body.addMesh(assimpModel.getCurrentAnimatedMesh(0), scale, true); // } bAnimate = true; assimpModel.setLoopStateForAllAnimations(OF_LOOP_NORMAL); assimpModel.playAllAnimations(); body.add(); body.enableKinematic(); //body.setProperties(1., 0.); // .25 (more restituition means more energy) , .95 ( friction ) // to add force to the ball on collision set restitution to > 1 body.setProperties(3, .95); // restitution, friction body.setDamping( .25 ); // btTransform transform; //btRigidBody* a_rb = body.getRigidBody(); //a_rb->getMotionState()->getWorldTransform( transform ); // rotate // btQuaternion currentRotation = transform.getRotation(); // btQuaternion rotate = btQuaternion(btVector3(0,0,1), ofDegToRad(degrees)); // btQuaternion rotate; // rotation.setRotation(btVector3(0,0,1), ofDegToRad(angle)); // rotate.setEuler(ofDegToRad(0), ofDegToRad(90), ofDegToRad(0)); // transform.setRotation(rotate * rotation); // a_rb->getMotionState()->setWorldTransform( transform ); //Set Rotation Objects setupRot(); body.activate(); setDefaultZ(); assimpPath.loadModel("Sysiphous/lineMesh.obj"); assimpPath.setPosition(0, 0, 0); currentVetice = 0; }