Beispiel #1
0
bool Level::Load(std::string aFilename) {
  //Open xml
  pugi::xml_document doc;
  if (!doc.load_file(aFilename.c_str())) {
    std::cout << "Could not open file " << aFilename << " on Level::Load" << std::endl;
    return false;
  }
  
  //Load map
  if(!mMap.Load(doc.child("level").child("map"))) {
    std::cout << "Level loading error: could not load <map>, son of <level> on " << aFilename << std::endl;
    assert(0);
    return false;
  }

  //Load paths
  for(pugi::xml_node const& pathNode : doc.child("level").child("paths").children("path")) {
    Path p;
    bool const ret_val = p.Load(pathNode);
    if(!ret_val) {
      std::cout << "Could not load a <path> node while loading a <level><paths>" << std::endl;
      assert(0);
      return false;
    }
    mAssociatedPaths.push_back(p);
  }

  //Load avalanchas
  float accum_time=0.0f;
  for(pugi::xml_node const& avalanchaNode : doc.child("level").child("avalanchas").children()) {
    Avalancha *const p = BuildAvalancha(avalanchaNode, accum_time);
    if(p==nullptr) {
      std::cout << "Could not load an <avalancha> node while loading a <level><avalanchas>" << std::endl;
      assert(0);
      return false;
    }
    accum_time += p->temporal_length();
    mAvalanchas.push_back(p);
  }
  return true;
}
Beispiel #2
0
void World::LoadScene(const char * scene_path)
{
	// Using case-insensitive strings and streams for easier parsing
	ci_ifstream input;
	input.open(scene_path, ios::in);

	// Invalid file
	if(input.fail() )
	{	 
		fprintf(stderr, "Error loading file: %s\n", scene_path);
		getchar();
		exit(-1);
	}

	ci_string item;
	while( std::getline( input, item, '[' ) )   
	{
        ci_istringstream iss( item );

		ci_string result;
		if( std::getline( iss, result, ']') )
		{
			if( result == "cube" )
			{
				// Box attributes
				CubeModel* cube = new CubeModel();
				cube->Load(iss);
				mModel.push_back(cube);
			}
            else if( result == "sphere" )
            {
                SphereModel* sphere = new SphereModel();
                sphere->Load(iss);
                mModel.push_back(sphere);
            }
            else if( result == "path" )
			{
				Path* path = new Path();
				path->Load(iss);
                mPath.push_back(path);
			}
            else if( result == "spline" )
			{
				BSpline* path = new BSpline();
				path->Load(iss);
                mSpline.push_back(path);
			}
		
			else if ( result.empty() == false && result[0] == '#')
			{
				// this is a comment line
			}
			else
			{
				fprintf(stderr, "Error loading scene file... !");
				getchar();
				exit(-1);
			}
	    }
	}
	input.close();

	// Set PATH vertex buffers
	for (vector<Path*>::iterator it = mPath.begin(); it < mPath.end(); ++it)
	{
		// Draw model
		(*it)->CreateVertexBuffer();
	}

    // Set B-SPLINE vertex buffers
    for (vector<BSpline*>::iterator it = mSpline.begin(); it < mSpline.end(); ++it)
	{
		// Draw model
		(*it)->CreateVertexBuffer();
	}

	//LOAD DAT OBJ MODEL YO
	vector<OBJModel*> pokemon = PokemonGenerator::GeneratePokemon();
	for (int i = 0; i < pokemon.size(); i++)
		mModel.push_back(pokemon[i]);
	srand(20);

	OBJModel* grass = new OBJModel("../Models/Grass_02.obj");
	for (int i = 0; i < 50; i++){

		OBJModel* newgrass = new OBJModel(*grass);
		newgrass->SetPosition(vec3(rand() % 150 - 75, 0, rand() % 150 - 75));
		newgrass->SetScaling(vec3(1, 1, 1));
		mModel.push_back(newgrass);
	}

	// DAYTIME - default
	groundDay = new SkyboxModel("../Models/cube.obj");
	groundDay->SetSwitch(true);
	groundDay->SetPosition(vec3(0, -2.5, 0));
	groundDay->SetScaling(vec3(150, 5, 150));
	mModel.push_back(groundDay);

	skyboxDay = new SkyboxModel("../Models/ds.obj");
	skyboxDay->SetSwitch(true);
	skyboxDay->SetPosition(vec3(0, 60, 0));
	skyboxDay->SetScaling(vec3(80, 80, 80));
	mModel.push_back(skyboxDay);
	
	// NIGHTTIME
	groundNight = new SkyboxModel("../Models/cube2.obj");
	groundNight->SetSwitch(false);
	groundNight->SetPosition(vec3(0, -2.5, 0));
	groundNight->SetScaling(vec3(150, 5, 150));
	mModel.push_back(groundNight);

	skyboxNight = new SkyboxModel("../Models/ns.obj");
	skyboxNight->SetSwitch(false);
	skyboxNight->SetPosition(vec3(0, 60, 0));
	skyboxNight->SetScaling(vec3(80, 80, 80));
	mModel.push_back(skyboxNight);

	
    LoadCameras();
}