コード例 #1
0
ファイル: Transform.cpp プロジェクト: ashleygwinnell/ark2d
		Matrix44 Transform::toMatrix() {
			Matrix44 m;
			m.translate(position.getX(), position.getY(), position.getZ());
    		m *= rotation.toMatrix();
    		m.scale(scale.getX(), scale.getY(), scale.getZ());
    		return m;
		}
コード例 #2
0
ファイル: BoidsApp.cpp プロジェクト: alterscape/CinderCVBoids
void BoidsApp::setup()
{	
	Rand::randomize();
	//setFullScreen(true);
	shouldBeFullscreen = false;
	
	mCenter				= Vec3f( getWindowWidth() * 0.5f, getWindowHeight() * 0.5f, 0.0f );
	mSaveFrames			= false;
	mIsRenderingPrint	= false;
	changeInterval		= 15.0;
	time(&lastChange);
	gravity				= false;
	
	// SETUP CAMERA
	mCameraDistance		= 350.0f;
	mEye				= Vec3f( 0.0f, 0.0f, mCameraDistance );
	mCenter				= Vec3f::zero();
	mUp					= Vec3f::yAxis();
	mCam.setPerspective( 75.0f, getWindowAspectRatio(), 5.0f, 5000.0f );
	lastFrameTime		= getElapsedSeconds();
	deltaT				= 0;
	newFlock			= 0;
	
	mParticleTexture	= gl::Texture( loadImage( loadResource( RES_PARTICLE ) ) );
	
	
	// Initialize the OpenCV input (Below added RS 2010-11-15)
	try {
		//ci::Device device = Capture.
		std::vector<boost::shared_ptr<Capture::Device> > devices = Capture::getDevices();
		
		std::cout << "Capture Devices:" << std::endl;
		std::vector<boost::shared_ptr<Capture::Device> >::iterator device_iterator;
		//for(device_iterator=devices.begin(); device_iterator!=devices.end(); device_iterator++)
		for(int i=0; i<devices.size();i++)
		{
			console() << "device " << i << ": " << devices[i]->getName() << std::endl;
			
		}
		
		//UNCOMMENT FOLLOWING LINE FOR BUILT-IN CAMERA
		//capture = Capture(320,240);
		
		//UNCOMMENT FOLLOWING LINE FOR UNIBRAIN OR WHATEVER
		capture = Capture(320,240,devices[0]);//,devices[0]);	//FIXME this is a dumb way to select a device
		
		capture.start();
		silhouetteDetector = new SilhouetteDetector(320,240);
	} catch ( ... ) {
		console() << "Failed to initialize capture device" << std::endl;
	}
	cvThreshholdLevel = 45;		
	// CREATE PARTICLE CONTROLLER
	flock_one.addBoids( NUM_INITIAL_PARTICLES );
	flock_two.addBoids( NUM_INITIAL_PARTICLES );
	flock_one.setColor(ColorA( CM_RGB, 0.784, 0.0, 0.714, 1.0));
	flock_one.silRepelStrength = -0.50f;
	flock_two.setColor(ColorA( CM_RGB, 0.0, 1.0, 0.0, 1.0));
	imageColor = ColorA( CM_RGB, 0.4, 0.4, 0.4, 1.0);
	
	flock_one.addOtherFlock(&flock_two);
	flock_two.addOtherFlock(&flock_one);
	// SETUP PARAMS
	mParams = params::InterfaceGl( "Flocking", Vec2i( 200, 310 ) );
	mParams.addParam( "Scene Rotation", &mSceneRotation, "opened=1" );//
	mParams.addSeparator();
	mParams.addParam( "Fullscreen", &shouldBeFullscreen,"keyIncr=f" ); //FIXME
	mParams.addSeparator();
	mParams.addParam( "Eye Distance", &mCameraDistance, "min=100.0 max=2000.0 step=50.0 keyIncr=s keyDecr=w" );
	//mParams.addParam( "Center Gravity", &flock_one.centralGravity, "keyIncr=g" );
	//mParams.addParam( "Flatten", &flock_one.flatten, "keyIncr=f" );
	mParams.addSeparator();
	//mParams.addParam( "Zone Radius", &flock_one.zoneRadius, "min=10.0 max=100.0 step=1.0 keyIncr=z keyDecr=Z" );
//	mParams.addParam( "Lower Thresh", &flock_one.lowerThresh, "min=0.025 max=1.0 step=0.025 keyIncr=l keyDecr=L" );
//	mParams.addParam( "Higher Thresh", &flock_one.higherThresh, "min=0.025 max=1.0 step=0.025 keyIncr=h keyDecr=H" );
//	mParams.addSeparator();
//	mParams.addParam( "Attract Strength", &flock_one.attractStrength, "min=0.001 max=0.1 step=0.001 keyIncr=a keyDecr=A" );
//	mParams.addParam( "Repel Strength", &flock_one.repelStrength, "min=0.001 max=0.1 step=0.001 keyIncr=r keyDecr=R" );
//	mParams.addParam( "Orient Strength", &flock_one.orientStrength, "min=0.001 max=0.1 step=0.001 keyIncr=o keyDecr=O" );
//	mParams.addSeparator();
	mParams.addParam( "CV Threshhold", &silhouetteDetector->cvThresholdLevel, "min=0 max=255 step=1 keyIncr=t keyDecr=T" );
	
	//setup transformation from camera space to opengl world space
	imageToScreenMap.setToIdentity();
	imageToScreenMap.translate(Vec3f(getWindowSize().x/2, getWindowSize().y/2, 0));	//translate over and down
	imageToScreenMap.scale(Vec3f(-1*getWindowSize().x/320.0f, -1*getWindowSize().y/240.0f,1.0f));	//scale up
	polygons = new vector<Vec2i_ptr_vec>();
	
	currentBoidRuleNumber = 0;
	
	// ** stuff to create boid rulesets ** //
	
	// State 1: stuckOnYou - both flocks are attracted to the silhouette
	BoidSysPair stuckOnYou;
	stuckOnYou.flockOneProps.zoneRadius			= 80.0f;
	stuckOnYou.flockOneProps.lowerThresh		= 0.5f;
	stuckOnYou.flockOneProps.higherThresh		= 0.8f;
	stuckOnYou.flockOneProps.attractStrength	= 0.004f;
	stuckOnYou.flockOneProps.repelStrength		= 0.01f;
	stuckOnYou.flockOneProps.orientStrength		= 0.01f;
	stuckOnYou.flockOneProps.silThresh			= 1000.0f;
	stuckOnYou.flockOneProps.silRepelStrength	= -0.50f;
	stuckOnYou.flockOneProps.gravity			= false;
	stuckOnYou.flockOneProps.baseColor			= ColorA( CM_RGB, 0.784, 0.0, 0.714, 1.0);
	
	stuckOnYou.flockTwoProps=stuckOnYou.flockOneProps;
	stuckOnYou.imageColor						= ColorA( 0.08f, 0.0f, 0.1f, 1.0f);
	boidRulesets.push_back(stuckOnYou);
	
	// State 2: repel - both flocks are repeled by the silhouette
	BoidSysPair repel;
	repel.flockOneProps.zoneRadius				= 80.0f;
	repel.flockOneProps.lowerThresh				= 0.5f;
	repel.flockOneProps.higherThresh			= 0.8f;
	repel.flockOneProps.attractStrength			= 0.004f;
	repel.flockOneProps.repelStrength			= 0.01f;
	repel.flockOneProps.orientStrength			= 0.01f;
	repel.flockOneProps.silThresh				= 500.0f;
	repel.flockOneProps.silRepelStrength		= 1.00f;
	repel.flockOneProps.gravity					= false;
	repel.flockOneProps.baseColor				= ColorA( CM_RGB, 0.157, 1.0, 0.0,1.0);

	repel.flockTwoProps=repel.flockOneProps;
	repel.imageColor							= ColorA( 0.08f, 0.0f, 0.1f, 1.0f);	
	boidRulesets.push_back(repel);
	
	
	//// State 3: grav - like repel, but with gravity added
	BoidSysPair grav;
	grav.flockOneProps=repel.flockOneProps;
	grav.flockOneProps.gravity					= true;
	grav.flockOneProps.repelStrength			= 0.005f;
	grav.flockOneProps.baseColor				= ColorA( CM_RGB, 0.157, 0.0, 1.0,1.0);
	grav.flockTwoProps=grav.flockOneProps;
	grav.imageColor								= ColorA( 0.08f, 0.0f, 0.1f, 1.0f);
	boidRulesets.push_back(grav);
	
	
	//// State 4: diff - one flock is attracted to the silhouette and the other is repeled
	BoidSysPair diff;
	
	diff.flockOneProps=repel.flockOneProps;
	diff.flockTwoProps=stuckOnYou.flockOneProps;
	diff.imageColor								= ColorA( 0.08f, 0.0f, 0.1f, 1.0f);
	boidRulesets.push_back(diff);
	 
	
}