Commit 385b7dc0 authored by Dat Nguyen's avatar Dat Nguyen

Added Hills

parent 3110e2c8
#include "ofApp.h"
bool shouldRemoveRigidBody( const shared_ptr<ofxBulletRigidBody>& ab ) {
return ab->getPosition().y > 55;
return ab->getPosition().y > 65;
}
//--------------------------------------------------------------
void ofApp::setup(){
ofSetVerticalSync(true);
ofSetFrameRate(60);
ofDisableArbTex();
camera.setup();
camera.setPosition(ofVec3f(0, 0.f, -100.f));
......@@ -20,10 +21,10 @@ void ofApp::setup(){
ground.setProperties(.25, .95);
ground.add();
light.setPosition( 0, -100, 0 );
light.setPosition( 0, -2000, 1900 );
shared_ptr< ofxBulletSphere > sphere( new ofxBulletSphere() );
sphere->create( world.world, ofVec3f(0,-2.55,0), 0., 20.0 );
sphere->create( world.world, ofVec3f(0,-10.55,0), 0., 20.0 );
sphere->enableKinematic();
sphere->setFriction( 0.8 );
sphere->add();
......@@ -35,6 +36,8 @@ void ofApp::setup(){
cylinders[i].set(20,140);
cylinders[i].setPosition(ofRandom(-ofGetWidth(),ofGetWidth()), -30, ofRandom(-600,600));
}
//Does not work on my OS
//ofHideCursor();
......@@ -51,7 +54,7 @@ void ofApp::setup(){
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);
((ofxBulletSphere*)shapes[ii])->create(world.world, ofVec3f(ofRandom(-3, 3), ofRandom(-5, -10), ofRandom(-1, 1)), 0.1);
shapes[ii]->setActivationState( DISABLE_DEACTIVATION );
shapes[ii]->add();
}
......@@ -62,18 +65,72 @@ void ofApp::setup(){
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);
((ofxBulletBox*)shapes[ii])->create(world.world, ofVec3f(ofRandom(-3, 3), ofRandom(-5, -10), ofRandom(-1, 1)), 0.2);
shapes[ii]->setActivationState( DISABLE_DEACTIVATION );
shapes[ii]->add();
}
shapes.push_back( new ofxBulletBox() );
((ofxBulletBox*)shapes[4])->init(20.65, 50.65, 20.65);
((ofxBulletBox*)shapes[4])->create(world.world, ofVec3f(50, 25, 100), 0.1);
((ofxBulletBox*)shapes[4])->create(world.world, ofVec3f(50, -20, 100), 0.1);
shapes[4]->setActivationState( DISABLE_DEACTIVATION );
shapes[4]->add();
bRenderShapes = true;
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( 129, 108, 91, 255); //hill colour
ofRect(0, 0, ofGetWidth(), ofGetHeight() );
//ofSetColor(120, 140, 0, 255);
int numIterations = 15;
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(255,255,255, 255); //line texture colour
ofSetLineWidth( 1. );
if( i % 2 == 0 ) ofSetLineWidth( 0.5 );
ofLine( tx, 0, tx, fbo.getHeight() );
ofLine( 0, ty, fbo.getWidth(), ty );
}
} fbo.end();
ofSetLineWidth( 1 );
omesh = ofMesh::plane( 7000, 7000, 30, 30, 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 = 45.+ofSignedNoise( verts[i].x*0.02, verts[i].y*0.02 + verts[i].z*0.02, ofGetElapsedTimef() * 0.1 + rseed ) * 60;
}
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;
bulletMesh = shared_ptr< ofxBulletTriMeshShape >( new ofxBulletTriMeshShape() );
bulletMesh->create( world.world, mesh, ofVec3f(0,0,0), 0.f, ofVec3f(-10000, -10000, -10000), ofVec3f(10000,10000,10000) );
bulletMesh->add();
bulletMesh->enableKinematic();
bulletMesh->setActivationState( DISABLE_DEACTIVATION );
}
//--------------------------------------------------------------
......@@ -92,8 +149,17 @@ void ofApp::draw(){
ofEnableLighting();
light.enable();
ofSetColor( 255,255,255 );
ground.draw();
//ofSetColor( 255,255,255 );
//ground.draw();
ofSetLineWidth(1.f);
ofSetColor( 255, 255, 255, 255 );
fbo.getTextureReference().bind();
glSamplerParameterf( fbo.getTextureReference().texData.textureTarget, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy );
ofSetTextureWrap( GL_REPEAT, GL_REPEAT );
mesh.draw();
fbo.getTextureReference().unbind();
ofSetHexColor( 0xC4EF02 );
for( int i = 0; i < rigidBodies.size(); i++ ) {
......
......@@ -35,15 +35,14 @@ class ofApp : public ofBaseApp{
btBoxShape* boxShape;
btSphereShape* sphereShape;
vector<ofxBulletRigidBody*> shapes;
vector<bool> bColliding;
int mousePickIndex;
ofVec3f mousePickPos;
bool bDrawDebug;
//vector<bool> bColliding;
bool bRenderShapes;
bool bAddCenterAttract;
bool bSpacebar;
ofMesh mesh, omesh;
shared_ptr<ofxBulletTriMeshShape> bulletMesh;
float anisotropy;
ofFbo fbo, fboSphere;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment