예제 #1
0
void BulletTestApp::setup()
{
    // Set up lighting
    mLight = new gl::Light( gl::Light::DIRECTIONAL, 0 );
    mLight->setDirection( Vec3f( 0.0f, 0.1f, 0.3f ).normalized() );
    mLight->setAmbient( ColorAf( 0.2f, 0.2f, 0.2f, 1.0f ) );
    mLight->setDiffuse( ColorAf( 1.0f, 1.0f, 1.0f, 1.0f ) );
    mLight->enable();

    // Load meshes
    loadModels();

    // Create a Bullet dynamics world
    mWorld = bullet::createWorld();

    // Load texture
    mTexGround     = gl::Texture( loadImage( loadResource( RES_TEX_GROUND     )));
    mTexBackBoard  = gl::Texture( loadImage( loadResource( RES_TEX_BACKBOARD  )));
    mTexRing       = gl::Texture( loadImage( loadResource( RES_TEX_RING       )));
    mTexBasketBall = gl::Texture( loadImage( loadResource( RES_TEX_BASKETBALL )));

    // Parameters
    mFrameRate      = 0.0f;
    mPoint          = 0;
    mViewX          = -27;
    mViewY          = -64;
    mViewZ          = 0;
    mStrengthX      = 0;
    mStrengthY      = 44;
    mStrengthZ      = 33;
// 	mStrengthY      = 0;
// 	mStrengthZ      = 0;
    mParams = params::InterfaceGl( "Params", Vec2i( 200, 250) );
    mParams.addParam( "Frame Rate", &mFrameRate, "", true );
    mParams.addParam( "Point"     , &mPoint    , "", true );
    mParams.addText ( "View" );
    mParams.addParam( "view_x"             , &mViewX, "min=-100 max=100 step=1 keyIncr=7 keyDecr=4" );
    mParams.addParam( "view_y"             , &mViewY, "min=-100 max=100 step=1 keyIncr=8 keyDecr=5" );
    mParams.addParam( "view_z"             , &mViewZ, "min=-100 max=100 step=1 keyIncr=9 keyDecr=6" );
    mParams.addText ( "Strength" );
    mParams.addParam( "strength_x"         , &mStrengthX, "min=-100 max=100 step=1 keyIncr=q keyDecr=a" );
    mParams.addParam( "strength_y"         , &mStrengthY, "min=-100 max=100 step=1 keyIncr=w keyDecr=s" );
    mParams.addParam( "strength_z"         , &mStrengthZ, "min=-100 max=100 step=1 keyIncr=e keyDecr=d" );

    // Initialize
    initTest();

    // Run first resize to initialize view
    resize( ResizeEvent( getWindowSize() ) );
}
예제 #2
0
void BulletTestApp::update()
{
    mFrameRate = getAverageFps();

    // Update light
    mLight->update( mCamera );

// 		// Set box rotation
// 		float rotation = math<float>::sin( ( float )getElapsedSeconds() * 0.3333f ) * 0.35f	;
// 		mGroundTransform.setRotation( btQuaternion( 0.25f, 0.0f, 1.0f + rotation * 0.1f, rotation ) );
// 		mGroundTransform.setOrigin( btVector3( 0.0f, -60.0f, 0.0f ) );
//
// 		// Apply rotation to box
// 		btRigidBody* body = bullet::toBulletRigidBody( mGround );
// 		body->getMotionState()->setWorldTransform( mGroundTransform );
// 		body->setWorldTransform( mGroundTransform );

    // Update dynamics world
    mWorld->update( mFrameRate );

    // Remove out of bounds objects
    for( bullet::Iter object = mWorld->begin(); object != mWorld->end(); )
    {
        if ( object != mWorld->begin() && object->getPosition().y < -800.0f )
        {
            object = mWorld->erase( object );
        }
        else
        {
            ++object;
        }
    }

    checkPoint();
}
예제 #3
0
void BulletTestApp::setup()
{
	mDragging	= false;
	mFrameRate	= 0.0f;
	mTest		= 9;
	mTestPrev	= mTest;

	// Set up lighting
	mLight = new gl::Light( gl::Light::DIRECTIONAL, 0 );
	mLight->setDirection( Vec3f( 0.0f, 0.1f, 0.3f ).normalized() );
	mLight->setAmbient( ColorAf( 0.2f, 0.2f, 0.2f, 1.0f ) );
	mLight->setDiffuse( ColorAf( 1.0f, 1.0f, 1.0f, 1.0f ) );
	mLight->enable();

	// Load meshes
	loadModels();

	// Create a Bullet dynamics world
	mWorld = bullet::createWorld();

	// Load texture
	mTexSquare	= gl::Texture( loadImage( loadResource( RES_TEX_SQUARE ) ) );
	mTexSphere	= gl::Texture( loadImage( loadResource( RES_TEX_SPHERE ) ) );
	mTexTerrain	= gl::Texture( loadImage( loadResource( RES_TEX_TERRAIN ) ) );
	mTexTerrain.setWrap( GL_REPEAT, GL_REPEAT );
	mTexTerrain.unbind();

	// Init terrain pointer
	mTerrain = 0;

	// Parameters
	mParams = params::InterfaceGl( "Params", Vec2i( 200, 120 ) );
	mParams.addParam( "Frame Rate",		&mFrameRate,								"", true );
	mParams.addParam( "Test",			&mTest,										"min=0 max=9 step=1 keyDecr=t keyIncr=T" ); 
	mParams.addButton( "Drop",			bind( &BulletTestApp::drop, this ),			"key=space" );
	mParams.addButton( "Screen shot",	bind( &BulletTestApp::screenShot, this ),	"key=s" );
	mParams.addButton( "Quit",			bind( &BulletTestApp::quit, this ),			"key=q" );

	// Initialize
	initTest();

	// Run first resize to initialize view
	resize( ResizeEvent( getWindowSize() ) );

}
예제 #4
0
void BulletTestApp::setup()
{

	// Set test mode
	mTest = 0;
	mTestPrev = mTest;

	// Set up lighting
	mLight = new gl::Light( gl::Light::DIRECTIONAL, 0 );
	mLight->setDirection( Vec3f( 0.0f, 0.1f, 0.3f ).normalized() );
	mLight->setAmbient( ColorAf( 0.2f, 0.2f, 0.2f, 1.0f ) );
	mLight->setDiffuse( ColorAf( 1.0f, 1.0f, 1.0f, 1.0f ) );
	mLight->enable();

	// Load meshes
	loadModels();

	// Create a Bullet dynamics world
	mWorld = bullet::createWorld();

	// Load texture
	mTexSquare = gl::Texture( loadImage( loadResource( RES_TEX_SQUARE ) ) );
	mTexSphere = gl::Texture( loadImage( loadResource( RES_TEX_SPHERE ) ) );
	mTexTerrain = gl::Texture( loadImage( loadResource( RES_TEX_TERRAIN ) ) );
	mTexTerrain.setWrap( GL_REPEAT, GL_REPEAT );
	mTexTerrain.unbind();

	// Init terrain pointer
	mTerrain = 0;

	// Parameters
	mFrameRate = 0.0f;
	mParams = params::InterfaceGl( "Params", Vec2i( 150, 100) );
	mParams.addParam( "Frame Rate", &mFrameRate, "", true );
	mParams.addParam( "Test", &mTest, "min=0 max=7 step=1 keyDecr=d keyIncr=D" ); 

	// Initialize
	initTest();

	// Run first resize to initialize view
	resize( ResizeEvent( getWindowSize() ) );

}
void VboMeshSampleApp::update()
{
	// Update FPS
	mFrameRate = getAverageFps();

	// Toggle fullscreen
	if ( mFullScreen != isFullScreen() ) {
		setFullScreen( mFullScreen );
	}

	// Reset the meshes if the segment count changes
	if ( mNumSegmentsPrev != mNumSegments ) {
		createMeshes();
		mNumSegmentsPrev = mNumSegments;
	}

	// Update light on every frame
	mLight->update( mCamera );
}
예제 #6
0
void BulletTestApp::update()
{

	// Run next test
	if ( mTest != mTestPrev ) {
		mTestPrev = mTest;
		initTest();
	}

	mFrameRate = getAverageFps();

	// Update light
	mLight->update( mCamera );

	if ( mTest < 3 ) {

		// Set box rotation
		float rotation = math<float>::sin( ( float )getElapsedSeconds() * 0.3333f ) * 0.35f	;
		mGroundTransform.setRotation( btQuaternion( 0.25f, 0.0f, 1.0f + rotation * 0.1f, rotation ) );
		mGroundTransform.setOrigin( btVector3( 0.0f, -60.0f, 0.0f ) );

		// Apply rotation to box
		btRigidBody* body = bullet::toBulletRigidBody( mGround );
		body->getMotionState()->setWorldTransform( mGroundTransform );
		body->setWorldTransform( mGroundTransform );

	} else if ( mTest == 6 ) {

		// Read data
		Channel32f& input = mTerrain->getData();

		// Get image dimensions
		int32_t height = input.getHeight();
		int32_t width = input.getWidth();
		
		// Create output channel
		Channel32f output = Channel32f( width, height );
		
		// Move pixel value over by one
		for ( int32_t y = 0; y < height; y++ ) {
			for ( int32_t x = 0; x < width; x++ ) {
				float value = input.getValue( Vec2i( x, y ) );
				Vec2i position( ( x + 1 ) % width, ( y + 1 ) % height );
				output.setValue( position, value );
			}

		}

		// Copy new data back to original
		input.copyFrom( output, output.getBounds() );

		// Shift texture coordinates to match positions
		vector<Vec2f>& texCoords = mTerrain->getTexCoords();
		Vec2f delta( 1.0f / (float)width, 1.0f / (float)height );
		for ( vector<Vec2f>::iterator uv = texCoords.begin(); uv != texCoords.end(); ++uv ) {
			*uv -= delta;
		}

		// Update terrain VBO
		mTerrain->updateVbo();

	} else if ( mTest == 7 ) {

		bool init = !mSurface;
		
		if ( mCapture.isCapturing() && mCapture.checkNewFrame() ) {
		
			mSurface = mCapture.getSurface();
			ip::flipVertical( &mSurface );

			if ( init ) {
				mTerrain = new DynamicTerrain( Channel32f( 160, 160 ), -1.0f, 1.0f, Vec3f( 2.0f, 70.0f, 2.0f ), 0.0f );
				mWorld->pushBack( mTerrain );
				btRigidBody* terrain = ( btRigidBody* )mTerrain->getBulletBody();
				terrain->setAngularFactor( 0.6f );
				terrain->setFriction( 0.6f );
			} else {
				mTerrain->getData().copyFrom( Channel32f( mSurface ), Area( 0, 0, 160, 160 ) );
				mTerrain->updateVbo();
			}

		}

	}
	
	// Update dynamics world
	mWorld->update( mFrameRate );

	/*if ( mGround ) { 
		Iter iter = mWorld->find( mGround );
		OutputDebugStringA( toString( iter->getPosition().x ).c_str() );
		OutputDebugStringA( "\n" );
	}*/

	// Remove out of bounbds objects
	for ( bullet::Iter object = mWorld->begin(); object != mWorld->end(); ) {
		if ( object != mWorld->begin() && object->getPosition().y < -800.0f ) {
			object = mWorld->erase( object );
		} else {
			++object;
		}
	}

	// Remove objects when count is too high
	uint32_t max = mTest >= 4 ? MAX_OBJECTS_TERRAIN : MAX_OBJECTS;
	if ( mWorld->getNumObjects() > max + 1 ) {
		for ( uint32_t i = 1; i < mWorld->getNumObjects() - MAX_OBJECTS_TERRAIN; i++ ) {
			mWorld->erase( mWorld->begin() + 1 );
		}
	}

}
void VboMeshSampleApp::setup()
{
	// Setting an unrealistically high frame rate effectively
	// disables frame rate limiting
	setFrameRate( 10000.0f );
	setWindowSize( 800, 600 );

	// Set up OpenGL to work with default lighting
	glShadeModel( GL_SMOOTH );
	gl::enable( GL_POLYGON_SMOOTH );
	glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST );
	gl::enable( GL_NORMALIZE );
	gl::enableAlphaBlending();
	gl::enableDepthRead();
	gl::enableDepthWrite();

	// Load the texture map
	mTexture = gl::Texture( loadImage( loadResource( RES_TEXTURE ) ) );

	// Define properties
	mFrameRate			= 0.0f;
	mFullScreen			= false;
	mLightEnabled		= true;
	mMeshIndex			= 0;
	mNumSegments		= 48;
	mNumSegmentsPrev	= mNumSegments;
	mScale				= Vec3f::one();
	mTextureEnabled		= true;
	mWireframe			= false;
	
	// Set up the arcball
	mArcball = Arcball( getWindowSize() );
	mArcball.setRadius( (float)getWindowHeight() * 0.5f );
	
	// Set up the camera
	mCamera = CameraPersp( getWindowWidth(), getWindowHeight(), 60.0f, 0.0001f, 10.0f );
	mCamera.lookAt( Vec3f( 0.0f, 0.0f, -5.0f ), Vec3f::zero() );

	// Set up the light
	mLight = new gl::Light( gl::Light::DIRECTIONAL, 0 );
	mLight->setAmbient( ColorAf::white() );
	mLight->setDiffuse( ColorAf::white() );
	mLight->setDirection( Vec3f::one() );
	mLight->setPosition( Vec3f::one() * -1.0f );
	mLight->setSpecular( ColorAf::white() );
	mLight->enable();

	// Define the mesh titles for the params GUI
	mMeshTitles.push_back( "Cube" );
	mMeshTitles.push_back( "Sphere" );
	mMeshTitles.push_back( "Cylinder" );
	mMeshTitles.push_back( "Cone" );
	mMeshTitles.push_back( "Circle" );
	mMeshTitles.push_back( "Square" );
	mMeshTitles.push_back( "Ring" );
	mMeshTitles.push_back( "Custom" );

	// Set up the params GUI
	mParams = params::InterfaceGl( "Params", Vec2i( 200, 320 ) );
	mParams.addParam( "Frame rate",		&mFrameRate,									"", true									);
	mParams.addSeparator();
	mParams.addParam( "Enable light",	&mLightEnabled,									"key=l"										);
	mParams.addParam( "Enable texture",	&mTextureEnabled,								"key=t"										);
	mParams.addParam( "Mesh type",		mMeshTitles, &mMeshIndex,						"keyDecr=m keyIncr=M"						);
	mParams.addParam( "Scale",			&mScale																						);
	mParams.addParam( "Segments",		&mNumSegments,									"keyDecr=s keyIncr=S min=3 max=1024 step=1"	);
	mParams.addParam( "Wireframe",		&mWireframe,									"key=w"										);
	mParams.addSeparator();
	mParams.addParam( "Full screen",	&mFullScreen,									"key=f"										);
	mParams.addButton( "Screen shot",	bind( &VboMeshSampleApp::screenShot, this ),	"key=space"									);
	mParams.addButton( "Quit",			bind( &VboMeshSampleApp::quit, this ),			"key=q"										);

	// Generate meshes
	createMeshes();
}