void SmilesApp::detectSmiles(const RImage<float> &pixels)
{
    mFaces.clear();
	// Find Smiles
	if( mMPSmile->findSmiles( pixels, mFaces, 1.00, wt_avg ) ){
        //console() << " findSmiles error " << endl;
        return;
	}
    mSmileResponse = 0;
    // The result is in faces(VisualObject).
    if(!mFaces.empty()) {
        for(list<VisualObject *>::iterator it = mFaces.begin(); it != mFaces.end(); ++it) {
            mFace = static_cast<FaceObject*>(*it);
            mSmileResponse = mFace->activation;
            mSmileResponse = max( 0.0f, min( mSmileResponse, mSmileLimit ) ) / mSmileLimit;
        }
        //console() << mFaces.size() << " faces detected!" << endl;
    }else{
        //console() << " no faces detected " << endl;
    }
    
	mSmileAverage[mSmileAverageIndex] = mSmileResponse;
	mSmileAverageIndex++;
	if(mSmileAverageIndex>=mSmileAverageNumOfFrames)mSmileAverageIndex=0;
	
	float smileSum = 0;
	for(int i=0;i<mSmileAverageNumOfFrames;i++){
		smileSum += mSmileAverage[i];
	}
	mSmileThreshold = smileSum/mSmileAverageNumOfFrames;
}
Example #2
0
	void Muzzleflasher::updateMuzzleflash(IPointableObject *unit, VisualObject *muzzleflash, const std::string &name, const std::string &helper, const VC3 &pos, const VC3 &scale)
	{
		game::Unit *u = (game::Unit *)unit;

		VisualObject *vo = u->getVisualObject();
		if (vo == NULL || vo->getStormModel() == NULL)
		{
			return;
		}

		IStorm3D_Model_Object *object = vo->getStormModel()->SearchObject(name.c_str());
		if(object == NULL)
		{
			// didn't find it - add it
			createMuzzleflash(unit, muzzleflash, name, helper);
			object = vo->getStormModel()->SearchObject(name.c_str());
			if(object == NULL)
			{
				return;
			}
		}

		object->SetPosition(pos);
		object->SetScale(scale);
		//object->SetRotation(rot);
	}
Example #3
0
void Scene::Draw()
{

	//myDirectXRenderer->LoadShaderFromFile("firstshader", "../Shaders/TextShader.fx", "TextShader", "ColorShader");

			myDirectXRenderer->SetUpWorld(currentCamera->getPosition(), currentCamera->getProjectionMatrix());

			//myDirectXRenderer->SetShader("firstshader");

			

			for(std::vector<VisualObject*>::iterator i = activeObjects.begin(); i != activeObjects.end(); ++i)
			{
				VisualObject* currentobj = *i;



				currentobj->draw(myDirectXRenderer);
				
    
    
			}

			//myDirectXRenderer->StopRenderingWithShaders();

}
Example #4
0
	void Muzzleflasher::createMuzzleflash(IPointableObject *unit, 
		VisualObject *muzzleflash, const std::string &name, const std::string &helper)
	{
		// WARNING: unsafe cast!
		game::Unit *u = (game::Unit *)unit;

		VisualObject *vo = u->getVisualObject();
		vo->combine(muzzleflash, name.c_str(), helper.c_str());
	}
Example #5
0
Explosion::Explosion(Graphics::IGraphics & graphics, VisualObject & object, Common::Game::Position direction) :
    m_graphics(graphics),
    m_object(object),
    m_direction(direction)
{
    auto & scene = graphics.getSceneManager();

    auto objectPosition = object.getOgreSceneNode().getPosition();
    auto origin = objectPosition - (graphics.toOgreVector3(m_direction) * 50);
    auto ogreDirection = graphics.toOgreVector3(m_direction).normalisedCopy();

    LOG_DEBUG << "Origin for raycast: " << origin << " (object pos: " << objectPosition << ", direction: " << m_direction << ")";

    Ogre::Ray ray(origin, ogreDirection);
    Graphics::Raycast raycast(graphics.getSceneManager());
    Graphics::RaycastResult result;

    raycast.cast(ray, [&](Ogre::Entity * entity, Ogre::Vector3 position) -> bool
    {
        if (entity == &object.getOgreEntity())
        {
            result.valid = true;
            result.entity = entity;
            result.position = position;

            return false;
        }
        else
        {
            return true;
        }
    });

    if (!result.valid)
    {
        throw std::runtime_error("cant raycast to determinate explosion position");
    }

    std::stringstream ss;
    ss << "explosion-particle-" << m_id++;
    m_ps = scene.createParticleSystem(ss.str(), "Explosion");

    // FIXME: hax caused by VisualObject which scales ogre node by 100
    auto explosionPositionDelta = (result.position - object.getOgreSceneNode().getPosition()) / 100;

    // FIXME: another hax caused by rotating mesh by 90d in VisualObject
    Ogre::Quaternion rotation(Ogre::Degree(90), Ogre::Vector3(0, 1, 0));
    explosionPositionDelta = rotation * explosionPositionDelta;

    LOG_DEBUG << "Creating explosion, object pos: " << object.getOgreSceneNode().getPosition() << ", explosion pos: " << explosionPositionDelta;

    auto * psNode = object.getOgreSceneNode().createChildSceneNode();
    psNode->setPosition(explosionPositionDelta);
    psNode->yaw(Ogre::Degree(-90));
    psNode->attachObject(m_ps);
}
Example #6
0
	void Muzzleflasher::deleteMuzzleflash(IPointableObject *unit, const std::string &name)
	{
		// WARNING: unsafe cast!
		game::Unit *u = (game::Unit *)unit;

		VisualObject *vo = u->getVisualObject();
		if (vo != NULL)
		{
			vo->removeObject(name.c_str());
		}
		else
		{
			Logger::getInstance()->warning(("Muzzleflasher::deleteMuzzleflash - no object found with name: " + name).c_str());
		}
	}
void SmilesApp::draw()
{
	gl::enableAlphaBlending();
	gl::clear( Color::black() );
    gl::color(1.0f, 1.0f, 1.0f);
    
    // draw webcam capture
	if( !mCapture || !mSurface )
		return;
    gl::draw( gl::Texture(mSurface) );
    
    if(mGreyChannel){
    gl::pushMatrices();{
        gl::translate(mSmileRect.getUpperLeft());
        gl::draw( gl::Texture(mGreyChannel) );
    }gl::popMatrices();
    }
    
    // draw rect that actually gets analysed:
    gl::color(ColorA(0.0f, 1.0f, 0.0f, 1.0f));
    gl::drawStrokedRect(mSmileRect);
    gl::drawStrokedCircle(mSmileRect.getUpperLeft(), 10);
    gl::drawStrokedCircle(mSmileRect.getUpperRight(), 10);
    gl::drawStrokedCircle(mSmileRect.getLowerLeft(), 10);
    gl::drawStrokedCircle(mSmileRect.getLowerRight(), 10);
    
    
    //draw mSmileThreshold
    gl::pushMatrices();{
        gl::color(ColorA(1.0f, 0.0f, 0.0f, 0.3f));
        gl::drawSolidRect(Rectf( 0, (1-mSmileThreshold)*getWindowHeight(), getWindowWidth(), getWindowHeight() ) );
        gl::drawStrokedRect( Rectf(0, 0, getWindowWidth(), getWindowHeight() ) );
    }gl::popMatrices();
    
    //draw faces
    if(!mFaces.empty()){
        gl::pushMatrices();{
            gl::translate(mSmileRect.getUpperLeft());
            gl::color(1.0f, 1.0f, 1.0f);
            for(list<VisualObject *>::iterator it = mFaces.begin(); it != mFaces.end(); ++it) {
                mFace = static_cast<FaceObject*>(*it);
                gl::drawStrokedRect(Rectf(mFace->x, mFace->y, mFace->x+mFace->xSize, mFace->y+mFace->ySize ));
            }
        }gl::popMatrices();
    }
    
    mParams.draw();
}
Example #8
0
	void Muzzleflasher::createMuzzleflash(IPointableObject *unit, 
		VisualObject *muzzleflash, int muzzleFlashBarrelNumber)
	{
		// WARNING: unsafe cast!
		game::Unit *u = (game::Unit *)unit;

		std::string barrelName = "WeaponBarrel";
		if (muzzleFlashBarrelNumber >= 2)
			barrelName += int2str(muzzleFlashBarrelNumber);

		std::string modelHelperName = std::string("HELPER_MODEL_") + barrelName;
		
		const char *weaponHelper = modelHelperName.c_str();
		//char *weaponHelper = "HELPER_MODEL_WeaponBarrel";

		VisualObject *vo = u->getVisualObject();
		vo->combine(muzzleflash, "muzzleflash", weaponHelper);
	}
	void BuildingAdder::addBuilding(Game *game, const VC3 &position, 
		const char *filename, GamePhysics *gamePhysics)
	{
		Building *b = new Building(filename);
		game->buildings->addBuilding(b);

    createVisualForBuilding(game, b);
    //VC2I mapPos = b->getMapPosition();
    //float x = gameMap->configToScaledX(mapPos.x);
    //float y = gameMap->configToScaledY(mapPos.y);
    //b->setPosition(VC3(x, gameMap->getScaledHeightAt(x, y), y));
		VC3 pos = position;
		b->setPosition(pos);

    game->getGameScene()->addBuildingObstacle(b, buildingadder_enableterraincut);
    
    VisualObject *vo = b->getVisualObject();
    if (vo != NULL)
    {
			// Damn, should change the buidlinghandler to use the
			// visual object instead of storm models...

      // Add to building handler too
      game->gameUI->buildingHandler.addBuilding(vo->model);

			b->addPhysics(gamePhysics);

// NOTE: these resources should be freed. (but cannot be, because we might be in physics simulation/because 
// the actual mesh cooking is done at next sync, not right now... (applies to PhysX)
// NOTE: also, ODE physics will pose same kind of problems (possibly even more due to multithreaded cooking)
// MOVED THIS LATER ON...

#ifdef PHYSICS_NONE
			if(vo->getStormModel())
			{
				vo->getStormModel()->FreeMemoryResources();
			}
#endif
    }

		// TODO: not an optimal solution doing this after every single
		// building!
    game->gameMap->applyObstacleHeightChanges();
	}
Example #10
0
	bool Muzzleflasher::getMuzzleflash(IPointableObject *unit, VisualObject *muzzleflash, const std::string &name, const std::string &helper, VC3 &pos, VC3 &scale, QUAT &rot)
	{
		game::Unit *u = (game::Unit *)unit;

		VisualObject *vo = u->getVisualObject();
		if (vo == NULL || vo->getStormModel() == NULL)
		{
			return false;
		}

		IStorm3D_Model_Object *object = vo->getStormModel()->SearchObject(name.c_str());
		if(object == NULL)
		{
			return false;
		}
		
		pos = object->GetPosition();
		scale = object->GetScale();
		rot = object->GetRotation();
		return true;
	}
  void BuildingAdder::createVisualForBuilding(Game *game, Building *building)
  {
    // another quick haxor

    // maybe should check that the visual does not already exist

    //VisualObjectModel *vom = new VisualObjectModel(building->getModelFilename());
		VisualObjectModel *vom = game->visualObjectModelStorage->getVisualObjectModel(building->getModelFilename());

    VisualObject *vo = vom->getNewObjectInstance();
    building->setVisualObject(vo);
    vo->setInScene(true);
    vo->setDataObject(building);

		// disable collision to "firethrough" collision layer...
		IStorm3D_Model *model = vo->getStormModel();
		if(model)
		{
			const VC3 &sunDir = game->getGameUI()->getTerrain()->getSunDirection();
			model->SetDirectional(sunDir, 1.f);
		}

		Iterator<IStorm3D_Model_Object *> *objectIterator;
		for(objectIterator = model->ITObject->Begin(); !objectIterator->IsEnd(); objectIterator->Next())
		{
			IStorm3D_Model_Object *object = objectIterator->GetCurrent();

			const char *name = object->GetName();

			if (strstr(name, "FireThrough") != NULL)
			{
				object->SetNoCollision(true);
			}
		}

		delete objectIterator;

		// add building for self-illum (lightmap brightness) changes...
		game->gameUI->getLightManager()->getSelfIlluminationChanger()->addModel(vo->getStormModel());
  }
Example #12
0
void ScribbleArea::loadMyFormat(const QString &fileName)
{
    QFile file(fileName);
    file.open(QIODevice::ReadOnly);
    QDataStream in(&file);
    in.setVersion(QDataStream::Qt_5_4);

    quint32 label;
    in >> label;
    if (label != 0xA0B0C0D0)
        return;

    in >> canvas >> backGround;

    while (!in.atEnd()) {
        QString label;
        in >> label;
        VisualObject *obj = factory.getPlugin(label);
        obj->readFromStram(in);
        AllShape.append(obj);
    }
    update();
}
Example #13
0
double MPBlink::findBlinks(const RImage<float> &pixels, VisualObject &faces,
                           float WINSHIFT, combine_mode mode){
  // First, find the faces
  static int lastimgWidth = 0, lastimgHeight = 0;
  if (pixels.width != lastimgWidth || pixels.height != lastimgHeight) {
    eyefinder.resetStream(pixels.width, pixels.height);
    lastimgWidth = pixels.width;
    lastimgHeight = pixels.height;
  }

  eyefinder.findEyes(pixels, faces, WINSHIFT, mode);
  if(!faces.size())
    return 0;
  get_eyes(pixels, faces);

  return 1;
}
Example #14
0
void MPBlink::get_eyes(const RImage<float> &pixels, VisualObject &faces){
  list<VisualObject *>::iterator it = faces.begin();
  FaceBoxList face;
  double act[10];
  for (; it != faces.end(); ++it) {
    FaceObject * f = static_cast<FaceObject*>(*it);
    if (f->eyes.rightEye && f->eyes.leftEye){
      if( debug ){
	printf("eyes.xLeft[%f] yLeft[%f]\n", f->eyes.xLeft, f->eyes.yLeft);
	printf("eyes.xRight[%f] yRight[%f]\n", f->eyes.xRight, f->eyes.yRight);
      }
      double xd = f->eyes.xLeft - f->eyes.xRight;
      double yd = f->eyes.yLeft - f->eyes.yRight;
      float eye_dist = sqrt((xd*xd +yd*yd));
      float sin_d = -yd/xd;
      float cos_d = eye_dist/xd;

      float h_eye_zero = max(0.0,f->eyes.xRight-eye_dist*(h_eye_factor+h_off_pct));
      float v_eye_zero = max(0.0,f->eyes.yRight-eye_dist*(v_eye_factor+v_off_pct));
      float xwidth = eye_dist*(1 + 2*h_eye_factor);
      float ywidth = eye_dist*(2*v_eye_factor);

      int xedges;
      int yedges;
      float xfrac;
      float yfrac;
      float yoff[eye_dest_width];
      double xstep = xwidth/static_cast<double>(eye_dest_width-1);
      double ystep = ywidth/static_cast<double>(eye_dest_height-1);

      float j;
      int i;
      for(i = 0, j = 0; i < eye_dest_width; ++i, j+=xstep){
        yoff[i] = -sin_d * j;
      }

      float tempx, tempy;
      float *p = eyes.array;
      float f00, f01, f11, f10, fx0, fx1;
      for(int y=0; y < eye_dest_height; ++y){
        float xinit = (sin_d * ystep*y)+h_eye_zero;
        float yinit = v_eye_zero + ystep*y;
        for(int x=0; x < eye_dest_width; ++x){
          tempx = xinit + xstep*x;
          tempy = yinit + yoff[x];
          xedges = static_cast<int>(tempx);
          yedges = static_cast<int>(tempy);
          xfrac = tempx - xedges;
          yfrac = tempy - yedges;

          f00 = pixels.getPixel(xedges,yedges);
          f01 = pixels.getPixel(xedges,yedges + 1);
          f10 = pixels.getPixel(xedges + 1,yedges);
          f11 = pixels.getPixel(xedges + 1,yedges + 1);

          // xfrac and y frac are the remainders
          fx0 = f00 + xfrac*(f10-f00);
          fx1 = f01 + xfrac*(f11-f01);
          *(p++) = (fx0 + yfrac*(fx1-fx0));
	  // eyes.setPixel(x,y,(fx0 + yfrac*(fx1-fx0)));
        }
      }
      //eyes.print();
      debug = false;
      int num_blink_windows = search(eyes, face, 0, 1.0, 0, act,0);
      (*it)->activation = act[0];
      if( debug ){
       	printf("num_blink_windows: %d,  activation: %f\n",
               num_blink_windows, act[0]);
      }
      //f->activation = cluster.UpdateCluster(f->activation) - f->activation;
    }
    else
      f->activation = 0.0f;
  }
}
Example #15
0
bool CamSimulator::getObjectsFromParamServer()
{
  XmlRpc::XmlRpcValue param_yaml;

  if (!nhandle_.getParam("objects", param_yaml))
  {
      ROS_ERROR("Cannot read 'objects' from parameter server");
      return false;
  }
  if(param_yaml.getType() != XmlRpc::XmlRpcValue::TypeArray) // list of objects
  {
      ROS_ERROR("'objects' struct is not correct.");
      return false;
  }
  
  bool retval = true;
  
  objects_.clear();
  
  
  // XmlRpc does not support an implicit conversion between int and double. 
  // Therefore we define a small function for cases in which conversion is desired!
  auto convDouble = [] (XmlRpc::XmlRpcValue& val) -> double
  {
    if (val.getType() == XmlRpc::XmlRpcValue::TypeInt) // XmlRpc cannot cast int to double
      return int(val);
    return val; // if not double, an exception is thrown;
  };
  
  // iterate objects
  for (int i = 0; i < param_yaml.size(); ++i)
  {
      if(param_yaml[i].getType() != XmlRpc::XmlRpcValue::TypeStruct)
      {
        ROS_ERROR_STREAM("invalid parameter struct 'objects' found");
        retval = false;
      }
              
      for (XmlRpc::XmlRpcValue::iterator it_obj=param_yaml[i].begin(); it_obj!=param_yaml[i].end(); ++it_obj) // object name + struct
      {
        // Create new empty object
        VisualObject object;
        object.name() = it_obj->first;
        
        if (it_obj->second.getType() != XmlRpc::XmlRpcValue::TypeStruct)
        {
          ROS_ERROR_STREAM("Syntax of object '" << object.name() << "' is invalid. Skipping object...");
          retval = false;
          continue;
        }
        
        // iterate elements of the struct
        for (XmlRpc::XmlRpcValue::iterator it_elem=it_obj->second.begin(); it_elem!=it_obj->second.end(); ++it_elem) // object name + struct
        {
            // check parameter pose
            if (it_elem->first == "pose")
            {
                // the second paretmer must be a double array of size 6
                if (it_elem->second.getType() == XmlRpc::XmlRpcValue::TypeArray && it_elem->second.size() == 6)
                {
                    try
                    {
                      object.position().setX( convDouble(it_elem->second[0]) );
                      object.position().setY( convDouble(it_elem->second[1]) );
                      object.position().setZ( convDouble(it_elem->second[2]) );
                      object.orientation() = tf::createQuaternionFromRPY( convDouble(it_elem->second[3]),
                                                                          convDouble(it_elem->second[4]),
                                                                          convDouble(it_elem->second[5]) );
                    }
                    catch (const XmlRpc::XmlRpcException& ex)
                    {
                      ROS_ERROR_STREAM("Cannot add pose element to object '" << object.name() << "': " << ex.getMessage());
                      retval = false;
                    }
                }
                else
                {
                  ROS_ERROR_STREAM("Object '" << object.name() << "' does not define a correct 6d pose");
                  retval = false;
                }
                continue;
            }
            
            // check parameter shape
            if (it_elem->first == "shape")
            {
              try
              {
                if (it_elem->second == "circle")
                {
                  object.shape() = VisualObject::Shape::CIRCLE;
                }
                else if (it_elem->second == "rectangle")
                {
                  object.shape() = VisualObject::Shape::RECTANGLE;
                }
                else
                {
                  ROS_ERROR_STREAM("Shape '" << it_elem->second << "' is not supported. Supported shapes are: 'circle', 'rectangle'. ");
                }
              }
              catch (const XmlRpc::XmlRpcException& ex)
              {
                ROS_ERROR_STREAM("Cannot add shape to object '" << object.name() << "': " << ex.getMessage());
                retval = false;
              }
              continue;
            }
            
            // check parameter width
            if (it_elem->first == "width")
            {
              try
              {
                object.width() = convDouble(it_elem->second);
              }
              catch (const XmlRpc::XmlRpcException& ex)
              {
                ROS_ERROR_STREAM("Cannot read width of object '" << object.name() << "': " << ex.getMessage());
                retval = false;
              }
              continue;
            }
            
            // check parameter height
            if (it_elem->first == "height")
            {
              try
              {
                object.height() = convDouble(it_elem->second);
              }
              catch (const XmlRpc::XmlRpcException& ex)
              {
                ROS_ERROR_STREAM("Cannot read height of object '" << object.name() << "': " << ex.getMessage());
                retval = false;
              }
              continue;
            }
            
            // check parameter color
            if (it_elem->first == "color")
            {
                // the second paretmer must be an int array of size 3
                if (it_elem->second.getType() == XmlRpc::XmlRpcValue::TypeArray && it_elem->second.size() == 3)
                {
                    try
                    {
                      object.color().r = it_elem->second[0];
                      object.color().g = it_elem->second[1];
                      object.color().b = it_elem->second[2];
                    }
                    catch (const XmlRpc::XmlRpcException& ex)
                    {
                      ROS_ERROR_STREAM("Cannot read color of object '" << object.name() << "': " << ex.getMessage());
                      retval = false;
                    }
                }
                else
                {
                  ROS_ERROR_STREAM("Object '" << object.name() << "' does not define a correct color (must be a 3d array)");
                  retval = false;
                }
                continue;
            }
        }
        
        
        // add object to container
        objects_.push_back(object);
      }
      
  }

  return retval;

}