Example #1
0
void facade::setMouseSpring(bool s) {
	mouseSpring = s;
	if(mouseSpring){
#ifdef USE_KINECT
		int k = 0;
		for(int i=0; i<physics.numberOfParticles() && currentSkeletonIndex>-1; i++) {
			msa::physics::Particle3D *a = physics.getParticle(i);
			msa::physics::Particle3D *b = bone[i%kinect::nui::SkeletonData::POSITION_COUNT];
			if(canIGo()) physics.makeSpring(a, b, ofMap(i, 0, physics.numberOfParticles(), min_strength, max_strength), ofRandom(min_width, max_width));
			k++;
		}
#else
		for(int i=0; i<physics.numberOfParticles(); i++) {
			msa::physics::Particle3D *a = physics.getParticle(i);
			msa::physics::Particle3D *b = &mouseNode;
			if(canIGo()) physics.makeSpring(a, b, ofMap(i, 0, physics.numberOfParticles(), min_strength, max_strength), ofRandom(min_width, max_width));
		}
#endif
	}else{
		for(int i=physics.numberOfSprings(); i>0; i--) {
			msa::physics::Spring3D *s = physics.getSpring(i);
			if(s) s->kill();
		}
	}
}
Example #2
0
bool	Player::move(Direction dir)
{
  switch (dir)
    {
    case Direction::UP:
      if (canIGo(_posY + 1, _posX))
	return (true);
      return (false);
    case Direction::DOWN :
      if (canIGo(_posY -1, _posX))
	return (true);
      return (false);
    case Direction::RIGHT:
      if (canIGo(_posY, _posX + 1))
	return (true);
      return (false);
    case Direction::LEFT:
      if (canIGo(_posY, _posX - 1))
	return (true);
      return (false);
    case Direction::NOP:
      return (false);
    }
  return (false);
}
Example #3
0
void facade::setMouseAttract(bool a) {
	mouseAttract = a;
	if(mouseAttract) {
		// loop through all particles and add attraction to the closest bone
		/*msa::physics::Particle3D * closestBone;
		float minDistance;
		float tempDistance;
		for(int i=0; i<physics.numberOfParticles(); i++) {
			closestBone = NULL;
			minDistance = 999999999;
			for(int j = 0; j < kinect::nui::SkeletonFrame::SKELETON_COUNT; ++j){
				for(int k = 0; k < kinect::nui::SkeletonData::POSITION_COUNT; ++k){
					tempDistance = bone[(j*kinect::nui::SkeletonData::POSITION_COUNT) + k]->getPosition().distance(physics.getParticle(i)->getPosition());
					if(tempDistance<minDistance){
						closestBone = bone[(j*kinect::nui::SkeletonData::POSITION_COUNT) + k];
						minDistance = tempDistance;
					}
				}
			}
			if(closestBone!=NULL){
				physics.makeAttraction(closestBone, physics.getParticle(i), ofRandom(MIN_ATTRACTION, MAX_ATTRACTION));
			}
		}*/

		int k = 0;
		for(int i=0; i<physics.numberOfParticles() && currentSkeletonIndex>-1; i++) {
#ifdef USE_KINECT
			if(canIGo()) physics.makeAttraction(bone[i%kinect::nui::SkeletonData::POSITION_COUNT], physics.getParticle(i), ofRandom(MIN_ATTRACTION, MAX_ATTRACTION));
			k++;
#else
			if(canIGo()) physics.makeAttraction(&mouseNode, physics.getParticle(i), ofRandom(MIN_ATTRACTION, MAX_ATTRACTION));
#endif		
		}
	} else {
		// loop through all existing attractsions and delete them
		for(int i=0; i<physics.numberOfAttractions(); i++) physics.getAttraction(i)->kill();
	}
}
Example #4
0
void facade::addRandomParticle() {
	float posX		= ofRandom(-width/2, width/2);
	float posY		= ofRandom(0, height);
	float posZ		= ofRandom(-width/2, width/2);
	float mass		= ofRandom(min_mass, max_mass);
	float bounce	= ofRandom(min_bounce, max_bounce);
	float radius	= ofMap(mass, min_mass, max_mass, NODE_MIN_RADIUS, NODE_MAX_RADIUS);
	
	// physics.makeParticle returns a particle pointer so you can customize it
	msa::physics::Particle3D *p = physics.makeParticle(ofVec3f(posX, posY, posZ));
	
	// and set a bunch of properties (you don't have to set all of them, there are defaults)
	p->setMass(mass)->setBounce(bounce)->setRadius(radius)->enableCollision()->makeFree();
	
	// add an attraction to the mouseNode
#ifdef USE_KINECT
	if(mouseAttract) physics.makeAttraction(bone[physics.numberOfParticles()%kinect::nui::SkeletonData::POSITION_COUNT], p, ofRandom(MIN_ATTRACTION, MAX_ATTRACTION));
	if(mouseSpring && canIGo()) physics.makeSpring(bone[physics.numberOfParticles()%kinect::nui::SkeletonData::POSITION_COUNT], p, ofRandom(min_strength, max_strength), ofRandom(min_width, max_width));
	if(mouseSpring && canIGo()) physics.makeSpring(bone[(physics.numberOfParticles()+1)%kinect::nui::SkeletonData::POSITION_COUNT], p, ofRandom(min_strength, max_strength), ofRandom(min_width, max_width));
#else
	if(mouseAttract && canIGo()) physics.makeAttraction(&mouseNode, p, ofRandom(MIN_ATTRACTION, MAX_ATTRACTION));
	if(mouseSpring && canIGo()) physics.makeSpring(&mouseNode, p, ofRandom(min_strength, max_strength), ofRandom(min_width, max_width));
#endif
}