void CommandPanelScript::vPostInit()
{
	auto ownerActor = m_OwnerActor.lock();
	auto gameLogic = SingletonContainer::getInstance()->get<BaseGameLogic>();
	auto sceneNode = ownerActor->getRenderComponent()->getSceneNode();

	auto backgroundActor = gameLogic->createActor(CommandPanelScriptImpl::s_BackgroundActorPath.c_str());
	ownerActor->addChild(*backgroundActor);
	//sceneNode->addChild(backgroundActor->getRenderComponent()->getSceneNode());

	auto listActor = gameLogic->createActor(CommandPanelScriptImpl::s_ListActorPath.c_str());
	ownerActor->addChild(*listActor);
	//sceneNode->addChild(listActor->getRenderComponent()->getSceneNode());
	pimpl->m_ListScript = listActor->getComponent<CommandListScript>();
}
Exemple #2
0
void MovingPathScript::MovingPathScriptImpl::setChildrenGridActors(const MovingPath & path, Actor & self)
{
	auto gameLogic = SingletonContainer::getInstance()->get<BaseGameLogic>();
	auto selfSceneNode = self.getRenderComponent()->getSceneNode();

	for (const auto & pathNode : path.getUnderlyingPath()) {
		const auto & index = pathNode.m_GridIndex;

		auto previousDirection = AdjacentDirection::INVALID;
		if (path.hasPreviousOf(index))
			previousDirection = path.getPreviousNodeOf(index).m_GridIndex.getAdjacentDirectionOf(index);

		auto nextDirection = AdjacentDirection::INVALID;
		if (path.hasNextOf(index))
			nextDirection = path.getNextNodeOf(index).m_GridIndex.getAdjacentDirectionOf(index);

		//Create the grid actor and attach it to self.
		auto gridActor = gameLogic->createActor(m_MovingPathGridActorPath.c_str());
		auto gridScript = gridActor->getComponent<MovingPathGridScript>();
		gridScript->setAppearanceWithPreviousAndNextDirection(previousDirection, nextDirection);
		gridScript->setPositionWithGridIndex(index);

		self.addChild(*gridActor);
		m_ChildrenGridActorIDs.emplace_back(gridActor);
		//selfSceneNode->addChild(gridActor->getRenderComponent()->getSceneNode());
	}
}
Exemple #3
0
void ActorBank::onEvent(int eventType, void* params)
{
	if (eventType == GAME_SYSTEM_EVENT_KEYUP)
	{
		int key = (int)params;	
		if (key == HGEK_P)
		{
			createActor(Location(CELL_SIZE_X+CELL_SIZE_X/2, CELL_SIZE_Y+CELL_SIZE_Y/2), g_Option.getUnitSize()*CELL_SIZE_X/2*0.75f);
		}
		else if (key == HGEK_LBUTTON)
		{
			Location mouseLocation;
			g_HGE->Input_GetMousePos(&mouseLocation.x, &mouseLocation.y);
			Actor* actor = findFirstActorConverLocation(mouseLocation);
			if (actor)
			{
				m_currentActor = actor;
			}
		}
		else if (key == HGEK_RBUTTON)
		{
			Location mouseLocation;
			g_HGE->Input_GetMousePos(&mouseLocation.x, &mouseLocation.y);
			if (m_currentActor)
			{
				//m_currentActor->move(mouseLocation, 800);
				m_currentActor->searchPath(mouseLocation);
			}
		}
	}
}
template <typename PointT> bool
pcl::visualization::PCLHistogramVisualizer::addFeatureHistogram (
    const pcl::PointCloud<PointT> &cloud, int hsize, 
    const std::string &id, int win_width, int win_height)
{
  RenWinInteractMap::iterator am_it = wins_.find (id);
  if (am_it != wins_.end ())
  {
    PCL_WARN ("[addFeatureHistogram] A window with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
    return (false);
  }

  vtkSmartPointer<vtkDoubleArray> xy_array = vtkSmartPointer<vtkDoubleArray>::New ();
  xy_array->SetNumberOfComponents (2);
  xy_array->SetNumberOfTuples (hsize);

  // Parse the cloud data and store it in the array
  double xy[2];
  for (int d = 0; d < hsize; ++d)
  {
    xy[0] = d;
    xy[1] = cloud.points[0].histogram[d];
    xy_array->SetTuple (d, xy);
  }
  RenWinInteract renwinint;
  createActor (xy_array, renwinint, id, win_width, win_height);

  // Save the pointer/ID pair to the global window map
  wins_[id] = renwinint;
#if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
  resetStoppedFlag ();
#endif
  return (true);
}
Exemple #5
0
PxRigidActor* createHeightFieldActor( PxHeightField* hf, float xScale, float yScale, double density, PxMaterial* mtl )
{
    PxHeightFieldGeometry geometry;
    geometry.heightField = hf;
    geometry.rowScale = xScale;
    geometry.columnScale = yScale;
    return createActor( geometry, density, mtl );
}
Exemple #6
0
CharacterObject::CharacterObject(GameWorld* engine, const glm::vec3& pos, const glm::quat& rot, const ModelRef& model, std::shared_ptr<CharacterData> data)
	: GameObject(engine, pos, rot, model)
	, currentState({})
	, currentVehicle(nullptr)
	, currentSeat(0)
	, running(false)
	, jumped(false)
	, jumpSpeed(DefaultJumpSpeed)
	, motionBlockedByActivity(false)
	, ped(data)
	, physCharacter(nullptr)
	, physObject(nullptr)
	, physShape(nullptr)
	, controller(nullptr)
{
	// TODO move AnimationGroup creation somewhere else.
	animations.idle = engine->data->animations["idle_stance"];
	animations.walk = engine->data->animations["walk_player"];
	animations.walk_start = engine->data->animations["walk_start"];
	animations.run  = engine->data->animations["run_player"];

	animations.walk_right = engine->data->animations["walk_player_right"];
	animations.walk_right_start = engine->data->animations["walk_start_right"];
	animations.walk_left = engine->data->animations["walk_player_left"];
	animations.walk_left_start = engine->data->animations["walk_start_left"];

	animations.walk_back = engine->data->animations["walk_player_back"];
	animations.walk_back_start = engine->data->animations["walk_start_back"];

	animations.jump_start = engine->data->animations["jump_launch"];
	animations.jump_glide = engine->data->animations["jump_glide"];
	animations.jump_land  = engine->data->animations["jump_land"];

	animations.car_sit     = engine->data->animations["car_sit"];
	animations.car_sit_low = engine->data->animations["car_lsit"];

	animations.car_open_lhs   = engine->data->animations["car_open_lhs"];
	animations.car_getin_lhs   = engine->data->animations["car_getin_lhs"];
	animations.car_getout_lhs   = engine->data->animations["car_getout_lhs"];
	animations.car_pullout_lhs   = engine->data->animations["car_pullout_lhs"];
	animations.car_jacked_lhs   = engine->data->animations["car_jackedlhs"];

	animations.car_open_rhs   = engine->data->animations["car_open_rhs"];
	animations.car_getin_rhs   = engine->data->animations["car_getin_rhs"];
	animations.car_getout_rhs   = engine->data->animations["car_getout_rhs"];
	animations.car_pullout_rhs   = engine->data->animations["car_pullout_rhs"];
	animations.car_jacked_rhs   = engine->data->animations["car_jackedrhs"];

	animations.kd_front   = engine->data->animations["kd_front"];
	animations.ko_shot_front   = engine->data->animations["ko_shot_front"];

	if(model) {
		skeleton = new Skeleton;
		animator = new Animator(model->resource, skeleton);

		createActor();
	}
}
template <typename PointT> bool
pcl::visualization::PCLHistogramVisualizer::addFeatureHistogram (
    const pcl::PointCloud<PointT> &cloud, 
    const std::string &field_name,
    const int index, 
    const std::string &id, int win_width, int win_height)
{
  if (index < 0 || index >= cloud.points.size ())
  {
    PCL_ERROR ("[addFeatureHistogram] Invalid point index (%d) given!\n", index);
    return (false);
  }

  // Get the fields present in this cloud
  std::vector<sensor_msgs::PointField> fields;
  // Check if our field exists
  int field_idx = pcl::getFieldIndex<PointT> (cloud, field_name, fields);
  if (field_idx == -1)
  {
    PCL_ERROR ("[addFeatureHistogram] The specified field <%s> does not exist!\n", field_name.c_str ());
    return (false);
  }

  RenWinInteractMap::iterator am_it = wins_.find (id);
  if (am_it != wins_.end ())
  {
    PCL_WARN ("[addFeatureHistogram] A window with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
    return (false);
  }

  vtkSmartPointer<vtkDoubleArray> xy_array = vtkSmartPointer<vtkDoubleArray>::New ();
  xy_array->SetNumberOfComponents (2);
  xy_array->SetNumberOfTuples (fields[field_idx].count);

  // Parse the cloud data and store it in the array
  double xy[2];
  for (int d = 0; d < fields[field_idx].count; ++d)
  {
    xy[0] = d;
    //xy[1] = cloud.points[index].histogram[d];
    float data;
    memcpy (&data, (const char*)&cloud.points[index] + fields[field_idx].offset + d * sizeof (float), sizeof (float));
    xy[1] = data;
    xy_array->SetTuple (d, xy);
  }
  RenWinInteract renwinint;
  createActor (xy_array, renwinint, id, win_width, win_height);

  // Save the pointer/ID pair to the global window map
  wins_[id] = renwinint;
#if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
  resetStoppedFlag ();
#endif
  return (true);
}
Exemple #8
0
void CharacterObject::setCurrentVehicle(VehicleObject *value, size_t seat)
{
	currentVehicle = value;
	currentSeat = seat;
	if(currentVehicle == nullptr && physCharacter == nullptr) {
		createActor();
	}
	else if(currentVehicle) {
		destroyActor();
	}
}
Exemple #9
0
void Destroyable::processDropRules()
{
  for( DropRule& rule : _dropRules )
  {
    if ( rule.chance > (dices::roll(dices::D100) / 100.0f) )
    {
      ActorPtr toDrop = createActor(rule);
      dropOnGround( toDrop );
    }
  }
}
Exemple #10
0
CommandListScript::CommandListScriptImpl::ItemActors CommandListScript::CommandListScriptImpl::_createItemActorsForGameCommands(const std::vector<GameCommand> & gameCommands) const
{
	auto itemActors = ItemActors{};
	auto gameLogic = SingletonContainer::getInstance()->get<BaseGameLogic>();

	for (const auto & command : gameCommands) {
		auto listItem = gameLogic->createActor(CommandListScriptImpl::s_ListItemActorPath.c_str());
		listItem->getComponent<CommandListItemScript>()->initWithGameCommand(command);

		itemActors.emplace_back(listItem);
	}

	return itemActors;
}
Exemple #11
0
  bool BaseGameLogic::loadGame(const std::string& resource_name)
  {
    LOGI << "Loading game from resource '" << resource_name << "'." << endl;
    LOGINC;

    // Load the resource.
    LOGI << "Loading the resource." << endl;
    Resource resource(resource_name);
    StrongResourceHandlePtr resource_handle = res_cache_->getHandle(resource);

    // Parse the resource.
    LOGI << "Parsing the resource." << endl;
    rapidxml::xml_document<> xml_doc;
    xml_doc.parse<0>(reinterpret_cast<char*>(resource_handle->getBuffer()));

    // Get the root node (Should normally be <World>).
    rapidxml::xml_node<>* xml_root = xml_doc.first_node();
    if (!xml_root)
    {
      LOGE << "No root node in game resource '" << resource_name << "'."
           << endl;
      return false;
    }
    LOG(LOGDEBUG) << "Root node: '" << xml_root->name() << "'." << endl;

    // Iterate over all actor nodes and create the actors.
    rapidxml::xml_node<>* xml_actor = xml_root->first_node("Actor");
    while (xml_actor)
    {
      std::string actor_resource =
          xml_actor->first_attribute("resource")->value();
      LOG(LOGDEBUG) << "Actor node resource attribute: '" << actor_resource
                    << "'." << endl;

      if (!createActor(actor_resource))
      {
        LOGE << "Creation of actor from resource '" << actor_resource
             << "' failed." << endl;
        return false;
      }

      xml_actor = xml_actor->next_sibling();
    }

    LOGDEC;

    return true;
  }
Exemple #12
0
	bool Phy2dWorld::loadFromXML(TiXmlElement *xmlNodePhy2DWorld)
	{
		releaseActors();

		TiXmlHandle hXmlNode=TiXmlHandle(xmlNodePhy2DWorld);
				
		// load actors
		TiXmlElement* pActorNode = hXmlNode.FirstChild( "Actors" ).FirstChild("Actor").Element();
		for( ; pActorNode; pActorNode=pActorNode->NextSiblingElement())
		{
			Phy2dActor *actor = createActor();
			actor->loadFromXML(pActorNode);
			actor->init();
		}		
				
		return true;
	}
Exemple #13
0
//-----------------------------------------------------------------------
void ActorObject::createRenderInstance(System* system)
{
    assert(system);
    assert(!mActor);
    assert(!mProxy);

    mSystem = system;

    PlacementObject::createRenderInstance(system);

    mProxy = new ObjectProxy(shared_from_this());

    if (!mActorName.empty())
    {
        createActor();
    }
}
Exemple #14
0
//-----------------------------------------------------------------------
void ActorObject::setActorName(const Ogre::String& actorName)
{
    if (mActorName != actorName)
    {
        if (mActor)
        {
            destroyActor();
        }

        mActorName = actorName;

        if (mProxy && !mActorName.empty())
        {
            // i assume we only call this function in FairyEditor, so I set the parameter "editable" to false
            createActor();
        }
    }
}
Exemple #15
0
void GameEngine::Initialize()
{
    uint32 flags = 0;
    flags += b2Draw::e_shapeBit;
    //flags += b2Draw::e_jointBit;
    //flags += b2Draw::e_aabbBit;
    //flags += b2Draw::e_pairBit;
    //flags += b2Draw::e_centerOfMassBit;
    m_debugDraw.SetFlags(flags);
    
    // setup stage
	int w = glutGet(GLUT_WINDOW_WIDTH);
	int h = glutGet(GLUT_WINDOW_HEIGHT);
    
    m_stage.lowerBound = b2Vec2(0, 0);
    m_stage.upperBound = b2Vec2(w, h);
    
    createActor();
    
    m_world->SetDebugDraw(&m_debugDraw);
    
    
    class MyContactListener : public b2ContactListener
    {
        virtual void BeginContact(b2Contact* contact)
        {
            printf("begin contact");
        }
        
        virtual void EndContact(b2Contact* contact)
        {
            printf("end contact");
        }
    };
    // TODO: memory leak
    //m_world->SetContactListener(new MyContactListener());
    
    initializedTime = glutGet(GLUT_ELAPSED_TIME);
}
Exemple #16
0
bool gfxRhino3D::loadCAD(QString filename){
  int i, layer;
  ON_Color objCol;
     
  //Load geometry...
  if (filename.endsWith(".3dm")){
    load3dm(filename);
    for (i=0;i<model.m_object_table.Count();i++){
      layer=model.m_object_table[i].m_attributes.m_layer_index;
      if (model.m_layer_table[layer].IsVisible()){
        if (ON::color_from_object == model.m_object_table[i].m_attributes.ColorSource()){
          objCol=model.m_object_table[i].m_attributes.m_color; 
        }else{
          objCol=model.m_layer_table[layer].Color();
        }
        parentObject->actor.push_back( createActor(model.m_object_table[i].m_object, objCol.FractionRed(), objCol.FractionGreen(), objCol.FractionBlue()) );
      }
    }
  }
  for (i=0;i<parentObject->actor.size();i++) parentObject->renderer->AddActor(parentObject->actor[i]);
  return true;
}
Exemple #17
0
bool gfxOSM::loadCAD(QString filename){
  QDomElement root;
  QDomNode xmlNode, node2;
  QDomElement element, element2;
  gfxOSMnode tmpnode;
  gfxOSMway  tmpway;
  int i;
  QString errMsg;
  int erl, erc;
  bool isdup;

  QFileInfo fi(filename);

  QFile file;
  file.setFileName(filename);
  if (!file.open( QIODevice::ReadOnly )){
    printf("OSMloader :: Could not open file\n");
    return false;
  }

  QDomDocument doc( "OSMFile" );
  if (!doc.setContent( &file, false, &errMsg, &erl, &erc)){
    printf("OSMloader :: Failed to set content\n");
    printf("OSMloader :: At line %i, Column %i\n", erl, erc);
    printf("OSMloader :: QDomDocument returned - %s\n",errMsg.toAscii().data());
    file.close();
    return false;
  }
  file.close();

  printf("OSMloader :: File loaded into memory\n");

  root=doc.documentElement();

  if (root.tagName() != "osm"){
    printf("OSMloader :: This is not an OpenStreetMap XML file\n");
    return false;
  }

  // Useful Info
  printf("OSMloader ::     Filesize = %7.3lf MB\n",(double)fi.size()/(1024.*1024.));
  printf("OSMloader ::      Version = %s\n",root.attribute( "version" ).toAscii().data());
  printf("OSMloader :: Created With = %s\n",root.attribute( "generator" ).toAscii().data());

  xmlNode=root.firstChild();
  node.clear();
  way.clear();

  xmlNode=root.firstChild();
  while (!xmlNode.isNull()){
    element=xmlNode.toElement();

    if (!element.isNull()){
      if (element.tagName()=="node"){
        tmpnode.read(xmlNode);
        isdup=false;
        for (i=0;i<(int)node.size();i++){
          if (tmpnode.ref==node[i].ref) isdup=true;
        }
        if (!isdup) node.push_back(tmpnode);
      }
      if (element.tagName()=="way"){
        tmpway.read(xmlNode);
        isdup=false;
        for (i=0;i<(int)way.size();i++){
          if (tmpnode.ref==way[i].ref) isdup=true;
        }
        if (!isdup) way.push_back(tmpway);
      }
    }
    xmlNode=xmlNode.nextSibling();
  }
  printf("OSMloader :: XML - Data Loaded, simplifying references\n");
  simplifyrefs();

  points = vtkSmartPointer<vtkPoints>::New();
  for (i=0;i<node.size();i++){
    node[i].plt=odPoint(node[i].lon, node[i].lat, 0);
 //   node[i].plt=planet.project(node[i].lon, node[i].lat);
 //   printf("Node position = %.2lf\t%.2lf\t%.2lf\n", node[i].plt.x, node[i].plt.y, node[i].plt.z);
    points->InsertNextPoint(node[i].plt.x, node[i].plt.y, node[i].plt.z);
  }
  
  for (i=0;i<way.size();i++){
    actor.push_back( createActor(i));
  }
  for (i=0;i<actor.size();i++) renderer->AddActor(actor[i]);
  
  return true;
}
Exemple #18
0
PxRigidActor* createBoxActor( const osg::Vec3& dim, double density, PxMaterial* mtl )
{
    PxBoxGeometry geometry( PxVec3(dim[0]*0.5f, dim[1]*0.5f, dim[2]*0.5f) );
    return createActor( geometry, density, mtl );
}
Exemple #19
0
PxRigidActor* createCapsuleActor( double radius, double height, double density, PxMaterial* mtl )
{
    PxCapsuleGeometry geometry( radius, height*0.5 );
    return createActor( geometry, density, mtl );
}
Exemple #20
0
PxRigidActor* createSphereActor( double radius, double density, PxMaterial* mtl )
{
    PxSphereGeometry geometry( radius );
    return createActor( geometry, density, mtl );
}
Exemple #21
0
PxRigidActor* createConvexMeshActor( PxConvexMesh* mesh, double density, PxMaterial* mtl )
{
    PxConvexMeshGeometry geometry( mesh );
    return createActor( geometry, density, mtl );
}